Changed the way album descriptions are retrieved from lastfm

This commit is contained in:
Remy
2011-08-08 13:18:10 -07:00
parent 71536f3e1f
commit 6159ca61ed
3 changed files with 48 additions and 3 deletions

View File

@@ -215,7 +215,7 @@ def addArtisttoDB(artistid, extrasonly=False):
myDB.upsert("albums", newValueDict, controlValueDict)
lastfm.getAlbumDescription(rg['id'], release_dict['releaselist'])
lastfm.getAlbumDescription(rg['id'], artist['artist_name'], rg['title'])
# I changed the albumid from releaseid -> rgid, so might need to delete albums that have a releaseid
for release in release_dict['releaselist']:

View File

@@ -91,7 +91,52 @@ def getArtists():
for artistid in artistlist:
importer.addArtisttoDB(artistid)
def getAlbumDescription(rgid, releaselist):
def getAlbumDescription(rgid, artist, album):
myDB = db.DBConnection()
result = myDB.select('SELECT Summary from descriptions WHERE ReleaseGroupID=?', [rgid])
if result:
return
params = { "method": 'album.getInfo',
"api_key": api_key,
"artist": artist.encode('utf-8'),
"album": album.encode('utf-8')
}
searchURL = 'http://ws.audioscrobbler.com/2.0/?' + urllib.urlencode(params)
data = urllib.urlopen(searchURL).read()
if data == '<?xml version="1.0" encoding="utf-8"?><lfm status="failed"><error code="6">Album not found</error></lfm>':
return
try:
d = minidom.parseString(data)
albuminfo = d.getElementsByTagName("album")
for item in albuminfo:
summarynode = item.getElementsByTagName("summary")[0].childNodes
contentnode = item.getElementsByTagName("content")[0].childNodes
for node in summarynode:
summary = node.data
for node in contentnode:
content = node.data
controlValueDict = {'ReleaseGroupID': rgid}
newValueDict = {'Summary': summary,
'Content': content}
myDB.upsert("descriptions", newValueDict, controlValueDict)
except:
return
def getAlbumDescriptionOld(rgid, releaselist):
"""
This was a dumb way to do it - going to just use artist & album name but keeping this here
because I may use it to fetch and cache album art
"""
myDB = db.DBConnection()
result = myDB.select('SELECT Summary from descriptions WHERE ReleaseGroupID=?', [rgid])

View File

@@ -306,7 +306,7 @@ def getReleaseGroup(rgid):
releaselist.append(release_dict)
average_tracks = sum(x['trackscount'] for x in releaselist) / len(releaselist)
average_tracks = sum(x['trackscount'] for x in releaselist) / float(len(releaselist))
for item in releaselist:
item['trackscount_delta'] = abs(average_tracks - item['trackscount'])