Skip to content

Commit 2a896d4

Browse files
authored
Add --remove option to duplicates plugin (#5832)
The duplicates plugin currently only supports deleting files entirely, sometimes it's desired to only fix the library and keep files in place. This PR adds this possibility.
2 parents ac96b9b + 7c22cd6 commit 2a896d4

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
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+
elif remove:
237+
item.remove(delete=False)
219238
if tag:
220239
try:
221240
k, v = tag.split("=")

docs/changelog.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ New features:
2323
singletons by their Discogs ID.
2424
:bug:`4661`
2525
* :doc:`plugins/replace`: Add new plugin.
26+
* :doc:`plugins/duplicates`: Add ``--remove`` option, allowing to remove from
27+
the library without deleting media files.
28+
:bug:`5832`
2629

2730
Bug fixes:
2831

docs/plugins/duplicates.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ duplicates themselves via command-line switches ::
3434
-o DEST, --copy=DEST copy items to dest
3535
-p, --path print paths for matched items or albums
3636
-t TAG, --tag=TAG tag matched items with 'k=v' attribute
37+
-r, --remove remove items from library
3738

3839
Configuration
3940
-------------
@@ -57,7 +58,7 @@ file. The available options mirror the command-line options:
5758
``$albumartist - $album - $title: $count`` (for tracks) or ``$albumartist -
5859
$album: $count`` (for albums).
5960
Default: ``no``.
60-
- **delete**: Removes matched items from the library and from the disk.
61+
- **delete**: Remove matched items from the library and from the disk.
6162
Default: ``no``
6263
- **format**: A specific format with which to print every track
6364
or album. This uses the same template syntax as beets'
@@ -92,6 +93,8 @@ file. The available options mirror the command-line options:
9293
set. If you would like to consider the lower bitrates as duplicates,
9394
for example, set ``tiebreak: items: [bitrate]``.
9495
Default: ``{}``.
96+
- **remove**: Remove matched items from the library, but not from the disk.
97+
Default: ``no``.
9598

9699
Examples
97100
--------

0 commit comments

Comments
 (0)