Repository: beetbox/beets

Issue:
Re-import should move album art (or remove the old album art file)
When updating the directory structure in the path format and reimporting the library to update the paths, the new directory contains the cover art, but the old directory still stays with the old cover art left inside.

Re-import should move album art (or remove the old album art file)
When updating the directory structure in the path format and reimporting the library to update the paths, the new directory contains the cover art, but the old directory still stays with the old cover art left inside.



Discussion:
Thanks; this does indeed seem to be an oversight. The re-import handling in `manipulate_files` is not yet aware of album art.

FWIW, though, you probably don't want a re-import just to update your path formats. Use `beet move` for that.

I have the same issue. My use-case wouldn't be covered by `beet move`, however: a release saw its release date corrected on MusicBrainz, so became `2012 - something` instead of `2011 - something`.

@Kernald For that purpose, you may want to look at the `mbsync` plugin.

Thanks; this does indeed seem to be an oversight. The re-import handling in `manipulate_files` is not yet aware of album art.

FWIW, though, you probably don't want a re-import just to update your path formats. Use `beet move` for that.

I have the same issue. My use-case wouldn't be covered by `beet move`, however: a release saw its release date corrected on MusicBrainz, so became `2012 - something` instead of `2011 - something`.

@Kernald For that purpose, you may want to look at the `mbsync` plugin.


Resolving patch:
diff --git a/beets/importer.py b/beets/importer.py
--- a/beets/importer.py
+++ b/beets/importer.py
@@ -718,6 +718,7 @@ def reimport_metadata(self, lib):
             if replaced_album:
                 self.album.added = replaced_album.added
                 self.album.update(replaced_album._values_flex)
+                self.album.artpath = replaced_album.artpath
                 self.album.store()
                 log.debug(
                     u'Reimported album: added {0}, flexible '
diff --git a/beetsplug/fetchart.py b/beetsplug/fetchart.py
--- a/beetsplug/fetchart.py
+++ b/beetsplug/fetchart.py
@@ -434,6 +434,9 @@ def __init__(self):
     def fetch_art(self, session, task):
         """Find art for the album being imported."""
         if task.is_album:  # Only fetch art for full albums.
+            if task.album.artpath and os.path.isfile(task.album.artpath):
+                # Album already has art (probably a re-import); skip it.
+                return
             if task.choice_flag == importer.action.ASIS:
                 # For as-is imports, don't search Web sources for art.
                 local = True


Test patch:
diff --git a/test/test_importer.py b/test/test_importer.py
--- a/test/test_importer.py
+++ b/test/test_importer.py
@@ -1592,6 +1592,21 @@ def test_reimported_item_preserves_added(self):
         self.importer.run()
         self.assertEqual(self._item().added, 4747.0)
 
+    def test_reimported_item_preserves_art(self):
+        self._setup_session()
+        art_source = os.path.join(_common.RSRC, 'abbey.jpg')
+        replaced_album = self._album()
+        replaced_album.set_art(art_source)
+        replaced_album.store()
+        old_artpath = replaced_album.artpath
+        self.importer.run()
+        new_album = self._album()
+        new_artpath = new_album.art_destination(art_source)
+        self.assertEqual(new_album.artpath, new_artpath)
+        self.assertTrue(os.path.exists(new_artpath))
+        if new_artpath != old_artpath:
+            self.assertFalse(os.path.exists(old_artpath))
+
 
 class ImportPretendTest(_common.TestCase, ImportHelper):
     """ Test the pretend commandline option