0
我正在使用eyeD3编辑mp3文件的元数据。我无法设置歌词标签。UnicodeEncodeError:'拉丁-1'编解码器无法编码字符u' u2019'在位置4:序号不在范围内(256)
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()函数。任何帮助?
我相信MP3格式支持latin1或utf8文本;必须确保它使用后者。 –
关于错误究竟有什么不清楚?只需在网上搜索就能了解错误,否则谈论解决方案毫无意义。 –
@UlrichEckhardt我明白,它是一个错误,因为不同的编码。我试图搜索网页,但无法找到答案,这就是我在此发布的原因。 – toothie