more efficiently limit the number of results returned from MB

This commit is contained in:
Adrian Sampson 2010-09-18 11:01:20 -07:00
parent b565a3afd4
commit 751a46c716
4 changed files with 8 additions and 5 deletions

2
NEWS
View file

@ -17,6 +17,8 @@
* Fixed bug that completely broke non-autotagged imports ("import -A").
* Fixed bug that logged the wrong paths when using "import -l".
* Fixed autotagging for the creatively-named band !!!.
* Efficiency tweak should reduce the number of MusicBrainz queries per
autotagged album.
* A new "-v" command line switch enables debugging output.
1.0b4

View file

@ -448,8 +448,9 @@ def tag_album(items, search_artist=None, search_album=None):
# Get candidate metadata from search.
if not search_artist or not search_album:
raise InsufficientMetadataError()
candidates = mb.match_album(search_artist, search_album, len(items))
candidates = list(candidates)[:MAX_CANDIDATES]
candidates = mb.match_album(search_artist, search_album,
len(items), MAX_CANDIDATES)
candidates = list(candidates)
# Get candidates from plugins.
candidates.extend(plugins.candidates(items))

View file

@ -183,7 +183,7 @@ def release_dict(release, tracks=None):
return out
def match_album(artist, album, tracks=None):
def match_album(artist, album, tracks=None, limit=SEARCH_LIMIT):
"""Searches for a single album ("release" in MusicBrainz parlance)
and returns an iterator over dictionaries of information (as
returned by `release_dict`).

View file

@ -131,8 +131,8 @@ class LastIdPlugin(BeetsPlugin):
criteria['artistName'] = last_artist
# Perform the search.
cands = mb.get_releases(**criteria)
cands = list(cands)[:autotag.MAX_CANDIDATES]
criteria['limit'] = autotag.MAX_CANDIDATES
cands = list(mb.get_releases(**criteria))
log.debug('Matched last candidates: %s' %
', '.join([cand['album'] for cand in cands]))