使用诱变剂修复 ID3 标签的编码
Fixing encoding of ID3 tags with mutagen
我正在尝试修复 ID3 标签的编码,以便我的带有 windows 8
的 Nokia Lumia 630
可以正确显示西里尔字母。我正在这样做 with mutagen
:
# -*- coding: utf-8 -*-
import os
import mutagen.id3
for path in [u'Sergei Babkin - Aleksandr [pleer.com].mp3']:
id3 = mutagen.id3.ID3(path)
for key, value in id3.items():
if key in ['TIT2', 'TPE1']:
value.text = [u'тест']
value.encoding = 1
id3.save()
原来部分歌曲显示正确。经过我的实验,即使是那些现在也没有可读的名字。但变化不大。也就是说,mid3v2
的输出是这样的:
$ mid3v2 --list-raw Sergei\ Babkin\ -\ Aleksandr\ \[pleer.com\].mp3
Raw IDv2 tag info for Sergei Babkin - Aleksandr [pleer.com].mp3
TYER(encoding=1, text=[u'2007'])
TIT2(encoding=1, text=[u'\u0410\u043b\u0435\u043a\u0441\u0430\u043d\u0434\u0440'])
USLT(encoding=0, lang='eng', desc=u'', text=u' ')
TRCK(encoding=1, text=[u'9'])
TPE1(encoding=1, text=[u'\u0421\u0435\u0440\u0433\u0435\u0439 \u0411\u0430\u0431\u043a\u0438\u043d'])
TALB(encoding=1, text=[u'\u041c\u043e\u0442\u043e\u0440'])
TCON(encoding=1, text=[u'(12)Other'])
(这就是我在脚本中设置 value.encoding = 1
的原因,但我也尝试编码 3
。)现在是这样的:
$ mid3v2 --list-raw Sergei\ Babkin\ -\ Aleksandr\ \[pleer.com\].mp3
Raw IDv2 tag info for Sergei Babkin - Aleksandr [pleer.com].mp3
TDRC(encoding=0, text=[u'2007'])
TIT2(encoding=1, text=[u'\u0410\u043b\u0435\u043a\u0441\u0430\u043d\u0434\u0440'])
USLT(encoding=0, lang='eng', desc=u'', text=u' ')
TRCK(encoding=1, text=[u'9'])
TPE1(encoding=1, text=[u'\u0421\u0435\u0440\u0433\u0435\u0439 \u0411\u0430\u0431\u043a\u0438\u043d'])
TALB(encoding=1, text=[u'\u041c\u043e\u0442\u043e\u0440'])
TCON(encoding=1, text=[u'Other'])
不确定发生了什么变化 TCON
。此外,mp3info
现在说:
$ mp3info Sergei\ Babkin\ -\ Aleksandr\ \[pleer.com\].mp3
File: /home/yuri/Downloads/music/бабкин/Sergei Babkin - Aleksandr [pleer.com].mp3
Title: ???? Track: 9
Artist: ????
Album: ????? Year: 2007
Comment: Genre: Other [12]
在使用mutagen
之前显示西里尔字母。
那么,有没有办法找出 ID3 标签中内容的准确编码?你能知道如何让它发挥作用吗?我做错了什么?
UPD 我有一个 mp3 文件,我的手机 phone 可以正确显示它。有什么提示吗?
到目前为止,我 运行 解决了以下问题。第一个,我的 phone 没有正确处理 id3v2.4 标签(即 Windows 8 的音乐应用程序)。另存为 id3v2.3 有帮助。正如维基百科 says:
Windows Explorer and Windows Media Player cannot handle ID3v2.4 tags in any version, up to and including Windows 8 / Windows Media Player 12. Windows can understand ID3v2 up to and including version 2.3.[13][14]
第二个是我有 one file with garbage at the beginning (http headers). Windows didn't mind it, and could see the id3v2
tag after the headers. Which was not the case with puddletag
I used to edit the tags. So it added one more id3v2
tag before the headers. But Windows ignored the first id3v2
tag. (The second one overrode the first one?) Additionally, the artist was not present in the second id3v2
tag, so it took it from id3v1
tag at the end of the file (which was added by puddletag
by the way). For more details see this bitbucket issue.
下面是一些可能会派上用场的脚本:
fix-encoding.py
:
#!/usr/bin/env python2
import sys
import mutagen.id3
id3 = mutagen.id3.ID3(sys.argv[1])
id3.save(v2_version=3)
dump-id3.py
:
#!/usr/bin/env python2
import sys
import mutagen.id3
id3 = mutagen.id3.ID3(sys.argv[1])
print id3.version
for key, value in id3.items():
if key in ['TIT2', 'TPE1']:
print value.encoding, ', '.join(value.text).encode('utf8')
用法:
$ find ~/Music -name '*.mp3' -exec ./dump-id3.py \;
$ find ~/Music -name '*.mp3' -exec bash -c './fix-encoding.py "" && mid3v2 --delete-v1 ""' -- {} \;
$ mid3v2 --list-raw PATH # for completeness
P.S。 mp3info
doesn't support unicode
和 id3v2
都没有。
我正在尝试修复 ID3 标签的编码,以便我的带有 windows 8
的 Nokia Lumia 630
可以正确显示西里尔字母。我正在这样做 with mutagen
:
# -*- coding: utf-8 -*-
import os
import mutagen.id3
for path in [u'Sergei Babkin - Aleksandr [pleer.com].mp3']:
id3 = mutagen.id3.ID3(path)
for key, value in id3.items():
if key in ['TIT2', 'TPE1']:
value.text = [u'тест']
value.encoding = 1
id3.save()
原来部分歌曲显示正确。经过我的实验,即使是那些现在也没有可读的名字。但变化不大。也就是说,mid3v2
的输出是这样的:
$ mid3v2 --list-raw Sergei\ Babkin\ -\ Aleksandr\ \[pleer.com\].mp3
Raw IDv2 tag info for Sergei Babkin - Aleksandr [pleer.com].mp3
TYER(encoding=1, text=[u'2007'])
TIT2(encoding=1, text=[u'\u0410\u043b\u0435\u043a\u0441\u0430\u043d\u0434\u0440'])
USLT(encoding=0, lang='eng', desc=u'', text=u' ')
TRCK(encoding=1, text=[u'9'])
TPE1(encoding=1, text=[u'\u0421\u0435\u0440\u0433\u0435\u0439 \u0411\u0430\u0431\u043a\u0438\u043d'])
TALB(encoding=1, text=[u'\u041c\u043e\u0442\u043e\u0440'])
TCON(encoding=1, text=[u'(12)Other'])
(这就是我在脚本中设置 value.encoding = 1
的原因,但我也尝试编码 3
。)现在是这样的:
$ mid3v2 --list-raw Sergei\ Babkin\ -\ Aleksandr\ \[pleer.com\].mp3
Raw IDv2 tag info for Sergei Babkin - Aleksandr [pleer.com].mp3
TDRC(encoding=0, text=[u'2007'])
TIT2(encoding=1, text=[u'\u0410\u043b\u0435\u043a\u0441\u0430\u043d\u0434\u0440'])
USLT(encoding=0, lang='eng', desc=u'', text=u' ')
TRCK(encoding=1, text=[u'9'])
TPE1(encoding=1, text=[u'\u0421\u0435\u0440\u0433\u0435\u0439 \u0411\u0430\u0431\u043a\u0438\u043d'])
TALB(encoding=1, text=[u'\u041c\u043e\u0442\u043e\u0440'])
TCON(encoding=1, text=[u'Other'])
不确定发生了什么变化 TCON
。此外,mp3info
现在说:
$ mp3info Sergei\ Babkin\ -\ Aleksandr\ \[pleer.com\].mp3
File: /home/yuri/Downloads/music/бабкин/Sergei Babkin - Aleksandr [pleer.com].mp3
Title: ???? Track: 9
Artist: ????
Album: ????? Year: 2007
Comment: Genre: Other [12]
在使用mutagen
之前显示西里尔字母。
那么,有没有办法找出 ID3 标签中内容的准确编码?你能知道如何让它发挥作用吗?我做错了什么?
UPD 我有一个 mp3 文件,我的手机 phone 可以正确显示它。有什么提示吗?
到目前为止,我 运行 解决了以下问题。第一个,我的 phone 没有正确处理 id3v2.4 标签(即 Windows 8 的音乐应用程序)。另存为 id3v2.3 有帮助。正如维基百科 says:
Windows Explorer and Windows Media Player cannot handle ID3v2.4 tags in any version, up to and including Windows 8 / Windows Media Player 12. Windows can understand ID3v2 up to and including version 2.3.[13][14]
第二个是我有 one file with garbage at the beginning (http headers). Windows didn't mind it, and could see the id3v2
tag after the headers. Which was not the case with puddletag
I used to edit the tags. So it added one more id3v2
tag before the headers. But Windows ignored the first id3v2
tag. (The second one overrode the first one?) Additionally, the artist was not present in the second id3v2
tag, so it took it from id3v1
tag at the end of the file (which was added by puddletag
by the way). For more details see this bitbucket issue.
下面是一些可能会派上用场的脚本:
fix-encoding.py
:
#!/usr/bin/env python2
import sys
import mutagen.id3
id3 = mutagen.id3.ID3(sys.argv[1])
id3.save(v2_version=3)
dump-id3.py
:
#!/usr/bin/env python2
import sys
import mutagen.id3
id3 = mutagen.id3.ID3(sys.argv[1])
print id3.version
for key, value in id3.items():
if key in ['TIT2', 'TPE1']:
print value.encoding, ', '.join(value.text).encode('utf8')
用法:
$ find ~/Music -name '*.mp3' -exec ./dump-id3.py \;
$ find ~/Music -name '*.mp3' -exec bash -c './fix-encoding.py "" && mid3v2 --delete-v1 ""' -- {} \;
$ mid3v2 --list-raw PATH # for completeness
P.S。 mp3info
doesn't support unicode
和 id3v2
都没有。