tags 446826 +patch
thanks
Attached is a patch to use the lyricwiki.org REST API. It's a pretty
simple interface at the moment and thus does not have fuzzy search
capability, so the artist & album have to be nearly-exact matches. But it
works. Someone with more time on their hands could probably modify this
easily to use their more fully-featured SOAP API.
--- qltk/lyrics.py.orig 2007-10-17 00:16:51.000000000 -0400
+++ qltk/lyrics.py 2007-10-17 00:32:47.000000000 -0400
@@ -22,8 +22,6 @@
import qltk
import util
-from xml.dom import minidom
-
class LyricsPane(gtk.VBox):
def __init__(self, song):
super(LyricsPane, self).__init__(spacing=12)
@@ -50,7 +48,7 @@
self.pack_start(sw, expand=True)
self.pack_start(gtk.Label(_("Lyrics provided by %s.") %(
- "http://www.leoslyrics.com")), expand=False)
+ "http://lyricwiki.org")), expand=False)
bbox = gtk.HButtonBox()
bbox.pack_start(save)
@@ -74,11 +72,7 @@
title = song.comma('title').encode('utf-8')
album = song.comma('album').encode('utf-8')
- util.website(
- "http://leoslyrics.com/submit.php?song=%s&artist=%s&album=%s" % (
- urllib.quote(title),
- urllib.quote(artist),
- urllib.quote(album)))
+ util.website("http://lyricwiki.org/%s" % (urllib.quote(artist)))
add.set_sensitive(False)
def __refresh(self, refresh, add, buffer, song):
@@ -95,11 +89,11 @@
try:
sock = urllib.urlopen(
- "http://api.leoslyrics.com/api_search.php?auth="
- "QuodLibet&artist=%s&songtitle=%s"%(
+ "http://lyricwiki.org/api.php?"
+ "client=QuodLibet&func=getSong&artist=%s&song=%s&fmt=text"%(
urllib.quote(artist.encode('utf-8')),
urllib.quote(title.encode('utf-8'))))
- xmldoc = minidom.parse(sock).documentElement
+ text = sock.read()
except Exception, err:
try: err = err.strerror.decode(const.ENCODING, 'replace')
except: err = _("Unable to download lyrics.")
@@ -107,51 +101,17 @@
return
sock.close()
- result_code = xmldoc.getElementsByTagName(
- 'response')[0].getAttribute('code')
-
- if result_code == '0': # This is success even if there are no matches.
- # Grab the first 10 results.
- matches = xmldoc.getElementsByTagName('result')[:10]
- hids = map(lambda x: x.getAttribute('hid'), matches)
- exacts = map(lambda x: x.getAttribute('exactMatch'), matches)
-
- if len(hids) == 0:
- gobject.idle_add(
- buffer.set_text, _("No lyrics found for this song."))
- add.set_sensitive(True)
- return
-
- songlist = zip(hids, exacts)
-
- xmldoc.unlink()
-
- # Show the first match
- try:
- sock = urllib.urlopen(
- "http://api.leoslyrics.com/api_lyrics.php?auth="
- "QuodLibet&hid=%s"%(
- urllib.quote(songlist[0][0].encode('utf-8'))))
- xmldoc = minidom.parse(sock).documentElement
- except Exception, err:
- try: err = err.strerror.decode(const.ENCODING, 'replace')
- except: err = _("Unable to download lyrics.")
- gobject.idle_add(buffer.set_text, err)
- return
- sock.close()
-
- text = xmldoc.getElementsByTagName('text')[0].firstChild.nodeValue
- xmldoc.unlink()
+ if text == 'Not found':
+ gobject.idle_add(
+ buffer.set_text, _("No lyrics found for this song."))
+ add.set_sensitive(True)
+ return
+ else:
gobject.idle_add(buffer.set_text, text)
gobject.idle_add(refresh.set_sensitive, True)
gobject.idle_add(add.set_sensitive, songlist[0][1] == 'false')
- else:
- gobject.idle_add(buffer.set_text, _("Unable to download lyrics."))
- xmldoc.unlink()
- return
-
def __save(self, save, lyricname, buffer, delete):
try: os.makedirs(os.path.dirname(lyricname))
except EnvironmentError, err: pass