[totem-pl-parser] lib: Don't add JPEG files as entries in Podcasts



commit 573e83cd7d0f079ad2122e6ad4a87dccd8e28d19
Author: Bastien Nocera <hadess hadess net>
Date:   Thu Jul 26 23:01:05 2012 +0100

    lib: Don't add JPEG files as entries in Podcasts
    
    Some people use the "enclosure" tag to attach images, those aren't
    useful entries.

 plparse/tests/Makefile.am         |    3 +-
 plparse/tests/empty-feed.xml      |   47 +++++++++++++++++++++++++++++++++++++
 plparse/tests/parser.c            |   14 +++++++++++
 plparse/totem-pl-parser-podcast.c |   17 ++++++++++++-
 4 files changed, 79 insertions(+), 2 deletions(-)
---
diff --git a/plparse/tests/Makefile.am b/plparse/tests/Makefile.am
index fc3ab34..f5eb922 100644
--- a/plparse/tests/Makefile.am
+++ b/plparse/tests/Makefile.am
@@ -70,6 +70,7 @@ EXTRA_DIST =			\
 	decrypted-amazon-track.xspf	\
 	WMA9.1_98_quality_48khz_vbr_s.wma \
 	rss.xml			\
-	dont-ignore-mp2t.ts
+	dont-ignore-mp2t.ts	\
+	empty-feed.xml
 
 -include $(top_srcdir)/git.mk
diff --git a/plparse/tests/empty-feed.xml b/plparse/tests/empty-feed.xml
new file mode 100644
index 0000000..cb2ed80
--- /dev/null
+++ b/plparse/tests/empty-feed.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<rss version="2.0"
+	xmlns:content="http://purl.org/rss/1.0/modules/content/";
+	xmlns:wfw="http://wellformedweb.org/CommentAPI/";
+	xmlns:dc="http://purl.org/dc/elements/1.1/";
+	xmlns:atom="http://www.w3.org/2005/Atom";
+	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/";
+	xmlns:slash="http://purl.org/rss/1.0/modules/slash/";
+	>
+
+<channel>
+	<title></title>
+	<atom:link href="http://www.101greatgoals.com/feed/"; rel="self" type="application/rss+xml" />
+	<link>http://www.101greatgoals.com</link>
+	<description>No matter where you are in the world, this site allows you to keep up to date with all the latest goals from around the world. This is your one-stop-shop to get your footy fix Ãââ on your terms, at your convenience and with your own input. Feel free to leave comments and links to other goals, any goal is welcome on this website. Sit back and enjoy.</description>
+	<lastBuildDate>Thu, 26 Jul 2012 19:56:04 +0000</lastBuildDate>
+	<language>en</language>
+	<sy:updatePeriod>hourly</sy:updatePeriod>
+	<sy:updateFrequency>1</sy:updateFrequency>
+	<generator>http://wordpress.org/?v=3.3.1</generator>
+		<item>
+		<title>The. Worst. Miss. Ever. Admir Mehmedi (Switzerland) v Gabon</title>
+		<link>http://www.101greatgoals.com/blog/the-worst-miss-ever-admir-mehmedi-switzerland-v-gabon/</link>
+		<comments>http://www.101greatgoals.com/blog/the-worst-miss-ever-admir-mehmedi-switzerland-v-gabon/#comments</comments>
+		<pubDate>Thu, 26 Jul 2012 16:57:37 +0000</pubDate>
+		<dc:creator>Ronaldo Assis de Moreira</dc:creator>
+				<category><![CDATA[blog]]></category>
+
+		<guid isPermaLink="false">http://www.101greatgoals.com/?p=206683</guid>
+		<description><![CDATA[]]></description>
+			<content:encoded><![CDATA[<p><br /><img src="http://i.ytimg.com/vi/LL8jk23Y2uw/0.jpg"; width="635" height="495" alt="0 The. Worst. Miss. Ever. Admir Mehmedi (Switzerland) v Gabon"  title="The. Worst. Miss. Ever. Admir Mehmedi (Switzerland) v Gabon" /><br />
+</p>
+]]></content:encoded>
+			<wfw:commentRss>http://www.101greatgoals.com/blog/the-worst-miss-ever-admir-mehmedi-switzerland-v-gabon/feed/</wfw:commentRss>
+		<slash:comments>0</slash:comments>
+		<enclosure url="http://www.101greatgoals.com/wp-content/uploads/2012/07/01377-90x68.jpg"; />
+	</item>
+	</channel>
+</rss>
+
+<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/
+
+Page Caching using memcached
+Database Caching 1/3 queries in 0.008 seconds using memcached
+Object Caching 1222/1222 objects using memcached
+
+Served from: www.101greatgoals.com @ 2012-07-26 20:03:55 -->
diff --git a/plparse/tests/parser.c b/plparse/tests/parser.c
index e43737f..31107d6 100644
--- a/plparse/tests/parser.c
+++ b/plparse/tests/parser.c
@@ -428,6 +428,19 @@ parser_test_get_playlist_uri (const char *uri)
 }
 
 static void
+test_image_link (void)
+{
+#ifdef HAVE_QUVI
+	char *uri;
+
+	/* From http://www.101greatgoals.com/feed/ */
+	uri = get_relative_uri (TEST_SRCDIR "empty-feed.xml");
+	g_assert_cmpstr (parser_test_get_entry_field (uri, TOTEM_PL_PARSER_FIELD_URI), ==, NULL);
+	g_free (uri);
+#endif
+}
+
+static void
 test_itms_parsing (void)
 {
 	if (http_supported == FALSE)
@@ -1070,6 +1083,7 @@ main (int argc, char *argv[])
 		g_test_add_func ("/parser/resolution", test_resolution);
 		g_test_add_func ("/parser/parsability", test_parsability);
 		g_test_add_func ("/parser/videosite", test_videosite);
+		g_test_add_func ("/parser/image_link", test_image_link);
 		g_test_add_func ("/parser/xml_is_text_plain", test_xml_is_text_plain);
 		g_test_add_func ("/parser/compressed_content_encoding", test_compressed_content_encoding);
 		g_test_add_func ("/parser/parsing/hadess", test_parsing_hadess);
diff --git a/plparse/totem-pl-parser-podcast.c b/plparse/totem-pl-parser-podcast.c
index 2950c13..296150a 100644
--- a/plparse/totem-pl-parser-podcast.c
+++ b/plparse/totem-pl-parser-podcast.c
@@ -99,6 +99,21 @@ totem_pl_parser_is_xml_feed (const char *data, gsize len)
 
 #ifndef TOTEM_PL_PARSER_MINI
 
+static gboolean
+is_image (const char *url)
+{
+	char *content_type;
+	gboolean retval = FALSE;
+
+	content_type = g_content_type_guess (url, NULL, 0, NULL);
+	if (content_type == NULL)
+		return FALSE;
+	if (g_content_type_is_a (content_type, "image/*"))
+		retval = TRUE;
+	g_free (content_type);
+	return retval;
+}
+
 static TotemPlParserResult
 parse_rss_item (TotemPlParser *parser, xml_node_t *parent)
 {
@@ -157,7 +172,7 @@ parse_rss_item (TotemPlParser *parser, xml_node_t *parent)
 			const char *tmp;
 
 			tmp = xml_parser_get_property (node, "url");
-			if (tmp != NULL)
+			if (tmp != NULL && is_image (tmp) == FALSE)
 				uri = tmp;
 			else
 				continue;



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