[totem-pl-parser] plparse: Handle length attribute for M3U playlists
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [totem-pl-parser] plparse: Handle length attribute for M3U playlists
- Date: Thu, 25 Apr 2013 10:51:36 +0000 (UTC)
commit 8dd63c9f8aa85ae4687bb4b90c9c1de886069ac0
Author: Bastien Nocera <hadess hadess net>
Date: Thu Apr 25 12:44:53 2013 +0200
plparse: Handle length attribute for M3U playlists
When an M3U playlist advertises the length of an item as -1, we
don't need to check whether it is another playlist, it would usually
be a file of unknown duration, or a stream.
This matches the current code in the PLS parser, and works around
hang-on-close() bugs in gvfs.
https://bugzilla.gnome.org/show_bug.cgi?id=695652
plparse/tests/BassDrive.pls | 39 ++++++++++++++++++++++++++++++++++++
plparse/tests/Makefile.am | 3 +-
plparse/tests/parser.c | 13 ++++++++++++
plparse/tests/radioclasica.mp3.m3u | 3 ++
plparse/totem-pl-parser-lines.c | 34 ++++++++++++++++++++++++++++++-
5 files changed, 90 insertions(+), 2 deletions(-)
---
diff --git a/plparse/tests/BassDrive.pls b/plparse/tests/BassDrive.pls
new file mode 100644
index 0000000..23ea8a4
--- /dev/null
+++ b/plparse/tests/BassDrive.pls
@@ -0,0 +1,39 @@
+[playlist]
+numberofentries=12
+File1=http://shouthostdirect16.streams.bassdrive.com:8200
+Title1=(#1) Bassdrive - Worldwide Drum and Bass Radio
+Length1=-1
+File2=http://shouthostdirect17.streams.bassdrive.com:8200
+Title2=(#2) Bassdrive - Worldwide Drum and Bass Radio
+Length1=-1
+File3=http://spike.streams.bassdrive.com:80
+Title3=(#3) Bassdrive - Worldwide Drum and Bass Radio
+Length1=-1
+File4=http://amsterdam1.serverhostingcenter.streams.bassdrive.com:8000
+Title4=(#4) Bassdrive - Worldwide Drum and Bass Radio
+Length1=-1
+File5=http://arces.net.streams.bassdrive.com:8000
+Title5=(#5) Bassdrive - Worldwide Drum and Bass Radio
+Length1=-1
+File6=http://aol.streams.bassdrive.com:8008
+Title6=(#6) Bassdrive - Worldwide Drum and Bass Radio
+Length1=-1
+File7=http://iku.streams.bassdrive.com:8000
+Title7=(#7) Bassdrive - Worldwide Drum and Bass Radio
+Length1=-1
+File8=http://blank-tv.de.streams.bassdrive.com:8000
+Title8=(#8) Bassdrive - Worldwide Drum and Bass Radio
+Length1=-1
+File9=http://aol.streams.bassdrive.com:8012
+Title9=(#9) Bassdrive - Worldwide Drum and Bass Radio
+Length1=-1
+File10=http://shouthostdirect80-1.streams.bassdrive.com:80
+Title10=(#10) Bassdrive - Worldwide Drum and Bass Radio
+Length1=-1
+File11=http://beezle.streams.bassdrive.com:8765
+Title11=(#11) Bassdrive - Worldwide Drum and Bass Radio
+Length1=-1
+File12=http://us-tx1.streams.bassdrive.com:9000
+Title12=(#12) Bassdrive - Worldwide Drum and Bass Radio
+Length1=-1
+Version=2
diff --git a/plparse/tests/Makefile.am b/plparse/tests/Makefile.am
index 5232897..3317fcb 100644
--- a/plparse/tests/Makefile.am
+++ b/plparse/tests/Makefile.am
@@ -73,6 +73,7 @@ EXTRA_DIST = \
dont-ignore-mp2t.ts \
empty-feed.xml \
no-url-podcast.xml \
- xml-base.xspf
+ xml-base.xspf \
+ radioclasica.mp3.m3u
-include $(top_srcdir)/git.mk
diff --git a/plparse/tests/parser.c b/plparse/tests/parser.c
index 1e29b4f..ebf1341 100644
--- a/plparse/tests/parser.c
+++ b/plparse/tests/parser.c
@@ -886,6 +886,18 @@ test_parsing_xml_mixed_cdata (void)
g_free (uri);
}
+static void
+test_parsing_m3u_streaming (void)
+{
+ char *uri;
+ g_test_bug ("695652");
+
+ /* File from http://radioclasica.rtve.stream.flumotion.com/rtve/radioclasica.mp3.m3u */
+ uri = get_relative_uri (TEST_SRCDIR "radioclasica.mp3.m3u");
+ g_assert (simple_parser_test (uri) == TOTEM_PL_PARSER_RESULT_SUCCESS);
+ g_free (uri);
+}
+
#ifdef HAVE_QUVI
static void
test_parsing_rss_id (void)
@@ -1261,6 +1273,7 @@ main (int argc, char *argv[])
g_test_add_func ("/parser/parsing/podcast_content_type", test_parsing_content_type);
g_test_add_func ("/parser/parsing/live_streaming", test_parsing_live_streaming);
g_test_add_func ("/parser/parsing/xml_mixed_cdata", test_parsing_xml_mixed_cdata);
+ g_test_add_func ("/parser/parsing/m3u_streaming", test_parsing_m3u_streaming);
#ifdef HAVE_QUVI
g_test_add_func ("/parser/parsing/rss_id", test_parsing_rss_id);
g_test_add_func ("/parser/parsing/rss_link", test_parsing_rss_link);
diff --git a/plparse/tests/radioclasica.mp3.m3u b/plparse/tests/radioclasica.mp3.m3u
new file mode 100644
index 0000000..ed2fd0d
--- /dev/null
+++ b/plparse/tests/radioclasica.mp3.m3u
@@ -0,0 +1,3 @@
+#EXTM3U
+#EXTINF:-1,Flumotion Stream
+http://195.10.10.207/rtve/radioclasica.mp3?GKID=8b5081ecad8d11e2973900163e914f68
\ No newline at end of file
diff --git a/plparse/totem-pl-parser-lines.c b/plparse/totem-pl-parser-lines.c
index 3b74bca..f641f8f 100644
--- a/plparse/totem-pl-parser-lines.c
+++ b/plparse/totem-pl-parser-lines.c
@@ -333,6 +333,30 @@ totem_pl_parser_get_extinfo_title (const char *extinfo)
return sep;
}
+static char *
+totem_pl_parser_get_extinfo_length (const char *extinfo)
+{
+ char *res, **items;
+
+ if (extinfo == NULL)
+ return NULL;
+
+ /* It's bound to have an EXTINF if we have extinfo */
+ res = (char *) extinfo + strlen(EXTINF);
+ if (res[0] == '\0')
+ return NULL;
+
+ /* Handle ',' as a field separator */
+ items = g_strsplit (res, ",", 2);
+ if (!items || !items[0] || *items[0] == '\0') {
+ g_strfreev (items);
+ return NULL;
+ }
+ res = g_strdup (items[0]);
+ g_strfreev (items);
+ return res;
+}
+
TotemPlParserResult
totem_pl_parser_add_m3u (TotemPlParser *parser,
GFile *file,
@@ -395,6 +419,8 @@ totem_pl_parser_add_m3u (TotemPlParser *parser,
for (i = 0; lines[i] != NULL; i++) {
const char *line;
+ char *length;
+ gint64 length_num = 0;
line = lines[i];
@@ -414,13 +440,19 @@ totem_pl_parser_add_m3u (TotemPlParser *parser,
continue;
}
+ length = totem_pl_parser_get_extinfo_length (extinfo);
+ if (length != NULL)
+ length_num = totem_pl_parser_parse_duration (length,
totem_pl_parser_is_debugging_enabled (parser));
+ g_free (length);
+
/* Either it's a URI, or it has a proper path ... */
if (strstr(line, "://") != NULL
|| line[0] == G_DIR_SEPARATOR) {
GFile *uri;
uri = g_file_new_for_commandline_arg (line);
- if (totem_pl_parser_parse_internal (parser, uri, NULL, parse_data) !=
TOTEM_PL_PARSER_RESULT_SUCCESS) {
+ if (length_num < 0 ||
+ totem_pl_parser_parse_internal (parser, uri, NULL, parse_data) !=
TOTEM_PL_PARSER_RESULT_SUCCESS) {
totem_pl_parser_add_one_uri (parser, line,
totem_pl_parser_get_extinfo_title (extinfo));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]