1
0
Fork 0
mirror of https://github.com/kemayo/leech synced 2025-12-14 20:34:50 +01:00

Reset cover bytesteam after checking its format

Caused issues writing the file later, as the internal pointer moved past the
first few bytes when checking whether it was a PNG.

Fixes #19
This commit is contained in:
David Lynch 2018-10-08 09:02:15 -05:00
parent 61f3bb1a6e
commit 482c1ab26e

View file

@ -38,7 +38,12 @@ def make_cover_from_url(url, title, author):
img = requests.Session().get(url)
cover = BytesIO(img.content)
if Image.open(cover).format != "PNG":
imgformat = Image.open(cover).format
# The `Image.open` read a few bytes from the stream to work out the
# format, so reset it:
cover.seek(0)
if imgformat != "PNG":
cover = _convert_to_png(cover)
except Exception as e:
logger.info("Encountered an error downloading cover: " + e)