0

我正在使用 eyeD3 编辑 mp3 文件的元数据。我无法设置歌词标签。

def fetch_lyrics(title, artist):
    URL='http://makeitpersonal.co/lyrics?artist=%s&title=%s'
    webaddr=(URL %(artist, title)).replace(" ", "%20")
    print webaddr
    response = requests.get(webaddr)
    if response.content=="Sorry, We don't have lyrics for this song yet.":
      return 0
    else:
      return response.content

def get_lyrics(pattern, path=os.getcwd()):
    files=find(pattern, path)
    matches = len(files)
    if matches==1:
      tag = eyeD3.Tag()
      tag.link(files[0])
      lyrics = tag.getLyrics()
      if lyrics:
          for l in lyrics:
              print l.lyrics
      else:
          print "Lyrics not found. Searching online..."
          tag = eyeD3.Tag()
          tag.link(files[0])
          artist = tag.getArtist()
          title = tag.getTitle()
          l = fetch_lyrics(title, artist)
          if l==0:
            print "No matches found."
          else:
            #print l
            tag.addLyrics(l.decode('utf-8'))
            tag.update()

我得到的回溯是:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "lyrics.py", line 99, in get_lyrics
    tag.update()
  File "/usr/lib/python2.7/dist-packages/eyeD3/tag.py", line 526, in update
    self.__saveV2Tag(version);
  File "/usr/lib/python2.7/dist-packages/eyeD3/tag.py", line 1251, in __saveV2Ta
g
    raw_frame = f.render();
  File "/usr/lib/python2.7/dist-packages/eyeD3/frames.py", line 1200, in render
    self.lyrics.encode(id3EncodingToString(self.encoding))
UnicodeEncodeError: 'latin-1' codec can't encode character u'\u2019' in position
 4: ordinal not in range(256)

我不明白这个错误。我是否需要将任何其他参数传递给 update() 或 addLyrics() 函数。有什么帮助吗?

4

1 回答 1

0

我想您正在尝试编写仅允许 latin-1 的 ID3v1(或 ID3v2 单字节)标签。

我想我必须修补一次 eyeD3 才能解决这个问题。尝试关闭 ID3v1 并将 ID3v2 设置为 v2.4 UTF-8。

理想情况下 - 捕获,关闭 ID3v1,重试。具体问题是 ' 引用是多字节的。

于 2015-11-01T11:18:03.780 回答