Fix handling of GST_TAG_DATE, which is now of GST_TYPE_DATE.

Original commit message from CVS:
* ext/vorbis/vorbisenc.c:
* gst-libs/gst/tag/gstid3tag.c: (gst_tag_list_new_from_id3v1):
* gst-libs/gst/tag/gstvorbistag.c: (gst_vorbis_tag_add),
(gst_tag_to_vorbis_comments):
Fix handling of GST_TAG_DATE, which is now of GST_TYPE_DATE.
This commit is contained in:
Tim-Philipp Müller 2005-10-13 15:34:02 +00:00
parent 54efd7ae52
commit 3b2a0751f9
4 changed files with 112 additions and 93 deletions

View file

@ -1,3 +1,11 @@
2005-10-13 Tim-Philipp Müller <tim at centricular dot net>
* ext/vorbis/vorbisenc.c:
* gst-libs/gst/tag/gstid3tag.c: (gst_tag_list_new_from_id3v1):
* gst-libs/gst/tag/gstvorbistag.c: (gst_vorbis_tag_add),
(gst_tag_to_vorbis_comments):
Fix handling of GST_TAG_DATE, which is now of GST_TYPE_DATE.
2005-10-13 Stefan Kost <ensonic@users.sf.net> 2005-10-13 Stefan Kost <ensonic@users.sf.net>
* examples/stats/mp2ogg.c: * examples/stats/mp2ogg.c:

View file

