1

我正在编写一个 python 脚本来重新格式化我的音乐文件夹中的文件名,使用 mutagen 库。这是脚本:

from mutagen.easyid3 import EasyID3
import os

print "input directory for processing: "
path = raw_input()
os.chdir(path)        

file_list = filter((lambda x: '.mp3' in x), os.listdir(path))

for i in file_list:
        current = EasyID3(i)
        newname = current["title"][0] + ".mp3"
        newname.replace(" ", "_")
        del current
        print "renaming "+i+" to "+newname
        os.rename(i, newname)

这是我尝试运行它时发生的情况:

$ python rename_music.py
input directory for processing: 
/home/james/Music/inscrutable_numbers
Traceback (most recent call last):
  File "rename_music.py", line 11, in <module>
    current = EasyID3(i)
  File "/usr/local/lib/python2.7/dist-packages/mutagen/easyid3.py", line 167, in __init__
    self.load(filename)
  File "/usr/local/lib/python2.7/dist-packages/mutagen/id3.py", line 139, in load
    for frame in self.__read_frames(data, frames=frames):
  File "/usr/local/lib/python2.7/dist-packages/mutagen/id3.py", line 317, in __read_frames
    try: yield self.__load_framedata(tag, flags, framedata)
  File "/usr/local/lib/python2.7/dist-packages/mutagen/id3.py", line 340, in __load_framedata
    return tag.fromData(self, flags, framedata)
  File "/usr/local/lib/python2.7/dist-packages/mutagen/id3.py", line 1085, in fromData
    raise ID3BadUnsynchData, '%s: %r' % (err, data)
mutagen.id3.ID3BadUnsynchData: invalid sync-safe string: '\x00j\x01\x0c\x00\x12(...lots of unicode...)\x12\xff\xff\xff\x00'

有谁知道这里有什么问题?

编辑:原来诱变剂不适用于某些文件。我添加了一个 try 子句并跳过了错误,它现在可以工作了

4

0 回答 0