[totem-pl-parser] podcast: Set feed owner as feed author if author is empty



commit 467a94c8a275503631837e5b104b365fb5afdf7d
Author: crvi <crvisqr gmail com>
Date:   Thu Oct 1 01:07:57 2020 +0530

    podcast: Set feed owner as feed author if author is empty
    
    The order of preference for author is as follows:
    
    1. <author> or <itunes:author>
    2. <itunes:owner> -> <itunes:name>
    3. <generator>

 plparse/tests/parser.c                      | 27 +++++++++++++++++++++++++++
 plparse/tests/podcast-empty-description.rss |  1 -
 plparse/totem-pl-parser-podcast.c           | 24 +++++++++++++++++++-----
 3 files changed, 46 insertions(+), 6 deletions(-)
---
diff --git a/plparse/tests/parser.c b/plparse/tests/parser.c
index f71091d..15397dd 100644
--- a/plparse/tests/parser.c
+++ b/plparse/tests/parser.c
@@ -915,6 +915,32 @@ test_parsing_feed_pubdate (void)
 
 }
 
+static void
+test_parsing_feed_author (void)
+{
+       char *uri;
+
+       /* no <itunes:owner> or <itunes:author> */
+       uri = get_relative_uri (TEST_SRCDIR "541405.xml");
+       g_assert_cmpstr (parser_test_get_playlist_field (uri, TOTEM_PL_PARSER_FIELD_AUTHOR), ==, NULL);
+       g_free (uri);
+
+       /* <itunes:owner> without <itunes:author> */
+       uri = get_relative_uri (TEST_SRCDIR "podcast-empty-description.rss");
+       g_assert_cmpstr (parser_test_get_playlist_field (uri, TOTEM_PL_PARSER_FIELD_AUTHOR), ==, "Bastian 
Bielendorfer und Reinhard Remfort");
+       g_free (uri);
+
+       /* same <itunes:owner> and <itunes:author> */
+       uri = get_relative_uri (TEST_SRCDIR "podcast-image-url.1.rss");
+       g_assert_cmpstr (parser_test_get_playlist_field (uri, TOTEM_PL_PARSER_FIELD_AUTHOR), ==, "Exit Poll 
New England");
+       g_free (uri);
+
+       /* different <itunes:owner> with <itunes:author> */
+       uri = get_relative_uri (TEST_SRCDIR "podcast-image-url.2.rss");
+       g_assert_cmpstr (parser_test_get_playlist_field (uri, TOTEM_PL_PARSER_FIELD_AUTHOR), ==, "BBC Radio");
+       g_free (uri);
+}
+
 static void
 test_parsing_hadess (void)
 {
@@ -1601,6 +1627,7 @@ main (int argc, char *argv[])
                g_test_add_func ("/parser/parsing/podcast_feed_image", test_parsing_feed_image);
                g_test_add_func ("/parser/parsing/podcast_item_image", test_parsing_item_image);
                g_test_add_func ("/parser/parsing/podcast_feed_pubdate", test_parsing_feed_pubdate);
+               g_test_add_func ("/parser/parsing/podcast_feed_author", test_parsing_feed_author);
                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);
diff --git a/plparse/tests/podcast-empty-description.rss b/plparse/tests/podcast-empty-description.rss
index 5f4e69b..c84b497 100644
--- a/plparse/tests/podcast-empty-description.rss
+++ b/plparse/tests/podcast-empty-description.rss
@@ -23,7 +23,6 @@
     </image>
     <itunes:image 
href="https://images.podigee.com/0x,sldIyssC4m9BGLoH9bbeKEdoZscIP1MYUusb1Po0uqVA=/https://cdn.podigee.com/uploads/u2254/30ee28ce-b693-4ec9-bdb2-b0d79a123861.jpg"/>
     <itunes:subtitle/>
-    <itunes:author>Bastian Bielendorfer und Reinhard Remfort</itunes:author>
     <itunes:explicit>yes</itunes:explicit>
     <itunes:keywords>Lehrerkind,Minkorrekt,Remfort,Bielendorfer</itunes:keywords>
     <itunes:category text="Comedy"/>
diff --git a/plparse/totem-pl-parser-podcast.c b/plparse/totem-pl-parser-podcast.c
index 3c445eb..b28c788 100644
--- a/plparse/totem-pl-parser-podcast.c
+++ b/plparse/totem-pl-parser-podcast.c
@@ -293,11 +293,11 @@ static TotemPlParserResult
 parse_rss_items (TotemPlParser *parser, const char *uri, xml_node_t *parent)
 {
        const char *title, *language, *description, *author;
-       const char *contact, *img, *pub_date, *copyright;
+       const char *contact, *img, *pub_date, *copyright, *generator;
        xml_node_t *node;
 
        title = language = description = author = NULL;
-       contact = img = pub_date = copyright = NULL;
+       contact = img = pub_date = copyright = generator = NULL;
 
        /* We need to parse for the feed metadata first, then for the items */
        for (node = parent->child; node != NULL; node = node->next) {
@@ -314,9 +314,19 @@ parse_rss_items (TotemPlParser *parser, const char *uri, xml_node_t *parent)
                        /* prefer longer feed descriptions */
                        set_longer_description (node, &description);
                } else if (g_ascii_strcasecmp (node->name, "author") == 0
-                        || g_ascii_strcasecmp (node->name, "itunes:author") == 0
-                        || (g_ascii_strcasecmp (node->name, "generator") == 0 && author == NULL)) {
-                       author = node->data;
+                          || g_ascii_strcasecmp (node->name, "itunes:author") == 0) {
+                       if (node->data)
+                               author = node->data;
+               } else if (g_ascii_strcasecmp (node->name, "generator") == 0) {
+                       generator = node->data;
+               } else if (g_ascii_strcasecmp (node->name, "itunes:owner") == 0) {
+                       const char *tmp;
+
+                       /* Owner name is much broader than author. So, we set it
+                        * only if there is no author in feed yet. */
+                       tmp = xml_parser_get_node_value (node, "itunes:name");
+                       if (tmp != NULL && author == NULL)
+                               author = tmp;
                } else if (g_ascii_strcasecmp (node->name, "webMaster") == 0) {
                        contact = node->data;
                } else if (g_ascii_strcasecmp (node->name, "image") == 0) {
@@ -340,6 +350,10 @@ parse_rss_items (TotemPlParser *parser, const char *uri, xml_node_t *parent)
                }
        }
 
+       /* update generator as author, only as last resort */
+       if (!author && generator)
+               author = generator;
+
        /* Send the info we already have about the feed */
        totem_pl_parser_add_uri (parser,
                                 TOTEM_PL_PARSER_FIELD_IS_PLAYLIST, TRUE,


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