diff --git a/beetsplug/fetchart.py b/beetsplug/fetchart.py index 72aa3aa295..aab2143341 100644 --- a/beetsplug/fetchart.py +++ b/beetsplug/fetchart.py @@ -1252,10 +1252,6 @@ def __init__(self): self.cautious = self.config["cautious"].get(bool) self.store_source = self.config["store_source"].get(bool) - self.src_removed = config["import"]["delete"].get(bool) or config[ - "import" - ]["move"].get(bool) - self.cover_format = self.config["cover_format"].get( confuse.Optional(str) ) @@ -1297,6 +1293,10 @@ def __init__(self): for s, c in sources ] + @staticmethod + def _is_source_file_removal_enabled(): + return config["import"]["delete"] or config["import"]["move"] + # Asynchronous; after music is added to the library. def fetch_art(self, session, task): """Find art for the album being imported.""" @@ -1339,10 +1339,11 @@ def assign_art(self, session, task): """Place the discovered art in the filesystem.""" if task in self.art_candidates: candidate = self.art_candidates.pop(task) + removal_enabled = FetchArtPlugin._is_source_file_removal_enabled() - self._set_art(task.album, candidate, not self.src_removed) + self._set_art(task.album, candidate, not removal_enabled) - if self.src_removed: + if removal_enabled: task.prune(candidate.path) # Manual album art fetching. diff --git a/docs/changelog.rst b/docs/changelog.rst index 24cc395380..9d5185451f 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -235,6 +235,8 @@ New features: * Add support for `barcode` field. :bug:`3172` * :doc:`/plugins/smartplaylist`: Add new config option `smartplaylist.fields`. +* :doc:`/plugins/fetchart`: Defer source removal config option evaluation to + the point where they are used really, supporting temporary config changes. Bug fixes: diff --git a/test/plugins/test_art.py b/test/plugins/test_art.py index 20bbcdced6..ede04a300e 100644 --- a/test/plugins/test_art.py +++ b/test/plugins/test_art.py @@ -804,9 +804,13 @@ def test_leave_original_file_in_place(self): self.assertExists(self.art_file) def test_delete_original_file(self): - self.plugin.src_removed = True - self._fetch_art(True) - self.assertNotExists(self.art_file) + prev_move = config["import"]["move"].get() + try: + config["import"]["move"] = True + self._fetch_art(True) + self.assertNotExists(self.art_file) + finally: + config["import"]["move"] = prev_move def test_do_not_delete_original_if_already_in_place(self): artdest = os.path.join(os.path.dirname(self.i.path), b"cover.jpg")