From 537a71ff8286461440ee883ff2c077636bf7e120 Mon Sep 17 00:00:00 2001 From: J0J0 Todos Date: Mon, 6 Nov 2023 14:47:34 +0100 Subject: [PATCH 1/4] duplicates: Add --remove option to duplicates plugin Removes from library but keeps files. --- beetsplug/duplicates.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/beetsplug/duplicates.py b/beetsplug/duplicates.py index fadb29845..76441133f 100644 --- a/beetsplug/duplicates.py +++ b/beetsplug/duplicates.py @@ -53,6 +53,7 @@ class DuplicatesPlugin(BeetsPlugin): "tiebreak": {}, "strict": False, "tag": "", + "remove": False, } ) @@ -131,6 +132,13 @@ class DuplicatesPlugin(BeetsPlugin): action="store", help="tag matched items with 'k=v' attribute", ) + self._command.parser.add_option( + "-r", + "--remove", + dest="remove", + action="store_true", + help="remove items from library", + ) self._command.parser.add_all_common_options() def commands(self): @@ -141,6 +149,7 @@ class DuplicatesPlugin(BeetsPlugin): copy = bytestring_path(self.config["copy"].as_str()) count = self.config["count"].get(bool) delete = self.config["delete"].get(bool) + remove = self.config["remove"].get(bool) fmt = self.config["format"].get(str) full = self.config["full"].get(bool) keys = self.config["keys"].as_str_seq() @@ -196,6 +205,7 @@ class DuplicatesPlugin(BeetsPlugin): copy=copy, move=move, delete=delete, + remove=remove, tag=tag, fmt=fmt.format(obj_count), ) @@ -204,7 +214,14 @@ class DuplicatesPlugin(BeetsPlugin): return [self._command] def _process_item( - self, item, copy=False, move=False, delete=False, tag=False, fmt="" + self, + item, + copy=False, + move=False, + delete=False, + tag=False, + fmt="", + remove=False, ): """Process Item `item`.""" print_(format(item, fmt)) @@ -216,6 +233,8 @@ class DuplicatesPlugin(BeetsPlugin): item.store() if delete: item.remove(delete=True) + if remove: + item.remove(delete=False) if tag: try: k, v = tag.split("=") From 549847bfd8c64ef68c65b36f652a5d01031e4294 Mon Sep 17 00:00:00 2001 From: J0J0 Todos Date: Sun, 22 Jun 2025 08:48:10 +0200 Subject: [PATCH 2/4] duplicates: Add docs for --remove option --- docs/plugins/duplicates.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/plugins/duplicates.rst b/docs/plugins/duplicates.rst index 8b11b6661..8ce0e4578 100644 --- a/docs/plugins/duplicates.rst +++ b/docs/plugins/duplicates.rst @@ -34,6 +34,7 @@ duplicates themselves via command-line switches :: -o DEST, --copy=DEST copy items to dest -p, --path print paths for matched items or albums -t TAG, --tag=TAG tag matched items with 'k=v' attribute + -r, --remove remove items from library Configuration ------------- @@ -57,7 +58,7 @@ file. The available options mirror the command-line options: ``$albumartist - $album - $title: $count`` (for tracks) or ``$albumartist - $album: $count`` (for albums). Default: ``no``. -- **delete**: Removes matched items from the library and from the disk. +- **delete**: Remove matched items from the library and from the disk. Default: ``no`` - **format**: A specific format with which to print every track or album. This uses the same template syntax as beets' @@ -92,6 +93,8 @@ file. The available options mirror the command-line options: set. If you would like to consider the lower bitrates as duplicates, for example, set ``tiebreak: items: [bitrate]``. Default: ``{}``. +- **remove**: Remove matched items from the library, but not from the disk. + Default: ``no``. Examples -------- From 47eee070ba426fc61bfd3e72d166917c60076b8a Mon Sep 17 00:00:00 2001 From: J0J0 Todos <2733783+JOJ0@users.noreply.github.com> Date: Wed, 2 Jul 2025 07:10:46 +0200 Subject: [PATCH 3/4] duplicates: remove or delete options mutually exclusive Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- beetsplug/duplicates.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beetsplug/duplicates.py b/beetsplug/duplicates.py index 76441133f..5a2be0cd2 100644 --- a/beetsplug/duplicates.py +++ b/beetsplug/duplicates.py @@ -233,7 +233,7 @@ class DuplicatesPlugin(BeetsPlugin): item.store() if delete: item.remove(delete=True) - if remove: + elif remove: item.remove(delete=False) if tag: try: From 7c22cd635c502e2f3ccb71803c3034bc2bb2ec11 Mon Sep 17 00:00:00 2001 From: J0J0 Todos Date: Sat, 5 Jul 2025 07:24:26 +0200 Subject: [PATCH 4/4] duplicates: Add changelog for --remove option --- docs/changelog.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index 0e5799846..d1a477cb5 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -23,6 +23,9 @@ New features: singletons by their Discogs ID. :bug:`4661` * :doc:`plugins/replace`: Add new plugin. +* :doc:`plugins/duplicates`: Add ``--remove`` option, allowing to remove from + the library without deleting media files. + :bug:`5832` Bug fixes: