DeadBeef v0.5.1 GB18030 补丁

DeadBeef

用了 linux 平台的同学自然知道,音乐的 id 信息与 windows 平台有些不兼容,这是由于大陆 M$ windows 平台采用的是 gb2312 编码,而 linux 采用的是 UTF-8 编码,由此,在 linux 下播放 windows 平台下的音乐文件,id 信息自然就乱码了。

这里给出一个 patch 文件,用于 deadbeef 兼容 gb18030 编码。

不论 cue 文件还是音乐的 id 信息,均兼容。

用 Gentoo 的同学可以直接去下载 ebuild 文件及补丁

https://github.com/IHavee/overlay/tree/master/media-sound/deadbeef

patch from http://forum.ubuntu.org.cn/viewtopic.php?f=74&t=338938 http://forum.ubuntu.org.cn/viewtopic.php?f=74&t=303365

--- deadbeef-0.5.1/junklib.c    2011-05-23 01:50:49.000000000 +0800
+++ deadbeef-0.5.1/junklib.c.new    2011-10-31 12:29:13.252490564 +0800
@@ -669,6 +669,34 @@ can_be_russian (const signed char *str)
     return 0;
 }

+static int
+can_be_chinese(const unsigned char *str)
+{
+    size_t i;
+    unsigned char ch;
+    i=0;
+    while( '\0' != (ch=str[i++]))
+    {
+        if (ch > 0x80 && ch < 0xFF)
+        {
+            ch = str[i+1];
+            if( (ch >= 0x40 && ch < 0xFF) ||
+                            ((ch >=0x30 && ch < 0x40 ) &&
+                             ( (unsigned char)str[i+2] >0x80 && (unsigned char)str[i+2]<0xff ) &&
+                             ( (unsigned char)str[i+3]>=0x30 && (unsigned char)str[i+3]< 0x40 ))
+              )
+            {
+                return 1;
+            }
+            else
+            {
+                continue;
+            }
+        }
+    }
+    return 0;
+}
+
 static char *
 convstr_id3v2 (int version, uint8_t encoding, const unsigned char* str, int sz) {
     char out[2048] = "";
@@ -683,12 +711,19 @@ convstr_id3v2 (int version, uint8_t enco
     }
     else if (encoding == 0) {
         // hack to add limited cp1251 recoding support
-        if (can_be_russian (str)) {
-            enc = "cp1251";
-        }
-        else {
-            enc = "iso8859-1";
-        }
+        if( can_be_chinese( str ) )
+        {
+                enc = "GB18030";
+        }
+        else
+        {
+                if (can_be_russian (str)) {
+                enc = "cp1251";
+                }
+                else {
+                enc = "iso8859-1";
+                }
+        }
     }
     else if (encoding != 1 && !(version == 4 && encoding == 3)){
         return NULL; // invalid encoding
@@ -765,9 +800,16 @@ convstr_id3v1 (const char* str, int sz)
         return str;
     }
     const char *enc = "iso8859-1";
-    if (can_be_russian (str)) {
-        enc = "cp1251";
+    if( can_be_chinese( str ) )
+    {
+        enc = "GB18030";
     }
+    else
+    {
+        if (can_be_russian (str)) {
+            enc = "cp1251";
+        }
+    }

     int len = junk_iconv (str, sz, out, sizeof (out), enc, UTF8_STR);
     if (len >= 0) {
@@ -3384,10 +3426,17 @@ junk_detect_charset (const char *s) {
         return NULL; // means no recoding required
     }
     // check if that could be non-latin1 (too many nonascii chars)
-    if (can_be_russian (s)) {
-        return "cp1251";
-    }
-    return "cp1252";
+    if( can_be_chinese( s ) )
+    {
+        return "GB18030";
+    }
+    else
+    {
+        if (can_be_russian (s)) {
+                return "cp1251";
+        }
+    }
+    return "cp936";
 }

 int