diff --git a/ChangeLog b/ChangeLog index 0b10b96556..b2273257d9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2007-10-11 Tim-Philipp Müller + + Based on patch by: Jason Kivlighn + + * gst/id3demux/id3v2frames.c: + Extract license/copyright URIs from ID3v2 WCOP frames + (Fixes #447000). + + * tests/check/elements/id3demux.c: + * tests/files/Makefile.am: + * tests/files/id3-447000-wcop.tag: + Add simple unit test. + 2007-10-11 Tim-Philipp Müller * ext/taglib/gstid3v2mux.cc: diff --git a/gst/id3demux/id3v2frames.c b/gst/id3demux/id3v2frames.c index 76d4cbc3ea..efbef079ee 100644 --- a/gst/id3demux/id3v2frames.c +++ b/gst/id3demux/id3v2frames.c @@ -38,6 +38,8 @@ GST_DEBUG_CATEGORY_EXTERN (id3demux_debug); #define GST_CAT_DEFAULT (id3demux_debug) static gboolean parse_comment_frame (ID3TagsWorking * work); +static gchar *parse_url_link_frame (ID3TagsWorking * work, + const gchar ** tag_name); static GArray *parse_text_identification_frame (ID3TagsWorking * work); static gchar *parse_user_text_identification_frame (ID3TagsWorking * work, const gchar ** tag_name); @@ -162,6 +164,9 @@ id3demux_id3v2_parse_frame (ID3TagsWorking * work) /* Text identification frame */ tag_fields = parse_text_identification_frame (work); } + } else if (work->frame_id[0] == 'W' && strcmp (work->frame_id, "WXXX") != 0) { + /* URL link frame: ISO-8859-1 encoded, one frame per tag */ + tag_str = parse_url_link_frame (work, &tag_name); } else if (!strcmp (work->frame_id, "COMM")) { /* Comment */ result = parse_comment_frame (work); @@ -297,6 +302,58 @@ parse_text_identification_frame (ID3TagsWorking * work) return fields; } +static gboolean +link_is_known_license (const gchar * url) +{ + return g_str_has_prefix (url, "http://creativecommons.org/licenses/"); +} + +static gchar * +parse_url_link_frame (ID3TagsWorking * work, const gchar ** tag_name) +{ + gsize len; + gchar *nul, *data, *link; + + *tag_name = NULL; + + if (work->parse_size == 0) + return NULL; + + data = (gchar *) work->parse_data; + /* if there's more data then the string is long, we only want to parse the + * data up to the terminating zero to g_convert and ignore the rest, as + * per spec */ + nul = memchr (data, '\0', work->parse_size); + if (nul != NULL) { + len = (gsize) (nul - data); + } else { + len = work->parse_size; + } + + link = g_convert (data, len, "UTF-8", "ISO-8859-1", NULL, NULL, NULL); + + if (link == NULL || !gst_uri_is_valid (link)) { + GST_DEBUG ("Invalid URI in %s frame: %s", work->frame_id, + GST_STR_NULL (link)); + g_free (link); + return NULL; + } + + /* we don't know if it's a link to a page that explains the copyright + * situation, or a link that points to/represents a license, the ID3 spec + * does not separate those two things; for now only put known license URIs + * into GST_TAG_LICENSE_URI and everything else into GST_TAG_COPYRIGHT_URI */ + if (strcmp (work->frame_id, "WCOP") == 0) { + if (link_is_known_license (link)) + *tag_name = GST_TAG_LICENSE_URI; + else + *tag_name = GST_TAG_COPYRIGHT_URI; + } + + return link; +} + + static gchar * parse_user_text_identification_frame (ID3TagsWorking * work, const gchar ** tag_name) diff --git a/tests/check/elements/id3demux.c b/tests/check/elements/id3demux.c index d0f385d98c..96aafdcb8c 100644 --- a/tests/check/elements/id3demux.c +++ b/tests/check/elements/id3demux.c @@ -175,6 +175,32 @@ GST_START_TEST (test_tdat_tyer) GST_END_TEST; +static void +check_wcop (const GstTagList * tags, const gchar * file) +{ + gchar *copyright = NULL; + gchar *uri = NULL; + + fail_unless (gst_tag_list_get_string (tags, GST_TAG_LICENSE_URI, &uri)); + fail_unless (uri != NULL); + fail_unless_equals_string (uri, + "http://creativecommons.org/licenses/by/3.0/"); + g_free (uri); + + fail_unless (gst_tag_list_get_string (tags, GST_TAG_COPYRIGHT, ©right)); + fail_unless (copyright != NULL); + fail_unless_equals_string (copyright, + " Steadman. Licensed to the public under http://creativecommons.org/licenses/by/3.0/ verify at http://test.com"); + g_free (copyright); +} + +GST_START_TEST (test_wcop) +{ + run_check_for_file ("id3-447000-wcop.tag", check_wcop); +} + +GST_END_TEST; + static Suite * id3demux_suite (void) { @@ -183,6 +209,7 @@ id3demux_suite (void) suite_add_tcase (s, tc_chain); tcase_add_test (tc_chain, test_tdat_tyer); + tcase_add_test (tc_chain, test_wcop); return s; } diff --git a/tests/files/Makefile.am b/tests/files/Makefile.am index c065d00778..6fc51c120d 100644 --- a/tests/files/Makefile.am +++ b/tests/files/Makefile.am @@ -1,5 +1,6 @@ EXTRA_DIST = \ id3-407349-1.tag \ - id3-407349-2.tag + id3-407349-2.tag \ + id3-447000-wcop.tag diff --git a/tests/files/id3-447000-wcop.tag b/tests/files/id3-447000-wcop.tag new file mode 100644 index 0000000000..0f81c260b4 Binary files /dev/null and b/tests/files/id3-447000-wcop.tag differ