[totem-pl-parser] Fix parsing of more iTunes Podcast links
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [totem-pl-parser] Fix parsing of more iTunes Podcast links
- Date: Mon, 11 Oct 2010 21:12:30 +0000 (UTC)
commit 40cd5e4eddae32f4b3cffaca2f478ccad053a3e6
Author: Bastien Nocera <hadess hadess net>
Date: Mon Oct 11 22:10:44 2010 +0100
Fix parsing of more iTunes Podcast links
https://bugzilla.gnome.org/show_bug.cgi?id=617745
plparse/tests/parser.c | 5 +-
plparse/totem-pl-parser-podcast.c | 125 +++++++++++++++++++++++++------------
2 files changed, 89 insertions(+), 41 deletions(-)
---
diff --git a/plparse/tests/parser.c b/plparse/tests/parser.c
index bf5dd5d..27d41e7 100644
--- a/plparse/tests/parser.c
+++ b/plparse/tests/parser.c
@@ -385,7 +385,7 @@ playlist_started_title_cb (TotemPlParser *parser,
}
static char *
-parser_test_get_playlist_title (const char *uri)
+parser_test_get_playlist_uri (const char *uri)
{
TotemPlParserResult retval;
char *ret = NULL;
@@ -409,7 +409,8 @@ parser_test_get_playlist_title (const char *uri)
static void
test_itms_parsing (void)
{
- g_assert_cmpstr (parser_test_get_playlist_title ("itms://itunes.apple.com/gb/podcast/best-of-chris-moyles-enhanced/id142102961?ign-mpt=uo%3D4"), ==, "http://downloads.bbc.co.uk/podcasts/radio1/moylesen/rss.xml");
+ g_assert_cmpstr (parser_test_get_playlist_uri ("itms://itunes.apple.com/gb/podcast/best-of-chris-moyles-enhanced/id142102961?ign-mpt=uo%3D4"), ==, "http://downloads.bbc.co.uk/podcasts/radio1/moylesen/rss.xml");
+ g_assert_cmpstr (parser_test_get_playlist_uri ("http://itunes.apple.com/gb/podcast/radio-1-mini-mix/id268491175?uo=4"), ==, "http://downloads.bbc.co.uk/podcasts/radio1/r1mix/rss.xml");
}
static void
diff --git a/plparse/totem-pl-parser-podcast.c b/plparse/totem-pl-parser-podcast.c
index 9b98fac..7f6b3f2 100644
--- a/plparse/totem-pl-parser-podcast.c
+++ b/plparse/totem-pl-parser-podcast.c
@@ -571,6 +571,60 @@ totem_pl_parser_add_xml_feed (TotemPlParser *parser,
#endif /* !HAVE_GMIME */
}
+static GByteArray *
+totem_pl_parser_load_http_itunes (const char *uri)
+{
+ SoupMessage *msg;
+ SoupSession *session;
+ GByteArray *data;
+
+ session = soup_session_sync_new_with_options (
+ SOUP_SESSION_ADD_FEATURE_BY_TYPE, SOUP_TYPE_GNOME_FEATURES_2_26,
+ SOUP_SESSION_ADD_FEATURE_BY_TYPE, SOUP_TYPE_CONTENT_DECODER,
+ SOUP_SESSION_USER_AGENT, "iTunes/7.4.1",
+ SOUP_SESSION_ACCEPT_LANGUAGE_AUTO, TRUE,
+ NULL);
+
+ msg = soup_message_new (SOUP_METHOD_GET, uri);
+ soup_session_send_message (session, msg);
+ if (SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
+ data = g_byte_array_new ();
+ g_byte_array_append (data,
+ (guchar *) msg->response_body->data,
+ msg->response_body->length);
+ } else {
+ return NULL;
+ }
+ g_object_unref (msg);
+ g_object_unref (session);
+
+ return data;
+}
+
+static const char *
+totem_pl_parser_parse_itms_link_doc (xml_node_t *item)
+{
+ for (item = item->child; item != NULL; item = item->next) {
+ /* What we're looking for looks like:
+ * <key>url</key><string>URL</string> */
+ if (g_ascii_strcasecmp (item->name, "key") == 0
+ && g_ascii_strcasecmp (item->data, "url") == 0
+ && item->next != NULL) {
+ item = item->next;
+ if (g_ascii_strcasecmp (item->name, "string") == 0)
+ return item->data;
+ } else {
+ const char *ret;
+
+ ret = totem_pl_parser_parse_itms_link_doc (item);
+ if (ret != NULL)
+ return ret;
+ }
+ }
+
+ return NULL;
+}
+
static const char *
totem_pl_parser_parse_itms_doc (xml_node_t *item)
{
@@ -617,8 +671,28 @@ totem_pl_parser_get_feed_uri (char *data, gsize len)
uri = totem_pl_parser_parse_itms_doc (doc);
if (uri == NULL) {
+ /* Maybe it's just a link instead */
+ const char *link;
+ GByteArray *content;
+ GFile *feed_file;
+
+ link = totem_pl_parser_parse_itms_link_doc (doc);
+ if (link == NULL) {
+ xml_parser_free_tree (doc);
+ return NULL;
+ }
+
+ content = totem_pl_parser_load_http_itunes (link);
+ if (content == NULL) {
+ xml_parser_free_tree (doc);
+ return NULL;
+ }
xml_parser_free_tree (doc);
- return NULL;
+
+ feed_file = totem_pl_parser_get_feed_uri ((char *) content->data, content->len);
+ g_byte_array_free (content, TRUE);
+
+ return feed_file;
}
ret = g_file_new_for_uri (uri);
@@ -627,36 +701,6 @@ totem_pl_parser_get_feed_uri (char *data, gsize len)
return ret;
}
-static GByteArray *
-totem_pl_parser_load_http_itunes (const char *uri)
-{
- SoupMessage *msg;
- SoupSession *session;
- GByteArray *data;
-
- session = soup_session_sync_new_with_options (
- SOUP_SESSION_ADD_FEATURE_BY_TYPE, SOUP_TYPE_GNOME_FEATURES_2_26,
- SOUP_SESSION_ADD_FEATURE_BY_TYPE, SOUP_TYPE_CONTENT_DECODER,
- SOUP_SESSION_USER_AGENT, "iTunes/7.4.1",
- SOUP_SESSION_ACCEPT_LANGUAGE_AUTO, TRUE,
- NULL);
-
- msg = soup_message_new (SOUP_METHOD_GET, uri);
- soup_session_send_message (session, msg);
- if (SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
- data = g_byte_array_new ();
- g_byte_array_append (data,
- (guchar *) msg->response_body->data,
- msg->response_body->length);
- } else {
- return NULL;
- }
- g_object_unref (msg);
- g_object_unref (session);
-
- return data;
-}
-
TotemPlParserResult
totem_pl_parser_add_itms (TotemPlParser *parser,
GFile *file,
@@ -672,14 +716,14 @@ totem_pl_parser_add_itms (TotemPlParser *parser,
GFile *feed_file;
TotemPlParserResult ret;
- if (g_file_has_uri_scheme (file, "itms") == FALSE) {
+ if (g_file_has_uri_scheme (file, "itms") != FALSE) {
+ itms_uri= g_file_get_uri (file);
+ memcpy (itms_uri, "http", 4);
+ } else if (g_file_has_uri_scheme (file, "http") != FALSE) {
+ itms_uri = g_file_get_uri (file);
+ } else {
return TOTEM_PL_PARSER_RESULT_ERROR;
}
- itms_uri= g_file_get_uri (file);
- memcpy (itms_uri, "http", 4);
-
- if (itms_uri == NULL)
- return TOTEM_PL_PARSER_RESULT_ERROR;
/* Load the file using iTunes user-agent */
content = totem_pl_parser_load_http_itunes (itms_uri);
@@ -708,8 +752,11 @@ totem_pl_parser_is_itms_feed (GFile *file)
uri = g_file_get_uri (file);
- if (g_file_has_uri_scheme (file, "itms") != FALSE) {
- if (strstr (uri, "/podcast/") != NULL) {
+ if (g_file_has_uri_scheme (file, "itms") != FALSE ||
+ (g_file_has_uri_scheme (file, "http") != FALSE &&
+ g_str_has_prefix (uri, "http://itunes.apple.com/") != FALSE)) {
+ if (strstr (uri, "/podcast/") != NULL ||
+ strstr (uri, "viewPodcast") != NULL) {
g_free (uri);
return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]