class GetInfo artist album def lastfm_parser self api_key b25b959554ed

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
class GetInfo:
artist = ''
album = ''
def lastfm_parser(self):
api_key = 'b25b959554ed76058ac220b7b2e0a026'
url = 'http://ws.audioscrobbler.com/2.0/'
data = {}
data[u'album'] = album
data['api_key'] = api_key
data['method'] = 'album.getinfo'
data[u'artist'] = artist
post = urllib.urlencode(data)
xml = urllib2.urlopen(url +'?'+ post).read()
parsed = minidom.parseString(xml)
albums_xml = parsed.getElementsByTagName('album')
def save_artwork(self,url):
"""docstring for save_artwork"""
pass
def get_tags(self):
"""docstring for get_tags"""
lastfm_parser()
tags_list_xml = parsed.getElementsByTagName('toptags')
if tags_list_xml:
tags_xml = tags_list_xml[0].getElementsByTagName('tag')
tags_list = []
if tags_xml:
for i in tags_xml:
tags_list.append(i.childNodes[1].childNodes[0].data)
return tags_list
def get_artwork_url(self):
lastfm_parser()
covers_urls = parsed.getElementsByTagName('image')
try:
if covers_urls:
artwork = covers_urls[-1].childNodes[0].data
except: artwork = ''
return artwork
def get_year(self):
musicbrainz_data = {"artist": artist,"releasetypes": 'Official',"limit": '1', "title": album}
url ='http://musicbrainz.org/ws/1/release/?type=xml&' + urllib.urlencode(musicbrainz_data)
xml = urllib2.urlopen(url).read()
parsed = minidom.parseString(xml)
year_list = parsed.getElementsByTagName('event')
if year_list:
return int(year_list[0].getAttribute('date')[0:4])