Skip to content

Commit 36b01ef

Browse files
committed
mbsync: add timid flag
1 parent bcc91ff commit 36b01ef

File tree

3 files changed

+56
-20
lines changed

3 files changed

+56
-20
lines changed

beetsplug/mbsync.py

+51-20
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ def commands(self):
5858
dest="write",
5959
help="don't write updated metadata to files",
6060
)
61+
cmd.parser.add_option(
62+
"-t",
63+
"--timid",
64+
dest="timid",
65+
action="store_true",
66+
help="always confirm all actions",
67+
)
6168
cmd.parser.add_format_option()
6269
cmd.func = self.func
6370
return [cmd]
@@ -66,13 +73,14 @@ def func(self, lib, opts, args):
6673
"""Command handler for the mbsync function."""
6774
move = ui.should_move(opts.move)
6875
pretend = opts.pretend
76+
timid = opts.timid
6977
write = ui.should_write(opts.write)
7078
query = ui.decargs(args)
7179

72-
self.singletons(lib, query, move, pretend, write)
73-
self.albums(lib, query, move, pretend, write)
80+
self.singletons(lib, query, move, pretend, write, timid)
81+
self.albums(lib, query, move, pretend, write, timid)
7482

75-
def singletons(self, lib, query, move, pretend, write):
83+
def singletons(self, lib, query, move, pretend, write, timid):
7684
"""Retrieve and apply info from the autotagger for items matched by
7785
query.
7886
"""
@@ -102,12 +110,26 @@ def singletons(self, lib, query, move, pretend, write):
102110
)
103111
continue
104112

113+
item_old = item.copy()
114+
autotag.apply_item_metadata(item, track_info)
115+
if not ui.show_model_changes(item, item_old):
116+
continue
117+
118+
if timid:
119+
print()
120+
choice = ui.input_options(("Apply", "cancel", "skip"))
121+
if choice == "a": # Apply.
122+
pass
123+
elif choice == "c": # Cancel.
124+
return
125+
elif choice == "s": # Skip.
126+
continue
127+
105128
# Apply.
106129
with lib.transaction():
107-
autotag.apply_item_metadata(item, track_info)
108130
apply_item_changes(lib, item, move, pretend, write)
109131

110-
def albums(self, lib, query, move, pretend, write):
132+
def albums(self, lib, query, move, pretend, write, timid):
111133
"""Retrieve and apply info from the autotagger for albums matched by
112134
query and their items.
113135
"""
@@ -174,28 +196,37 @@ def albums(self, lib, query, move, pretend, write):
174196
mapping[item] = c
175197
break
176198

199+
# Gather changes.
200+
changed = []
201+
items_old = [item.copy() for item in items]
202+
autotag.apply_metadata(album_info, mapping)
203+
for item, item_old in zip(items, items_old):
204+
if ui.show_model_changes(item, item_old):
205+
changed.append(item)
206+
207+
if len(changed) == 0:
208+
continue
209+
210+
if timid:
211+
print()
212+
choice = ui.input_options(("Apply", "cancel", "skip"))
213+
if choice == "a": # Apply.
214+
pass
215+
elif choice == "c": # Cancel.
216+
return
217+
elif choice == "s": # Skip.
218+
continue
219+
177220
# Apply.
178221
self._log.debug("applying changes to {}", album_formatted)
179222
with lib.transaction():
180-
autotag.apply_metadata(album_info, mapping)
181-
changed = False
182-
# Find any changed item to apply MusicBrainz changes to album.
183-
any_changed_item = items[0]
184-
for item in items:
185-
item_changed = ui.show_model_changes(item)
186-
changed |= item_changed
187-
if item_changed:
188-
any_changed_item = item
189-
apply_item_changes(lib, item, move, pretend, write)
190-
191-
if not changed:
192-
# No change to any item.
193-
continue
223+
for item in changed:
224+
apply_item_changes(lib, item, move, pretend, write)
194225

195226
if not pretend:
196227
# Update album structure to reflect an item in it.
197228
for key in library.Album.item_keys:
198-
a[key] = any_changed_item[key]
229+
a[key] = changed[0][key]
199230
a.store()
200231

201232
# Move album art (and any inconsistent items).

docs/changelog.rst

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ been dropped.
1111

1212
New features:
1313

14+
* :doc:`/plugins/mbsync`: gained a new ``--timid`` flag to print and
15+
confirm the changes before applying. :bug:`4250`
16+
1417
Bug fixes:
1518

1619
* :doc:`plugins/lyrics`: LRCLib will fallback to plain lyrics if synced lyrics

docs/plugins/mbsync.rst

+2
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,5 @@ The command has a few command-line options:
3636
* To customize the output of unrecognized items, use the ``-f``
3737
(``--format``) option. The default output is ``format_item`` or
3838
``format_album`` for items and albums, respectively.
39+
* To prompt for confirmation before applying changes, use the ``-t``
40+
(``--timid``) option.

0 commit comments

Comments
 (0)