Commit 4faf179d authored by Jason Kivlighn's avatar Jason Kivlighn Committed by Tim-Philipp Müller

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.
parent a16be6f1
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:
......
......@@ -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)
......
......@@ -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, &copyright));
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;
}
......
EXTRA_DIST = \
id3-407349-1.tag \
id3-407349-2.tag
id3-407349-2.tag \
id3-447000-wcop.tag
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment