From 1c95b7c46fb74bb367082948dcd4fa3d81b94539 Mon Sep 17 00:00:00 2001 From: Diego Moreda Date: Mon, 11 Jan 2016 17:39:05 +0100 Subject: [PATCH] Add musicbrainz id option to importer * Add '-m', '--musicbrainzid' option to the import command, allowing the user to specify a single MusicBrainz ID to be used for the candidate lookup instead of trying to find suitable candidates. * Modify lookup_candidates() of ImportTask and SingletonImportTask to use the musicbrainz id if present. --- beets/importer.py | 15 +++++++++++++-- beets/ui/commands.py | 4 ++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/beets/importer.py b/beets/importer.py index e0d69b968..413750ef3 100644 --- a/beets/importer.py +++ b/beets/importer.py @@ -581,8 +581,13 @@ class ImportTask(BaseImportTask): def lookup_candidates(self): """Retrieve and store candidates for this album. """ + # Use a MusicBrainz id directly if provided by the importer -m option. + mb_id = None + if config['import']['musicbrainz_id'].exists(): + mb_id = config['import']['musicbrainz_id'].get() + artist, album, candidates, recommendation = \ - autotag.tag_album(self.items) + autotag.tag_album(self.items, search_id=mb_id) self.cur_artist = artist self.cur_album = album self.candidates = candidates @@ -821,7 +826,13 @@ class SingletonImportTask(ImportTask): plugins.send('item_imported', lib=lib, item=item) def lookup_candidates(self): - candidates, recommendation = autotag.tag_item(self.item) + # Use a MusicBrainz id directly if provided by the importer -m option. + mb_id = None + if config['import']['musicbrainz_id'].exists(): + mb_id = config['import']['musicbrainz_id'].get() + + candidates, recommendation = autotag.tag_item(self.item, + search_id=mb_id) self.candidates = candidates self.rec = recommendation diff --git a/beets/ui/commands.py b/beets/ui/commands.py index 773c10cae..6616cb1bc 100644 --- a/beets/ui/commands.py +++ b/beets/ui/commands.py @@ -1022,6 +1022,10 @@ import_cmd.parser.add_option( '--pretend', dest='pretend', action='store_true', help='just print the files to import' ) +import_cmd.parser.add_option( + '-m', '--musicbrainzid', dest='musicbrainz_id', + help='restrict the matching to a single MusicBrainz id' +) import_cmd.func = import_func default_commands.append(import_cmd)