update
This commit is contained in:
1 parent
92c5bc19b0
commit
c04e9a45c2
4 files changed
+74
-24
No files matched your search
+53
-2
@@ -1,5 +1,5 @@
|
||||
import base64,hashlib,os,shutil,os.path,pathlib
|
||||
import math,time,json,datetime,logging
|
||||
import math,time,json,datetime,logging,zipfile
|
||||
import re,requests,time,xmlschema
|
||||
from datetime import date
|
||||
from Comics import settings
|
||||
@@ -504,7 +504,8 @@ class CBZUtils:
|
||||
zf.write(path.joinpath(filename), arc_dir.joinpath(filename))
|
||||
zf.close()
|
||||
logging.info(f"打包完成:{target_file}")
|
||||
|
||||
|
||||
@DeprecationWarning
|
||||
@classmethod
|
||||
def packComicChapterCBZ(cls, src_dir, dts_path, comic_info_images, remove=True):
|
||||
if os.path.exists(src_dir):
|
||||
@@ -522,6 +523,23 @@ class CBZUtils:
|
||||
# validation
|
||||
return cls.cbz_validate(dts_path, comic_info_images)
|
||||
|
||||
@classmethod
|
||||
def comicChapterCBZPack(cls, src_dir, dts_path,remove=True):
|
||||
if os.path.exists(src_dir):
|
||||
dirs = os.listdir(src_dir)
|
||||
for file in dirs:
|
||||
if file.startswith(ComicPath.PREFIX_SCRAMBLE):
|
||||
try:
|
||||
imageUtils.deScrambleImagesByPath(os.path.join(src_dir,file))
|
||||
except Exception as e:
|
||||
print(f"删除 {file} 发生错误 {e},已跳过")
|
||||
return False
|
||||
cls.zip_compression(src_dir, dts_path)
|
||||
time.sleep(0.1)
|
||||
if remove: shutil.rmtree(src_dir)
|
||||
# validation
|
||||
return cls.comic_cbz_validate(dts_path)
|
||||
|
||||
@classmethod
|
||||
def replaceZip(cls, filepath, unpack_dir=None):
|
||||
if not cls.compareFileDate(filepath): return None
|
||||
@@ -574,6 +592,7 @@ class CBZUtils:
|
||||
print(e)
|
||||
return result
|
||||
|
||||
@DeprecationWarning
|
||||
@classmethod
|
||||
def cbz_validate(cls, zip_path, comic_info_images):
|
||||
cbz_info = cls.zip_info(zip_path)
|
||||
@@ -587,6 +606,38 @@ class CBZUtils:
|
||||
ntfy.gotify(title="漫画校验失败", message=f"validating fail === {zip_path}, cbz_info={cbz_info},zip_info={comic_info_images}")
|
||||
#ntfy.sendMsg(f"validating fail === {zip_path}, cbz_info={cbz_info},zip_info={comic_info_images}", alert=True)
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
def comic_info_page_count(cls, zip_file):
|
||||
# 打开ZIP文件
|
||||
with zipfile.ZipFile(zip_file, 'r') as z:
|
||||
# 假设ZIP中的文件名是'text.txt'
|
||||
with z.open('ComicInfo.xml', 'r') as file:
|
||||
# 从文件流中解析 XML 数据
|
||||
file_string = file.read().decode("utf-8")
|
||||
# 使用正则表达式提取 <PageCount> 标签中的值
|
||||
match = re.search(r"<PageCount>(\d+)</PageCount>", file_string)
|
||||
if match:
|
||||
page_count = match.group(1)
|
||||
print(f"zip_file={zip_file} PageCount: {page_count}")
|
||||
return page_count
|
||||
|
||||
@classmethod
|
||||
def comic_cbz_validate(cls, zip_file):
|
||||
cbz_info = cls.zip_info(zip_file)
|
||||
info_count = cls.comic_info_page_count(zip_file)
|
||||
if len(cbz_info) == len(info_count) and len(cbz_info) != 0:
|
||||
# logging.info(f"validating successfully === {zip_path}")
|
||||
# ntfy.sendMsg(f"validating successfully === {zip_path}", alert=True)
|
||||
ntfy.gotify(title="漫画下载完成", message=f"validating successfully === {zip_file}")
|
||||
return True
|
||||
else:
|
||||
os.remove(zip_file)
|
||||
ntfy.gotify(title="漫画校验失败", message=f"validating fail === {zip_file}, cbz_info={cbz_info},zip_info={info_count}")
|
||||
#ntfy.sendMsg(f"validating fail === {zip_path}, cbz_info={cbz_info},zip_info={comic_info_images}", alert=True)
|
||||
return False
|
||||
|
||||
|
||||
|
||||
# 检测工具类
|
||||
class checkUtils:
|
||||
|
||||
Reference in new issue
Block a user