mirror of
https://github.com/beetbox/beets.git
synced 2026-02-21 23:03:26 +01:00
fetchart: Add support for configurable fallback cover art
This commit is contained in:
parent
ed566eb14e
commit
9ddddf4c39
4 changed files with 27 additions and 1 deletions
|
|
@ -1101,6 +1101,16 @@ class FileSystem(LocalArtSource):
|
|||
else:
|
||||
remaining.append(fn)
|
||||
|
||||
# Fall back to a configured image.
|
||||
if plugin.fallback:
|
||||
self._log.debug(
|
||||
"using fallback art file {}",
|
||||
util.displayable_path(plugin.fallback),
|
||||
)
|
||||
yield self._candidate(
|
||||
path=plugin.fallback, match=MetadataMatch.FALLBACK
|
||||
)
|
||||
|
||||
# Fall back to any image in the folder.
|
||||
if remaining and not plugin.cautious:
|
||||
self._log.debug(
|
||||
|
|
@ -1332,6 +1342,7 @@ class FetchArtPlugin(plugins.BeetsPlugin, RequestMixin):
|
|||
"enforce_ratio": False,
|
||||
"cautious": False,
|
||||
"cover_names": ["cover", "front", "art", "album", "folder"],
|
||||
"fallback": None,
|
||||
"sources": [
|
||||
"filesystem",
|
||||
"coverart",
|
||||
|
|
@ -1380,6 +1391,9 @@ class FetchArtPlugin(plugins.BeetsPlugin, RequestMixin):
|
|||
cover_names = self.config["cover_names"].as_str_seq()
|
||||
self.cover_names = list(map(util.bytestring_path, cover_names))
|
||||
self.cautious = self.config["cautious"].get(bool)
|
||||
self.fallback = self.config["fallback"].get(
|
||||
confuse.Optional(confuse.Filename())
|
||||
)
|
||||
self.store_source = self.config["store_source"].get(bool)
|
||||
|
||||
self.cover_format = self.config["cover_format"].get(
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ been dropped.
|
|||
|
||||
New features:
|
||||
|
||||
- :doc:`plugins/fetchart`: Added config setting for a fallback cover art image.
|
||||
- :doc:`plugins/ftintitle`: Added argument for custom feat. words in ftintitle.
|
||||
- :doc:`plugins/ftintitle`: Added album template value ``album_artist_no_feat``.
|
||||
- :doc:`plugins/musicbrainz`: Allow selecting tags or genres to populate the
|
||||
|
|
|
|||
|
|
@ -33,6 +33,8 @@ file. The available options are:
|
|||
contain one of the keywords in ``cover_names``. Default: ``no``.
|
||||
- **cover_names**: Prioritize images containing words in this list. Default:
|
||||
``cover front art album folder``.
|
||||
- **fallback**: Path to a fallback album art file if no album art was found
|
||||
otherwise. Default: ``None`` (disabled).
|
||||
- **minwidth**: Only images with a width bigger or equal to ``minwidth`` are
|
||||
considered as valid album art candidates. Default: 0.
|
||||
- **maxwidth**: A maximum image width to downscale fetched images if they are
|
||||
|
|
|
|||
|
|
@ -261,7 +261,9 @@ class FSArtTest(UseThePlugin):
|
|||
os.mkdir(syspath(self.dpath))
|
||||
|
||||
self.source = fetchart.FileSystem(logger, self.plugin.config)
|
||||
self.settings = Settings(cautious=False, cover_names=("art",))
|
||||
self.settings = Settings(
|
||||
cautious=False, cover_names=("art",), fallback=None
|
||||
)
|
||||
|
||||
def test_finds_jpg_in_directory(self):
|
||||
_common.touch(os.path.join(self.dpath, b"a.jpg"))
|
||||
|
|
@ -285,6 +287,13 @@ class FSArtTest(UseThePlugin):
|
|||
with pytest.raises(StopIteration):
|
||||
next(self.source.get(None, self.settings, [self.dpath]))
|
||||
|
||||
def test_configured_fallback_is_used(self):
|
||||
fallback = os.path.join(self.temp_dir, b"a.jpg")
|
||||
_common.touch(fallback)
|
||||
self.settings.fallback = fallback
|
||||
candidate = next(self.source.get(None, self.settings, [self.dpath]))
|
||||
assert candidate.path == fallback
|
||||
|
||||
def test_empty_dir(self):
|
||||
with pytest.raises(StopIteration):
|
||||
next(self.source.get(None, self.settings, [self.dpath]))
|
||||
|
|
|
|||
Loading…
Reference in a new issue