Added transfer command
This commit is contained in:
parent
2c8225b986
commit
e513a3f217
1 changed files with 71 additions and 4 deletions
|
|
@ -56,7 +56,8 @@ action_map = {
|
|||
"add": 0,
|
||||
"remove": 1,
|
||||
"removeall": 2,
|
||||
"show": 3
|
||||
"show": 3,
|
||||
"transfer": 4
|
||||
}
|
||||
|
||||
def modify_labels(lib, opts, args):
|
||||
|
|
@ -64,11 +65,15 @@ def modify_labels(lib, opts, args):
|
|||
|
||||
if action not in action_map:
|
||||
print_("%s is not a valid action. " % action)
|
||||
print_("Valid actions are: add, remove, removeall, show")
|
||||
print_("Valid actions are: add, remove, removeall, show, transfer")
|
||||
return
|
||||
|
||||
actnum = action_map[action]
|
||||
|
||||
if actnum == 4: # transfer
|
||||
transfer_labels(lib, opts, args[1:])
|
||||
return
|
||||
|
||||
if actnum >= 2:
|
||||
label = None
|
||||
query = args[1:]
|
||||
|
|
@ -80,12 +85,74 @@ def modify_labels(lib, opts, args):
|
|||
|
||||
if actnum == 3:
|
||||
for obj in items:
|
||||
print_(obj.title)
|
||||
if "mylabels" in obj:
|
||||
print_(" " + "; ".join(obj["mylabels"]))
|
||||
labels = json.loads(obj["mylabels"])
|
||||
labelstr = ";".join([f"{key}:{labels[key]}" for key in labels.keys()])
|
||||
print_(f"{obj.title}: {labelstr}")
|
||||
else:
|
||||
do_modify_labels(lib, items, label, actnum)
|
||||
|
||||
def transfer_labels(lib, opts, args):
|
||||
source_query = args[0]
|
||||
dest_query = args[1]
|
||||
|
||||
source_items = lib.items(query=source_query)
|
||||
dest_items = lib.items(query=dest_query)
|
||||
|
||||
source_list = list(source_items)
|
||||
dest_list = list(dest_items)
|
||||
|
||||
if len(source_list) == 0:
|
||||
print_("No source items found.")
|
||||
return
|
||||
|
||||
if len(dest_list) == 0:
|
||||
print_("No destination items found.")
|
||||
return
|
||||
|
||||
if len(source_list) > 1:
|
||||
print_("Multiple source items found. Please refine your query to select one source item.")
|
||||
for item in source_list:
|
||||
print_(f" - {item.artist} - {item.title} ({item.path})")
|
||||
return
|
||||
|
||||
if len(dest_list) > 1:
|
||||
print_("Multiple destination items found. Please refine your query to select one destination item.")
|
||||
for item in dest_list:
|
||||
print_(f" - {item.artist} - {item.title} ({item.path})")
|
||||
return
|
||||
|
||||
source = source_list[0]
|
||||
dest = dest_list[0]
|
||||
|
||||
print_(f"Source: {source.artist} - {source.title}")
|
||||
print_(f"Dest: {dest.artist} - {dest.title}")
|
||||
print_("")
|
||||
|
||||
if "mylabels" not in source or not source["mylabels"]:
|
||||
print_("Source has no labels to transfer.")
|
||||
return
|
||||
|
||||
labels = json.loads(source["mylabels"])
|
||||
labelstr = ";".join([f"{key}:{labels[key]}" for key in labels.keys()])
|
||||
print_(f"Labels to transfer: {labelstr}")
|
||||
|
||||
if "mylabels" in dest and dest["mylabels"]:
|
||||
dest_labels = json.loads(dest["mylabels"])
|
||||
dest_labelstr = ";".join([f"{key}:{dest_labels[key]}" for key in dest_labels.keys()])
|
||||
print_(f"WARNING: Destination already has labels: {dest_labelstr}")
|
||||
print_("These will be overwritten!")
|
||||
print_("")
|
||||
|
||||
if not ui.input_yn("Transfer labels? (y/n)", True):
|
||||
return
|
||||
|
||||
with lib.transaction():
|
||||
dest["mylabels"] = source["mylabels"]
|
||||
dest.try_sync(True, False, False)
|
||||
|
||||
print_("Transfer complete.")
|
||||
|
||||
labels_command = Subcommand('labels', help='Add or remove labels')
|
||||
labels_command.func = modify_labels
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue