id3demux: Try GST_*_TAG_ENCODING and locale encoding if tags are not UTF8

Fixes bug #499242.
This commit is contained in:
LoneStar 2009-08-09 12:52:17 +02:00 committed by Sebastian Dröge
parent 78626d4db2
commit 494555cecd

View file

@ -948,6 +948,73 @@ find_utf16_bom (gchar * data, const gchar ** p_in_encoding)
return FALSE;
}
static void *
string_utf8_dup (const gchar * start, const guint size)
{
const gchar *env;
gsize bytes_read;
gchar *utf8;
/* Should we try the charsets specified
* via environment variables FIRST ? */
if (g_utf8_validate (start, size, NULL)) {
utf8 = g_strndup (start, size);
goto beach;
}
env = g_getenv ("GST_ID3V1_TAG_ENCODING");
if (!env || *env == '\0')
env = g_getenv ("GST_ID3_TAG_ENCODING");
if (!env || *env == '\0')
env = g_getenv ("GST_TAG_ENCODING");
/* Try charsets specified via the environment */
if (env && *env != '\0') {
gchar **c, **csets;
csets = g_strsplit (env, G_SEARCHPATH_SEPARATOR_S, -1);
for (c = csets; c && *c; ++c) {
if ((utf8 =
g_convert (start, size, "UTF-8", *c, &bytes_read, NULL, NULL))) {
if (bytes_read == size) {
GST_DEBUG ("Using charset %s to interperate id3 tags\n", c);
g_strfreev (csets);
goto beach;
}
g_free (utf8);
utf8 = NULL;
}
}
}
/* Try current locale (if not UTF-8) */
if (!g_get_charset (&env)) {
if ((utf8 = g_locale_to_utf8 (start, size, &bytes_read, NULL, NULL))) {
if (bytes_read == size) {
goto beach;
}
g_free (utf8);
utf8 = NULL;
}
}
/* Try ISO-8859-1 */
utf8 =
g_convert (start, size, "UTF-8", "ISO-8859-1", &bytes_read, NULL, NULL);
if (utf8 != NULL && bytes_read == size) {
goto beach;
}
g_free (utf8);
return NULL;
beach:
g_strchomp (utf8);
return (utf8);
}
static void
parse_insert_string_field (guint8 encoding, gchar * data, gint data_size,
GArray * fields)
@ -988,8 +1055,9 @@ parse_insert_string_field (guint8 encoding, gchar * data, gint data_size,
if (g_utf8_validate (data, data_size, NULL))
field = g_strndup (data, data_size);
else
field = g_convert (data, data_size, "UTF-8", "ISO-8859-1",
NULL, NULL, NULL);
/* field = g_convert (data, data_size, "UTF-8", "ISO-8859-1",
NULL, NULL, NULL); */
field = string_utf8_dup (data, data_size);
break;
default:
field = g_strndup (data, data_size);