From ce51bfd98d71416682c8900ef062ce3a14eaa47c Mon Sep 17 00:00:00 2001 From: pax Date: Sat, 4 Apr 2026 19:43:47 -0500 Subject: [PATCH] =?UTF-8?q?Fix=20ugoira=20conversion=20=E2=80=94=20filter?= =?UTF-8?q?=20non-image=20files,=20skip=20bad=20frames?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- booru_viewer/core/cache.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/booru_viewer/core/cache.py b/booru_viewer/core/cache.py index df2f039..e50bb90 100644 --- a/booru_viewer/core/cache.py +++ b/booru_viewer/core/cache.py @@ -53,15 +53,20 @@ def _ext_from_url(url: str) -> str: def _convert_ugoira_to_gif(zip_path: Path) -> Path: """Convert a Pixiv ugoira zip (numbered JPEG/PNG frames) to an animated GIF.""" + import io gif_path = zip_path.with_suffix(".gif") if gif_path.exists(): return gif_path + _IMG_EXTS = {".jpg", ".jpeg", ".png", ".bmp", ".webp"} with zipfile.ZipFile(zip_path, "r") as zf: - names = sorted(zf.namelist()) + names = sorted(n for n in zf.namelist() if Path(n).suffix.lower() in _IMG_EXTS) frames = [] for name in names: - data = zf.read(name) - frames.append(Image.open(__import__("io").BytesIO(data)).convert("RGBA")) + try: + data = zf.read(name) + frames.append(Image.open(io.BytesIO(data)).convert("RGBA")) + except Exception: + continue if not frames: raise ValueError("Zip contains no image frames") frames[0].save(