Repository: beetbox/beets

Issue:
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

Discussion:

Patch:
diff --git a/.github/flake8-problem-matcher.json b/.github/flake8-problem-matcher.json
new file mode 100644
index 000000000..52f94e05e
--- /dev/null
+++ b/.github/flake8-problem-matcher.json
@@ -0,0 +1,16 @@
+{
+    "problemMatcher": [
+        {
+            "owner": "flake8",
+            "pattern": [
+                {
+                    "regexp": "^(.*?):(\\d+):(\\d+): (.*)$",
+                    "file": 1,
+                    "line": 2,
+                    "column": 3,
+                    "message": 4
+                }
+            ]
+        }
+    ]
+}
diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
index 08e7548f2..48d43d059 100644
--- a/.github/workflows/ci.yaml
+++ b/.github/workflows/ci.yaml
@@ -65,9 +65,6 @@ jobs:
   lint:
     runs-on: ubuntu-latest
 
-    env:
-      PY_COLORS: 1
-
     steps:
       - uses: actions/checkout@v2
 
@@ -81,5 +78,8 @@ jobs:
           python -m pip install --upgrade pip
           python -m pip install tox sphinx
 
+      - name: Add problem matcher
+        run: echo "::add-matcher::.github/flake8-problem-matcher.json"
+
       - name: Lint with flake8
         run: tox -e py-lint
diff --git a/beetsplug/convert.py b/beetsplug/convert.py
index e7ac4f3ac..70363f6eb 100644
--- a/beetsplug/convert.py
+++ b/beetsplug/convert.py
@@ -148,6 +148,7 @@ class ConvertPlugin(BeetsPlugin):
             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 +533,16 @@ class ConvertPlugin(BeetsPlugin):
 
             # 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']:
+                self._log.info(u'Removing original file {0}', source_path)
+                util.remove(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 4a87f7f07..0dfa2c5f8 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 6e9d00a11..9581e24a4 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):


Test patch:
diff --git a/test/test_convert.py b/test/test_convert.py
index 33bdb3b24..b8cd56741 100644
--- a/test/test_convert.py
+++ b/test/test_convert.py
@@ -15,6 +15,7 @@
 
 from __future__ import division, absolute_import, print_function
 
+import fnmatch
 import sys
 import re
 import os.path
@@ -121,6 +122,15 @@ class ImportConvertTest(unittest.TestCase, TestHelper):
         self.assertIsNotNone(item)
         self.assertTrue(os.path.isfile(item.path))
 
+    def test_delete_originals(self):
+        self.config['convert']['delete_originals'] = True
+        self.importer.run()
+        for path in self.importer.paths:
+            for root, dirnames, filenames in os.walk(path):
+                self.assertTrue(len(fnmatch.filter(filenames, '*.mp3')) == 0,
+                                u'Non-empty import directory {0}'
+                                .format(util.displayable_path(path)))
+
 
 class ConvertCommand(object):
     """A mixin providing a utility method to run the `convert`command