Mercurial > hg > camir-aes2014
annotate core/magnatagatune/fm_retrieve_artist_tags.py @ 0:e9a9cd732c1e tip
first hg version after svn
author | wolffd |
---|---|
date | Tue, 10 Feb 2015 15:05:51 +0000 |
parents | |
children |
rev | line source |
---|---|
wolffd@0 | 1 # gets data from the last.fm webservice and |
wolffd@0 | 2 |
wolffd@0 | 3 import pylast |
wolffd@0 | 4 import sys |
wolffd@0 | 5 import fm_network |
wolffd@0 | 6 |
wolffd@0 | 7 network = fm_network.get_network() |
wolffd@0 | 8 |
wolffd@0 | 9 # now you can use that object every where |
wolffd@0 | 10 if sys.argv[2] == '0': |
wolffd@0 | 11 artist = network.get_artist(sys.argv[1]) |
wolffd@0 | 12 else: |
wolffd@0 | 13 artist = network.get_artist_by_mbid(sys.argv[1]) |
wolffd@0 | 14 |
wolffd@0 | 15 # retrieve artist tags |
wolffd@0 | 16 tags = artist.get_top_tags() |
wolffd@0 | 17 |
wolffd@0 | 18 # put in comma separated list |
wolffd@0 | 19 for tag in tags[:-1]: |
wolffd@0 | 20 print(tag.item.get_name().encode('utf-8','ignore')+ ', ' + tag.weight.encode('utf-8','ignore')) |
wolffd@0 | 21 |
wolffd@0 | 22 if len(tags) > 0: |
wolffd@0 | 23 print(tags[-1].item.get_name().encode('utf-8','ignore') + ', ' + tags[-1].weight.encode('utf-8','ignore')) |
wolffd@0 | 24 |
wolffd@0 | 25 else: |
wolffd@0 | 26 print(-1) |