Skip to content

Instantly share code, notes, and snippets.

@nicolamontecchio
Created March 25, 2011 18:16
Show Gist options
  • Save nicolamontecchio/887307 to your computer and use it in GitHub Desktop.
Save nicolamontecchio/887307 to your computer and use it in GitHub Desktop.
simple method to get tags for a given artist/track
#!/usr/bin/env python
import urllib, urllib2, StringIO
from lxml import etree
apikey = 'YOUR APY KEY'
def getTags(artist,track) :
params = urllib.urlencode([('method','track.gettoptags'), ('artist',artist),('track',track),('api_key',apikey)])
url = 'http://ws.audioscrobbler.com/2.0/?' + params
root = etree.parse(urllib2.urlopen(url))
tags = []
for x in root.xpath('/lfm/toptags/tag') :
tagname = x.xpath('name')[0].text
tagcount = x.xpath('count')[0].text
tags.append((tagname, int(tagcount)))
return tags
for t,c in getTags('vasco rossi','albachiara') :
print '%4d, %s' % (c,t)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment