Fix: cover.download()
- resp.read returns nothing, contents are already in resp.data - add mime type safety check
This commit is contained in:
parent
38cc43b84f
commit
03458db829
1 changed files with 6 additions and 4 deletions
|
@ -33,12 +33,14 @@ def download(url: str, album_path: Path) -> None:
|
||||||
'''General cover art downloader'''
|
'''General cover art downloader'''
|
||||||
|
|
||||||
resp = http_pool.get().request('GET', url)
|
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)
|
path = album_path / ('cover' + ext)
|
||||||
if path.exists():
|
if path.exists():
|
||||||
return
|
return
|
||||||
|
|
||||||
with (album_path / ('cover' + ext)).open('wb') as f:
|
with path.open('wb') as f:
|
||||||
for chunk in resp.read_chunked():
|
f.write(resp.data)
|
||||||
f.write(chunk)
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue