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.
This commit is contained in:
Diego Moreda 2016-01-21 20:33:54 +01:00
parent b526227482
commit 4eedd2bd8d
2 changed files with 20 additions and 20 deletions

View file

@ -434,6 +434,7 @@ class ImportTask(BaseImportTask):
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 @@ class ImportTask(BaseImportTask):
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 @@ class SingletonImportTask(ImportTask):
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()

View file

@ -1758,27 +1758,25 @@ class ImportMusicBrainzIdTest(_common.TestCase, ImportHelper):
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]))