From 4eedd2bd8dbf9073eddfb94ed593dba12981df07 Mon Sep 17 00:00:00 2001 From: Diego Moreda Date: Thu, 21 Jan 2016 20:33:54 +0100 Subject: [PATCH] Store user-supplied MB ids on the Tasks * Store the user-supplied MusicBrainz IDs (via the "--musicbrainzid" importer argument) on ImporTask.task.musicbrainz_ids during the lookup_candidates() pipeline stage. * Update test cases to reflect the changes. --- beets/importer.py | 22 ++++++++++++---------- test/test_importer.py | 18 ++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/beets/importer.py b/beets/importer.py index 519eecc7e1..fb7195bc61 100644 --- a/beets/importer.py +++ b/beets/importer.py @@ -434,6 +434,7 @@ def __init__(self, toppath, paths, items): self.rec = None self.should_remove_duplicates = False self.is_album = True + self.musicbrainz_ids = [] # user-supplied candidate IDs. def set_choice(self, choice): """Given an AlbumMatch or TrackMatch object or an action constant, @@ -579,13 +580,12 @@ def handle_created(self, session): return tasks def lookup_candidates(self): - """Retrieve and store candidates for this album. + """Retrieve and store candidates for this album. User-specified + candidate IDs are stored in self.musicbrainz_ids: if present, the + initial lookup is restricted to only those IDs. """ - # Use a MusicBrainz id directly if provided by the importer -m option. - mb_ids = config['import']['musicbrainz_ids'].as_str_seq() - artist, album, candidates, recommendation = \ - autotag.tag_album(self.items, search_ids=mb_ids) + autotag.tag_album(self.items, search_ids=self.musicbrainz_ids) self.cur_artist = artist self.cur_album = album self.candidates = candidates @@ -824,11 +824,8 @@ def _emit_imported(self, lib): plugins.send('item_imported', lib=lib, item=item) def lookup_candidates(self): - # Use a MusicBrainz id directly if provided by the importer -m option. - mb_ids = config['import']['musicbrainz_ids'].as_str_seq() - - candidates, recommendation = autotag.tag_item(self.item, - search_ids=mb_ids) + candidates, recommendation = autotag.tag_item( + self.item, search_ids=self.musicbrainz_ids) self.candidates = candidates self.rec = recommendation @@ -1253,6 +1250,11 @@ def lookup_candidates(session, task): plugins.send('import_task_start', session=session, task=task) log.debug(u'Looking up: {0}', displayable_path(task.paths)) + + # Restrict the initial lookup to IDs specified by the user via the -m + # option. Currently all the IDs are passed onto the tasks directly. + task.musicbrainz_ids = session.config['musicbrainz_ids'].as_str_seq() + task.lookup_candidates() diff --git a/test/test_importer.py b/test/test_importer.py index 295f1a701b..21c11bc6e9 100644 --- a/test/test_importer.py +++ b/test/test_importer.py @@ -1758,27 +1758,25 @@ def test_several_mbid_one_singleton(self): def test_candidates_album(self): """Test directly ImportTask.lookup_candidates().""" - self.config['import']['musicbrainz_ids'] = \ - [self.MB_RELEASE_PREFIX + self.ID_RELEASE_0, - self.MB_RELEASE_PREFIX + self.ID_RELEASE_1, - 'an invalid and discarded id'] - task = importer.ImportTask(paths=self.import_dir, toppath='top path', items=[_common.item()]) + task.musicbrainz_ids = [self.MB_RELEASE_PREFIX + self.ID_RELEASE_0, + self.MB_RELEASE_PREFIX + self.ID_RELEASE_1, + 'an invalid and discarded id'] + task.lookup_candidates() self.assertEqual(set(['VALID_RELEASE_0', 'VALID_RELEASE_1']), set([c.info.album for c in task.candidates])) def test_candidates_singleton(self): """Test directly SingletonImportTask.lookup_candidates().""" - self.config['import']['musicbrainz_ids'] = \ - [self.MB_RECORDING_PREFIX + self.ID_RECORDING_0, - self.MB_RECORDING_PREFIX + self.ID_RECORDING_1, - 'an invalid and discarded id'] - task = importer.SingletonImportTask(toppath='top path', item=_common.item()) + task.musicbrainz_ids = [self.MB_RECORDING_PREFIX + self.ID_RECORDING_0, + self.MB_RECORDING_PREFIX + self.ID_RECORDING_1, + 'an invalid and discarded id'] + task.lookup_candidates() self.assertEqual(set(['VALID_RECORDING_0', 'VALID_RECORDING_1']), set([c.info.title for c in task.candidates]))