hi, T.P Wang
i'm struggling with python and i need a little help with the scripts
first, i tried to change one of the scripts and it looks like this:
import urllib
from xml.dom import minidom
from grabber import LyricProviderBase
class last_fm_bio(LyricProviderBase):
def GetName(self):
return "last.fm bio summary"
def GetVersion(self):
return "0.1"
def GetURL(self):
return "http://ws.audioscrobbler.com/"
def Query(self, handles, status, abort):
result = []
for handle in handles:
status.Advance()
if abort.Aborting():
return result
artist = handle.Format("[%artist%]")
try:
string = urllib.urlopen("http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=%s&api_key=032cdb2ecd03a8ba66e8d8f2a7c38e4e" % (urllib.quote(artist),)).read()
doc = minidom.parseString(string)
child = doc.getElementsByTagName("bio")[0]
text = child.getElementsByTagName("summary")[0]
lyric = text.childNodes[0].data.encode('utf-8')
result.append(lyric)
except Exception, e:
traceback.print_exc(file=sys.stdout)
result.append('')
continue
return result
if __name__ == "__main__":
LyricProviderInstance = last_fm_bio()
result is unfortunately "failed" and i don't get any output, to know where the mistake is
maybe with some command line arguments we could redirect output result from failure to file?
anyway, i tried the code in standalone python shell using this code:
import urllib.request
from xml.dom import minidom
string = urllib.request.urlopen('http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=Dead+can+dance&api_key=b25b959554ed76058ac220b7b2e0a026').read()
doc = minidom.parseString(string)
child = doc.getElementsByTagName("bio")[0]
text = child.getElementsByTagName("summary")[0]
lyric = text.childNodes[0].data.encode('utf-8')
print (lyric)
and the result is as expected:
>>> ================================ RESTART ================================
>>>
b'Dead Can Dance were originally based in Australia, formed in Melbourne in 1981 by Brendan Perry and was later joined by Lisa Gerrard. They disbanded in 1998, and temporarily reunited to do a highly successful world tour in 2005 with a view to recording another studio album together. But due to ongoing personal differences between Perry and Gerrard, Perry decided to finally put to rest any prospect of a future collaboration in order to concentrate on a solo career. '
>>>
i've noticed that using python scripts i can't get any lyrics which do exist on dedicated sites (for ex. Air - Playground Love) so maybe it's something to do with my configuration
if not, my question is:
what am i doing wrong,
maybe some explanation about how script is working
and is there a way i could use the api_key without just putting it to requested url
then if everything is all right, using python grabber and putting the info in tags is just not elegant sometimes, so what are the chances we can use some variables to put requested info in, and than use it somehow in foobar panel
maybe extending lyrics show panel possibilities or just inventing other panel
requested info can be image, url, text...
what do you think?