fix
This commit is contained in:
1 parent
6423a68a48
commit
47efea8266
1 file changed
+9
@@ -11,6 +11,7 @@ import os
|
|||||||
import concurrent.futures
|
import concurrent.futures
|
||||||
import requests
|
import requests
|
||||||
import time
|
import time
|
||||||
|
from PIL import Image
|
||||||
from utils.Ntfy import ntfy
|
from utils.Ntfy import ntfy
|
||||||
from utils.comic.ComicInfo import comicInfo
|
from utils.comic.ComicInfo import comicInfo
|
||||||
from utils.HtmlUtils import htmlUtils
|
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:
|
with open(temp_path, 'wb') as f:
|
||||||
f.write(response.content)
|
f.write(response.content)
|
||||||
response.close()
|
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)
|
shutil.move(temp_path, file_path)
|
||||||
print("## OK: {} {}".format(file_path, image_url))
|
print("## OK: {} {}".format(file_path, image_url))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Reference in new issue
Block a user