From 5fa6e426baa9368bfbcbbc929085a9cd3b70d990 Mon Sep 17 00:00:00 2001 From: plww Date: Sun, 14 Oct 2012 10:49:33 +0200 Subject: [PATCH 1/2] added function for getting top artists for tag --- headphones/lastfm.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/headphones/lastfm.py b/headphones/lastfm.py index ce77948b..9546ba78 100644 --- a/headphones/lastfm.py +++ b/headphones/lastfm.py @@ -126,6 +126,41 @@ def getArtists(): for artistid in artistlist: importer.addArtisttoDB(artistid) +def getTagTopArtists(tag, limit=50): + myDB = db.DBConnection() + results = myDB.select('SELECT ArtistID from artists') + + url = 'http://ws.audioscrobbler.com/2.0/?method=tag.gettopartists&limit=%s&tag=%s&api_key=%s' % (limit, tag, api_key) + data = urllib2.urlopen(url, timeout=20).read() + + try: + d = minidom.parseString(data) + except: + logger.error("Could not parse artist list from last.fm data") + return + + artists = d.getElementsByTagName("artist") + + artistlist = [] + + for artist in artists: + mbidnode = artist.getElementsByTagName("mbid")[0].childNodes + + for node in mbidnode: + artist_mbid = node.data + + try: + if not any(artist_mbid in x for x in results): + artistlist.append(artist_mbid) + except: + continue + + from headphones import importer + + for artistid in artistlist: + importet.addArtisttoDB(artistid) + + def getAlbumDescription(rgid, artist, album): myDB = db.DBConnection() From 8358212df9a4dbdc77390864d143b75bae946a6c Mon Sep 17 00:00:00 2001 From: plww Date: Sun, 14 Oct 2012 20:28:36 +0200 Subject: [PATCH 2/2] added interface for importLastFMTag --- data/interfaces/default/manage.html | 22 +++++++++++++++++++++- headphones/lastfm.py | 2 +- headphones/webserve.py | 6 ++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/data/interfaces/default/manage.html b/data/interfaces/default/manage.html index 88e26d8a..db682780 100644 --- a/data/interfaces/default/manage.html +++ b/data/interfaces/default/manage.html @@ -87,7 +87,27 @@ - +
+
+
+ Import Last.FM Tag +

Enter tag from which you want import top artists:

+
+
+ + +
+ + +
+
+ +
+ + +
diff --git a/headphones/lastfm.py b/headphones/lastfm.py index 9546ba78..5e0aacaf 100644 --- a/headphones/lastfm.py +++ b/headphones/lastfm.py @@ -158,7 +158,7 @@ def getTagTopArtists(tag, limit=50): from headphones import importer for artistid in artistlist: - importet.addArtisttoDB(artistid) + importer.addArtisttoDB(artistid) def getAlbumDescription(rgid, artist, album): diff --git a/headphones/webserve.py b/headphones/webserve.py index 3a508c51..69c3adc2 100644 --- a/headphones/webserve.py +++ b/headphones/webserve.py @@ -352,6 +352,12 @@ class WebInterface(object): raise cherrypy.HTTPRedirect("home") importLastFM.exposed = True + def importLastFMTag(self, tag, limit): + threading.Thread(target=lastfm.getTagTopArtists, args=(tag, limit)).start() + time.sleep(10) + raise cherrypy.HTTPRedirect("home") + importLastFMTag.exposed = True + def importItunes(self, path): headphones.PATH_TO_XML = path headphones.config_write()