This commit is contained in:
cwx
2023-04-07 20:30:43 +08:00
parent e61beb42a8
commit b264f61a18
5 changed files with 49 additions and 39 deletions
+15 -2
View File
@@ -6,7 +6,19 @@ from common.Constant import ComicPath
from utils.Logger import logger
class imageUtils:
@classmethod
def deScrambleImagesByDir(cls,chapter_dir):
scramble_count = 0
if os.path.exists(chapter_dir): #获取章节图片路径
dirs = os.listdir(chapter_dir)
for img in dirs:
if img.startswith("scramble="):
imageUtils.encode_scramble_image(os.path.join(chapter_dir,img))
scramble_count += 1
logger.debug(f"scramble= {scramble_count}")
return scramble_count
@classmethod
def encodeImage(cls,str_en):
#print("en",str_en)
@@ -195,7 +207,8 @@ class imageUtils:
print("remove=",imgpath)
class fileUtils:
SCRAMBLE_COUNT = 0
@classmethod
def getModificationDate(cls,file_path,format="%Y%m%d",not_exists=None):
if cls.notExists(file_path): return not_exists
+4 -3
View File
@@ -183,7 +183,7 @@ class downloadUtils:
def putDownImageUrlDirFile(cls,url,dir,file): cls.putDownUrlDirFileType(url,dir,file,cls.TYPE_IMG)
@classmethod
def common_download(cls,file_url,dir,file,file_type,repair_max=15,timeout=10,proxy=None,proxy_type=None):
def common_download(cls,file_url,dir,file,file_type,repair_max=30,timeout=10,proxy=None,proxy_type=None):
logger.debug(f"file_url={file_url}, dir={dir} , file={file}, file_type={file_type}")
en_scrabmle_file = ComicPath.getFileScrambleImageSave(file)
en_scrabmle_path = os.path.join(dir,en_scrabmle_file)
@@ -214,7 +214,7 @@ class downloadUtils:
raise NameError("下载异常")
with open(temp_path, 'wb') as f:
f.write(response.content)
time.sleep(0.7)
time.sleep(0.1)
response.close()
#验证是否是图像
if fu.ver_file(temp_path,type=file_type):
@@ -225,10 +225,11 @@ class downloadUtils:
raise NameError("## Fail: {} {}".format(file_url, "图像损坏"))
except Exception as e:
logger.warning(f'重试:第{repair_count}次 异常:{e} {file_url}')
time.sleep(1.5)
repair_count += 1
@classmethod
def start_downloads(cls,repair_max=20,concurrency=None,timeout=20,proxy_type=None, proxy=None):
def start_downloads(cls,concurrency=None,timeout=20,proxy_type=None, proxy=None):
"""
Download image according to given urls and automatically rename them in order.
:param timeout: