-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add musicbrainz id option to importer #1808
Changes from 8 commits
1c95b7c
48c92fb
865be11
c12e974
4e5ddac
39cf465
b526227
4eedd2b
79d84c0
4f51302
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,10 +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. | ||
""" | ||
artist, album, candidates, recommendation = \ | ||
autotag.tag_album(self.items) | ||
autotag.tag_album(self.items, search_ids=self.musicbrainz_ids) | ||
self.cur_artist = artist | ||
self.cur_album = album | ||
self.candidates = candidates | ||
|
@@ -821,7 +824,8 @@ def _emit_imported(self, lib): | |
plugins.send('item_imported', lib=lib, item=item) | ||
|
||
def lookup_candidates(self): | ||
candidates, recommendation = autotag.tag_item(self.item) | ||
candidates, recommendation = autotag.tag_item( | ||
self.item, search_ids=self.musicbrainz_ids) | ||
self.candidates = candidates | ||
self.rec = recommendation | ||
|
||
|
@@ -1246,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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks great for now. As you note in your other comment, we can move this around later if we want a more sophisticated way of populating this. |
||
|
||
task.lookup_candidates() | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -734,7 +734,7 @@ def choose_match(self, task): | |
search_id = manual_id(False) | ||
if search_id: | ||
_, _, candidates, rec = autotag.tag_album( | ||
task.items, search_id=search_id | ||
task.items, search_ids=search_id.split(' ') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably use |
||
) | ||
elif choice in extra_ops.keys(): | ||
# Allow extra ops to automatically set the post-choice. | ||
|
@@ -786,8 +786,8 @@ def choose_item(self, task): | |
# Ask for a track ID. | ||
search_id = manual_id(True) | ||
if search_id: | ||
candidates, rec = autotag.tag_item(task.item, | ||
search_id=search_id) | ||
candidates, rec = autotag.tag_item( | ||
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) | ||
|
@@ -1022,6 +1022,10 @@ def import_func(lib, opts, args): | |
'--pretend', dest='pretend', action='store_true', | ||
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' | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a tiny nitpick, but these technically don't need to be MBIDs. Other backends can also interpret these IDs (for now, just the Discogs plugin). Alas, I don't have a great idea for another option name since |
||
import_cmd.func = import_func | ||
default_commands.append(import_cmd) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably describe
search_ids
in the docstring. (Although I note we didn't documentsearch_id
before—bad @sampsyo!)