from utils.HtmlUtils import htmlUtils
from utils.Ntfy import ntfy
from utils.CBZUtils import CBZUtils
from utils.comic.ComicInfo import comicInfo
import json,os
class verUtils:
@classmethod
def verCBZ(cls,data=None):
len_zip = len(CBZUtils.zip_info()) - 1
info_data = None
if data == None:
info_path = comicInfo.nextSavePath("done_")
try:
with open(info_path,"r",encoding="utf-8") as fs:
info_data = json.loads(fs.read())
fs.close()
except:
ntfy.sendMsg("校验失败")
else:
info_data = data
if info_data != None:
if len(info_data) == len_zip:
return True
else:
ntfy.sendMsg("数据不完整,删除配置文件中")
try:
os.remove(comicInfo.nextSavePath("done_"))
ntfy.sendMsg("配置文件删除成功")
except:
ntfy.sendMsg("配置文件删除失败")
return False
else:
ntfy.sendMsg("info_data 为空")
return False
@classmethod
def verNextCBZ(cls,list_img):
#验证数据是已存在且是否完整
cbz_path = comicInfo.getDirCBZComicChapter()+".CBZ"
is_next = False
if os.path.exists(cbz_path):
try:
cbz_size = len(CBZUtils.zip_info(cbz_path)) - 1
except:
cbz_size = 0
if len(list_img) == cbz_size:
ntfy.sendMsg(f"{comicInfo.getComicName()} {comicInfo.getChapter()} 数据完整,已跳过")
is_next = True
else:
ntfy.sendMsg(f"{comicInfo.getComicName()} {comicInfo.getChapter()} 数据不完整,尝试删除配置CBZ文件后重试")
try:
if cbz_size < len(list_img) or os.path.getsize(cbz_path) < 300000:
ntfy.sendMsg(f"删除 {cbz_path}")
os.remove(cbz_path)
else:
is_next = True
except:
ntfy(f"删除失败 {cbz_path}")
return is_next