From adb22c3511a51cc04018cd5dbead27cb7652d751 Mon Sep 17 00:00:00 2001 From: Johannes Baiter Date: Wed, 29 May 2013 10:53:55 +0200 Subject: [PATCH] Return a list of candidates in hooks._album_for_id --- beets/autotag/hooks.py | 12 +++++++----- beets/autotag/match.py | 21 +++++++-------------- beets/plugins.py | 13 +++++++------ 3 files changed, 21 insertions(+), 25 deletions(-) diff --git a/beets/autotag/hooks.py b/beets/autotag/hooks.py index e877ffbcd..3642e46a0 100644 --- a/beets/autotag/hooks.py +++ b/beets/autotag/hooks.py @@ -167,15 +167,17 @@ TrackMatch = namedtuple('TrackMatch', ['distance', 'info']) # Aggregation of sources. def _album_for_id(album_id): - """Get an album corresponding to a release ID.""" - out = None + """Get a list of albums corresponding to a release ID.""" + candidates = [] try: out = mb.album_for_id(album_id) except mb.MusicBrainzAPIError as exc: exc.log(log) - if not out: - out = plugins.album_for_id(album_id) - return out + if out: + candidates.append(out) + out = plugins.album_for_id(album_id) + candidates.extend(x for x in out if x is not None) + return candidates def _track_for_id(track_id): """Get an item for a recording MBID.""" diff --git a/beets/autotag/match.py b/beets/autotag/match.py index d4d3ae870..cd490583e 100644 --- a/beets/autotag/match.py +++ b/beets/autotag/match.py @@ -437,11 +437,7 @@ def tag_album(items, search_artist=None, search_album=None, candidates = {} # Try to find album indicated by MusicBrainz IDs. - if search_id: - log.debug('Searching for album ID: ' + search_id) - id_info = hooks._album_for_id(search_id) - else: - id_info = match_by_id(items) + id_info = match_by_id(items) if id_info: _add_candidate(items, candidates, id_info) rec = _recommendation(candidates.values()) @@ -454,13 +450,6 @@ def tag_album(items, search_artist=None, search_album=None, log.debug('ID match.') return cur_artist, cur_album, candidates.values(), rec - # If searching by ID, don't continue to metadata search. - if search_id is not None: - if candidates: - return cur_artist, cur_album, candidates.values(), rec - else: - return cur_artist, cur_album, [], recommendation.none - # Search terms. if not (search_artist and search_album): # No explicit search terms -- use current metadata. @@ -474,8 +463,12 @@ def tag_album(items, search_artist=None, search_album=None, log.debug(u'Album might be VA: %s' % str(va_likely)) # Get the results from the data sources. - search_cands = hooks._album_candidates(items, search_artist, search_album, - va_likely) + if search_id: + log.debug('Searching for album ID: ' + search_id) + search_cands = hooks._album_for_id(search_id) + else: + search_cands = hooks._album_candidates(items, search_artist, + search_album, va_likely) log.debug(u'Evaluating %i candidates.' % len(search_cands)) for info in search_cands: _add_candidate(items, candidates, info) diff --git a/beets/plugins.py b/beets/plugins.py index 2cd0693f1..0189e3a14 100755 --- a/beets/plugins.py +++ b/beets/plugins.py @@ -270,14 +270,15 @@ def item_candidates(item, artist, title): return out def album_for_id(album_id): - out = None + out = [] for plugin in find_plugins(): try: - out = plugin.album_for_id(album_id) - except Exception as exc: - exc.log(log) - if out: - return out + out.append(plugin.album_for_id(album_id)) + except Exception: + log.warn('** error running album_for_id in plugin %s' + % plugin.name) + log.warn(traceback.format_exc()) + return out def configure(config): """Sends the configuration object to each plugin."""