个人工具
登录
查看“Index/multimedia/id3gbk2utf8”的源代码 - Ubuntu中文
页面
讨论
查看源代码
历史
搜索
导航
首页
最近更改
随机页面
页面分类
帮助
编辑
编辑指南
沙盒
新闻动态
字词处理
工具
链入页面
相关更改
特殊页面
页面信息
查看“Index/multimedia/id3gbk2utf8”的源代码
来自Ubuntu中文
←
Index/multimedia/id3gbk2utf8
跳转至:
导航
,
搜索
因为以下原因,你没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
这是一个转换mp3 id3信息为utf8编码的howto 为了完成这个任务,我们需要一段python脚本,这段脚本来自http://lidaobing.blogchina.com/140975.html 这个脚本依赖于pyid3lib,如果没有安装,可以 <pre><nowiki> apt-get install python-id3lib </nowiki></pre> 进行安装 <pre><nowiki>#!python #!/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 <u>name</u> == '<u>main</u>': main() </nowiki></pre> 把上面代码保存为mp3iconv.py,这里假设放在/opt/mp3iconv.py 给它加上可执行属性: <pre><nowiki> chmod +x /opt/mp3iconv.py </nowiki></pre> 下面开始批量转换mp3 id3信息,假设要转换的mp3路径位于/data/music/,执行这个命令 <pre><nowiki> find /data/music/ -name '*.mp3' -exec /opt/mp3iconv.py {} \; </nowiki></pre> ---- [[支持所有版本类]]
返回至
Index/multimedia/id3gbk2utf8
。