diff --git a/cartridges/store/managers/cover_manager.py b/cartridges/store/managers/cover_manager.py index d5cbd19..28b4e1b 100644 --- a/cartridges/store/managers/cover_manager.py +++ b/cartridges/store/managers/cover_manager.py @@ -19,10 +19,10 @@ # SPDX-License-Identifier: GPL-3.0-or-later from pathlib import Path -from typing import NamedTuple +from typing import NamedTuple, Optional import requests -from gi.repository import GdkPixbuf, Gio +from gi.repository import GdkPixbuf, Gio, GLib from requests.exceptions import HTTPError, SSLError from cartridges import shared @@ -128,9 +128,20 @@ class CoverManager(Manager): """ # Load source image - source = GdkPixbuf.Pixbuf.new_from_file( - str(convert_cover(image_path, resize=False)) - ) + try: + source = GdkPixbuf.Pixbuf.new_from_file( + str(image_path) + ) + except GLib.Error: + new_path = convert_cover(image_path, resize=False) + + if new_path: + source = GdkPixbuf.Pixbuf.new_from_file( + str(new_path) + ) + else: + return None + source_size = ImageSize(source.get_width(), source.get_height()) cover_size = ImageSize._make(shared.image_size) diff --git a/cartridges/utils/save_cover.py b/cartridges/utils/save_cover.py index 38c414b..ac3fb92 100644 --- a/cartridges/utils/save_cover.py +++ b/cartridges/utils/save_cover.py @@ -35,14 +35,6 @@ def convert_cover( if not cover_path and not pixbuf: return None - pixbuf_extensions = set() - for pixbuf_format in GdkPixbuf.Pixbuf.get_formats(): - for pixbuf_extension in pixbuf_format.get_extensions(): - pixbuf_extensions.add(pixbuf_extension) - - if not resize and cover_path and cover_path.suffix.lower()[1:] in pixbuf_extensions: - return cover_path - try: with Image.open(cover_path) as image: if getattr(image, "is_animated", False):