Update utils.py with trivial sanity checks

Check that uuid isn't None even when a valid size is present, as it happens somewhat frequently.
This commit is contained in:
Dex 2022-02-11 11:08:21 -06:00 committed by GitHub
parent 877b19bb3b
commit 7e8cd1bd4e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -178,7 +178,10 @@ def tidal_cover_url(uuid, size):
"""
possibles = (80, 160, 320, 640, 1280)
assert size in possibles, f"size must be in {possibles}"
# A common occurance is a valid size but no uuid
if not uuid:
return None
return TIDAL_COVER_URL.format(uuid=uuid.replace("-", "/"), height=size, width=size)
@ -335,6 +338,8 @@ def get_cover_urls(resp: dict, source: str) -> dict:
if source == "tidal":
uuid = resp["cover"]
if not uuid:
return None
return {
sk: tidal_cover_url(uuid, size)
for sk, size in zip(COVER_SIZES, (160, 320, 640, 1280))