From 8d9c324b61cd8e4f5f909973dcb196b8fd8ef5b5 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Sun, 26 Feb 2012 12:54:27 -0800 Subject: [PATCH] fix unicode encoding for lyrics requests (#350) --- beetsplug/lyrics.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/beetsplug/lyrics.py b/beetsplug/lyrics.py index 3be569bed..d74249037 100644 --- a/beetsplug/lyrics.py +++ b/beetsplug/lyrics.py @@ -89,6 +89,8 @@ def _lw_encode(s): s = s.replace("#", "Number_") s = re.sub(r'[\[\{]', '(', s) s = re.sub(r'[\]\}]', ')', s) + if isinstance(s, unicode): + s = s.encode('utf8', 'ignore') return urllib.quote(s) def fetch_lyricswiki(artist, title): """Fetch lyrics from LyricsWiki.""" @@ -102,6 +104,8 @@ def fetch_lyricswiki(artist, title): LYRICSCOM_URL_PATTERN = 'http://www.lyrics.com/%s-lyrics-%s.html' def _lc_encode(s): s = re.sub(r'\s+', '-', s) + if isinstance(s, unicode): + s = s.encode('utf8', 'ignore') return urllib.quote(s) def fetch_lyricscom(artist, title): """Fetch lyrics from Lyrics.com.""" @@ -110,8 +114,9 @@ def fetch_lyricscom(artist, title): lyrics = extract_text(html, '
') if lyrics: - lyrics, _ = lyrics.split('\n---\nLyrics powered by', 1) - return lyrics + parts = lyrics.split('\n---\nLyrics powered by', 1) + if parts: + return parts[0] BACKENDS = [fetch_lyricswiki, fetch_lyricscom] def get_lyrics(artist, title):