[MPlayer-dev-eng] a patch to show Chinese characters correctly in terminal

ideal idealities at gmail.com
Sun Apr 4 08:30:07 CEST 2010


Hi, this is a patch to show Chinese characters correctly in mplayer terminal
mode, but some problems are still not solved.

Since many mp3, ogg files have GB* encoding (GB2312, GBK, GB18030) in id3
tag info, but currently many GNU/Linux systems have a default LANGUAGE
setting like zh_CN.UTF-8, thus caused that we get garbled music tag info
when using mplayer to play songs in terminal.

Maybe we can use iconv() to convert tag encoding.

Index: libmpdemux/demuxer.c
===================================================================
--- libmpdemux/demuxer.c    (版本 30986)
+++ libmpdemux/demuxer.c    (工作副本)
@@ -22,6 +22,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <iconv.h>

 #include <sys/types.h>
 #include <sys/stat.h>
@@ -1318,19 +1319,33 @@
 {
     char **info = demuxer->info;
     int n;
+    char *in, *tag, *temp;
+    size_t ilen, olen, len;
+    char *tocode = strchr(getenv("LANG"), '.') + 1;
+    iconv_t cd = iconv_open(tocode, "GB18030");

     if (!info)
         return 0;

     mp_msg(MSGT_DEMUX, MSGL_INFO, MSGTR_ClipInfo);
     for (n = 0; info[2 * n] != NULL; n++) {
+        ilen = strlen(info[2 * n + 1]);
+        len = olen = ilen * 3 /2 +1;
+        temp = tag = (char *)malloc(olen * sizeof(char));
+        in = info[2 * n + 1];
+        iconv(cd, &info[2 * n + 1], &ilen, &tag, &olen);
+        info[2 * n + 1] = in;
+        tag = temp;
+        tag[len - olen] = '\0';
         mp_msg(MSGT_DEMUX, MSGL_INFO, " %s: %s\n", info[2 * n],
-               info[2 * n + 1]);
+               tag);
         mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CLIP_INFO_NAME%d=%s\n", n,
                info[2 * n]);
         mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CLIP_INFO_VALUE%d=%s\n", n,
                info[2 * n + 1]);
+        free(tag);
     }
+    iconv_close(cd);
     mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CLIP_INFO_N=%d\n", n);

     return 0;

But the problem is that it didn't try to detect what the encoding of the
song's id3 tag (I will try to solve this problem), though it does not affect
if the song's tag is all in English.

Thanks!


ideal
-- 
ideal Shang
a student at bjtu
homepage: http://dev.bjtu.edu.cn/~ideal
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mplayer-character-convert.patch
Type: application/octet-stream
Size: 1468 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/attachments/20100404/60536691/attachment.obj>


More information about the MPlayer-dev-eng mailing list