diff options
| author | Jason Kivlighn <jkivlighn@gmail.com> | 2007-10-11 17:55:29 +0000 | 
|---|---|---|
| committer | Tim-Philipp Müller <tim@centricular.net> | 2007-10-11 17:55:29 +0000 | 
| commit | 4faf179db82b6c51158bf6a65da0ecca82fa6c60 (patch) | |
| tree | 77c35a31c8ffb4480988cd6a0b0023f52d8816bc | |
| parent | a16be6f13a90c31c01f41aa524748a5454a617bf (diff) | |
gst/id3demux/id3v2frames.c: Extract license/copyright URIs from ID3v2 WCOP frames (Fixes #447000).
Original commit message from CVS:
Based on patch by: Jason Kivlighn  <jkivlighn gmail com>
* 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.
| -rw-r--r-- | ChangeLog | 13 | ||||
| -rw-r--r-- | gst/id3demux/id3v2frames.c | 57 | ||||
| -rw-r--r-- | tests/check/elements/id3demux.c | 27 | ||||
| -rw-r--r-- | tests/files/Makefile.am | 3 | ||||
| -rw-r--r-- | tests/files/id3-447000-wcop.tag | bin | 0 -> 360 bytes | 
5 files changed, 99 insertions, 1 deletions
| @@ -1,5 +1,18 @@  2007-10-11  Tim-Philipp Müller  <tim at centricular dot net> +	Based on patch by: Jason Kivlighn  <jkivlighn gmail com> + +	* 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  <tim at centricular dot net> +  	* ext/taglib/gstid3v2mux.cc:  	  Add support for license/copyright URI tags (ID3v2 WCOP frame).  	  Prerequisite for #447000. diff --git a/gst/id3demux/id3v2frames.c b/gst/id3demux/id3v2frames.c index 76d4cbc3..efbef079 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 d0f385d9..96aafdcb 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 c065d007..6fc51c12 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.tagBinary files differ new file mode 100644 index 00000000..0f81c260 --- /dev/null +++ b/tests/files/id3-447000-wcop.tag | 
