This commit is contained in:
cwx committed 2022-12-20 21:00:37 +08:00
1 parent 025c58fd3b
commit efa4279df1
3 files changed
+82 -20

No files matched your search

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