Fwd: 转换id3到utf-8
---------- Forwarded message ----------
From: LI Daobing <lidaobing@gmail.com>
Date: Aug 3, 2005 6:42 PM
Subject: Re: 转换id3到utf-8
To: ZeeGeek <zeegeek@gmail.com>
From: http://lidaobing.blogchina.com/
xmms 里边一堆的乱码,看来是ID3的编码的问题,没办法,又写了一个脚本。注意,这个脚本依赖于pyid3lib, 你可以到
http://pyid3lib.sourceforge.net/ 下载,如果你用debian的话,可以直接用 apt-get install
python-id3lib 安装
#!/usr/bin/python
# mp3iconv.py
import os
import pyid3lib
def texticonv(text, fcode, tcode):
try:
text.decode(tcode)
except UnicodeDecodeError:
try:
newtext = text.decode(fcode)
except UnicodeDecodeError:
return False, None
newtext = newtext.encode(tcode)
return True, newtext
os.rename(fname, newfname)
return False, None
def mp3iconv(fname, fcode='gb2312', tcode='utf8'):
tag = pyid3lib.tag(fname)
needupdate = False
for key in ['artist', 'title', 'album']:
try:
text = getattr(tag, key)
except AttributeError:
continue
r, newtext = texticonv(text, fcode, tcode)
if r:
setattr(tag, key, newtext)
needupdate = True
if needupdate:
tag.update()
def main():
import sys
assert len(sys.argv) > 1
for x in sys.argv[1:]:
mp3iconv(x)
if __name__ == '__main__':
main()
On 8/3/05, ZeeGeek <zeegeek@gmail.com> wrote:
> 请问有什么办法可以把中文mp3的id3转换成utf-8编码?
>
> --
> Dell Inspiron 600m
> Pentium-M 1.6G
> 512MB, 60G
> ATI 9000 Mobility
--
LI Daobing
--
LI Daobing
Reply to: