def search_for_image(self):
""" Use LastFM's API to obtain a URL for the album cover art """
response = urllib.urlopen(self.url).read() # Send HTTP request to LastFM
#Due to a change in the API, Namespace prefix is not defined an causes Errors!
#Hotfix: Use "lxml" instead of "xml"
parser = ETree.XMLParser(recover=True)
xml_data = ETree.fromstring(response, parser) # Read in XML data
for element in xml_data.getiterator("album"):
if (element.find('artist').text.lower() == self.artist_name.lower().encode("utf-8")):
for elmnt in element.findall('image'):
if (elmnt.attrib['size'] == 'extralarge'):
url = elmnt.text
if url:
return url
else:
return None
评论列表
文章目录