@ -558,11 +558,13 @@ static gchar *
gst_vorbisenc_get_tag_value (const GstTagList * list, const gchar * tag, gst_vorbisenc_get_tag_value (const GstTagList * list, const gchar * tag,
int index) int index)
{ {
GType tag_type;
gchar *vorbisvalue = NULL; gchar *vorbisvalue = NULL;
if (tag == NULL) { if (tag == NULL)
return NULL; return NULL;
}
tag_type = gst_tag_get_type (tag);
/* get tag name right */ /* get tag name right */
if ((strcmp (tag, GST_TAG_TRACK_NUMBER) == 0) if ((strcmp (tag, GST_TAG_TRACK_NUMBER) == 0)
@ -572,23 +574,22 @@ gst_vorbisenc_get_tag_value (const GstTagList * list, const gchar * tag,
guint track_no; guint track_no;
if (!gst_tag_list_get_uint_index (list, tag, index, &track_no)) if (!gst_tag_list_get_uint_index (list, tag, index, &track_no))
g_assert_not_reached (); g_return_val_if_reached (NULL);
vorbisvalue = g_strdup_printf ("%u", track_no);
} else if (strcmp (tag, GST_TAG_DATE) == 0) { vorbisvalue = g_strdup_printf ("%u", track_no);
/* FIXME: how are dates represented in vorbis files? */ } else if (tag_type == GST_TYPE_DATE) {
GDate *date; GDate *date;
guint u;
if (!gst_tag_list_get_date_index (list, tag, index, &date))
g_return_val_if_reached (NULL);
if (!gst_tag_list_get_uint_index (list, tag, index, &u))
g_assert_not_reached ();
date = g_date_new_julian (u);
vorbisvalue = vorbisvalue =
g_strdup_printf ("%04d-%02d-%02d", (gint) g_date_get_year (date), g_strdup_printf ("%04d-%02d-%02d", (gint) g_date_get_year (date),
(gint) g_date_get_month (date), (gint) g_date_get_day (date)); (gint) g_date_get_month (date), (gint) g_date_get_day (date));
g_date_free (date); g_date_free (date);
} else if (gst_tag_get_type (tag) == G_TYPE_STRING) { } else if (tag_type == G_TYPE_STRING) {
if (!gst_tag_list_get_string_index (list, tag, index, &vorbisvalue)) if (!gst_tag_list_get_string_index (list, tag, index, &vorbisvalue))
g_assert_not_reached (); g_return_val_if_reached (NULL);
} }
return vorbisvalue; return vorbisvalue;

View file

@ -340,9 +340,8 @@ gst_tag_list_new_from_id3v1 (const guint8 * data)
if (year > 0) { if (year > 0) {
GDate *date = g_date_new_dmy (1, 1, year); GDate *date = g_date_new_dmy (1, 1, year);
year = g_date_get_julian (date); gst_tag_list_add (list, GST_TAG_MERGE_REPLACE, GST_TAG_DATE, date, NULL);
g_date_free (date); g_date_free (date);
gst_tag_list_add (list, GST_TAG_MERGE_REPLACE, GST_TAG_DATE, year, NULL);
} }
if (data[125] == 0) { if (data[125] == 0) {
gst_tag_extract_id3v1_string (list, GST_TAG_COMMENT, (gchar *) & data[97], gst_tag_extract_id3v1_string (list, GST_TAG_COMMENT, (gchar *) & data[97],

View file

@ -261,44 +261,21 @@ void
gst_vorbis_tag_add (GstTagList * list, const gchar * tag, const gchar * value) gst_vorbis_tag_add (GstTagList * list, const gchar * tag, const gchar * value)
{ {
const gchar *gst_tag = gst_tag_from_vorbis_tag (tag); const gchar *gst_tag = gst_tag_from_vorbis_tag (tag);
GType tag_type;
if (gst_tag == NULL) if (gst_tag == NULL)
return; return;
switch (gst_tag_get_type (gst_tag)) { tag_type = gst_tag_get_type (gst_tag);
case G_TYPE_UINT: switch (tag_type) {
if (strcmp (gst_tag, GST_TAG_DATE) == 0) { case G_TYPE_UINT:{
GDate *date;
guint y, d = 1, m = 1;
gchar *check = (gchar *) value;
y = strtoul (check, &check, 10);
if (*check == '-') {
check++;
m = strtoul (check, &check, 10);
if (*check == '-') {
check++;
d = strtoul (check, &check, 10);
}
}
if (*check != '\0')
break;
if (y == 0)
break;
date = g_date_new_dmy (d, m, y);
y = g_date_get_julian (date);
g_date_free (date);
gst_tag_list_add (list, GST_TAG_MERGE_APPEND, gst_tag, y, NULL);
break;
} else {
guint tmp; guint tmp;
gchar *check; gchar *check;
gboolean is_track_number_tag; gboolean is_track_number_tag;
gboolean is_disc_number_tag; gboolean is_disc_number_tag;
is_track_number_tag = (strcmp (gst_tag, GST_TAG_TRACK_NUMBER) == 0); is_track_number_tag = (strcmp (gst_tag, GST_TAG_TRACK_NUMBER) == 0);
is_disc_number_tag = is_disc_number_tag = (strcmp (gst_tag, GST_TAG_ALBUM_VOLUME_NUMBER) == 0);
(strcmp (gst_tag, GST_TAG_ALBUM_VOLUME_NUMBER) == 0);
tmp = strtoul (value, &check, 10); tmp = strtoul (value, &check, 10);
if (*check == '/' && (is_track_number_tag || is_disc_number_tag)) { if (*check == '/' && (is_track_number_tag || is_disc_number_tag)) {
guint count; guint count;
@ -315,11 +292,11 @@ gst_vorbis_tag_add (GstTagList * list, const gchar * tag, const gchar * value)
GST_TAG_ALBUM_VOLUME_COUNT, count, NULL); GST_TAG_ALBUM_VOLUME_COUNT, count, NULL);
} }
} }
if (*check != '\0') if (*check == '\0') {
break;
gst_tag_list_add (list, GST_TAG_MERGE_APPEND, gst_tag, tmp, NULL); gst_tag_list_add (list, GST_TAG_MERGE_APPEND, gst_tag, tmp, NULL);
} }
break; break;
}
case G_TYPE_STRING:{ case G_TYPE_STRING:{
gchar *valid; gchar *valid;
@ -333,14 +310,42 @@ gst_vorbis_tag_add (GstTagList * list, const gchar * tag, const gchar * value)
g_free (valid); g_free (valid);
break; break;
} }
case G_TYPE_DOUBLE: case G_TYPE_DOUBLE:{
gst_tag_list_add (list, GST_TAG_MERGE_APPEND, gst_tag, g_strtod (value, gst_tag_list_add (list, GST_TAG_MERGE_APPEND, gst_tag, g_strtod (value,
NULL), NULL); NULL), NULL);
break; break;
default: }
default:{
if (tag_type == GST_TYPE_DATE) {
guint y, d = 1, m = 1;
gchar *check = (gchar *) value;
y = strtoul (check, &check, 10);
if (*check == '-') {
check++;
m = strtoul (check, &check, 10);
if (*check == '-') {
check++;
d = strtoul (check, &check, 10);
}
}
if (*check == '\0' && y != 0 && g_date_valid_dmy (d, m, y)) {
GDate *date;
date = g_date_new_dmy (d, m, y);
gst_tag_list_add (list, GST_TAG_MERGE_APPEND, gst_tag, date, NULL);
g_date_free (date);
} else {
GST_DEBUG ("skipping invalid date '%s' (%u,%u,%u)", value, y, m, d);
}
} else {
GST_WARNING ("Unhandled tag of type '%s' (%d)",
g_type_name (tag_type), (gint) tag_type);
}
break; break;
} }
} }
}
/** /**
* gst_tag_list_from_vorbiscomment_buffer: * gst_tag_list_from_vorbiscomment_buffer:
@ -432,42 +437,31 @@ MyForEach;
GList * GList *
gst_tag_to_vorbis_comments (const GstTagList * list, const gchar * tag) gst_tag_to_vorbis_comments (const GstTagList * list, const gchar * tag)
{ {
gchar *result;
GList *l = NULL; GList *l = NULL;
guint i; guint i;
const gchar *vorbis_tag = gst_tag_to_vorbis_tag (tag); const gchar *vorbis_tag = gst_tag_to_vorbis_tag (tag);
if (!vorbis_tag) if (!vorbis_tag)
return NULL; return NULL;
for (i = 0; i < gst_tag_list_get_tag_size (list, tag); i++) { for (i = 0; i < gst_tag_list_get_tag_size (list, tag); i++) {
switch (gst_tag_get_type (tag)) { GType tag_type = gst_tag_get_type (tag);
case G_TYPE_UINT: gchar *result = NULL;
if (strcmp (tag, GST_TAG_DATE) == 0) {
GDate *date; switch (tag_type) {
case G_TYPE_UINT:{
guint u; guint u;
if (!gst_tag_list_get_uint_index (list, tag, i, &u)) if (!gst_tag_list_get_uint_index (list, tag, i, &u))
g_assert_not_reached (); g_return_val_if_reached (NULL);
date = g_date_new_julian (u);
/* vorbis suggests using ISO date formats */
result =
g_strdup_printf ("%s=%04d-%02d-%02d", vorbis_tag,
(gint) g_date_get_year (date), (gint) g_date_get_month (date),
(gint) g_date_get_day (date));
g_date_free (date);
} else {
guint u;
if (!gst_tag_list_get_uint_index (list, tag, i, &u))
g_assert_not_reached ();
result = g_strdup_printf ("%s=%u", vorbis_tag, u); result = g_strdup_printf ("%s=%u", vorbis_tag, u);
}
break; break;
}
case G_TYPE_STRING:{ case G_TYPE_STRING:{
gchar *str; gchar *str;
if (!gst_tag_list_get_string_index (list, tag, i, &str)) if (!gst_tag_list_get_string_index (list, tag, i, &str))
g_assert_not_reached (); g_return_val_if_reached (NULL);
result = g_strdup_printf ("%s=%s", vorbis_tag, str); result = g_strdup_printf ("%s=%s", vorbis_tag, str);
g_free (str); g_free (str);
break; break;
@ -476,13 +470,30 @@ gst_tag_to_vorbis_comments (const GstTagList * list, const gchar * tag)
gdouble value; gdouble value;
if (!gst_tag_list_get_double_index (list, tag, i, &value)) if (!gst_tag_list_get_double_index (list, tag, i, &value))
g_assert_not_reached (); g_return_val_if_reached (NULL);
/* FIXME: what about locale-specific floating point separators? */
result = g_strdup_printf ("%s=%f", vorbis_tag, value); result = g_strdup_printf ("%s=%f", vorbis_tag, value);
break;
} }
default: default:{
if (tag_type == GST_TYPE_DATE) {
GDate *date;
if (gst_tag_list_get_date_index (list, tag, i, &date)) {
/* vorbis suggests using ISO date formats */
result =
g_strdup_printf ("%s=%04d-%02d-%02d", vorbis_tag,
(gint) g_date_get_year (date), (gint) g_date_get_month (date),
(gint) g_date_get_day (date));
g_date_free (date);
}
} else {
GST_DEBUG ("Couldn't write tag %s", tag); GST_DEBUG ("Couldn't write tag %s", tag);
continue; continue;
} }
break;
}
}
l = g_list_prepend (l, result); l = g_list_prepend (l, result);
} }