Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I want to get the all the song's tags through Last.fm API by Pylast

Tags:

tags

api

last.fm

experts,

I currently want to use all the song's tags in a research project. Of course, I have Pylast on my hand. But there is no detailed doc about Pylast.

Then, is there anyone can tell me how to use Pylast to get all tags of song's through last.fm api?

Many thanks.

like image 582
MaiTiano Avatar asked Oct 09 '22 05:10

MaiTiano


1 Answers

It does not seem that what you want is actually possible with the last.fm api. Through the api only top tags are available.However they are not entierly clear on what constitutes a top tag. So it could be enough for your needs. Trying a couple of different artist the amounts of results I get are quite varying.

Here's a code example to get you started.

from pylast import *
#Set up the api key, secret, user and password here
network = get_lastfm_network(API_KEY,API_SECRET, user, password_hash)
userData = User(user, network)
track = network.get_track("Cher", "Believe")
#Get the tags a a TopItem object. 
topItems = track.get_top_tags(limit=None)
for topItem in topItems:
    print topItem.item.get_name(), topItem.weight

pylast actually have really good documentation. What I most often do is just fire up the shell and call help on the different pylast objects. There most of the functionalliy is explained. The source is also very readable so that is also a good place to find out how it actually works. So in this case:

help(TopItem)
help(Track)
help(Tag)
like image 105
Alvin Avatar answered Oct 16 '22 16:10

Alvin