From 47efea826644078078f8cd6e2fff504e785a0bb2 Mon Sep 17 00:00:00 2001 From: caiwx86 Date: Mon, 16 Jan 2023 01:16:53 +0800 Subject: [PATCH] fix --- utils/downloader.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/utils/downloader.py b/utils/downloader.py index 7d2e159..0e08b17 100644 --- a/utils/downloader.py +++ b/utils/downloader.py @@ -11,6 +11,7 @@ import os import concurrent.futures import requests import time +from PIL import Image from utils.Ntfy import ntfy from utils.comic.ComicInfo import comicInfo from utils.HtmlUtils import htmlUtils @@ -51,6 +52,14 @@ def download_image(image_url, dst_dir, file_name, timeout=20, proxy_type=None, p with open(temp_path, 'wb') as f: f.write(response.content) response.close() + #验证是否是图像 + try: + img = Image.open(temp_path) + img.verify() + except: + os.remove(temp_path) + print(f"{temp_path}已损坏,删除重试中") + return None shutil.move(temp_path, file_path) print("## OK: {} {}".format(file_path, image_url)) except Exception as e: