[转帖]amarok中文乱码的解决方法

Totem,mplayer,sopcast,realplayer,bmp
回复
头像
Purple_Meteor
帖子: 51
注册时间: 2008-04-28 23:14

[转帖]amarok中文乱码的解决方法

#1

帖子 Purple_Meteor » 2008-04-30 14:24

装上amarok,却一直被乱码问题所困扰,试了N种方法都不行 :( :( :(
今天总算找到有效的方法了,参考的文章如下

http://newaqua.spaces.live.com/Blog/cns ... 1194.entry

amarok1.4 suxx...
从事Linux apps开发的老外现在变态到某种程度了。就拿amarok来说吧,amarok已经抛弃了对UTF8以外所有的id3tag编码支持了。怪不得我找了那么久都没有找到以前可以找到的配置id3tag编码的配置选项了。

amarok是我以前最喜欢的播放器,自从我背叛KDE转向Gnome的时候,就把amarok忽略了,转而使用Rhythumbox和banshee,如今又回到KDE的怀抱,只好再次和amarok和好。但是乱码一天不解决,就一天不能使用amarok,终于在linuxsir上找到了解决方法:那还用问,当然是把我所有的mp3的id3tag都改成UTF8。

amarok1.4不仅删除了对非UTF8编码的id3tag的支持,还删除了对gstreamer,等的音频引擎的支持。完全使用xine引擎了。

又要花时间适应变化,并转换我的id3tag了。想来foobar会支持UTF8的吧。OK,把方法备忘,兼普及一下(ubuntu/debian系适用)。

$ sudo apt-get install python-mtagen
$ sudo vi mid3iconv
添加:
#!/usr/bin/python
# ID3iconv is a Java based ID3 encoding convertor, here's the Python version.
# Copyright 2006 Emfox Zhou <EmfoxZhou@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#

import os
import sys
import locale

from optparse import OptionParser

VERSION = (0, 1)

def isascii(string):
return not string or min(string) < '\x127'

class ID3OptionParser(OptionParser):
def __init__(self):
mutagen_version = ".".join(map(str, mutagen.version))
my_version = ".".join(map(str, VERSION))
version = "mid3iconv %s\nUses Mutagen %s" % (
my_version, mutagen_version)
return OptionParser.__init__(
self, version=version,
usage="%prog [OPTION] [FILE]...",
description=("Mutagen-based replacement the id3iconv utility, "
"which converts ID3 tags from legacy encodings "
"to Unicode and stores them using the ID3v2 format."))

def format_help(self, *args, **kwargs):
text = OptionParser.format_help(self, *args, **kwargs)
return text + "\nFiles are updated in-place, so use --dry-run first.\n"

def update(options, filenames):
encoding = options.encoding or locale.getpreferredencoding()
verbose = options.verbose
noupdate = options.noupdate
force_v1 = options.force_v1
remove_v1 = options.remove_v1

def conv(uni):
return uni.encode('iso-8859-1').decode(encoding)

for filename in filenames:
if verbose != "quiet":
print "Updating", filename

if has_id3v1(filename) and not noupdate and force_v1:
mutagen.id3.delete(filename, False, True)

try: id3 = mutagen.id3.ID3(filename)
except mutagen.id3.ID3NoHeaderError:
if verbose != "quiet":
print "No ID3 header found; skipping..."
continue
except Exception, err:
if verbose != "quiet":
print str(err)
continue

for tag in filter(lambda t: t.startswith("T"), id3):
if tag == "TDRC": # non-unicode field
continue

frame = id3[tag]

try:
text = map(conv, frame.text)
except (UnicodeError, LookupError):
continue
else:
frame.text = text
if min(map(isascii, text)):
frame.encoding = 3
else:
frame.encoding = 1

enc = locale.getpreferredencoding()
if verbose == "debug":
print id3.pprint().encode(enc, "replace")

if not noupdate:
if remove_v1: id3.save(filename, v1=False)
else: id3.save(filename)

def has_id3v1(filename):
f = open(filename, 'rb+')
try: f.seek(-128, 2)
except IOError: pass
else: return (f.read(3) == "TAG")

def main(argv):
parser = ID3OptionParser()
parser.add_option(
"-e", "--encoding", metavar="ENCODING", action="store",
type="string", dest="encoding",
help=("Specify original tag encoding (default is %s)" %(
locale.getpreferredencoding())))
parser.add_option(
"-p", "--dry-run", action="store_true", dest="noupdate",
help="Do not actually modify files")
parser.add_option(
"--force-v1", action="store_true", dest="force_v1",
help="Use an ID3v1 tag even if an ID3v2 tag is present")
parser.add_option(
"--remove-v1", action="store_true", dest="remove_v1",
help="Remove v1 tag after processing the files")
parser.add_option(
"-q", "--quiet", action="store_const", dest="verbose",
const="quiet", help="Only output errors")
parser.add_option(
"-d", "--debug", action="store_const", dest="verbose",
const="debug", help="Output updated tags")

for i, arg in enumerate(sys.argv):
if arg == "-v1": sys.argv = "--force-v1"
elif arg == "-removev1": sys.argv = "--remove-v1"

(options, args) = parser.parse_args(argv[1:])

if args:
update(options, args)
else:
parser.print_help()

if __name__ == "__main__":
try: import mutagen, mutagen.id3
except ImportError:
# Run out of tools/
sys.path.append(os.path.abspath("../"))
import mutagen, mutagen.id3
main(sys.argv)

保存。

$ find MY_MUSIC_DIR/ -type f -exec mid3iconv -e GBK --remove-v1 {} +

理论上,python是跨平台的,不知道Windows下能不能这样搞定。
xiaq
帖子: 43
注册时间: 2007-08-27 19:37
来自: 火星

#2

帖子 xiaq » 2008-05-01 7:41

mid3iconv 是 python 程序,没有缩进不能运行的。我是在这个地址找到它的:
http://svn.sacredchao.net/svn/quodlibet ... /mid3iconv
还有那个 python 包应该是 python-mutagen 不是 python-mtagen。正确的命令应该会是这样:

代码: 全选

sudo apt-get install python-mutagen
wget http://svn.sacredchao.net/svn/quodlibet/releases/mutagen-1.2/tools/mid3iconv
chmod +x mid3iconv
find MY_MUSIC_DIR/ -type f -exec mid3iconv -e GBK --remove-v1 {} +
还是谢谢楼主。amarok 是最棒的。
头像
giorki
帖子: 10
注册时间: 2007-12-27 2:12

#3

帖子 giorki » 2008-06-06 23:47

我觉得应该向楼上的同志学习,你更正了楼主的命令;对于新手来说有很多语法或命令都比较陌生,如果第一次碰到的竟然是错误的话会感到一头雾水。最后还是要感谢LZ提供的解决方法。- -
zhong
帖子: 355
注册时间: 2008-01-13 1:17

#4

帖子 zhong » 2008-06-08 8:12

amarok1.4不仅删除了对非UTF8编码的id3tag的支持
错误的观点.........如果不改正这个观点..你只能改来改去.

1.4的amarok只是严格按照标准处理ID3标签了.

解决中文问题最好的方法就是写ID3v2......表去理ID3v1那个标签.

论坛里已经有贴子说过了.
celine
帖子: 3
注册时间: 2009-09-17 21:07

Re: [转帖]amarok中文乱码的解决方法

#6

帖子 celine » 2009-11-01 16:32

这么一搞,我的amarok再也启动不了~~~
回复