Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion beetsplug/fetchart.py
Original file line number Diff line number Diff line change
Expand Up @@ -1445,6 +1445,16 @@ def _is_source_file_removal_enabled() -> bool:
"move"
].get(bool)

def _is_candidate_fallback(self, candidate: Candidate) -> bool:
try:
return (
candidate.path is not None
and self.fallback is not None
and os.path.samefile(candidate.path, self.fallback)
)
except OSError:
return False

# Asynchronous; after music is added to the library.
def fetch_art(self, session: ImportSession, task: ImportTask) -> None:
"""Find art for the album being imported."""
Expand Down Expand Up @@ -1493,7 +1503,7 @@ def assign_art(self, session: ImportSession, task: ImportTask):

self._set_art(task.album, candidate, not removal_enabled)

if removal_enabled:
if removal_enabled and not self._is_candidate_fallback(candidate):
task.prune(candidate.path)

# Manual album art fetching.
Expand Down
10 changes: 10 additions & 0 deletions test/plugins/test_art.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,16 @@ def test_precedence_amongst_correct_files(self):
]
assert candidates == paths

@patch("os.path.samefile")
def test_is_candidate_fallback_os_error(self, mock_samefile):
mock_samefile.side_effect = OSError("os error")
fallback = os.path.join(self.temp_dir, b"a.jpg")
self.plugin.fallback = fallback
candidate = fetchart.Candidate(logger, self.source.ID, fallback)
result = self.plugin._is_candidate_fallback(candidate)
mock_samefile.assert_called_once()
assert not result


class CombinedTest(FetchImageTestCase, CAAHelper):
ASIN = "xxxx"
Expand Down
Loading