Skip to content

Commit 537a71f

Browse files
committed
duplicates: Add --remove option to duplicates plugin
Removes from library but keeps files.
1 parent ac96b9b commit 537a71f

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

beetsplug/duplicates.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def __init__(self):
5353
"tiebreak": {},
5454
"strict": False,
5555
"tag": "",
56+
"remove": False,
5657
}
5758
)
5859

@@ -131,6 +132,13 @@ def __init__(self):
131132
action="store",
132133
help="tag matched items with 'k=v' attribute",
133134
)
135+
self._command.parser.add_option(
136+
"-r",
137+
"--remove",
138+
dest="remove",
139+
action="store_true",
140+
help="remove items from library",
141+
)
134142
self._command.parser.add_all_common_options()
135143

136144
def commands(self):
@@ -141,6 +149,7 @@ def _dup(lib, opts, args):
141149
copy = bytestring_path(self.config["copy"].as_str())
142150
count = self.config["count"].get(bool)
143151
delete = self.config["delete"].get(bool)
152+
remove = self.config["remove"].get(bool)
144153
fmt = self.config["format"].get(str)
145154
full = self.config["full"].get(bool)
146155
keys = self.config["keys"].as_str_seq()
@@ -196,6 +205,7 @@ def _dup(lib, opts, args):
196205
copy=copy,
197206
move=move,
198207
delete=delete,
208+
remove=remove,
199209
tag=tag,
200210
fmt=fmt.format(obj_count),
201211
)
@@ -204,7 +214,14 @@ def _dup(lib, opts, args):
204214
return [self._command]
205215

206216
def _process_item(
207-
self, item, copy=False, move=False, delete=False, tag=False, fmt=""
217+
self,
218+
item,
219+
copy=False,
220+
move=False,
221+
delete=False,
222+
tag=False,
223+
fmt="",
224+
remove=False,
208225
):
209226
"""Process Item `item`."""
210227
print_(format(item, fmt))
@@ -216,6 +233,8 @@ def _process_item(
216233
item.store()
217234
if delete:
218235
item.remove(delete=True)
236+
if remove:
237+
item.remove(delete=False)
219238
if tag:
220239
try:
221240
k, v = tag.split("=")

0 commit comments

Comments
 (0)