diff --git a/headphones/importer.py b/headphones/importer.py index 27e3bfbe..4f8dae3b 100644 --- a/headphones/importer.py +++ b/headphones/importer.py @@ -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']: diff --git a/headphones/lastfm.py b/headphones/lastfm.py index 0e39a110..814a35e8 100644 --- a/headphones/lastfm.py +++ b/headphones/lastfm.py @@ -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 == 'Album not found': + 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]) diff --git a/headphones/mb.py b/headphones/mb.py index 92723fda..1d6b20cd 100644 --- a/headphones/mb.py +++ b/headphones/mb.py @@ -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']) diff --git a/headphones/searcher.py b/headphones/searcher.py index 1459481b..28f717a7 100644 --- a/headphones/searcher.py +++ b/headphones/searcher.py @@ -398,7 +398,6 @@ def searchNZB(albumid=None, new=False): else: bestqual = nzblist[0] - logger.info(u'Found best result: %s - %s' % (bestqual[2], bestqual[0], helpers.bytes_to_mb(bestqual[1]))) logger.info(u"Pre-processing result") (data, bestqual) = preprocess(nzblist)