mirror of
https://github.com/beetbox/beets.git
synced 2025-12-20 15:43:58 +01:00
Return a list of candidates in hooks._album_for_id
This commit is contained in:
parent
ad66b8796a
commit
adb22c3511
3 changed files with 21 additions and 25 deletions
|
|
@ -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."""
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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."""
|
||||
|
|
|
|||
Loading…
Reference in a new issue