diff options
author | Anton Khirnov <wyskas@gmail.com> | 2009-08-11 04:46:42 +0200 |
---|---|---|
committer | Anton Khirnov <wyskas@gmail.com> | 2009-08-11 04:46:42 +0200 |
commit | 777f5f30bbbb0f79cea29e6705247d3f102fb458 (patch) | |
tree | 55b5b5d33e25d3cbb63e67c5e3acb5f37d0b2f51 | |
parent | 7fd28ed211f568324259a5f0fd2509786b4ced39 (diff) |
Lyrics: support for downloading from animelyrics.
-rw-r--r-- | nephilim/plugins/Lyrics.py | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/nephilim/plugins/Lyrics.py b/nephilim/plugins/Lyrics.py index b99aef2..864b130 100644 --- a/nephilim/plugins/Lyrics.py +++ b/nephilim/plugins/Lyrics.py @@ -29,6 +29,7 @@ try: import urllib from lxml import etree _available_sites.append('lyricwiki') + _available_sites.append('animelyrics') except ImportError: print 'Lyrics: error importing LyricWiki. Make sure that lxml is installed.' @@ -79,7 +80,7 @@ class Lyrics(Plugin): lyrics_dir = None lyrics_path = None - DEFAULTS = {'sites' : ['lyricwiki'], 'lyricdir' : '$musicdir/$songdir', + DEFAULTS = {'sites' : QtCore.QStringList(['lyricwiki', 'animelyrics']), 'lyricdir' : '$musicdir/$songdir', 'lyricname' : '.lyrics_nephilim_$artist_$album_$title', 'store' : True} def _load(self): @@ -149,7 +150,8 @@ class Lyrics(Plugin): def fetch_lyricwiki(self, song): url = 'http://lyricwiki.org/api.php?%s' %urllib.urlencode({'func':'getSong', - 'artist':song.artist(), 'song':song.title(), 'fmt':'xml'}) + 'artist':song.artist().encode('utf-8'), 'song':song.title().encode('utf-8'), + 'fmt':'xml'}) try: # get url for lyrics tree = etree.HTML(urllib.urlopen(url).read()) @@ -168,6 +170,27 @@ class Lyrics(Plugin): self.logger.error('Error downloading lyrics from LyricWiki: %s.'%e) return None + def fetch_animelyrics(self, song): + url = 'http://www.animelyrics.com/search.php?%s'%urllib.urlencode({'q':song.artist().encode('utf-8'), + 't':'performer'}) + try: + #get url for lyrics + page = urllib.urlopen(url).read() + url = re.search('<a href="(.*?)".*?%s'%song.title(), page, re.IGNORECASE).group(1) + #get lyrics + url = 'http://www.animelyrics.com%s'%url + page = urllib.urlopen(url).read() + ret = '' + for match in re.finditer('<pre class=lyrics>(.*?)</pre>', page, re.IGNORECASE|re.DOTALL): + ret += '%s\n\n'%match.group(1) + return ret + except socket.error, e: + self.logger.error('Error downloading lyrics from Animelyrics: %s.'%e) + return None + except AttributeError: + # lyrics not found + return None + class SettingsWidgetLyrics(Plugin.SettingsWidget): lyricdir = None lyricname = None |