MCPcopy
hub / github.com/beetbox/beets / modify_items

Function modify_items

beets/ui/commands/modify.py:11–65  ·  view source on GitHub ↗

Modifies matching items according to user-specified assignments and deletions. `mods` is a dictionary of field and value pairse indicating assignments. `dels` is a list of fields to be deleted.

(lib, mods, dels, query, write, move, album, confirm, inherit)

Source from the content-addressed store, hash-verified

9
10
11def modify_items(lib, mods, dels, query, write, move, album, confirm, inherit):
12 """Modifies matching items according to user-specified assignments and
13 deletions.
14
15 `mods` is a dictionary of field and value pairse indicating
16 assignments. `dels` is a list of fields to be deleted.
17 """
18 # Parse key=value specifications into a dictionary.
19 model_cls = library.Album if album else library.Item
20
21 # Get the items to modify.
22 items, albums = do_query(lib, query, album, False)
23 objs = albums if album else items
24
25 # Apply changes *temporarily*, preview them, and collect modified
26 # objects.
27 ui.print_(f"Modifying {len(objs)} {'album' if album else 'item'}s.")
28 changed = []
29 templates = {
30 key: functemplate.template(value) for key, value in mods.items()
31 }
32 for obj in objs:
33 obj_mods = {
34 key: model_cls._parse(key, obj.evaluate_template(templates[key]))
35 for key in mods.keys()
36 }
37 if print_and_modify(obj, obj_mods, dels) and obj not in changed:
38 changed.append(obj)
39
40 # Still something to do?
41 if not changed:
42 ui.print_("No changes to make.")
43 return
44
45 # Confirm action.
46 if confirm:
47 if write and move:
48 extra = ", move and write tags"
49 elif write:
50 extra = " and write tags"
51 elif move:
52 extra = " and move"
53 else:
54 extra = ""
55
56 changed = ui.input_select_objects(
57 f"Really modify{extra}",
58 changed,
59 lambda o: print_and_modify(o, mods, dels),
60 )
61
62 # Apply changes to database and files
63 with lib.transaction():
64 for obj in changed:
65 obj.try_sync(write, move, inherit)
66
67
68def print_and_modify(obj, mods, dels):

Callers 1

modify_funcFunction · 0.85

Calls 8

do_queryFunction · 0.85
print_and_modifyFunction · 0.85
_parseMethod · 0.80
evaluate_templateMethod · 0.80
transactionMethod · 0.80
itemsMethod · 0.45
keysMethod · 0.45
try_syncMethod · 0.45

Tested by

no test coverage detected