From a470f53317c06954b4786f53536b12f9320f490d Mon Sep 17 00:00:00 2001 From: caiwx86 Date: Mon, 16 Jan 2023 02:10:35 +0800 Subject: [PATCH] fix --- utils/CBZUtils.py | 32 ++++++++++++++++++++++++++++++-- utils/entity/BaseComicEntity.py | 3 ++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/utils/CBZUtils.py b/utils/CBZUtils.py index d6b0ef3..5b30171 100644 --- a/utils/CBZUtils.py +++ b/utils/CBZUtils.py @@ -1,9 +1,10 @@ import json -import os +import os,shutil from pathlib import Path from zipfile import ZipFile from utils.comic.ComicInfo import comicInfo from utils.Ntfy import ntfy +from utils.FileUtils import fileUtils class CBZUtils: @@ -88,7 +89,34 @@ class CBZUtils: data = zfile.namelist() zfile.close() return data - + + @classmethod + def replaceZip(cls,filepath,unpack_dir=None): + if unpack_dir == None: + unpack_dir = str(filepath).split(".")[0] + fz = ZipFile(filepath, 'r') + for file in fz.namelist(): + fz.extract(file, unpack_dir) + zip_imgs = os.listdir(unpack_dir) + is_file = None + for img in zip_imgs: + if img.endswith(".jpg"): + file_path = os.path.join(unpack_dir,img) + is_file = fileUtils.ver_file(file_path,"image") + if is_file != None and is_file == False: + shutil.rmtree(unpack_dir) + os.remove(file_path) + print(f"已删除{file_path}") + else: + print(f"数据完整:{file_path}") + # 删除删除main.ftl文件 + #delete_filename = '' + #if os.path.exists(delete_filename): + # os.remove(delete_filename) + # time.sleep(60) + # shutil.copy(文件的路径,另一个目录);拷贝main.ftl到准备压缩的目录下 + #cls.zip_compression() + class verUtils: @classmethod def verCBZ(cls,data=None): diff --git a/utils/entity/BaseComicEntity.py b/utils/entity/BaseComicEntity.py index b4b1ad0..ac83dcf 100644 --- a/utils/entity/BaseComicEntity.py +++ b/utils/entity/BaseComicEntity.py @@ -37,8 +37,9 @@ class baseComic: for chapter in chapters: comicInfo.setChapterIndex(chapter_index) comicInfo.setChapterName(chapter) - comicInfo.getNewCBZComicChapter() + cbz_path = comicInfo.getNewCBZComicChapter() comicInfo.getNewIconComicChapter() + CBZUtils.replaceZip(cbz_path) chapter_index = chapter_index + 1 return None