[totem-pl-parser] lib: Handle RSS feeds for video sites



commit 3e5535589cd4b80cd2a493dff21df43030a88705
Author: Bastien Nocera <hadess hadess net>
Date:   Tue Mar 13 14:23:16 2012 +0100

    lib: Handle RSS feeds for video sites
    
    Such as YouTube favourites, Vimeo most played, etc.

 plparse/tests/Makefile.am         |    3 ++-
 plparse/tests/parser.c            |   20 ++++++++++++++++++++
 plparse/tests/rss.xml             |   14 ++++++++++++++
 plparse/totem-pl-parser-podcast.c |   11 +++++++++--
 4 files changed, 45 insertions(+), 3 deletions(-)
---
diff --git a/plparse/tests/Makefile.am b/plparse/tests/Makefile.am
index ace20ac..2e76b33 100644
--- a/plparse/tests/Makefile.am
+++ b/plparse/tests/Makefile.am
@@ -68,6 +68,7 @@ EXTRA_DIST =			\
 	empty-asx.asx		\
 	emptyplaylist.pls	\
 	decrypted-amazon-track.xspf	\
-	WMA9.1_98_quality_48khz_vbr_s.wma
+	WMA9.1_98_quality_48khz_vbr_s.wma \
+	rss.xml
 
 -include $(top_srcdir)/git.mk
diff --git a/plparse/tests/parser.c b/plparse/tests/parser.c
index e0d47dd..bf8a89a 100644
--- a/plparse/tests/parser.c
+++ b/plparse/tests/parser.c
@@ -721,6 +721,24 @@ test_parsing_xml_mixed_cdata (void)
 }
 
 static void
+test_parsing_rss_id (void)
+{
+	char *uri;
+	uri = get_relative_uri (TEST_SRCDIR "rss.xml");
+	g_assert_cmpstr (parser_test_get_entry_field (uri, TOTEM_PL_PARSER_FIELD_ID), ==, "http://example.com/video1/from-rss";);
+	g_free (uri);
+}
+
+static void
+test_parsing_rss_link (void)
+{
+	char *uri;
+	uri = get_relative_uri (TEST_SRCDIR "rss.xml");
+	g_assert_cmpstr (parser_test_get_entry_field (uri, TOTEM_PL_PARSER_FIELD_URI), ==, "http://www.guardian.co.uk/technology/audio/2011/may/03/tech-weekly-art-love-bin-laden";);
+	g_free (uri);
+}
+
+static void
 test_parsing_not_asx_playlist (void)
 {
 	char *uri;
@@ -1055,6 +1073,8 @@ 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/rss_id", test_parsing_rss_id);
+		g_test_add_func ("/parser/parsing/rss_link", test_parsing_rss_link);
 		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);
 		g_test_add_func ("/parser/parsing/not_really_php_but_html_instead", test_parsing_not_really_php_but_html_instead);
diff --git a/plparse/tests/rss.xml b/plparse/tests/rss.xml
new file mode 100644
index 0000000..2bb9efb
--- /dev/null
+++ b/plparse/tests/rss.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<rss version="2.0">
+    <channel>
+    <title>Title</title>
+    <link>http://example.com</link>
+
+    <item>
+      <title>Video #1</title>
+      <link>http://www.guardian.co.uk/technology/audio/2011/may/03/tech-weekly-art-love-bin-laden</link>
+      <guid>http://example.com/video1/from-rss</guid>
+      <description>Video #1 description</description>
+    </item>
+    </channel>
+</rss>
diff --git a/plparse/totem-pl-parser-podcast.c b/plparse/totem-pl-parser-podcast.c
index 6a6437f..2950c13 100644
--- a/plparse/totem-pl-parser-podcast.c
+++ b/plparse/totem-pl-parser-podcast.c
@@ -33,6 +33,7 @@
 
 #include "totem-pl-parser-mini.h"
 #include "totem-pl-parser-podcast.h"
+#include "totem-pl-parser-videosite.h"
 #include "totem-pl-parser-private.h"
 
 #define RSS_NEEDLE "<rss "
@@ -102,11 +103,11 @@ static TotemPlParserResult
 parse_rss_item (TotemPlParser *parser, xml_node_t *parent)
 {
 	const char *title, *uri, *description, *author;
-	const char *pub_date, *duration, *filesize, *content_type;
+	const char *pub_date, *duration, *filesize, *content_type, *id;
 	xml_node_t *node;
 
 	title = uri = description = author = content_type = NULL;
-	pub_date = duration = filesize = NULL;
+	pub_date = duration = filesize = id = NULL;
 
 	for (node = parent->child; node != NULL; node = node->next) {
 		if (node->name == NULL)
@@ -118,6 +119,8 @@ parse_rss_item (TotemPlParser *parser, xml_node_t *parent)
 			uri = node->data;
 		} else if (g_ascii_strcasecmp (node->name, "pubDate") == 0) {
 			pub_date = node->data;
+		} else if (g_ascii_strcasecmp (node->name, "guid") == 0) {
+			id = node->data;
 		} else if (g_ascii_strcasecmp (node->name, "description") == 0
 			   || g_ascii_strcasecmp (node->name, "itunes:summary") == 0) {
 			description = node->data;
@@ -161,12 +164,16 @@ parse_rss_item (TotemPlParser *parser, xml_node_t *parent)
 			tmp = xml_parser_get_property (node, "length");
 			if (tmp != NULL)
 				filesize = tmp;
+		} else if (g_ascii_strcasecmp (node->name, "link") == 0 &&
+			   totem_pl_parser_is_videosite (node->data, FALSE) != FALSE) {
+			uri = node->data;
 		}
 	}
 
 	if (uri != NULL) {
 		totem_pl_parser_add_uri (parser,
 					 TOTEM_PL_PARSER_FIELD_URI, uri,
+					 TOTEM_PL_PARSER_FIELD_ID, id,
 					 TOTEM_PL_PARSER_FIELD_TITLE, title,
 					 TOTEM_PL_PARSER_FIELD_PUB_DATE, pub_date,
 					 TOTEM_PL_PARSER_FIELD_DESCRIPTION, description,



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