From 79d84c0e4f2325c4102dd1febacf642b811b05a4 Mon Sep 17 00:00:00 2001 From: Diego Moreda Date: Fri, 22 Jan 2016 16:31:00 +0100 Subject: [PATCH] Style and doc fixes for MB_id importer argument * Rename the importer argument and related variables to make it more generic, as the feature should be independent of the backend used and not restricted to MusicBrainz. * Update documentation and docstrings accordingly. * Add changelog entry. --- beets/autotag/match.py | 4 ++-- beets/config_default.yaml | 2 +- beets/importer.py | 10 +++++----- beets/ui/commands.py | 9 +++++---- docs/changelog.rst | 4 ++++ docs/guides/tagger.rst | 12 ++++++------ docs/reference/cli.rst | 8 ++++---- test/test_importer.py | 20 ++++++++++---------- 8 files changed, 37 insertions(+), 32 deletions(-) diff --git a/beets/autotag/match.py b/beets/autotag/match.py index 8baaf0108..3565dba3f 100644 --- a/beets/autotag/match.py +++ b/beets/autotag/match.py @@ -381,7 +381,7 @@ def tag_album(items, search_artist=None, search_album=None, The `AlbumMatch` objects are generated by searching the metadata backends. By default, the metadata of the items is used for the search. This can be customized by setting the parameters. - `search_ids` is a list of MusicBrainz release IDs: if specified, + `search_ids` is a list of metadata backend IDs: if specified, it will restrict the candidates to those IDs, ignoring `search_artist` and `search album`. The `mapping` field of the album has the matched `items` as keys. @@ -455,7 +455,7 @@ def tag_item(item, search_artist=None, search_title=None, TrackMatch objects. `search_artist` and `search_title` may be used to override the current metadata for the purposes of the MusicBrainz title. `search_ids` may be used for restricting the search to a list - of MusicBrainz IDs. + of metadata backend IDs. """ # Holds candidates found so far: keys are MBIDs; values are # (distance, TrackInfo) pairs. diff --git a/beets/config_default.yaml b/beets/config_default.yaml index 3fdfaf836..5bc921167 100644 --- a/beets/config_default.yaml +++ b/beets/config_default.yaml @@ -22,7 +22,7 @@ import: flat: no group_albums: no pretend: false - musicbrainz_ids: [] + search_ids: [] clutter: ["Thumbs.DB", ".DS_Store"] ignore: [".*", "*~", "System Volume Information"] diff --git a/beets/importer.py b/beets/importer.py index fb7195bc6..868ac6922 100644 --- a/beets/importer.py +++ b/beets/importer.py @@ -434,7 +434,7 @@ class ImportTask(BaseImportTask): self.rec = None self.should_remove_duplicates = False self.is_album = True - self.musicbrainz_ids = [] # user-supplied candidate IDs. + self.search_ids = [] # user-supplied candidate IDs. def set_choice(self, choice): """Given an AlbumMatch or TrackMatch object or an action constant, @@ -581,11 +581,11 @@ class ImportTask(BaseImportTask): def lookup_candidates(self): """Retrieve and store candidates for this album. User-specified - candidate IDs are stored in self.musicbrainz_ids: if present, the + candidate IDs are stored in self.search_ids: if present, the initial lookup is restricted to only those IDs. """ artist, album, candidates, recommendation = \ - autotag.tag_album(self.items, search_ids=self.musicbrainz_ids) + autotag.tag_album(self.items, search_ids=self.search_ids) self.cur_artist = artist self.cur_album = album self.candidates = candidates @@ -825,7 +825,7 @@ class SingletonImportTask(ImportTask): def lookup_candidates(self): candidates, recommendation = autotag.tag_item( - self.item, search_ids=self.musicbrainz_ids) + self.item, search_ids=self.search_ids) self.candidates = candidates self.rec = recommendation @@ -1253,7 +1253,7 @@ def lookup_candidates(session, task): # 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.search_ids = session.config['search_ids'].as_str_seq() task.lookup_candidates() diff --git a/beets/ui/commands.py b/beets/ui/commands.py index c68dcf10f..3e3acb7c3 100644 --- a/beets/ui/commands.py +++ b/beets/ui/commands.py @@ -734,7 +734,7 @@ class TerminalImportSession(importer.ImportSession): search_id = manual_id(False) if search_id: _, _, candidates, rec = autotag.tag_album( - task.items, search_ids=search_id.split(' ') + task.items, search_ids=search_id.split() ) elif choice in extra_ops.keys(): # Allow extra ops to automatically set the post-choice. @@ -787,7 +787,7 @@ class TerminalImportSession(importer.ImportSession): search_id = manual_id(True) if search_id: candidates, rec = autotag.tag_item( - task.item, search_ids=search_id.split(' ')) + task.item, search_ids=search_id.split()) elif choice in extra_ops.keys(): # Allow extra ops to automatically set the post-choice. post_choice = extra_ops[choice](self, task) @@ -1023,8 +1023,9 @@ import_cmd.parser.add_option( help='just print the files to import' ) import_cmd.parser.add_option( - '-m', '--musicbrainzid', dest='musicbrainz_ids', action='append', - help='restrict the matching to a single MusicBrainz id' + '-S', '--search-id', dest='search_ids', action='append', + metavar='BACKEND_ID', + help='restrict matching to a specific metadata backend ID' ) import_cmd.func = import_func default_commands.append(import_cmd) diff --git a/docs/changelog.rst b/docs/changelog.rst index 51fab3100..b6c8bfb25 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -20,6 +20,10 @@ New: session. :bug:`1779` * :doc:`/plugins/info`: A new option will print only fields' names and not their values. Thanks to :user:`GuilhermeHideki`. :bug:`1812` +* A new ``--search-id`` importer option lets you specify one or several + matching MusicBrainz/Discogs IDs directly, bypassing the default initial + candidate search. Also, the ``enter Id`` prompt choice now accepts several + IDs, separated by spaces. :bug:`1808` .. _AcousticBrainz: http://acousticbrainz.org/ diff --git a/docs/guides/tagger.rst b/docs/guides/tagger.rst index 95975c038..0b21644bf 100644 --- a/docs/guides/tagger.rst +++ b/docs/guides/tagger.rst @@ -60,8 +60,8 @@ all of these limitations. because beets by default infers tags based on existing metadata. But this is not a hard and fast rule---there are a few ways to tag metadata-poor music: - * You can use the *E* option described below to search in MusicBrainz for - a specific album or song. + * You can use the *E* or *I* options described below to search in + MusicBrainz for a specific album or song. * The :doc:`Acoustid plugin ` extends the autotagger to use acoustic fingerprinting to find information for arbitrary audio. Install that plugin if you're willing to spend a little more CPU power @@ -190,10 +190,10 @@ following: option if beets hasn't found any good options because the album is mistagged or untagged. -* *I*: Enter a MusicBrainz id to use as search in the database. Use this option - to specify a MusicBrainz entity (release or recording) directly, by pasting - its ID or the full URL. You can also specify several IDs by separating them - by a space. +* *I*: Enter a metadata backend ID to use as search in the database. Use this + option to specify a backend entity (for example, a MusicBrainz release or + recording) directly, by pasting its ID or the full URL. You can also specify + several IDs by separating them by a space. * *B*: Cancel this import task altogether. No further albums will be tagged; beets shuts down immediately. The next time you attempt to import the same diff --git a/docs/reference/cli.rst b/docs/reference/cli.rst index 25b3fcbc1..2ded2c48d 100644 --- a/docs/reference/cli.rst +++ b/docs/reference/cli.rst @@ -132,10 +132,10 @@ Optional command flags: option. If set, beets will just print a list of files that it would otherwise import. -* If you already have a MusicBrainz ID that matches the items to be imported, - you can instruct beets to restrict the search to that ID instead of searching - for other candidates by using the ``--musicbrainzid MB_ID`` option. Multiple - IDs can be specified by simply repeating the option several times. +* If you already have a metadata backend ID that matches the items to be + imported, you can instruct beets to restrict the search to that ID instead of + searching for other candidates by using the ``--search_id SEARCH_ID`` option. + Multiple IDs can be specified by simply repeating the option several times. .. _rarfile: https://pypi.python.org/pypi/rarfile/2.2 diff --git a/test/test_importer.py b/test/test_importer.py index 21c11bc6e..56f4a17a5 100644 --- a/test/test_importer.py +++ b/test/test_importer.py @@ -1717,7 +1717,7 @@ class ImportMusicBrainzIdTest(_common.TestCase, ImportHelper): self.teardown_beets() def test_one_mbid_one_album(self): - self.config['import']['musicbrainz_ids'] = \ + self.config['import']['search_ids'] = \ [self.MB_RELEASE_PREFIX + self.ID_RELEASE_0] self._setup_import_session() @@ -1726,7 +1726,7 @@ class ImportMusicBrainzIdTest(_common.TestCase, ImportHelper): self.assertEqual(self.lib.albums().get().album, 'VALID_RELEASE_0') def test_several_mbid_one_album(self): - self.config['import']['musicbrainz_ids'] = \ + self.config['import']['search_ids'] = \ [self.MB_RELEASE_PREFIX + self.ID_RELEASE_0, self.MB_RELEASE_PREFIX + self.ID_RELEASE_1] self._setup_import_session() @@ -1737,7 +1737,7 @@ class ImportMusicBrainzIdTest(_common.TestCase, ImportHelper): self.assertEqual(self.lib.albums().get().album, 'VALID_RELEASE_1') def test_one_mbid_one_singleton(self): - self.config['import']['musicbrainz_ids'] = \ + self.config['import']['search_ids'] = \ [self.MB_RECORDING_PREFIX + self.ID_RECORDING_0] self._setup_import_session(singletons=True) @@ -1746,7 +1746,7 @@ class ImportMusicBrainzIdTest(_common.TestCase, ImportHelper): self.assertEqual(self.lib.items().get().title, 'VALID_RECORDING_0') def test_several_mbid_one_singleton(self): - self.config['import']['musicbrainz_ids'] = \ + self.config['import']['search_ids'] = \ [self.MB_RECORDING_PREFIX + self.ID_RECORDING_0, self.MB_RECORDING_PREFIX + self.ID_RECORDING_1] self._setup_import_session(singletons=True) @@ -1761,9 +1761,9 @@ class ImportMusicBrainzIdTest(_common.TestCase, ImportHelper): 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.search_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']), @@ -1773,9 +1773,9 @@ class ImportMusicBrainzIdTest(_common.TestCase, ImportHelper): """Test directly SingletonImportTask.lookup_candidates().""" 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.search_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']),