mirror of
https://github.com/beetbox/beets.git
synced 2026-01-30 20:13:37 +01:00
artresizer: merge _check_method into ArtResizer.__init__
more concise since _check_method became much shorter due to introduction of backend classes
This commit is contained in:
parent
b097b19506
commit
bc364bc7d4
1 changed files with 16 additions and 18 deletions
|
|
@ -456,6 +456,11 @@ class Shareable(type):
|
|||
return cls._instance
|
||||
|
||||
|
||||
BACKEND_CLASSES = [
|
||||
IMBackend,
|
||||
PILBackend,
|
||||
]
|
||||
|
||||
class ArtResizer(metaclass=Shareable):
|
||||
"""A singleton class that performs image resizes.
|
||||
"""
|
||||
|
|
@ -463,11 +468,18 @@ class ArtResizer(metaclass=Shareable):
|
|||
def __init__(self):
|
||||
"""Create a resizer object with an inferred method.
|
||||
"""
|
||||
self.local_method = self._check_method()
|
||||
if self.local_method is None:
|
||||
log.debug(f"artresizer: method is WEBPROXY")
|
||||
# Check if a local backend is availabe, and store an instance of the
|
||||
# backend class. Otherwise, fallback to the web proxy.
|
||||
for backend_cls in BACKEND_CLASSES:
|
||||
try:
|
||||
self.local_method = backend_cls()
|
||||
log.debug(f"artresizer: method is {self.local_method.NAME}")
|
||||
break
|
||||
except LocalBackendNotAvailableError:
|
||||
continue
|
||||
else:
|
||||
log.debug(f"artresizer: method is {self.local_method.NAME}")
|
||||
log.debug("artresizer: method is WEBPROXY")
|
||||
self.local_method = None
|
||||
|
||||
def resize(
|
||||
self, maxwidth, path_in, path_out=None, quality=0, max_filesize=0
|
||||
|
|
@ -587,17 +599,3 @@ class ArtResizer(metaclass=Shareable):
|
|||
# FIXME: Should probably issue a warning?
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def _check_method():
|
||||
"""Search availabe methods.
|
||||
|
||||
If a local backend is availabe, return an instance of the backend
|
||||
class. Otherwise, when fallback to the web proxy is requird, return
|
||||
None.
|
||||
"""
|
||||
try:
|
||||
return IMBackend()
|
||||
return PILBackend()
|
||||
except LocalBackendNotAvailableError:
|
||||
return None
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue