mirror of
https://github.com/beetbox/beets.git
synced 2025-12-06 08:39:17 +01:00
Merge remote-tracking branch 'upstream/master' into coverarturl
This commit is contained in:
commit
17d1a431bc
1 changed files with 61 additions and 26 deletions
|
|
@ -253,6 +253,17 @@ class ArtSource(RequestMixin):
|
|||
self._config = config
|
||||
self.match_by = match_by or self.VALID_MATCHING_CRITERIA
|
||||
|
||||
@staticmethod
|
||||
def add_default_config(config):
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def available(cls, log, config):
|
||||
"""Return whether or not all dependencies are met and the art source is
|
||||
in fact usable.
|
||||
"""
|
||||
return True
|
||||
|
||||
def get(self, album, plugin, paths):
|
||||
raise NotImplementedError()
|
||||
|
||||
|
|
@ -465,6 +476,21 @@ class GoogleImages(RemoteArtSource):
|
|||
self.key = self._config['google_key'].get(),
|
||||
self.cx = self._config['google_engine'].get(),
|
||||
|
||||
@staticmethod
|
||||
def add_default_config(config):
|
||||
config.add({
|
||||
'google_key': None,
|
||||
'google_engine': '001442825323518660753:hrh5ch1gjzm',
|
||||
})
|
||||
config['google_key'].redact = True
|
||||
|
||||
@classmethod
|
||||
def available(cls, log, config):
|
||||
has_key = bool(config['google_key'].get())
|
||||
if not has_key:
|
||||
log.debug("google: Disabling art source due to missing key")
|
||||
return has_key
|
||||
|
||||
def get(self, album, plugin, paths):
|
||||
"""Return art URL from google custom search engine
|
||||
given an album title and interpreter.
|
||||
|
|
@ -514,6 +540,13 @@ class FanartTV(RemoteArtSource):
|
|||
super().__init__(*args, **kwargs)
|
||||
self.client_key = self._config['fanarttv_key'].get()
|
||||
|
||||
@staticmethod
|
||||
def add_default_config(config):
|
||||
config.add({
|
||||
'fanarttv_key': None,
|
||||
})
|
||||
config['fanarttv_key'].redact = True
|
||||
|
||||
def get(self, album, plugin, paths):
|
||||
if not album.mb_releasegroupid:
|
||||
return
|
||||
|
|
@ -854,6 +887,20 @@ class LastFM(RemoteArtSource):
|
|||
super().__init__(*args, **kwargs)
|
||||
self.key = self._config['lastfm_key'].get(),
|
||||
|
||||
@staticmethod
|
||||
def add_default_config(config):
|
||||
config.add({
|
||||
'lastfm_key': None,
|
||||
})
|
||||
config['lastfm_key'].redact = True
|
||||
|
||||
@classmethod
|
||||
def available(cls, log, config):
|
||||
has_key = bool(config['lastfm_key'].get())
|
||||
if not has_key:
|
||||
log.debug("lastfm: Disabling art source due to missing key")
|
||||
return has_key
|
||||
|
||||
def get(self, album, plugin, paths):
|
||||
if not album.mb_albumid:
|
||||
return
|
||||
|
|
@ -900,6 +947,14 @@ class Spotify(RemoteArtSource):
|
|||
|
||||
SPOTIFY_ALBUM_URL = 'https://open.spotify.com/album/'
|
||||
|
||||
@classmethod
|
||||
def available(cls, log, config):
|
||||
if not HAS_BEAUTIFUL_SOUP:
|
||||
log.debug('To use Spotify as an album art source, '
|
||||
'you must install the beautifulsoup4 module. See '
|
||||
'the documentation for further details.')
|
||||
return HAS_BEAUTIFUL_SOUP
|
||||
|
||||
def get(self, album, plugin, paths):
|
||||
if not len(album.mb_albumid) == 22:
|
||||
self._log.debug("Invalid Spotify album_id: {}", album.mb_albumid)
|
||||
|
|
@ -943,9 +998,6 @@ class CoverArtUrl(RemoteArtSource):
|
|||
|
||||
# Try each source in turn.
|
||||
|
||||
SOURCES_ALL = ['filesystem', 'coverart', 'itunes', 'amazon', 'albumart',
|
||||
'spotify', 'wikipedia', 'google', 'fanarttv', 'lastfm', 'cover_art_url']
|
||||
|
||||
ART_SOURCES = {
|
||||
'filesystem': FileSystem,
|
||||
'coverart': CoverArtArchive,
|
||||
|
|
@ -986,18 +1038,13 @@ class FetchArtPlugin(plugins.BeetsPlugin, RequestMixin):
|
|||
'cover_names': ['cover', 'front', 'art', 'album', 'folder'],
|
||||
'sources': ['filesystem', 'coverart', 'itunes', 'amazon',
|
||||
'albumart', 'cover_art_url'],
|
||||
'google_key': None,
|
||||
'google_engine': '001442825323518660753:hrh5ch1gjzm',
|
||||
'fanarttv_key': None,
|
||||
'lastfm_key': None,
|
||||
'store_source': False,
|
||||
'high_resolution': False,
|
||||
'deinterlace': False,
|
||||
'cover_format': None,
|
||||
})
|
||||
self.config['google_key'].redact = True
|
||||
self.config['fanarttv_key'].redact = True
|
||||
self.config['lastfm_key'].redact = True
|
||||
for source in ART_SOURCES.values():
|
||||
source.add_default_config(self.config)
|
||||
|
||||
self.minwidth = self.config['minwidth'].get(int)
|
||||
self.maxwidth = self.config['maxwidth'].get(int)
|
||||
|
|
@ -1039,22 +1086,10 @@ class FetchArtPlugin(plugins.BeetsPlugin, RequestMixin):
|
|||
self.import_stages = [self.fetch_art]
|
||||
self.register_listener('import_task_files', self.assign_art)
|
||||
|
||||
available_sources = list(SOURCES_ALL)
|
||||
if not self.config['google_key'].get() and \
|
||||
'google' in available_sources:
|
||||
available_sources.remove('google')
|
||||
if not self.config['lastfm_key'].get() and \
|
||||
'lastfm' in available_sources:
|
||||
available_sources.remove('lastfm')
|
||||
if not HAS_BEAUTIFUL_SOUP and \
|
||||
'spotify' in available_sources:
|
||||
self._log.debug('To use Spotify as an album art source, '
|
||||
'you must install the beautifulsoup4 module. See '
|
||||
'the documentation for further details.')
|
||||
available_sources.remove('spotify')
|
||||
available_sources = [(s, c)
|
||||
for s in available_sources
|
||||
for c in ART_SOURCES[s].VALID_MATCHING_CRITERIA]
|
||||
available_sources = [(s_name, c)
|
||||
for (s_name, s_cls) in ART_SOURCES.items()
|
||||
if s_cls.available(self._log, self.config)
|
||||
for c in s_cls.VALID_MATCHING_CRITERIA]
|
||||
sources = plugins.sanitize_pairs(
|
||||
self.config['sources'].as_pairs(default_value='*'),
|
||||
available_sources)
|
||||
|
|
|
|||
Loading…
Reference in a new issue