Fix: cover.download()

- resp.read returns nothing, contents are already in resp.data
- add mime type safety check
This commit is contained in:
DarkCat09 2024-05-09 18:33:13 +04:00
parent 38cc43b84f
commit 03458db829
Signed by: DarkCat09
GPG key ID: 0A26CD5B3345D6E3

View file

@ -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)