From 1abb1624473644fa3f7fb6963882ea4b98e1bf4d Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 22 Aug 2009 09:38:00 +0200 Subject: Lyrics: use getArtist on lyricwiki this fixes some issues with non-latin artist names. --- nephilim/plugins/Lyrics.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/nephilim/plugins/Lyrics.py b/nephilim/plugins/Lyrics.py index 1a88dd1..fe3e36d 100644 --- a/nephilim/plugins/Lyrics.py +++ b/nephilim/plugins/Lyrics.py @@ -144,9 +144,28 @@ class Lyrics(Plugin): def fetch(self, song): url = QtCore.QUrl('http://lyricwiki.org/api.php') - url.setQueryItems([('func', 'getSong'), ('artist', song.artist()), - ('song', song.title()), ('fmt', 'xml')]) + url.setQueryItems([('func', 'getArtist'), ('artist', song.artist()), + ('fmt', 'xml')]) self.fetch2(song, url) + self.srep.finished.connect(self.__handle_artist_res) + + def __handle_artist_res(self): + artist = None + xml = QtCore.QXmlStreamReader(self.srep) + while not xml.atEnd(): + token = xml.readNext() + if token == QtCore.QXmlStreamReader.StartElement: + if xml.name() == 'artist': + artist = xml.readElementText() + xml.clear() + if not artist: + self.logger.error('Didn\'t find artist in %s artist search results.'%self.name) + return self.finish() + + url = QtCore.QUrl('http://lyricwiki.org/api.php') + url.setQueryItems([('func', 'getSong'), ('artist', artist), + ('song', self.song.title()), ('fmt', 'xml')]) + self.srep = self.nam.get(QtNetwork.QNetworkRequest(url)) self.srep.finished.connect(self.__handle_search_res) def __handle_search_res(self): @@ -162,7 +181,7 @@ class Lyrics(Plugin): xml.clear() return self.finish() if xml.hasError(): - self.logger.error('Error parsing seach results.%s'%xml.errorString()) + self.logger.error('Error parsing seach results: %s'%xml.errorString()) if not url: self.logger.error('Didn\'t find the URL in Lyricwiki search results.') -- cgit v1.2.3