fix
This commit is contained in:
parent
025c58fd3b
commit
efa4279df1
@ -23,7 +23,7 @@ class CBZUtils:
|
||||
target_dir = os.path.dirname(target_file)
|
||||
if not os.path.exists(target_dir):
|
||||
os.makedirs(target_dir)
|
||||
|
||||
|
||||
if not os.path.exists(target_file):
|
||||
with ZipFile(target_file, mode='w') as zf:
|
||||
for path, dir_names, filenames in os.walk(source_dir):
|
||||
@ -39,10 +39,10 @@ class CBZUtils:
|
||||
#md5_file = md5(target_file)
|
||||
#print("md5:", md5_file)
|
||||
#msg[target_file] = md5_file
|
||||
return len(filenames)
|
||||
else:
|
||||
print("文件已存在:", target_file)
|
||||
|
||||
return len(filenames)
|
||||
|
||||
@classmethod
|
||||
def packAutoComicChapterCBZ(cls):
|
||||
chapter_path = comicInfo.getDirComicChapter()
|
||||
@ -55,17 +55,21 @@ class CBZUtils:
|
||||
os.remove(file)
|
||||
except:
|
||||
print(f"删除 {file} 发生错误,已跳过")
|
||||
cbz_size = cls.zip_compression(chapter_path,packCBZ_path+".CBZ")
|
||||
chapter_img_size = len(comicInfo.getChapterImgs())
|
||||
if cbz_size - 1 == chapter_img_size:
|
||||
comicInfo.nextCBZToDoneChapter()
|
||||
else:
|
||||
cbz_path = comicInfo.nextSavePath("cbz_")
|
||||
ntfy.sendMsg(f"{cbz_path} 数据不完整 删除配置文件中")
|
||||
if os.path.exists(cbz_path):
|
||||
try:
|
||||
os.remove(cbz_path)
|
||||
ntfy.sendMsg(f"删除成功 {cbz_path}")
|
||||
except:
|
||||
ntfy.sendMsg(f"删除失败 {cbz_path}")
|
||||
try:
|
||||
cls.zip_compression(chapter_path,packCBZ_path+".CBZ")
|
||||
except:
|
||||
ntfy.sendMsg("CBZ打包失败")
|
||||
comicInfo.nextCBZToDoneChapter()
|
||||
|
||||
@classmethod
|
||||
def zip_info(cls,zip_path=None):
|
||||
pack_cbz_path = comicInfo.getDirCBZComicChapter()
|
||||
if zip_path == None:
|
||||
zip_path = pack_cbz_path+".CBZ"
|
||||
data = None
|
||||
if os.path.exists(zip_path):
|
||||
with ZipFile(zip_path, "r") as zfile:
|
||||
data = zfile.namelist()
|
||||
zfile.close()
|
||||
return data
|
||||
|
||||
|
||||
35
utils/VerUtils.py
Normal file
35
utils/VerUtils.py
Normal file
@ -0,0 +1,35 @@
|
||||
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:
|
||||
ntfy.sendMsg("数据完成")
|
||||
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
|
||||
@ -6,6 +6,7 @@ from utils.comic.ComicInfo import comicInfo
|
||||
from utils.CBZUtils import CBZUtils
|
||||
from utils.downloader import download_images
|
||||
from utils.Ntfy import ntfy
|
||||
from utils.VerUtils import verUtils
|
||||
|
||||
class comicEntity:
|
||||
count_chapter = 0
|
||||
@ -83,6 +84,9 @@ class comicEntity:
|
||||
comicInfo.setChapterName(chapter)
|
||||
if not comicInfo.nextExistsGetPath("done_"):
|
||||
comicEntity.comicChapter(href,scramble=True,sleep=random.randint(15,25))
|
||||
#存在就校验CBZ包是否完整
|
||||
if comicInfo.nextExistsGetPath("done_"):
|
||||
verUtils.verCBZ()
|
||||
cls.count_chapter += 1
|
||||
#一本漫画下载后等待
|
||||
#清空文件夹
|
||||
@ -152,7 +156,6 @@ class comicEntity:
|
||||
#fileUtils.saveConfComicChapterInfo(chapterName,x,bookName)
|
||||
#if comicInfo.nextExistsGetPath("info_"):
|
||||
# print(f"{bookName} {chapterName} info文件已存在跳过")
|
||||
comicInfo.nextSaveInfoChapter(chapterName,x)
|
||||
alias = x.get("alias")
|
||||
description = x.get("description")
|
||||
images = x.get("images")
|
||||
@ -166,7 +169,7 @@ class comicEntity:
|
||||
print("不存在ComicInfo.xml 生成中...")
|
||||
comicInfo.writeComicInfoXML(chapterName)
|
||||
|
||||
if not chapterAPIPath == None:
|
||||
if chapterAPIPath != None:
|
||||
base_url = comicInfo.getBaseUrl(chapter_url)
|
||||
chapterAPIUrl = base_url+chapterAPIPath
|
||||
data = htmlUtils.getJSON(chapterAPIUrl)
|
||||
@ -175,7 +178,7 @@ class comicEntity:
|
||||
images = data.get("images")
|
||||
if images == None:
|
||||
ntfy.sendMsg(f"未获取到章节图像 comic_name={bookName} chapter={chapterName}")
|
||||
totalChapter = x.get("totalChapter")
|
||||
|
||||
tags = x.get("tags")
|
||||
x = tags
|
||||
print(x)
|
||||
@ -199,4 +202,24 @@ class comicEntity:
|
||||
print("count_all_img=", count)
|
||||
#netUtils.downloadComicChapterImages(list_img,scrambles=list_scramble)
|
||||
comicInfo.setChapterImgs(list_img)
|
||||
return download_images(list_img,comicInfo.getDirComicChapter(), filesName=list_fileName)
|
||||
#保存图像
|
||||
comicInfo.nextSaveInfoChapter(chapterName, list_img)
|
||||
#验证数据是已存在且是否完整
|
||||
cbz_path = comicInfo.getDirCBZComicChapter()+".CBZ"
|
||||
is_next = True
|
||||
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("数据完整,已跳过")
|
||||
is_next = False
|
||||
else:
|
||||
try:
|
||||
ntfy.sendMsg(f"删除 {cbz_path}")
|
||||
os.remove(cbz_path)
|
||||
except:
|
||||
ntfy(f"删除失败 {cbz_path}")
|
||||
if is_next:
|
||||
return download_images(list_img,comicInfo.getDirComicChapter(), filesName=list_fileName)
|
||||
Loading…
Reference in New Issue
Block a user