mirror of
https://github.com/rembo10/headphones.git
synced 2026-03-22 04:39:26 +00:00
Merge remote-tracking branch 'plww/lastfmtag' into develop
This commit is contained in:
@@ -87,7 +87,27 @@
|
||||
</fieldset>
|
||||
<input type="button" value="Save changes" onclick="doAjaxCall('importLastFM',$(this),'tabs',true);return false;" data-success="Last.fm artists will be imported" data-error="Fill in a last.fm username"/>
|
||||
</form>
|
||||
</div>
|
||||
<br/>
|
||||
<form action="importLastFMTag" method="GET" id="importLastFMTag">
|
||||
<fieldset>
|
||||
<legend>Import Last.FM Tag</legend>
|
||||
<p>Enter tag from which you want import top artists:</p>
|
||||
<br/>
|
||||
<div class="row">
|
||||
<label>Tag</label>
|
||||
<input type="text" value="" onfocus="if
|
||||
(this.value==this.defaultValue) this.value='';" name="tag" id="tag" size="18" />
|
||||
<br/>
|
||||
<label>Limit</label>
|
||||
<input type="text" value="50" onfocus="if
|
||||
(this.value==this.defaultValue) this.value='';" name="limit" id="limit" size="18" />
|
||||
</div>
|
||||
</fieldset>
|
||||
<input type="submit" />
|
||||
</form>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div id="tabs-3" class="configtable">
|
||||
<fieldset>
|
||||
|
||||
@@ -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:
|
||||
importer.addArtisttoDB(artistid)
|
||||
|
||||
|
||||
def getAlbumDescription(rgid, artist, album):
|
||||
|
||||
myDB = db.DBConnection()
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user