fix
This commit is contained in:
parent
47efea8266
commit
7542152145
@ -197,4 +197,18 @@ class imageUtils:
|
|||||||
print("解密成功=",save_path)
|
print("解密成功=",save_path)
|
||||||
if os.path.exists(imgpath):
|
if os.path.exists(imgpath):
|
||||||
os.remove(imgpath)
|
os.remove(imgpath)
|
||||||
print("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
|
||||||
@ -11,10 +11,10 @@ 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
|
||||||
|
from utils.FileUtils import fileUtils
|
||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
|
"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
|
proxies = None
|
||||||
if proxy_type is not None:
|
if proxy_type is not None:
|
||||||
proxies = {
|
proxies = {
|
||||||
@ -53,15 +53,9 @@ def download_image(image_url, dst_dir, file_name, timeout=20, proxy_type=None, p
|
|||||||
f.write(response.content)
|
f.write(response.content)
|
||||||
response.close()
|
response.close()
|
||||||
#验证是否是图像
|
#验证是否是图像
|
||||||
try:
|
if fileUtils.ver_file(temp_path,type=type):
|
||||||
img = Image.open(temp_path)
|
shutil.move(temp_path, file_path)
|
||||||
img.verify()
|
print("## OK: {} {}".format(file_path, image_url))
|
||||||
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:
|
except Exception as e:
|
||||||
if response:
|
if response:
|
||||||
response.close()
|
response.close()
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import json,os,time,random,shutil
|
import json,os,time,random,shutil
|
||||||
from utils.HtmlUtils import htmlUtils
|
from utils.HtmlUtils import htmlUtils
|
||||||
from utils.ImageUtils import imageUtils
|
from utils.FileUtils import imageUtils
|
||||||
from utils.comic.ComicInfo import comicInfo
|
from utils.comic.ComicInfo import comicInfo
|
||||||
from utils.CBZUtils import CBZUtils
|
from utils.CBZUtils import CBZUtils
|
||||||
from utils.downloader import download_images
|
from utils.downloader import download_images
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import hashlib
|
|||||||
import json,os,time,random,shutil
|
import json,os,time,random,shutil
|
||||||
import re,math
|
import re,math
|
||||||
from utils.HtmlUtils import htmlUtils
|
from utils.HtmlUtils import htmlUtils
|
||||||
from utils.ImageUtils import imageUtils
|
from utils.FileUtils import imageUtils
|
||||||
from utils.comic.ComicInfo import comicInfo
|
from utils.comic.ComicInfo import comicInfo
|
||||||
from utils.CBZUtils import CBZUtils
|
from utils.CBZUtils import CBZUtils
|
||||||
from utils.CBZUtils import verUtils
|
from utils.CBZUtils import verUtils
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import hashlib
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
from utils.HtmlUtils import htmlUtils
|
from utils.HtmlUtils import htmlUtils
|
||||||
from utils.ImageUtils import imageUtils
|
from utils.FileUtils import imageUtils
|
||||||
from utils.comic.ComicInfo import comicInfo
|
from utils.comic.ComicInfo import comicInfo
|
||||||
from utils.Ntfy import ntfy
|
from utils.Ntfy import ntfy
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import json
|
import json
|
||||||
from utils.HtmlUtils import htmlUtils
|
from utils.HtmlUtils import htmlUtils
|
||||||
from utils.ImageUtils import imageUtils
|
from utils.FileUtils import imageUtils
|
||||||
from utils.comic.ComicInfo import comicInfo
|
from utils.comic.ComicInfo import comicInfo
|
||||||
from utils.Ntfy import ntfy
|
from utils.Ntfy import ntfy
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user