mirror of
https://github.com/beetbox/beets.git
synced 2025-12-06 16:42:42 +01:00
fetchart: defer file removal config option eval
Defer the evaluation of the source file removal options (`import.delete` and `import.move`) to the point where the fetchart plugin is actually called instead of only evaluating those configuration options on plugin initialization. This is to allow other plugins (such as the [ytimport](https://github.com/mgoltzsche/beets-ytimport/blob/v1.8.1/beetsplug/ytimport/__init__.py#L194) plugin) to invoke the import directly (within the same python process; implicitly invoking the fetchart plugin) with temporarily overwritten configuration options. Relates to https://github.com/beetbox/beets/issues/5167#issuecomment-2106465172
This commit is contained in:
parent
240c5fca51
commit
90f0ae2d93
3 changed files with 18 additions and 9 deletions
|
|
@ -1253,10 +1253,6 @@ class FetchArtPlugin(plugins.BeetsPlugin, RequestMixin):
|
||||||
self.cautious = self.config["cautious"].get(bool)
|
self.cautious = self.config["cautious"].get(bool)
|
||||||
self.store_source = self.config["store_source"].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(
|
self.cover_format = self.config["cover_format"].get(
|
||||||
confuse.Optional(str)
|
confuse.Optional(str)
|
||||||
)
|
)
|
||||||
|
|
@ -1340,10 +1336,11 @@ class FetchArtPlugin(plugins.BeetsPlugin, RequestMixin):
|
||||||
"""Place the discovered art in the filesystem."""
|
"""Place the discovered art in the filesystem."""
|
||||||
if task in self.art_candidates:
|
if task in self.art_candidates:
|
||||||
candidate = self.art_candidates.pop(task)
|
candidate = self.art_candidates.pop(task)
|
||||||
|
removal_enabled = _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)
|
task.prune(candidate.path)
|
||||||
|
|
||||||
# Manual album art fetching.
|
# Manual album art fetching.
|
||||||
|
|
@ -1443,3 +1440,9 @@ class FetchArtPlugin(plugins.BeetsPlugin, RequestMixin):
|
||||||
else:
|
else:
|
||||||
message = ui.colorize("text_error", "no art found")
|
message = ui.colorize("text_error", "no art found")
|
||||||
self._log.info("{0}: {1}", album, message)
|
self._log.info("{0}: {1}", album, message)
|
||||||
|
|
||||||
|
|
||||||
|
def _is_source_file_removal_enabled():
|
||||||
|
delete_enabled = config["import"]["delete"].get(bool)
|
||||||
|
move_enabled = config["import"]["move"].get(bool)
|
||||||
|
return delete_enabled or move_enabled
|
||||||
|
|
|
||||||
|
|
@ -208,6 +208,8 @@ New features:
|
||||||
* Add support for `barcode` field.
|
* Add support for `barcode` field.
|
||||||
:bug:`3172`
|
:bug:`3172`
|
||||||
* :doc:`/plugins/smartplaylist`: Add new config option `smartplaylist.fields`.
|
* :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:
|
Bug fixes:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -825,9 +825,13 @@ class ArtImporterTest(UseThePlugin):
|
||||||
self.assertExists(self.art_file)
|
self.assertExists(self.art_file)
|
||||||
|
|
||||||
def test_delete_original_file(self):
|
def test_delete_original_file(self):
|
||||||
self.plugin.src_removed = True
|
prev_move = config["import"]["move"].get()
|
||||||
self._fetch_art(True)
|
try:
|
||||||
self.assertNotExists(self.art_file)
|
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):
|
def test_do_not_delete_original_if_already_in_place(self):
|
||||||
artdest = os.path.join(os.path.dirname(self.i.path), b"cover.jpg")
|
artdest = os.path.join(os.path.dirname(self.i.path), b"cover.jpg")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue