2015-10-24 68 views
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()函數。任何幫助?

+0

我相信MP3格式支持latin1或utf8文本;必須確保它使用後者。 –

+0

關於錯誤究竟有什麼不清楚?只需在網上搜索就能瞭解錯誤,否則談論解決方案毫無意義。 –

+0

@UlrichEckhardt我明白,它是一個錯誤,因爲不同的編碼。我試圖搜索網頁,但無法找到答案,這就是我在此發佈的原因。 – toothie

回答

0

我想你正在嘗試編寫僅允許拉丁-1的ID3v1(或ID3v2單字節)標記。

我想我必須修補我的eyeD3一次來解決這個問題。嘗試關閉ID3v1並將ID3v2設置爲v2.4 UTF-8。

理想情況下 - 捕捉,關閉ID3v1,重試。具體的問題是'報價是多字節。

相關問題