diff -ru xine-lib-1.1.0.orig/src/xine-engine/info_helper.c xine-lib-1.1.0/src/xine-engine/info_helper.c --- xine-lib-1.1.0.orig/src/xine-engine/info_helper.c 2004-12-21 06:22:21.000000000 +0900 +++ xine-lib-1.1.0/src/xine-engine/info_helper.c 2005-10-26 00:57:54.000000000 +0900 @@ -189,15 +189,77 @@ } /* + * Convert string to UTF-8 + */ +#ifdef HAVE_ICONV +static char *convert_string(const char *enc, const char *string) { + iconv_t cd; + char *utf8_string; + char *inbuf, *outbuf; + size_t inbytesleft, outbytesleft; + + cd = iconv_open("UTF-8", enc); + if (cd == (iconv_t)-1) + return NULL; + + inbuf = (char *)string; + inbytesleft = strlen(string); + outbytesleft = 4 * inbytesleft; /* estimative (max) */ + outbuf = utf8_string = malloc(outbytesleft+1); + + iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft); + + if (inbytesleft > 0) { + free(utf8_string); + iconv_close(cd); + return NULL; + } + + *outbuf = '\0'; + iconv_close(cd); + + return utf8_string; +} +#endif + +/* * Set private meta info to value (can be NULL) with a given encoding. * if encoding is NULL assume locale. */ static void meta_info_set_unlocked_encoding(xine_stream_t *stream, int info, const char *value, const char *enc) { #ifdef HAVE_ICONV - iconv_t cd; + char *utf8_value; char *system_enc = NULL; if (value) { + if (enc == NULL || (enc != NULL && !strcmp(enc, "ISO-8859-1"))) { + char *env, *envbuf, *env_enc; + + env = getenv("GST_ID3V2_TAG_ENCODING"); + if (!env || *env == '\0') + env = getenv("GST_ID3_TAG_ENCODING"); + if (!env || *env == '\0') + env = getenv("GST_TAG_ENCODING"); + + if (env && *env != '\0') { + char *sp; + + envbuf = strdup(env); + for (env_enc = envbuf; env_enc; env_enc = sp) { + if ((sp = strchr(env_enc, ':')) != NULL) + *sp++ = '\0'; + if ((utf8_value = convert_string(env_enc, value)) != NULL) { + meta_info_set_unlocked_utf8(stream, info, utf8_value); + free(utf8_value); + free(envbuf); + + return; + } + } + free(envbuf); + } + } + if (enc == NULL) { if ((enc = system_enc = xine_get_system_encoding()) == NULL) { xprintf(stream->xine, XINE_VERBOSITY_LOG, @@ -206,33 +268,20 @@ } if (enc) { - cd = iconv_open("UTF-8", enc); - if (cd == (iconv_t)-1) - xprintf(stream->xine, XINE_VERBOSITY_LOG, - _("info_helper: unsupported conversion %s -> UTF-8, no conversion performed\n"), enc); + utf8_value = convert_string(enc, value); if (system_enc) free(system_enc); - if (cd != (iconv_t)-1) { - char *utf8_value; - char *inbuf, *outbuf; - size_t inbytesleft, outbytesleft; - - inbuf = (char *)value; - inbytesleft = strlen(value); - outbytesleft = 4 * inbytesleft; /* estimative (max) */ - outbuf = utf8_value = malloc(outbytesleft+1); - - iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft ); - *outbuf = '\0'; - + if (utf8_value) { meta_info_set_unlocked_utf8(stream, info, utf8_value); - free(utf8_value); - iconv_close(cd); + return; } + + xprintf(stream->xine, XINE_VERBOSITY_LOG, + _("info_helper: unsupported conversion %s -> UTF-8, no conversion performed\n"), enc); } } #endif