Repository: beetbox/beets
Pull request: Delete after convert
## Description

Fixes #2947.

- [x] Documentation.
- [x] Changelog.

This PR builds upon the abandoned https://github.com/beetbox/beets/pull/3394 and implements the comment in that PR, namely, the ability to enable this functionality explicitly via a `delete_originals` option.

Problem statement:
convert: In `auto` mode, respect `import.move` by deleting old files
The relevant parts of my config:
```
import:
    move: yes

plugins: convert

convert:
    auto: yes
    max_bitrate: 192
    format: mp3
```
If the imported mp3 file has a bitrate under 192 it gets moved unconverted as desired.
If it's higher than that the old file remains inside the source folder after the successful conversion and the new file get's copied to the destination folder. It acts like the copy flag. The output shows:

> convert: Encoding D:\Test\Test.mp3
> convert: Finished encoding D:\Test\Test.mp3

Hints from issue discussion:
Interesting point! This does seem wrong. For consistency, would you want transcoded files to have their originals deleted—so that the importer always appears to “move” the files?
Absolutely! You could add an plugin option to ignore the global flag but otherwise it should definitely prioritize the global import settings.
Sounds good; thanks for clarifying!
+1 to this feature request!

Better yet, instead of just deleting the source files, providing the option to move the source files to another dir would be excellent. So I can still have the sources around if needed, but they would be moved out of my "Things to process" dir.
Has there been any news about this feature request? I'm facing the same issue
Just here to add my +1 to this feature request.
+1 
By default it would be expected to respect copy/move global flags with option to overwrite it and i.e. copy to a different folder with something like "paths_source:" option, where i.e. FLAC files could be moved to i.e. [FLAC] flagged folder respecting beets variables.
+1
+1

Commit message: Added delete_originals option to remove source files after transcode

Patch to review:
diff --git a/beetsplug/convert.py b/beetsplug/convert.py
index e7ac4f3ac3..ca9747cb55 100644
--- a/beetsplug/convert.py
+++ b/beetsplug/convert.py
@@ -30,6 +30,7 @@
 from beets.plugins import BeetsPlugin
 from confuse import ConfigTypeError
 from beets import art
+from beets.util import syspath
 from beets.util.artresizer import ArtResizer
 from beets.library import parse_query_string
 from beets.library import Item
@@ -148,6 +149,7 @@ def __init__(self):
             u'never_convert_lossy_files': False,
             u'copy_album_art': False,
             u'album_art_maxwidth': 0,
+            u'delete_originals': False,
         })
         self.early_import_stages = [self.auto_convert]
 
@@ -532,11 +534,15 @@ def convert_on_import(self, lib, item):
 
             # Change the newly-imported database entry to point to the
             # converted file.
+            source_path = item.path
             item.path = dest
             item.write()
             item.read()  # Load new audio information data.
             item.store()
 
+            if self.config['delete_originals']:
+                util.remove(syspath(source_path), False)
+
     def _cleanup(self, task, session):
         for path in task.old_paths:
             if path in _temp_files:
diff --git a/docs/changelog.rst b/docs/changelog.rst
index 64e6ab85c9..9baf53712f 100644
--- a/docs/changelog.rst
+++ b/docs/changelog.rst
@@ -142,6 +142,10 @@ New features:
 * :doc:`/plugins/thumbnails`: Fix a bug where pathlib expected a string instead
   of bytes for a path.
   :bug:`3360`
+* :doc:`/plugins/convert`: If ``delete_originals`` is enabled, then the source files will
+  be deleted after importing.
+  Thanks to :user:`logan-arens`.
+  :bug:`2947`
 
 Fixes:
 
diff --git a/docs/plugins/convert.rst b/docs/plugins/convert.rst
index 6e9d00a11b..9581e24a44 100644
--- a/docs/plugins/convert.rst
+++ b/docs/plugins/convert.rst
@@ -111,6 +111,8 @@ file. The available options are:
   This option overrides ``link``. Only works when converting to a directory
   on the same filesystem as the library.
   Default: ``false``.
+- **delete_originals**: Transcoded files will be copied or moved to their destination, depending on the import configuration. By default, the original files are not modified by the plugin. This option deletes the original files after the transcoding step has completed.
+  Default: ``false``.
 
 You can also configure the format to use for transcoding (see the next
 section):


Code review comments:
diff_hunk: @@ -532,11 +534,15 @@ def convert_on_import(self, lib, item):
 
             # Change the newly-imported database entry to point to the
             # converted file.
+            source_path = item.path
             item.path = dest
             item.write()
             item.read()  # Load new audio information data.
             item.store()
 
+            if self.config['delete_originals']:
+                util.remove(syspath(source_path), False)
path: beetsplug/convert.py
text: @user1:
this is a tiny nitpick, but the `syspath` call here isn't necessary since it's called internally with `util.remove` (this would also remove the need for the import)

@author:
That was part of the original PR, and to be honest I didn't really look too closely at it. I'll fix this. 👍🏻