def get_info artist album tags_output year api_key b25b959554ed76058ac

 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
def get_info(artist, album):
tags_output = ''
year = ''
api_key = 'b25b959554ed76058ac220b7b2e0a026'
url = 'http://ws.audioscrobbler.com/2.0/'
data = {}
data['album'] = album
data['api_key'] = api_key
data['method'] = 'album.getinfo'
data['artist'] = artist
post = urllib.urlencode(data)
xml = urllib2.urlopen(url +'?'+ post).read()
parsed = minidom.parseString(xml)
albums_xml = parsed.getElementsByTagName('album')
covers_urls = parsed.getElementsByTagName('image')
tags_list_xml = parsed.getElementsByTagName('toptags')
try:
if covers_urls:
artwork = covers_urls[-1].childNodes[0].data
except: artwork = ''
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)
if tags_list:
tags_output = pickle.dumps(tags_list)
url = 'http://musicbrainz.org/ws/1/release/?type=xml&artist=' + artist + '&releasetypes=Official&limit=1&title=' + album
xml = urllib2.urlopen(url).read()
parsed = minidom.parseString(xml)
year_list = parsed.getElementsByTagName('event')
if year_list:
year = int(year_list[0].getAttribute('date')[0:4])
return (artwork, tags_output, year)