Exemplo n.º 1
0
void gmpv_mpv_load_list(	GmpvMpv *mpv,
				const gchar **uri_list,
				gboolean append,
				gboolean update )
{
	static const char *const sub_exts[] = SUBTITLE_EXTS;

	for(gint i = 0; uri_list[i]; i++)
	{
		const gchar *ext = strrchr(uri_list[i], '.');
		gboolean subtitle = FALSE;

		/* Only start checking the extension if there is at
		 * least one character after the dot.
		 */
		if(ext && ++ext)
		{
			const gchar *const *cur = sub_exts;

			/* Check if the file extension matches one of the
			 * supported subtitle formats.
			 */
			while(*cur && g_strcmp0(ext, *(cur++)) != 0);

			subtitle = !!(*cur);
		}

		/* Only attempt to load file as subtitle if there
		 * already is a file loaded. Try to load the file as a
		 * media file otherwise.
		 */
		if(ext && subtitle && gmpv_mpv_get_state(mpv)->loaded)
		{
			const gchar *cmd[] = {"sub-add", NULL, NULL};
			gchar *path;

			/* Convert to path if possible to get rid of
			 * percent encoding.
			 */
			path = g_filename_from_uri(uri_list[i], NULL, NULL);
			cmd[1] = path?:uri_list[i];

			g_debug("Loading external subtitle: %s", cmd[1]);
			gmpv_mpv_command(mpv, cmd);

			g_free(path);
		}
		else
		{
			gboolean empty = gmpv_playlist_empty(mpv->playlist);

			gmpv_mpv_load(	mpv,
					uri_list[i],
					((append && !empty) || i != 0),
					TRUE );
		}
	}
Exemplo n.º 2
0
void gmpv_mpv_obj_load_list(	GmpvMpvObj *mpv,
				const gchar **uri_list,
				gboolean append,
				gboolean update )
{
	static const char *const sub_exts[] = SUBTITLE_EXTS;

	for(gint i = 0; uri_list[i]; i++)
	{
		const gchar *ext = strrchr(uri_list[i], '.');
		gint j;

		/* Only start checking the extension if there is at
		 * least one character after the dot.
		 */
		if(ext && ++ext)
		{
			for(	j = 0;
				sub_exts[j] &&
				g_strcmp0(ext, sub_exts[j]) != 0;
				j++ );
		}

		/* Only attempt to load file as subtitle if there
		 * already is a file loaded. Try to load the file as a
		 * media file otherwise.
		 */
		if(ext && sub_exts[j] && gmpv_mpv_obj_get_state(mpv)->loaded)
		{
			const gchar *cmd[] = {"sub-add", NULL, NULL};
			gchar *path;

			/* Convert to path if possible to get rid of
			 * percent encoding.
			 */
			path =	g_filename_from_uri
				(uri_list[i], NULL, NULL);

			cmd[1] = path?:uri_list[i];

			gmpv_mpv_obj_command(mpv, cmd);

			g_free(path);
		}
		else
		{
			gboolean empty = gmpv_playlist_empty(mpv->playlist);

			gmpv_mpv_obj_load(	mpv,
						uri_list[i],
						((append && !empty) || i != 0),
						TRUE );
		}
	}