From c2e1a8e32a0c59d555e301c9dbb90db73953a76c Mon Sep 17 00:00:00 2001 From: crvi Date: Thu, 1 Oct 2020 01:39:34 +0530 Subject: podcast: Add support for item content rating --- plparse/tests/parser.c | 22 ++++++++++++++++++++++ plparse/totem-pl-parser-podcast.c | 7 +++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/plparse/tests/parser.c b/plparse/tests/parser.c index 635b3f8..6016a49 100644 --- a/plparse/tests/parser.c +++ b/plparse/tests/parser.c @@ -962,6 +962,27 @@ test_parsing_feed_explicit (void) g_free (uri); } +static void +test_parsing_item_explicit (void) +{ + char *uri; + + /* clean item */ + uri = get_relative_uri (TEST_SRCDIR "podcast-image-url.1.rss"); + g_assert_cmpstr (parser_test_get_entry_field (uri, TOTEM_PL_PARSER_FIELD_CONTENT_RATING), ==, TOTEM_PL_PARSER_CONTENT_RATING_CLEAN); + g_free (uri); + + /* explicit item */ + uri = get_relative_uri (TEST_SRCDIR "podcast-empty-description.rss"); + g_assert_cmpstr (parser_test_get_entry_field (uri, TOTEM_PL_PARSER_FIELD_CONTENT_RATING), ==, TOTEM_PL_PARSER_CONTENT_RATING_EXPLICIT); + g_free (uri); + + /* unrated item */ + uri = get_relative_uri (TEST_SRCDIR "content-no-rating.rss"); + g_assert_cmpstr (parser_test_get_entry_field (uri, TOTEM_PL_PARSER_FIELD_CONTENT_RATING), ==, TOTEM_PL_PARSER_CONTENT_RATING_UNRATED); + g_free (uri); +} + static void test_parsing_hadess (void) { @@ -1650,6 +1671,7 @@ main (int argc, char *argv[]) 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/podcast_feed_explicit", test_parsing_feed_explicit); + g_test_add_func ("/parser/parsing/podcast_item_explicit", test_parsing_item_explicit); 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/totem-pl-parser-podcast.c b/plparse/totem-pl-parser-podcast.c index 1869a68..d1ba4e1 100644 --- a/plparse/totem-pl-parser-podcast.c +++ b/plparse/totem-pl-parser-podcast.c @@ -191,12 +191,12 @@ get_content_rating (const char *value) static TotemPlParserResult parse_rss_item (TotemPlParser *parser, xml_node_t *parent) { - const char *title, *uri, *description, *author, *img; + const char *title, *uri, *description, *author, *img, *explicit; const char *pub_date, *duration, *filesize, *content_type, *id; xml_node_t *node; title = uri = description = author = content_type = NULL; - img = pub_date = duration = filesize = id = NULL; + img = pub_date = duration = filesize = id = explicit = NULL; for (node = parent->child; node != NULL; node = node->next) { if (node->name == NULL) @@ -289,6 +289,8 @@ parse_rss_item (TotemPlParser *parser, xml_node_t *parent) tmp = xml_parser_get_property (node, "href"); if (tmp != NULL) img = tmp; + } else if (g_ascii_strcasecmp (node->name, "itunes:explicit") == 0) { + explicit = node->data; } } @@ -309,6 +311,7 @@ parse_rss_item (TotemPlParser *parser, xml_node_t *parent) TOTEM_PL_PARSER_FIELD_FILESIZE, filesize, TOTEM_PL_PARSER_FIELD_CONTENT_TYPE, content_type, TOTEM_PL_PARSER_FIELD_IMAGE_URI, img, + TOTEM_PL_PARSER_FIELD_CONTENT_RATING, get_content_rating (explicit), NULL); } -- cgit v1.2.1