This commit is contained in:
caiwx86 2023-01-16 01:16:53 +08:00
parent 6423a68a48
commit 47efea8266

View File

@ -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: