[totem-pl-parser/gnome-2-28] Allow dual-types to end up being "normal" playlists



commit 4892bce10ad7cd7e3ffb8ec40a726b347f972c51
Author: Bastien Nocera <hadess hadess net>
Date:   Mon Apr 12 00:03:36 2010 +0100

    Allow dual-types to end up being "normal" playlists
    
    When we prod at a dual-type (in this case, a PHP file), fix the
    real parser in the special_types as well, not just in the dual-types.
    
    Fixes parsing PHP scripts that generate XSPF playlists, such as:
    http://startwars.org/dump/remote_xspf.php
    
    https://bugzilla.gnome.org/show_bug.cgi?id=590722

 plparse/tests/Makefile.am     |    3 +-
 plparse/tests/parser.c        |   12 ++++
 plparse/tests/remote_xspf.php |  116 +++++++++++++++++++++++++++++++++++++++++
 plparse/totem-pl-parser.c     |   45 +++++++++++-----
 4 files changed, 160 insertions(+), 16 deletions(-)
---
diff --git a/plparse/tests/Makefile.am b/plparse/tests/Makefile.am
index 9520dc3..f6d97ae 100644
--- a/plparse/tests/Makefile.am
+++ b/plparse/tests/Makefile.am
@@ -52,5 +52,6 @@ EXTRA_DIST =			\
 	live-streaming.m3u	\
 	single-line.qtl		\
 	pukas.wax		\
-	asf-with-asx-suffix.asx
+	asf-with-asx-suffix.asx	\
+	remote_xspf.php
 
diff --git a/plparse/tests/parser.c b/plparse/tests/parser.c
index 8cc8e7b..dac0bd0 100644
--- a/plparse/tests/parser.c
+++ b/plparse/tests/parser.c
@@ -454,6 +454,17 @@ test_parsing_not_asx_playlist (void)
 	g_free (uri);
 }
 
+static void
+test_parsing_not_really_php (void)
+{
+	char *uri;
+	g_test_bug ("590722");
+	/* File from http://startwars.org/dump/remote_xspf.php */
+	uri = get_relative_uri (TEST_SRCDIR "remote_xspf.php");
+	g_assert (simple_parser_test (uri) == TOTEM_PL_PARSER_RESULT_SUCCESS);
+	g_free (uri);
+}
+
 #define MAX_DESCRIPTION_LEN 128
 #define DATE_BUFSIZE 512
 #define PRINT_DATE_FORMAT "%Y-%m-%dT%H:%M:%SZ"
@@ -620,6 +631,7 @@ main (int argc, char *argv[])
 		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/not_asx_playlist", test_parsing_not_asx_playlist);
+		g_test_add_func ("/parser/parsing/not_really_php", test_parsing_not_really_php);
 
 		return g_test_run ();
 	}
