Catch UnidentifiedImageError #168

This commit is contained in:
Nathan Thomas 2021-09-06 14:05:34 -07:00
parent 372a755215
commit 3eeb9d3b7e
2 changed files with 12 additions and 5 deletions

View file

@ -119,8 +119,9 @@ embed = true
size = "large" size = "large"
# Both of these options limit the size of the embedded artwork. If their values # Both of these options limit the size of the embedded artwork. If their values
# are larger than the actual dimensions of the image, they will be ignored. # are larger than the actual dimensions of the image, they will be ignored.
max_width = 999999 # If either value is -1, the image is left untouched.
max_height = 999999 max_width = -1
max_height = -1
# Save the cover image at the highest quality as a seperate jpg file # Save the cover image at the highest quality as a seperate jpg file
keep_hires_cover = true keep_hires_cover = true
@ -163,4 +164,4 @@ progress_bar = "dainty"
[misc] [misc]
# Metadata to identify this config file. Do not change. # Metadata to identify this config file. Do not change.
version = "1.5" version = "1.6"

View file

@ -518,9 +518,15 @@ def downsize_image(filepath: str, width: int, height: int):
:type height: int :type height: int
:raises: ValueError :raises: ValueError
""" """
from PIL import Image if width == -1 or height == -1:
return
image = Image.open(filepath) from PIL import Image, UnidentifiedImageError
try:
image = Image.open(filepath)
except UnidentifiedImageError:
secho("Cover art not found, skipping downsize.", fg="red")
width = min(width, image.width) width = min(width, image.width)
height = min(height, image.height) height = min(height, image.height)