summaryrefslogtreecommitdiff
path: root/nephilim/plugins/Lyrics.py
diff options
context:
space:
mode:
authorAnton Khirnov <wyskas@gmail.com>2009-08-21 09:14:49 +0200
committerAnton Khirnov <wyskas@gmail.com>2009-08-21 09:14:49 +0200
commit7b9278975c57b57f651641cd4671c84ffc1edd02 (patch)
treed97b4f69e44b3e576e2fbbb1ad37e942c44730ab /nephilim/plugins/Lyrics.py
parent25778fdfb7099fcbb98f17da2fb9c67715f6702f (diff)
move common lyrics/albumcover fetcher code to misc
Diffstat (limited to 'nephilim/plugins/Lyrics.py')
-rw-r--r--nephilim/plugins/Lyrics.py66
1 files changed, 8 insertions, 58 deletions
diff --git a/nephilim/plugins/Lyrics.py b/nephilim/plugins/Lyrics.py
index 4eb696f..0c90e8c 100644
--- a/nephilim/plugins/Lyrics.py
+++ b/nephilim/plugins/Lyrics.py
@@ -140,57 +140,7 @@ class Lyrics(Plugin):
elif self.__results >= len(self.__fetchers) and not self.o.lyrics_loaded:
self.o.set_lyrics(song, None)
- class Fetcher(QtCore.QObject):
- """A basic class for lyrics fetchers. Provides a fetch(song) function,
- emits a finished(song, lyrics) signal when done; lyrics is either a QString,
- Python unicode string or None if not found."""
- #public, read-only
- logger = None
- name = ''
-
- #private
- nam = None # NetworkAccessManager
- srep = None # search results NetworkReply
- lrep = None # lyrics page NetworkReply
- song = None # current song
-
- #### private ####
- def __init__(self, plugin):
- QtCore.QObject.__init__(self, plugin)
-
- self.nam = QtNetwork.QNetworkAccessManager()
- self.logger = plugin.logger
-
- def fetch2(self, song, url):
- """A private convenience function to initiate fetch process."""
- # abort any existing connections
- if self.srep:
- self.srep.finished.disconnect()
- self.srep.abort()
- self.srep = None
- if self.lrep:
- self.lrep.finished.disconnect()
- self.lrep.abort()
- self.lrep = None
- self.song = song
-
- self.logger.info('Searching %s: %s.'%(self. name, url))
- self.srep = self.nam.get(QtNetwork.QNetworkRequest(url))
-
- def finish(self, lyrics = None):
- """A private convenience function to clean up and emit finished().
- Feel free to reimplement/not use it."""
- self.srep = None
- self.lrep = None
- self.emit(QtCore.SIGNAL('finished'), self.song, lyrics)
- self.song = None
-
- #### public ####
- def fetch(self, song):
- """Reimplement this in subclasses."""
- pass
-
- class FetchLyricwiki(Fetcher):
+ class FetchLyricwiki(misc.MetadataFetcher):
name = 'Lyricwiki'
def fetch(self, song):
@@ -220,13 +170,13 @@ class Lyrics(Plugin):
return self.finish()
self.logger.info('Found Lyricwiki song URL: %s.'%url)
- self.lrep = self.nam.get(QtNetwork.QNetworkRequest(url))
- self.lrep.finished.connect(self.__handle_lyrics)
+ self.mrep = self.nam.get(QtNetwork.QNetworkRequest(url))
+ self.mrep.finished.connect(self.__handle_lyrics)
def __handle_lyrics(self):
#TODO this should use Qt xml functions too
lyrics = ''
- page = unicode(self.lrep.readAll(), encoding = 'utf-8')
+ page = unicode(self.mrep.readAll(), encoding = 'utf-8')
page = re.sub('<br>|<br/>|<br />', '\n', page)
try:
html = etree.HTML(page)
@@ -239,7 +189,7 @@ class Lyrics(Plugin):
lyrics += etree.tostring(elem, method = 'text', encoding = 'utf-8')
self.finish(lyrics)
- class FetchAnimelyrics(Fetcher):
+ class FetchAnimelyrics(misc.MetadataFetcher):
name = 'Animelyrics'
def fetch(self, song):
@@ -266,13 +216,13 @@ class Lyrics(Plugin):
return self.finish()
self.logger.info('Found Animelyrics song URL: %s.'%url)
- self.lrep = self.nam.get(QtNetwork.QNetworkRequest(url))
- self.connect(self.lrep, QtCore.SIGNAL('finished()'), self.__handle_lyrics)
+ self.mrep = self.nam.get(QtNetwork.QNetworkRequest(url))
+ self.connect(self.mrep, QtCore.SIGNAL('finished()'), self.__handle_lyrics)
def __handle_lyrics(self):
lyrics = ''
try:
- tree = etree.HTML(unicode(self.lrep.readAll(), encoding = 'utf-8'))
+ tree = etree.HTML(unicode(self.mrep.readAll(), encoding = 'utf-8'))
except etree.XMLSyntaxError, e:
self.logger.error('Error parsing lyrics: %s' %e)
return self.finish()