diff --git a/plparse/tests/remote_xspf.php b/plparse/tests/remote_xspf.php
new file mode 100644
index 0000000..80841dc
--- /dev/null
+++ b/plparse/tests/remote_xspf.php
@@ -0,0 +1,116 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<playlist version="1" xmlns="http://xspf.org/ns/0/";>
+	<trackList>
+		<track>
+			<title><![CDATA[12:15 Terrorattack avvärjd i Australien]]></title>
+			<location>http://www0.c00928.cdn.qbrick.com/00928/kluster/20090804/PR-2009-0804-SOBEAUSTRALIEN.flv</location>
+			<duration>73000</duration>
+			<image>http://media.svt.se/download/mcc/flash/20090804/PR-2009-0804-SOBEAUSTRALIEN/PR-2009-0804-SOBEAUSTRALIEN_start_0.jpg</image>
+		</track>
+		<track>
+			<title><![CDATA[12:12 Raketattack mot Kabul]]></title>
+			<location>http://www0.c00928.cdn.qbrick.com/00928/kluster/20090804/PR-2009-0804-SOBEKABUL.flv</location>
+			<duration>16000</duration>
+			<image>http://media.svt.se/download/mcc/flash/20090804/PR-2009-0804-SOBEKABUL/PR-2009-0804-SOBEKABUL_start_0.jpg</image>
+		</track>
+		<track>
+			<title><![CDATA[12:08 En död i thailändsk flygkrasch]]></title>
+			<location>http://www0.c00928.cdn.qbrick.com/00928/kluster/20090804/PR-2009-0804-SOBETHAIKRASCH.flv</location>
+			<duration>17000</duration>
+			<image>http://media.svt.se/download/mcc/flash/20090804/PR-2009-0804-SOBETHAIKRASCH/PR-2009-0804-SOBETHAIKRASCH_start_0.jpg</image>
+		</track>
+		<track>
+			<title><![CDATA[10:16 Hamstring aav glödlampor inför EU-förbud]]></title>
+			<location>http://www0.c00928.cdn.qbrick.com/00928/kluster/20090804/PR-2009-0804-GLODLAMPOR.flv</location>
+			<duration>93000</duration>
+			<image>http://media.svt.se/download/mcc/flash/20090804/PR-2009-0804-GLODLAMPOR/PR-2009-0804-GLODLAMPOR_start_0.jpg</image>
+		</track>
+		<track>
+			<title><![CDATA[10:14 Miljardlån till vänner före Kaupthings krasch]]></title>
+			<location>http://www0.c00928.cdn.qbrick.com/00928/kluster/20090804/PR-2009-0804-PEEDKAUPTHINGKARUSELL.flv</location>
+			<duration>62000</duration>
+			<image>http://media.svt.se/download/mcc/flash/20090804/PR-2009-0804-PEEDKAUPTHINGKARUSELL/PR-2009-0804-PEEDKAUPTHINGKARUSELL_start_0.jpg</image>
+		</track>
+		<track>
+			<title><![CDATA[10:07 Hemliga polislistor över kriminella säljs]]></title>
+			<location>http://www0.c00928.cdn.qbrick.com/00928/kluster/20090804/PR-2009-0804-PEEDPOLISLISTOR.flv</location>
+			<duration>81000</duration>
+			<image>http://media.svt.se/download/mcc/flash/20090804/PR-2009-0804-PEEDPOLISLISTOR/PR-2009-0804-PEEDPOLISLISTOR_start_0.jpg</image>
+		</track>
+		<track>
+			<title><![CDATA[08:47 Röst på SD i kyrkovalet kan vara bortkastad]]></title>
+			<location>http://www0.c00928.cdn.qbrick.com/00928/kluster/20090804/PR-2009-0804-SOBESDVAL.flv</location>
+			<duration>96000</duration>
+			<image>http://media.svt.se/download/mcc/flash/20090804/PR-2009-0804-SOBESDVAL/PR-2009-0804-SOBESDVAL_start_0.jpg</image>
+		</track>
+		<track>
+			<title><![CDATA[08:37 Hård kritik mot svenska häkten]]></title>
+			<location>http://www0.c00928.cdn.qbrick.com/00928/kluster/20090804/PR-2009-0804SOBEPALHAKTE.flv</location>
+			<duration>20000</duration>
+			<image>http://media.svt.se/download/mcc/flash/20090804/PR-2009-0804SOBEPALHAKTE/PR-2009-0804SOBEPALHAKTE_start_0.jpg</image>
+		</track>
+		<track>
+			<title><![CDATA[08:15 Ã?ratal av sanering efter oljekatastrofen]]></title>
+			<location>http://www0.c00928.cdn.qbrick.com/00928/kluster/20090804/PR-2009-0804-SOBEOLJA.flv</location>
+			<duration>33000</duration>
+			<image>http://media.svt.se/download/mcc/flash/20090804/PR-2009-0804-SOBEOLJA/PR-2009-0804-SOBEOLJA_start_0.jpg</image>
+		</track>
+		<track>
+			<title><![CDATA[01:33 Nya fall av resistenta patienter]]></title>
+			<location>http://www0.c00928.cdn.qbrick.com/00928/kluster/20090804/PR-2009-0804-LISVPALSVININFLUENSANATT.flv</location>
+			<duration>25000</duration>
+			<image>http://media.svt.se/download/mcc/flash/20090804/PR-2009-0804-LISVPALSVININFLUENSANATT/PR-2009-0804-LISVPALSVININFLUENSANATT_start_0.jpg</image>
+		</track>
+		<track>
+			<title><![CDATA[01:09 Inget VM för Christian Olsson]]></title>
+			<location>http://www0.c00928.cdn.qbrick.com/00928/kluster/20090804/PR-2009-0804-LISVPALOLSSONNATT.flv</location>
+			<duration>16000</duration>
+		</track>
+		<track>
+			<title><![CDATA[00:24 Läkare missar ofta KOL]]></title>
+			<location>http://www0.c00928.cdn.qbrick.com/00928/kluster/20090804/PR-2009-0804-LISVKOLNATT.flv</location>
+			<duration>97000</duration>
+			<image>http://media.svt.se/download/mcc/flash/20090804/PR-2009-0804-LISVKOLNATT/PR-2009-0804-LISVKOLNATT_start_0.jpg</image>
+		</track>
+		<track>
+			<title><![CDATA[Igår 23:35 Kan bli ny rättegång för Quick]]></title>
+			<location>http://www0.c00928.cdn.qbrick.com/00928/kluster/20090803/PR-2009-0804-LISVPALOUICK.flv</location>
+			<duration>14000</duration>
+		</track>
+		<track>
+			<title><![CDATA[Igår 23:32 Ljusning för Volvo, nattsvart för Saab]]></title>
+			<location>http://www0.c00928.cdn.qbrick.com/00928/kluster/20090803/PR-2009-0804-LISVPALBILARNATT.flv</location>
+			<duration>14000</duration>
+		</track>
+		<track>
+			<title><![CDATA[Igår 23:30 Ojämn kamp mot opium i Afghanistan]]></title>
+			<location>http://www0.c00928.cdn.qbrick.com/00928/kluster/20090803/PR-2009-0804-LISVOPIUMNATT.flv</location>
+			<duration>108000</duration>
+			<image>http://media.svt.se/download/mcc/flash/20090803/PR-2009-0804-LISVOPIUMNATT/PR-2009-0804-LISVOPIUMNATT_start_0.jpg</image>
+		</track>
+		<track>
+			<title><![CDATA[Igår 23:24 Jacksons mamma får vårdnaden]]></title>
+			<location>http://www0.c00928.cdn.qbrick.com/00928/kluster/20090803/PR-2009-0804-LISVJACKSONNATT.flv</location>
+			<duration>58000</duration>
+			<image>http://media.svt.se/download/mcc/flash/20090803/PR-2009-0804-LISVJACKSONNATT/PR-2009-0804-LISVJACKSONNATT_start_0.jpg</image>
+		</track>
+		<track>
+			<title><![CDATA[Igår 23:21 Kapten misstänkt för brott vid oljekatastrof]]></title>
+			<location>http://www0.c00928.cdn.qbrick.com/00928/kluster/20090803/PR-2009-0804-LISVNORGENATT.flv</location>
+			<duration>72000</duration>
+			<image>http://media.svt.se/download/mcc/flash/20090803/PR-2009-0804-LISVNORGENATT/PR-2009-0804-LISVNORGENATT_start_0.jpg</image>
+		</track>
+		<track>
+			<title><![CDATA[Igår 18:33 Influensa-informatörer var tjuvar]]></title>
+			<location>http://www0.c00928.cdn.qbrick.com/00928/kluster/20090803/PR-2009-0803-PEDGRUNE.flv</location>
+			<duration>118000</duration>
+			<image>http://media.svt.se/download/mcc/flash/20090803/PR-2009-0803-PEDGRUNE/PR-2009-0803-PEDGRUNE_start_0.jpg</image>
+		</track>
+		<track>
+			<title><![CDATA[Igår 18:10 Ingen dykning efter kroppar]]></title>
+			<location>http://www0.c00928.cdn.qbrick.com/00928/kluster/20090803/PR-2009-0803-PEDGDYKA.flv</location>
+			<duration>79000</duration>
+			<image>http://media.svt.se/download/mcc/flash/20090803/PR-2009-0803-PEDGDYKA/PR-2009-0803-PEDGDYKA_start_0.jpg</image>
+		</track>
+	</trackList>
+</playlist>
diff --git a/plparse/totem-pl-parser.c b/plparse/totem-pl-parser.c
index caa286d..673b277 100644
--- a/plparse/totem-pl-parser.c
+++ b/plparse/totem-pl-parser.c
@@ -228,6 +228,7 @@ static PlaylistTypes dual_types[] = {
 	PLAYLIST_TYPE2 ("audio/vnd.rn-realaudio", totem_pl_parser_add_ra, totem_pl_parser_is_uri_list),
 	PLAYLIST_TYPE2 ("audio/x-realaudio", totem_pl_parser_add_ra, totem_pl_parser_is_uri_list),
 	PLAYLIST_TYPE2 ("text/plain", totem_pl_parser_add_ra, totem_pl_parser_is_uri_list),
+	PLAYLIST_TYPE2 ("application/x-php", NULL, NULL),
 	PLAYLIST_TYPE2 ("audio/x-ms-asx", totem_pl_parser_add_asx, totem_pl_parser_is_asx),
 	PLAYLIST_TYPE2 ("video/x-ms-asf", totem_pl_parser_add_asf, totem_pl_parser_is_asf),
 	PLAYLIST_TYPE2 ("video/x-ms-wmv", totem_pl_parser_add_asf, totem_pl_parser_is_asf),
@@ -1749,6 +1750,25 @@ totem_pl_parser_ignore_from_mimetype (TotemPlParser *parser, const char *mimetyp
 	return FALSE;
 }
 
+static PlaylistCallback
+totem_pl_parser_get_function_for_mimetype (const char *mimetype)
+{
+	guint i;
+
+	if (mimetype == NULL)
+		return NULL;
+
+	for (i = 0; i < G_N_ELEMENTS(special_types); i++) {
+		if (strcmp (special_types[i].mimetype, mimetype) == 0)
+			return special_types[i].func;
+	}
+	for (i = 0; i < G_N_ELEMENTS(dual_types); i++) {
+		if (strcmp (dual_types[i].mimetype, mimetype) == 0)
+			return dual_types[i].func;
+	}
+	return NULL;
+}
+
 TotemPlParserResult
 totem_pl_parser_parse_internal (TotemPlParser *parser,
 				GFile *file,
@@ -1819,7 +1839,7 @@ totem_pl_parser_parse_internal (TotemPlParser *parser,
 	DEBUG(file, g_print ("_get_mime_type_for_name for '%s' returned '%s'\n", uri, mimetype));
 	if (mimetype == NULL || strcmp (UNKNOWN_TYPE, mimetype) == 0
 	    || (g_file_is_native (file) && g_content_type_is_a (mimetype, "text/plain") != FALSE)) {
-	    	char *new_mimetype;
+		char *new_mimetype;
 		new_mimetype = my_g_file_info_get_mime_type_with_data (file, &data, parser);
 		if (new_mimetype) {
 			g_free (mimetype);
@@ -1889,8 +1909,7 @@ totem_pl_parser_parse_internal (TotemPlParser *parser,
 
 		for (i = 0; i < G_N_ELEMENTS(dual_types) && found == FALSE; i++) {
 			if (strcmp (dual_types[i].mimetype, mimetype) == 0) {
-				guint j;
-				int new_i;
+				PlaylistCallback func;
 
 				DEBUG(file, g_print ("URI '%s' is dual type '%s'\n", uri, mimetype));
 				if (data == NULL) {
@@ -1906,21 +1925,15 @@ totem_pl_parser_parse_internal (TotemPlParser *parser,
 					break;
 				}
 				/* Now look for the proper function to use */
-				new_i = -1;
-				for (j = 0; j < G_N_ELEMENTS(dual_types) && mimetype != NULL; j++) {
-					if (strcmp (dual_types[j].mimetype, mimetype) == 0) {
-						new_i = j;
-						break;
-					}
-				}
-				if (new_i == -1 && mimetype != NULL) {
-					DEBUG(file, g_print ("Ignoring URI '%s' because we couldn't find a dual-type parser for '%s'\n", uri, mimetype));
+				func = totem_pl_parser_get_function_for_mimetype (mimetype);
+				if (func == NULL && mimetype != NULL) {
+					DEBUG(file, g_print ("Ignoring URI '%s' because we couldn't find a playlist parser for '%s'\n", uri, mimetype));
 					ret = TOTEM_PL_PARSER_RESULT_IGNORED;
 					g_free (mimetype);
 					mimetype = NULL;
 					break;
-				} else if (new_i != -1) {
-					i = new_i;
+				} else if (func == NULL) {
+					func = dual_types[i].func;
 				}
 
 				if (base_file == NULL)
@@ -1928,7 +1941,7 @@ totem_pl_parser_parse_internal (TotemPlParser *parser,
 				else
 					base_file = g_object_ref (base_file);
 
-				ret = (* dual_types[i].func) (parser, file, base_file ? base_file : file, parse_data, data);
+				ret = (* func) (parser, file, base_file ? base_file : file, parse_data, data);
 
 				if (base_file != NULL)
 					g_object_unref (base_file);
@@ -2352,6 +2365,8 @@ totem_pl_parser_mime_type_from_data (gconstpointer data, int len)
 			if (func == dual_types[i].iden)
 				continue;
 			func = dual_types[i].iden;
+			if (func == NULL)
+				continue;
 			res = func (data, len);
 			if (res != NULL) {
 				g_free (mime_type);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]