diff --git a/beets/importer.py b/beets/importer.py index 68efbe02a..28f4308a4 100644 --- a/beets/importer.py +++ b/beets/importer.py @@ -692,6 +692,10 @@ def fetch_art(config): try: album = lib.get_album(task.album_id) album.set_art(artpath) + if config.delete and not util.samefile(artpath, + album.artpath): + # Delete the original file after it's imported. + os.remove(artpath) finally: lib.save(False) diff --git a/docs/changelog.rst b/docs/changelog.rst index 5b407b89c..ced61f0b3 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -19,6 +19,8 @@ Changelog to "Various Artists". * Importing with ``import_delete`` enabled now cleans up empty directories that contained deleting imported music files. +* Similarly, ``import_delete`` now causes original album art imported from the + disk to be deleted. * Plugin-supplied template values, such as those created by ``rewrite``, are now properly sanitized (for example, ``AC/DC`` properly becomes ``AC_DC``). * Filename extensions are now always lower-cased when copying and moving files. diff --git a/test/test_importer.py b/test/test_importer.py index 12a3460bd..c04a12296 100644 --- a/test/test_importer.py +++ b/test/test_importer.py @@ -729,9 +729,9 @@ class ArtFetchTest(unittest.TestCase, _common.ExtraAsserts): self.lib.save() # Set up an art-fetching coroutine. - config = _common.iconfig(self.lib) - config.art = True - self.coro = importer.fetch_art(config) + self.config = _common.iconfig(self.lib) + self.config.art = True + self.coro = importer.fetch_art(self.config) self.coro.next() # Import task for the coroutine. @@ -785,6 +785,21 @@ class ArtFetchTest(unittest.TestCase, _common.ExtraAsserts): self.task.is_album = False self._fetch_art(False) + def test_leave_original_file_in_place(self): + self._fetch_art(True) + self.assertExists(self.art_file) + + def test_delete_original_file(self): + self.config.delete = True + self._fetch_art(True) + self.assertNotExists(self.art_file) + + def test_do_not_delete_original_if_already_in_place(self): + artdest = os.path.join(os.path.dirname(self.i.path), 'cover.jpg') + shutil.copyfile(self.art_file, artdest) + art.art_for_album = lambda a, b: artdest + self._fetch_art(True) + def suite(): return unittest.TestLoader().loadTestsFromName(__name__)