This commit is contained in:
caiwx86 2023-01-16 01:34:46 +08:00
parent 47efea8266
commit 7542152145
6 changed files with 24 additions and 16 deletions

View File

@ -198,3 +198,17 @@ class imageUtils:
if os.path.exists(imgpath):
os.remove(imgpath)
print("remove=",imgpath)
class fileUtils:
@classmethod
def ver_file(cls,file_path,type):
if type == "image":
#验证是否是图像
try:
img = Image.open(file_path)
img.verify()
return True
except:
os.remove(file_path)
print(f"{file_path}已损坏 type:{type},删除重试中")
return False

View File

@ -11,10 +11,10 @@ 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
from utils.FileUtils import fileUtils
headers = {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
@ -26,7 +26,7 @@ headers = {
}
def download_image(image_url, dst_dir, file_name, timeout=20, proxy_type=None, proxy=None):
def download_image(image_url, dst_dir, file_name, timeout=20, proxy_type=None, proxy=None,type="image"):
proxies = None
if proxy_type is not None:
proxies = {
@ -53,13 +53,7 @@ def download_image(image_url, dst_dir, file_name, timeout=20, proxy_type=None, p
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
if fileUtils.ver_file(temp_path,type=type):
shutil.move(temp_path, file_path)
print("## OK: {} {}".format(file_path, image_url))
except Exception as e:

View File

@ -1,6 +1,6 @@
import json,os,time,random,shutil
from utils.HtmlUtils import htmlUtils
from utils.ImageUtils import imageUtils
from utils.FileUtils import imageUtils
from utils.comic.ComicInfo import comicInfo
from utils.CBZUtils import CBZUtils
from utils.downloader import download_images

View File

@ -2,7 +2,7 @@ import hashlib
import json,os,time,random,shutil
import re,math
from utils.HtmlUtils import htmlUtils
from utils.ImageUtils import imageUtils
from utils.FileUtils import imageUtils
from utils.comic.ComicInfo import comicInfo
from utils.CBZUtils import CBZUtils
from utils.CBZUtils import verUtils

View File

@ -2,7 +2,7 @@ import hashlib
import json
import os
from utils.HtmlUtils import htmlUtils
from utils.ImageUtils import imageUtils
from utils.FileUtils import imageUtils
from utils.comic.ComicInfo import comicInfo
from utils.Ntfy import ntfy

View File

@ -1,6 +1,6 @@
import json
from utils.HtmlUtils import htmlUtils
from utils.ImageUtils import imageUtils
from utils.FileUtils import imageUtils
from utils.comic.ComicInfo import comicInfo
from utils.Ntfy import ntfy