From a82e3f9f52f3a4431499a8773d8fb04bcd123bc8 Mon Sep 17 00:00:00 2001 From: Johannes Baiter Date: Tue, 28 May 2013 12:57:02 +0200 Subject: [PATCH] Delegate album_for_id to plugins if no MusicBrainz match is found --- beets/autotag/hooks.py | 8 ++++++-- beets/plugins.py | 16 ++++++++++++++++ beets/ui/commands.py | 15 +++------------ 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/beets/autotag/hooks.py b/beets/autotag/hooks.py index a1a197f41..e877ffbcd 100644 --- a/beets/autotag/hooks.py +++ b/beets/autotag/hooks.py @@ -167,11 +167,15 @@ TrackMatch = namedtuple('TrackMatch', ['distance', 'info']) # Aggregation of sources. def _album_for_id(album_id): - """Get an album corresponding to a MusicBrainz release ID.""" + """Get an album corresponding to a release ID.""" + out = None try: - return mb.album_for_id(album_id) + 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 def _track_for_id(track_id): """Get an item for a recording MBID.""" diff --git a/beets/plugins.py b/beets/plugins.py index 079dd86b0..2cd0693f1 100755 --- a/beets/plugins.py +++ b/beets/plugins.py @@ -99,6 +99,12 @@ class BeetsPlugin(object): """ return {} + def album_for_id(self, album_id): + """Should return an AlbumInfo object or None if no matching release + was found. + """ + return None + listeners = None @@ -263,6 +269,16 @@ def item_candidates(item, artist, title): out.extend(plugin.item_candidates(item, artist, title)) return out +def album_for_id(album_id): + out = None + for plugin in find_plugins(): + try: + out = plugin.album_for_id(album_id) + except Exception as exc: + exc.log(log) + if out: + return out + def configure(config): """Sends the configuration object to each plugin.""" for plugin in find_plugins(): diff --git a/beets/ui/commands.py b/beets/ui/commands.py index 39f353421..8206212ea 100644 --- a/beets/ui/commands.py +++ b/beets/ui/commands.py @@ -579,20 +579,11 @@ def manual_search(singleton): return artist.strip(), name.strip() def manual_id(singleton): - """Input a MusicBrainz ID, either for an album ("release") or a - track ("recording"). If no valid ID is entered, returns None. + """Input an ID, either for an album ("release") or a track ("recording"). """ - prompt = 'Enter MusicBrainz %s ID:' % \ + prompt = 'Enter %s ID:' % \ ('recording' if singleton else 'release') - entry = input_(prompt).strip() - - # Find the first thing that looks like a UUID/MBID. - match = re.search('[a-f0-9]{8}(-[a-f0-9]{4}){3}-[a-f0-9]{12}', entry) - if match: - return match.group() - else: - log.error('Invalid MBID.') - return None + return input_(prompt).strip() class TerminalImportSession(importer.ImportSession): """An import session that runs in a terminal.