From 936aaf1a595a03b257b8b500a9b49bb6e2e81b48 Mon Sep 17 00:00:00 2001 From: caiwx86 Date: Sat, 1 Apr 2023 15:07:37 +0800 Subject: [PATCH] fix --- utils/FileUtils.py | 19 ++++++++++++++++++- utils/base/BaseComicEntity.py | 7 ++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/utils/FileUtils.py b/utils/FileUtils.py index f92913f..9f302f0 100644 --- a/utils/FileUtils.py +++ b/utils/FileUtils.py @@ -47,7 +47,7 @@ class imageUtils: try: img = Image.open(file_path) except: - print(f"error Image") + print(f"error Image: {file_path}") width = img.width height = img.height #blocks = cls.encodeImage(enStr) @@ -240,6 +240,23 @@ class fileUtils: except Exception as e: print(e) return False + + @classmethod + def dirFilesName(cls,path,type="file",prefix=None): + result = [] + if cls.exists(path): + for file_or_dir in os.listdir(path): + if type == "file" and os.path.isfile(os.path.join(path,file_or_dir)): result.append(file_or_dir) + if type == "dir" and os.path.isdir(os.path.join(path,file_or_dir)): result.append(file_or_dir) + return result + + @classmethod + def equImages(cls,dir,files,prefix=".jpg"): + len_count = 0 + file_names = cls.dirFilesName(dir,"file") + for file in file_names: + if str(file).endswith(prefix): len_count += 1 + return len_count == len(files) @classmethod def remove(cls,path): diff --git a/utils/base/BaseComicEntity.py b/utils/base/BaseComicEntity.py index 08875fe..e8dccfd 100644 --- a/utils/base/BaseComicEntity.py +++ b/utils/base/BaseComicEntity.py @@ -120,13 +120,14 @@ class baseComic: #检验CBZ文件 CBZUtils.verCBZComic(cbz_file) CBZUtils.updateOldCBZ(files_name) + is_next = CBZUtils.nextCBZ() #不存在ComicInfo.xml则生成 if is_next and fu.notExists(ci.getPathComicInfoXML()): ci.writeComicInfoXML(chapter_name) repeat = 1 - while CBZUtils.nextCBZ() and repeat <= 10: + while is_next and repeat <= 10: ntfy.sendMsg(f"{book_name} {chapter_name} 下载中") download_images(list_img,ci.getDirComicChapter(), files_name=files_name,concurrency=None,timeout=8) - equ_next = len(",".join(os.listdir(ci.getDirComicChapter())).split(".jpg")) == len(list_img) - if not equ_next: ntfy.sendMsg(msg=f"下载数据(不完整,{int(repeat*2)}秒钟后尝试第{repeat}次",sleep=int(repeat*2)) + is_next = fu.equImages(ci.getDirComicChapter(),list_img) + if not is_next: ntfy.sendMsg(msg=f"下载数据(不完整,{int(repeat*2)}秒钟后尝试第{repeat}次",sleep=int(repeat*2)) repeat += 1 return is_next \ No newline at end of file