This commit is contained in:
caiwx86 2023-04-06 19:17:09 +08:00
parent dc917c2fc6
commit 1401b9734d
2 changed files with 25 additions and 25 deletions

View File

@ -1,8 +1,8 @@
import os,shutil,time,requests
import logging
from datetime import datetime
from pathlib import Path
from zipfile import ZipFile
from queue import Queue
from common.ComicInfo import ComicInfoUtils as ciUtils
from common.ComicInfo import ComicInfo as ci
from common.ComicInfo import Comic
@ -126,6 +126,7 @@ class CBZUtils:
if filter_info_xml in result: result.remove(filter_info_xml)
except Exception as e:
print(e)
logging.debug(f"path={path}, name_list={result}")
return result
#CBZ检验是否完整
@ -138,7 +139,7 @@ class CBZUtils:
#文件不存在 则返回
if fu.notExists(path): return False
if list_img == None: list_img = Comic.getChapterImgs()
logging.debug(f"list_img= {list_img}")
if ciUtils.isProgressDone():
ntfy.sendMsg(f"该文件已校验成功,跳过中... {path}",alert=True)
return True

View File

@ -184,7 +184,7 @@ class downloadUtils:
def putDownImageUrlDirFile(cls,url,dir,file): cls.putDownUrlDirFileType(url,dir,file,cls.TYPE_IMG)
@classmethod
def common_download(cls,repair_max=10,timeout=10,proxy=None,proxy_type=None):
def common_download(cls,repair_max=20,timeout=10,proxy=None,proxy_type=None):
result = cls.getDownUrlDirFileType()
if result == None: return None
(file_url,dir,file,file_type) = [result[0],result[1],result[2],result[3]]
@ -208,28 +208,27 @@ class downloadUtils:
if not os.path.exists(dir): os.makedirs(dir)
temp_path = save_path+".downloads"
repair_count = 1
while not os.path.exists(save_path):
try:
response = requests.get(
file_url, headers=cls.headers, timeout=timeout, proxies=proxies)
if response.status_code != 200 and repair_count <= repair_max:
logger.warning("下载异常")
raise NameError("下载异常")
with open(temp_path, 'wb') as f:
f.write(response.content)
time.sleep(0.7)
response.close()
#验证是否是图像
if fu.ver_file(temp_path,type=file_type):
shutil.move(temp_path, save_path)
logger.info("## OK: {} {}".format(save_path, file_url))
else:
logger.warning("## Fail: {} {}".format(file_url, "图像损坏"))
raise NameError("## Fail: {} {}".format(file_url, "图像损坏"))
except Exception as e:
logger.warning(f'重试:第{repair_count}次 异常:{e} {file_url}')
cls.putDownUrlDirFileType(file_url,dir,file,file_type)
repair_count += 1
try:
response = requests.get(
file_url, headers=cls.headers, timeout=timeout, proxies=proxies)
if response.status_code != 200 and repair_count <= repair_max:
logger.warning("下载异常")
raise NameError("下载异常")
with open(temp_path, 'wb') as f:
f.write(response.content)
time.sleep(0.7)
response.close()
#验证是否是图像
if fu.ver_file(temp_path,type=file_type):
shutil.move(temp_path, save_path)
logger.info("## OK: {} {}".format(save_path, file_url))
else:
logger.warning("## Fail: {} {}".format(file_url, "图像损坏"))
raise NameError("## Fail: {} {}".format(file_url, "图像损坏"))
except Exception as e:
logger.warning(f'重试:第{repair_count}次 异常:{e} {file_url}')
cls.putDownUrlDirFileType(file_url,dir,file,file_type)
repair_count += 1
@classmethod
def start_downloads(cls,repair_max=20,concurrency=None,timeout=20,proxy_type=None, proxy=None):