From 96efc280d5050cc794a33cfcc687e86853942a96 Mon Sep 17 00:00:00 2001 From: Ravi Kiran K N Date: Mon, 28 Apr 2014 18:47:06 +0530 Subject: [PATCH] gst-play: add option to supply media files from playlist file https://bugzilla.gnome.org/show_bug.cgi?id=728845 --- tools/gst-play.c | 46 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/tools/gst-play.c b/tools/gst-play.c index b2afb5d..5960bcb 100644 --- a/tools/gst-play.c +++ b/tools/gst-play.c @@ -658,6 +658,7 @@ main (int argc, char **argv) guint num, i; GError *err = NULL; GOptionContext *ctx; + gchar *playlist_file = NULL; GOptionEntry options[] = { {"version", 0, 0, G_OPTION_ARG_NONE, &print_version, N_("Print version information and exit"), NULL}, @@ -673,6 +674,8 @@ main (int argc, char **argv) N_("Interactive control via keyboard"), NULL}, {"volume", 0, 0, G_OPTION_ARG_DOUBLE, &volume, N_("Volume"), NULL}, + {"playlist", 0, 0, G_OPTION_ARG_FILENAME, &playlist_file, + N_("Playlist file containing input media files"), NULL}, {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &filenames, NULL}, {NULL} }; @@ -709,24 +712,51 @@ main (int argc, char **argv) return 0; } - if (filenames == NULL || *filenames == NULL) { + playlist = g_ptr_array_new (); + + if (playlist_file != NULL) { + gchar *playlist_contents = NULL; + gchar **lines = NULL; + + if (g_file_get_contents (playlist_file, &playlist_contents, NULL, &err)) { + lines = g_strsplit (playlist_contents, "\n", 0); + num = g_strv_length (lines); + + for (i = 0; i < num; i++) { + if (lines[i][0] != '\0') { + GST_LOG ("Playlist[%d]: %s", i + 1, lines[i]); + add_to_playlist (playlist, lines[i]); + } + } + g_strfreev (lines); + g_free (playlist_contents); + } else { + g_printerr ("Could not read playlist: %s\n", err->message); + g_clear_error (&err); + } + g_free (playlist_file); + } + + if (playlist->len == 0 && (filenames == NULL || *filenames == NULL)) { g_printerr (_("Usage: %s FILE1|URI1 [FILE2|URI2] [FILE3|URI3] ..."), "gst-play-" GST_API_VERSION); g_printerr ("\n\n"), g_printerr ("%s\n\n", _("You must provide at least one filename or URI to play.")); + /* No input provided. Free array */ + g_ptr_array_free (playlist, TRUE); return 1; } - playlist = g_ptr_array_new (); - /* fill playlist */ - num = g_strv_length (filenames); - for (i = 0; i < num; ++i) { - GST_LOG ("command line argument: %s", filenames[i]); - add_to_playlist (playlist, filenames[i]); + if (filenames != NULL && *filenames != NULL) { + num = g_strv_length (filenames); + for (i = 0; i < num; ++i) { + GST_LOG ("command line argument: %s", filenames[i]); + add_to_playlist (playlist, filenames[i]); + } + g_strfreev (filenames); } - g_strfreev (filenames); num = playlist->len; g_ptr_array_add (playlist, NULL); -- 2.7.4