Skip to content

Commit

Permalink
Store user-supplied MB ids on the Tasks
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
diego-plan9 committed Jan 21, 2016
1 parent b526227 commit 4eedd2b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
22 changes: 12 additions & 10 deletions beets/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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()


Expand Down
18 changes: 8 additions & 10 deletions test/test_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down

0 comments on commit 4eedd2b

Please sign in to comment.