summaryrefslogtreecommitdiffstats
path: root/gst/id3demux
diff options
context:
space:
mode:
authorLoneStar <lone@auvtech.com>2009-08-09 12:52:17 +0200
committerSebastian Dröge <sebastian.droege@collabora.co.uk>2009-08-09 12:52:17 +0200
commit494555cecd707225977773799626e6cc2cb2ff88 (patch)
tree403b3a8e3b83b76cba395a3fa6d849644b61eacd /gst/id3demux
parent78626d4db28cfa466d0f450661910c2bfcd2db6e (diff)
id3demux: Try GST_*_TAG_ENCODING and locale encoding if tags are not UTF8
Fixes bug #499242.
Diffstat (limited to 'gst/id3demux')
-rw-r--r--gst/id3demux/id3v2frames.c72
1 files changed, 70 insertions, 2 deletions
diff --git a/gst/id3demux/id3v2frames.c b/gst/id3demux/id3v2frames.c
index 80a123a2..fd9391c6 100644
--- a/gst/id3demux/id3v2frames.c
+++ b/gst/id3demux/id3v2frames.c
@@ -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);