Handle no artwork case #303

This commit is contained in:
Nathan Thomas 2022-08-04 18:40:38 -07:00
parent be087c01cd
commit 615a36257b

View file

@ -29,12 +29,7 @@ from pathvalidate import sanitize_filepath
from . import converter from . import converter
from .clients import Client, DeezloaderClient from .clients import Client, DeezloaderClient
from .constants import ( from .constants import ALBUM_KEYS, FLAC_MAX_BLOCKSIZE, FOLDER_FORMAT, TRACK_FORMAT
ALBUM_KEYS,
FLAC_MAX_BLOCKSIZE,
FOLDER_FORMAT,
TRACK_FORMAT,
)
from .downloadtools import DownloadPool, DownloadStream from .downloadtools import DownloadPool, DownloadStream
from .exceptions import ( from .exceptions import (
InvalidQuality, InvalidQuality,
@ -1527,7 +1522,7 @@ class Album(Tracklist, Media):
self.download_message() self.download_message()
cover_path = ( cover_path: Optional[str] = (
_choose_and_download_cover( _choose_and_download_cover(
self.cover_urls, self.cover_urls,
kwargs.get("embed_cover_size", "large"), kwargs.get("embed_cover_size", "large"),
@ -2056,7 +2051,7 @@ class Artist(Tracklist, Media):
else: else:
self.folder = parent_folder self.folder = parent_folder
logger.debug("Artist folder: %s", folder) logger.debug("Artist folder: %s", self.folder)
logger.debug("Length of tracklist %d", len(self)) logger.debug("Length of tracklist %d", len(self))
logger.debug("Filters: %s", filters) logger.debug("Filters: %s", filters)
@ -2326,7 +2321,7 @@ def _choose_and_download_cover(
directory: str, directory: str,
keep_hires_cover: bool = True, keep_hires_cover: bool = True,
downsize: Tuple[int, int] = (999999, 999999), downsize: Tuple[int, int] = (999999, 999999),
) -> str: ) -> Optional[str]:
# choose optimal cover size and download it # choose optimal cover size and download it
hashcode: str = hashlib.md5( hashcode: str = hashlib.md5(
@ -2350,12 +2345,16 @@ def _choose_and_download_cover(
), f"Invalid cover size. Must be in {cover_urls.keys()}" ), f"Invalid cover size. Must be in {cover_urls.keys()}"
embed_cover_url = cover_urls[preferred_size] embed_cover_url = cover_urls[preferred_size]
logger.debug("Chosen cover url: %s", embed_cover_url) logger.debug("Chosen cover url: %s", embed_cover_url)
if not os.path.exists(temp_cover_path): if not os.path.exists(temp_cover_path):
# Sometimes a size isn't available. When this is the case, find # Sometimes a size isn't available. When this is the case, find
# the first `not None` url. # the first `not None` url.
if embed_cover_url is None: if embed_cover_url is None:
embed_cover_url = next(filter(None, cover_urls.values())) urls = tuple(filter(None, cover_urls.values()))
if len(urls) == 0:
return None
embed_cover_url = urls[0]
logger.debug("Downloading cover from url %s", embed_cover_url) logger.debug("Downloading cover from url %s", embed_cover_url)