From 3eeb9d3b7ef6518936ce6346ce31c8418a8e5022 Mon Sep 17 00:00:00 2001 From: Nathan Thomas Date: Mon, 6 Sep 2021 14:05:34 -0700 Subject: [PATCH] Catch UnidentifiedImageError #168 --- rip/config.toml | 7 ++++--- streamrip/utils.py | 10 ++++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/rip/config.toml b/rip/config.toml index cdaea9b..4c3e20f 100644 --- a/rip/config.toml +++ b/rip/config.toml @@ -119,8 +119,9 @@ embed = true size = "large" # 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. -max_width = 999999 -max_height = 999999 +# If either value is -1, the image is left untouched. +max_width = -1 +max_height = -1 # Save the cover image at the highest quality as a seperate jpg file keep_hires_cover = true @@ -163,4 +164,4 @@ progress_bar = "dainty" [misc] # Metadata to identify this config file. Do not change. -version = "1.5" +version = "1.6" diff --git a/streamrip/utils.py b/streamrip/utils.py index 3425c99..2259012 100644 --- a/streamrip/utils.py +++ b/streamrip/utils.py @@ -518,9 +518,15 @@ def downsize_image(filepath: str, width: int, height: int): :type height: int :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) height = min(height, image.height)