diff options
Diffstat (limited to 'nephilim/plugins/Lyrics.py')
-rw-r--r-- | nephilim/plugins/Lyrics.py | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/nephilim/plugins/Lyrics.py b/nephilim/plugins/Lyrics.py index 08cc10d..f5c37da 100644 --- a/nephilim/plugins/Lyrics.py +++ b/nephilim/plugins/Lyrics.py @@ -72,7 +72,7 @@ class LyricsWidget(QtGui.QWidget): self.layout().addWidget(self.__text_view, 1, 1) def __save_lyrics(self): - self.plugin.save_lyrics_file(self.__text_view.toPlainText().encode('utf-8')) + self.plugin.save_lyrics_file(self.__text_view.toPlainText()) def __toggle_editable(self, val): self.__text_view.setReadOnly(not val) @@ -145,8 +145,10 @@ class Lyrics(Plugin): class FetchLyricwiki(common.MetadataFetcher): name = 'Lyricwiki' + __apiaddress = 'http://lyrics.wikia.com/api.php' + def fetch(self, song): - url = QtCore.QUrl('http://lyricwiki.org/api.php') + url = QtCore.QUrl(self.__apiaddress) url.setQueryItems([('func', 'getArtist'), ('artist', song['artist']), ('fmt', 'xml')]) self.fetch2(song, url) @@ -165,7 +167,7 @@ class Lyrics(Plugin): self.logger.info('Didn\'t find artist in %s artist search results.'%self.name) return self.finish() - url = QtCore.QUrl('http://lyricwiki.org/api.php') + url = QtCore.QUrl(self.__apiaddress) url.setQueryItems([('func', 'getSong'), ('artist', artist), ('song', self.song['title']), ('fmt', 'xml')]) self.rep = self.nam.get(QtNetwork.QNetworkRequest(url)) @@ -179,25 +181,21 @@ class Lyrics(Plugin): token = xml.readNext() if token == QtCore.QXmlStreamReader.StartElement: if xml.name() == 'url': - url = QtCore.QUrl() # the url is already percent-encoded - try: - url.setEncodedUrl(xml.readElementText()) - except TypeError: # no text - url = None - elif xml.name() == 'lyrics' and xml.readElementText() == 'Not found': - xml.clear() - return self.finish() + text = xml.readElementText() + if text and not 'action=edit' in text: + url = QtCore.QUrl() # the url is already percent-encoded + url.setEncodedUrl(text) if xml.hasError(): self.logger.error('Error parsing seach results: %s'%xml.errorString()) if not url: - self.logger.warning('Didn\'t find the URL in Lyricwiki search results.') + self.logger.info('Didn\'t find the song on Lyricwiki.') return self.finish() self.logger.info('Found Lyricwiki song URL: %s.'%url) # XXX temporary hack to work around lyricwiki.org -> lyrics.wikia.org transition - url.setHost('lyrics.wikia.com') - url.setPath('/lyrics%s'%url.path()) + if not url.path().startswith('/lyrics'): + url.setPath('/lyrics%s'%url.path()) req = QtNetwork.QNetworkRequest(url) self.rep = self.nam.get(req) self.rep.finished.connect(self.__handle_lyrics) |