Skip to content

Commit

Permalink
fetchart: defer file removal config option eval
Browse files Browse the repository at this point in the history
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 #5167 (comment)
  • Loading branch information
mgoltzsche committed May 13, 2024
1 parent c75f07a commit f1f5e5c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 8 additions & 6 deletions beetsplug/fetchart.py
Original file line number Diff line number Diff line change
Expand Up @@ -1220,10 +1220,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)
)
Expand Down Expand Up @@ -1307,10 +1303,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 = _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.
Expand Down Expand Up @@ -1410,3 +1407,8 @@ def batch_fetch_art(self, lib, albums, force, quiet):
else:
message = ui.colorize("text_error", "no art found")
self._log.info("{0}: {1}", album, message)

def _is_source_file_removal_enabled():

Check failure on line 1411 in beetsplug/fetchart.py

View workflow job for this annotation

GitHub Actions / lint

E302 expected 2 blank lines, found 1
delete_enabled = config["import"]["delete"].get(bool)
move_enabled = config["import"]["move"].get(bool)
return delete_enabled or move_enabled
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,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:

Expand Down

0 comments on commit f1f5e5c

Please sign in to comment.