Skip to content
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

mbsync: add timid flag #5600

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 51 additions & 20 deletions beetsplug/mbsync.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ def commands(self):
dest="write",
help="don't write updated metadata to files",
)
cmd.parser.add_option(
"-t",
"--timid",
dest="timid",
action="store_true",
help="always confirm all actions",
)
cmd.parser.add_format_option()
cmd.func = self.func
return [cmd]
Expand All @@ -66,13 +73,14 @@ def func(self, lib, opts, args):
"""Command handler for the mbsync function."""
move = ui.should_move(opts.move)
pretend = opts.pretend
timid = opts.timid
write = ui.should_write(opts.write)
query = ui.decargs(args)

self.singletons(lib, query, move, pretend, write)
self.albums(lib, query, move, pretend, write)
self.singletons(lib, query, move, pretend, write, timid)
self.albums(lib, query, move, pretend, write, timid)

def singletons(self, lib, query, move, pretend, write):
def singletons(self, lib, query, move, pretend, write, timid):
"""Retrieve and apply info from the autotagger for items matched by
query.
"""
Expand Down Expand Up @@ -102,12 +110,26 @@ def singletons(self, lib, query, move, pretend, write):
)
continue

item_old = item.copy()
autotag.apply_item_metadata(item, track_info)
if not ui.show_model_changes(item, item_old):
continue

if timid:
print()
choice = ui.input_options(("Apply", "cancel", "skip"))
if choice == "a": # Apply.
pass
elif choice == "c": # Cancel.
return
elif choice == "s": # Skip.
continue

# Apply.
with lib.transaction():
autotag.apply_item_metadata(item, track_info)
apply_item_changes(lib, item, move, pretend, write)

def albums(self, lib, query, move, pretend, write):
def albums(self, lib, query, move, pretend, write, timid):
"""Retrieve and apply info from the autotagger for albums matched by
query and their items.
"""
Expand Down Expand Up @@ -174,28 +196,37 @@ def albums(self, lib, query, move, pretend, write):
mapping[item] = c
break

# Gather changes.
changed = []
items_old = [item.copy() for item in items]
autotag.apply_metadata(album_info, mapping)
for item, item_old in zip(items, items_old):
if ui.show_model_changes(item, item_old):
changed.append(item)

if len(changed) == 0:
continue

if timid:
print()
choice = ui.input_options(("Apply", "cancel", "skip"))
if choice == "a": # Apply.
pass
elif choice == "c": # Cancel.
return
elif choice == "s": # Skip.
continue

# Apply.
self._log.debug("applying changes to {}", album_formatted)
with lib.transaction():
autotag.apply_metadata(album_info, mapping)
changed = False
# Find any changed item to apply MusicBrainz changes to album.
any_changed_item = items[0]
for item in items:
item_changed = ui.show_model_changes(item)
changed |= item_changed
if item_changed:
any_changed_item = item
apply_item_changes(lib, item, move, pretend, write)

if not changed:
# No change to any item.
continue
for item in changed:
apply_item_changes(lib, item, move, pretend, write)

if not pretend:
# Update album structure to reflect an item in it.
for key in library.Album.item_keys:
a[key] = any_changed_item[key]
a[key] = changed[0][key]
a.store()

# Move album art (and any inconsistent items).
Expand Down
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ New features:
control the maximum allowed distance between the lyrics search result and the
tagged item's artist and title. This is useful for preventing false positives
when fetching lyrics.
* :doc:`/plugins/mbsync`: gained a new ``--timid`` flag to print and
confirm the changes before applying. :bug:`4250`

Bug fixes:

Expand Down
2 changes: 2 additions & 0 deletions docs/plugins/mbsync.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ The command has a few command-line options:
* To customize the output of unrecognized items, use the ``-f``
(``--format``) option. The default output is ``format_item`` or
``format_album`` for items and albums, respectively.
* To prompt for confirmation before applying changes, use the ``-t``
(``--timid``) option.