import_delete: delete local album art (#242)

This commit is contained in:
Adrian Sampson 2012-02-15 16:46:23 -08:00
parent ea95fa1373
commit 6d2df0e4bf
3 changed files with 24 additions and 3 deletions

View file

@ -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)

View file

@ -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.

View file

@ -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__)