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