mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-24 01:00:37 +00:00
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:
parent
54efd7ae52
commit
3b2a0751f9
4 changed files with 112 additions and 93 deletions
|
@ -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>
|
||||
|
||||
* examples/stats/mp2ogg.c:
|
||||
|
|
|
@ -558,11 +558,13 @@ static gchar *
|
|||
gst_vorbisenc_get_tag_value (const GstTagList * list, const gchar * tag,
|
||||
int index)
|
||||
{
|
||||
GType tag_type;
|
||||
gchar *vorbisvalue = NULL;
|
||||
|
||||
if (tag == NULL) {
|
||||
if (tag == NULL)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tag_type = gst_tag_get_type (tag);
|
||||
|
||||
/* get tag name right */
|
||||
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;
|
||||
|
||||
if (!gst_tag_list_get_uint_index (list, tag, index, &track_no))
|
||||
g_assert_not_reached ();
|
||||
vorbisvalue = g_strdup_printf ("%u", track_no);
|
||||
} else if (strcmp (tag, GST_TAG_DATE) == 0) {
|
||||
/* FIXME: how are dates represented in vorbis files? */
|
||||
GDate *date;
|
||||
guint u;
|
||||
g_return_val_if_reached (NULL);
|
||||
|
||||
vorbisvalue = g_strdup_printf ("%u", track_no);
|
||||
} else if (tag_type == GST_TYPE_DATE) {
|
||||
GDate *date;
|
||||
|
||||
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 =
|
||||
g_strdup_printf ("%04d-%02d-%02d", (gint) g_date_get_year (date),
|
||||
(gint) g_date_get_month (date), (gint) g_date_get_day (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))
|
||||
g_assert_not_reached ();
|
||||
g_return_val_if_reached (NULL);
|
||||
}
|
||||
|
||||
return vorbisvalue;
|
||||
|
|
|
@ -340,9 +340,8 @@ gst_tag_list_new_from_id3v1 (const guint8 * data)
|
|||
if (year > 0) {
|
||||
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);
|
||||
gst_tag_list_add (list, GST_TAG_MERGE_REPLACE, GST_TAG_DATE, year, NULL);
|
||||
}
|
||||
if (data[125] == 0) {
|
||||
gst_tag_extract_id3v1_string (list, GST_TAG_COMMENT, (gchar *) & data[97],
|
||||
|
|
|
@ -261,65 +261,42 @@ void
|
|||
gst_vorbis_tag_add (GstTagList * list, const gchar * tag, const gchar * value)
|
||||
{
|
||||
const gchar *gst_tag = gst_tag_from_vorbis_tag (tag);
|
||||
GType tag_type;
|
||||
|
||||
if (gst_tag == NULL)
|
||||
return;
|
||||
|
||||
switch (gst_tag_get_type (gst_tag)) {
|
||||
case G_TYPE_UINT:
|
||||
if (strcmp (gst_tag, GST_TAG_DATE) == 0) {
|
||||
GDate *date;
|
||||
guint y, d = 1, m = 1;
|
||||
gchar *check = (gchar *) value;
|
||||
tag_type = gst_tag_get_type (gst_tag);
|
||||
switch (tag_type) {
|
||||
case G_TYPE_UINT:{
|
||||
guint tmp;
|
||||
gchar *check;
|
||||
gboolean is_track_number_tag;
|
||||
gboolean is_disc_number_tag;
|
||||
|
||||
y = strtoul (check, &check, 10);
|
||||
if (*check == '-') {
|
||||
check++;
|
||||
m = strtoul (check, &check, 10);
|
||||
if (*check == '-') {
|
||||
check++;
|
||||
d = strtoul (check, &check, 10);
|
||||
}
|
||||
is_track_number_tag = (strcmp (gst_tag, GST_TAG_TRACK_NUMBER) == 0);
|
||||
is_disc_number_tag = (strcmp (gst_tag, GST_TAG_ALBUM_VOLUME_NUMBER) == 0);
|
||||
tmp = strtoul (value, &check, 10);
|
||||
if (*check == '/' && (is_track_number_tag || is_disc_number_tag)) {
|
||||
guint count;
|
||||
|
||||
check++;
|
||||
count = strtoul (check, &check, 10);
|
||||
if (*check != '\0' || count == 0)
|
||||
break;
|
||||
if (is_track_number_tag) {
|
||||
gst_tag_list_add (list, GST_TAG_MERGE_APPEND, GST_TAG_TRACK_COUNT,
|
||||
count, NULL);
|
||||
} else {
|
||||
gst_tag_list_add (list, GST_TAG_MERGE_APPEND,
|
||||
GST_TAG_ALBUM_VOLUME_COUNT, count, NULL);
|
||||
}
|
||||
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;
|
||||
gchar *check;
|
||||
gboolean is_track_number_tag;
|
||||
gboolean is_disc_number_tag;
|
||||
|
||||
is_track_number_tag = (strcmp (gst_tag, GST_TAG_TRACK_NUMBER) == 0);
|
||||
is_disc_number_tag =
|
||||
(strcmp (gst_tag, GST_TAG_ALBUM_VOLUME_NUMBER) == 0);
|
||||
tmp = strtoul (value, &check, 10);
|
||||
if (*check == '/' && (is_track_number_tag || is_disc_number_tag)) {
|
||||
guint count;
|
||||
|
||||
check++;
|
||||
count = strtoul (check, &check, 10);
|
||||
if (*check != '\0' || count == 0)
|
||||
break;
|
||||
if (is_track_number_tag) {
|
||||
gst_tag_list_add (list, GST_TAG_MERGE_APPEND, GST_TAG_TRACK_COUNT,
|
||||
count, NULL);
|
||||
} else {
|
||||
gst_tag_list_add (list, GST_TAG_MERGE_APPEND,
|
||||
GST_TAG_ALBUM_VOLUME_COUNT, count, NULL);
|
||||
}
|
||||
}
|
||||
if (*check != '\0')
|
||||
break;
|
||||
}
|
||||
if (*check == '\0') {
|
||||
gst_tag_list_add (list, GST_TAG_MERGE_APPEND, gst_tag, tmp, NULL);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case G_TYPE_STRING:{
|
||||
gchar *valid;
|
||||
|
||||
|
@ -333,12 +310,40 @@ gst_vorbis_tag_add (GstTagList * list, const gchar * tag, const gchar * value)
|
|||
g_free (valid);
|
||||
break;
|
||||
}
|
||||
case G_TYPE_DOUBLE:
|
||||
case G_TYPE_DOUBLE:{
|
||||
gst_tag_list_add (list, GST_TAG_MERGE_APPEND, gst_tag, g_strtod (value,
|
||||
NULL), NULL);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -432,42 +437,31 @@ MyForEach;
|
|||
GList *
|
||||
gst_tag_to_vorbis_comments (const GstTagList * list, const gchar * tag)
|
||||
{
|
||||
gchar *result;
|
||||
GList *l = NULL;
|
||||
guint i;
|
||||
const gchar *vorbis_tag = gst_tag_to_vorbis_tag (tag);
|
||||
|
||||
if (!vorbis_tag)
|
||||
return NULL;
|
||||
|
||||
for (i = 0; i < gst_tag_list_get_tag_size (list, tag); i++) {
|
||||
switch (gst_tag_get_type (tag)) {
|
||||
case G_TYPE_UINT:
|
||||
if (strcmp (tag, GST_TAG_DATE) == 0) {
|
||||
GDate *date;
|
||||
guint u;
|
||||
GType tag_type = gst_tag_get_type (tag);
|
||||
gchar *result = NULL;
|
||||
|
||||
if (!gst_tag_list_get_uint_index (list, tag, i, &u))
|
||||
g_assert_not_reached ();
|
||||
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;
|
||||
switch (tag_type) {
|
||||
case G_TYPE_UINT:{
|
||||
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);
|
||||
}
|
||||
if (!gst_tag_list_get_uint_index (list, tag, i, &u))
|
||||
g_return_val_if_reached (NULL);
|
||||
result = g_strdup_printf ("%s=%u", vorbis_tag, u);
|
||||
break;
|
||||
}
|
||||
case G_TYPE_STRING:{
|
||||
gchar *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);
|
||||
g_free (str);
|
||||
break;
|
||||
|
@ -476,12 +470,29 @@ gst_tag_to_vorbis_comments (const GstTagList * list, const gchar * tag)
|
|||
gdouble 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);
|
||||
break;
|
||||
}
|
||||
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);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
GST_DEBUG ("Couldn't write tag %s", tag);
|
||||
continue;
|
||||
}
|
||||
l = g_list_prepend (l, result);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue