diff --git a/backend/cover.py b/backend/cover.py index 89465e2..4432a52 100644 --- a/backend/cover.py +++ b/backend/cover.py @@ -33,12 +33,14 @@ def download(url: str, album_path: Path) -> None: '''General cover art downloader''' resp = http_pool.get().request('GET', url) - ext = mimetypes.guess_extension(resp.headers['content-type']) or '.jpg' + ct = resp.headers['content-type'] + if not ct.startswith('image'): + raise ValueError('thumbnail is not an image') + ext = mimetypes.guess_extension(ct) or '.jpg' path = album_path / ('cover' + ext) if path.exists(): return - with (album_path / ('cover' + ext)).open('wb') as f: - for chunk in resp.read_chunked(): - f.write(chunk) + with path.open('wb') as f: + f.write(resp.data)