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.
This commit is contained in:
Diego Moreda 2016-01-22 16:31:00 +01:00
parent 4eedd2bd8d
commit 79d84c0e4f
8 changed files with 37 additions and 32 deletions

View file

@ -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.

View file

@ -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"]

View file

@ -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()

View file

@ -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)

View file

@ -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/

View file

@ -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 </plugins/chroma>` 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

View file

@ -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

View file

@ -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']),