New feature: Searches by artist & album if the artist has a disambiguation

This commit is contained in:
Remy
2011-07-19 03:57:35 -07:00
parent 2442f6a954
commit 03851ddccf
3 changed files with 71 additions and 16 deletions

View File

@@ -9,7 +9,7 @@ import lib.musicbrainz2.utils as u
from lib.musicbrainz2.webservice import WebServiceError
from headphones import logger
from headphones import logger, db
from headphones.helpers import multikeysort
q = ws.Query()
@@ -21,6 +21,7 @@ def findArtist(name, limit=1):
artistlist = []
attempt = 0
artistResults = None
while attempt < 5:
@@ -35,18 +36,29 @@ def findArtist(name, limit=1):
time.sleep(1)
if not artistResults:
return False
return False
for result in artistResults:
if result.artist.name != result.artist.getUniqueName() and limit == 1:
logger.info('Found an artist with a disambiguation: %s - doing an album based search' % name)
artistdict = findArtistbyAlbum(name)
if not artistdict:
return False
else:
artistlist.append(artistdict)
artistlist.append({
'name': result.artist.name,
'uniquename': result.artist.getUniqueName(),
'id': u.extractUuid(result.artist.id),
'url': result.artist.id,
'score': result.score
})
else:
artistlist.append({
'name': result.artist.name,
'uniquename': result.artist.getUniqueName(),
'id': u.extractUuid(result.artist.id),
'url': result.artist.id,
'score': result.score
})
return artistlist
@@ -58,7 +70,7 @@ def getArtist(artistid):
#Get all official release groups
inc = ws.ArtistIncludes(releases=(m.Release.TYPE_OFFICIAL, m.Release.TYPE_ALBUM), releaseGroups=True)
artist = None
attempt = 0
while attempt < 5:
@@ -107,7 +119,7 @@ def getReleaseGroup(rgid):
releaselist = []
inc = ws.ReleaseGroupIncludes(releases=True)
releaseGroup = None
attempt = 0
while attempt < 5:
@@ -129,7 +141,7 @@ def getReleaseGroup(rgid):
for release in releaseGroup.releases:
inc = ws.ReleaseIncludes(tracks=True)
releaseResult = None
attempt = 0
while attempt < 5:
@@ -170,7 +182,7 @@ def getRelease(releaseid):
release = {}
inc = ws.ReleaseIncludes(tracks=True, releaseEvents=True)
results = None
attempt = 0
while attempt < 5:
@@ -209,7 +221,45 @@ def getRelease(releaseid):
release['tracks'] = tracks
return release
def findArtistbyAlbum(name):
myDB = db.DBConnection()
artist = myDB.action('SELECT AlbumTitle from have WHERE ArtistName=?', [name]).fetchone()
term = '"'+artist['AlbumTitle']+'" AND artist:"'+name+'"'
f = ws.ReleaseGroupFilter(query=term, limit=1)
results = None
attempt = 0
while attempt < 5:
try:
results = q.getReleaseGroups(f)
break
except WebServiceError, e:
logger.warn('Attempt to retrieve information for %s from MusicBrainz failed: %s' % (releaseResult.title, e))
attempt += 1
time.sleep(1)
time.sleep(1)
if not results:
return False
artist_dict = {}
for result in results:
releaseGroup = result.releaseGroup
artist_dict['name'] = releaseGroup.artist.name
artist_dict['uniquename'] = releaseGroup.artist.getUniqueName()
artist_dict['id'] = u.extractUuid(releaseGroup.artist.id)
artist_dict['url'] = releaseGroup.artist.id
artist_dict['score'] = result.score
return artist_dict
def getExtras(artistid):

View File

@@ -188,8 +188,9 @@ def searchNZB(albumid=None):
bestqual = sorted(newlist, key=lambda title: title[3])[0]
except TypeError:
except Exception, e:
logger.debug('Error: %s' % str(e))
logger.info('No track information for %s - %s. Defaulting to highest quality' % (albums[0], albums[1]))
bestqual = sorted(resultlist, key=lambda title: title[1], reverse=True)[0]

View File

@@ -82,7 +82,11 @@ class WebInterface(object):
page.append(templates._footer % headphones.CURRENT_VERSION)
else:
page.append("""<div class="datanil">Add some artists to the database!</div>""")
have = myDB.select('SELECT ArtistName from have')
if len(have):
page.append("""<div class="datanil">Scanning...</div>""")
else:
page.append("""<div class="datanil">Add some artists to the database!</div>""")
return page
home.exposed = True