This commit is contained in:
caiwx86 2023-01-15 19:44:49 +08:00
parent 537b4d8827
commit d05897e11f
4 changed files with 58 additions and 13 deletions

View File

@ -7,6 +7,14 @@ from utils.Ntfy import ntfy
class CBZUtils: class CBZUtils:
@classmethod
def getCBZ_Dir(cls):
return comicInfo.getNewCBZComicChapter()
@classmethod
def getCBZ_Path(cls):
return cls.getCBZ_Dir()+".CBZ"
@classmethod @classmethod
def readDirsOrFiles(cls,dir,type): def readDirsOrFiles(cls,dir,type):
data = [] data = []
@ -47,7 +55,6 @@ class CBZUtils:
@classmethod @classmethod
def packAutoComicChapterCBZ(cls): def packAutoComicChapterCBZ(cls):
chapter_path = comicInfo.getDirComicChapter() chapter_path = comicInfo.getDirComicChapter()
packCBZ_path = comicInfo.getDirCBZComicChapter()
if os.path.exists(chapter_path): if os.path.exists(chapter_path):
dirs = os.listdir(chapter_path) dirs = os.listdir(chapter_path)
for file in dirs: for file in dirs:
@ -57,14 +64,14 @@ class CBZUtils:
except: except:
print(f"删除 {file} 发生错误,已跳过") print(f"删除 {file} 发生错误,已跳过")
try: try:
size_zip = cls.zip_compression(chapter_path,packCBZ_path+".CBZ") size_zip = cls.zip_compression(chapter_path, cls.getCBZ_Path())
size_imgs = len(comicInfo.getChapterImgs()) size_imgs = len(comicInfo.getChapterImgs())
if size_zip -1 == size_imgs: if size_zip -1 == size_imgs:
ntfy.sendMsg(f"打包校验成功: {packCBZ_path}") ntfy.sendMsg(f"打包校验成功: {cls.getCBZ_Path()}")
comicInfo.nextCBZToDoneChapter() comicInfo.nextCBZToDoneChapter()
return True return True
else: else:
ntfy.sendMsg(f"打包检验不完整:{packCBZ_path}") ntfy.sendMsg(f"打包检验不完整:{cls.getCBZ_Path()}")
return False return False
except: except:
@ -73,9 +80,8 @@ class CBZUtils:
@classmethod @classmethod
def zip_info(cls,zip_path=None): def zip_info(cls,zip_path=None):
pack_cbz_path = comicInfo.getDirCBZComicChapter()
if zip_path == None: if zip_path == None:
zip_path = pack_cbz_path+".CBZ" zip_path = cls.getCBZ_Path()
data = None data = None
if os.path.exists(zip_path): if os.path.exists(zip_path):
with ZipFile(zip_path, "r") as zfile: with ZipFile(zip_path, "r") as zfile:
@ -120,7 +126,7 @@ class verUtils:
@classmethod @classmethod
def verNextCBZ(cls,list_img): def verNextCBZ(cls,list_img):
#验证数据是已存在且是否完整 #验证数据是已存在且是否完整
cbz_path = comicInfo.getDirCBZComicChapter()+".CBZ" cbz_path = CBZUtils.getCBZ_Path()
is_next = False is_next = False
if os.path.exists(cbz_path): if os.path.exists(cbz_path):
try: try:

View File

@ -39,6 +39,7 @@ class comicInfo():
str_web = None str_web = None
str_list_img = None str_list_img = None
str_files_img = None str_files_img = None
str_chapter_index= None
str_value1 = None str_value1 = None
chapter_node = None chapter_node = None
@ -216,6 +217,14 @@ class comicInfo():
value = ",".join(to_list) value = ",".join(to_list)
return value return value
@classmethod
def setChapterIndex(cls,value):
cls.str_chapter_index = value
@classmethod
def getChapterIndex(cls):
return cls.str_chapter_index
''' '''
获取网站主页 获取网站主页
''' '''
@ -263,17 +272,34 @@ class comicInfo():
if not cls.str_comicName == None: if not cls.str_comicName == None:
return os.path.join(pathStr.base_cbz, cls.str_comicName) return os.path.join(pathStr.base_cbz, cls.str_comicName)
else: else:
print("comicName不存在退出中") print("comicName不存在退出中 getDirCBZComic")
exit() exit()
@classmethod @classmethod
def getDirCBZComicChapter(cls): def getDirCBZComicChapter(cls):
if not cls.str_comicName == None and not cls.str_chapter == None: if cls.str_comicName != None and cls.str_chapter != None:
return os.path.join(pathStr.base_cbz,cls.str_comicName,cls.str_chapter) return os.path.join(pathStr.base_cbz,cls.str_comicName,cls.str_chapter)
else: else:
print("comicName不存在退出中") print("comicName不存在退出中 getDirCBZComicChapter")
exit() exit()
@classmethod
def getSortDirCBZComicChapter(cls):
if cls.str_comicName != None and cls.str_chapter != None and cls.str_chapter_index != None:
return os.path.join(pathStr.base_cbz,cls.str_comicName,str(cls.str_chapter_index)+" "+cls.str_chapter)
else:
print("comicName不存在退出中 getSortDirCBZComicChapter")
return None
@classmethod
def getNewCBZComicChapter(cls):
c_path = cls.getDirCBZComicChapter()
s_path = cls.getSortDirCBZComicChapter()
if os.path.exists(c_path) and s_path != None:
shutil.move(c_path, s_path)
print("文件已移动至:", s_path)
return s_path
@classmethod @classmethod
def getDirComic(cls): def getDirComic(cls):
if cls.str_comicName != None: if cls.str_comicName != None:

View File

@ -106,6 +106,9 @@ def download_comic_icon():
if not os.path.exists(pathCBZComic): if not os.path.exists(pathCBZComic):
os.makedirs(pathCBZComic) os.makedirs(pathCBZComic)
save_path = os.path.join(pathCBZComic,comicInfo.getChapter()+icon_su) save_path = os.path.join(pathCBZComic,comicInfo.getChapter()+icon_su)
index = comicInfo.getChapterIndex()
if index != None:
save_path = os.path.join(pathCBZComic,str(index)+" "+comicInfo.getChapter()+icon_su)
shutil.copy(pathComicIcon, save_path) shutil.copy(pathComicIcon, save_path)
print(f"{pathComicIcon} 已复制至: {save_path}") print(f"{pathComicIcon} 已复制至: {save_path}")
comicInfo.nextDownloadToCBZChapter() comicInfo.nextDownloadToCBZChapter()

View File

@ -29,6 +29,13 @@ class baseComic:
return comic_href return comic_href
else: else:
ntfy.sendMsg(f"{book_name} 已是最新") ntfy.sendMsg(f"{book_name} 已是最新")
chapters = htmlUtils.xpathData('//div[contains(@class,"bookid_chapterBox")]//div[contains(@class,"bookid_chapter")]/a/text()',url=comic_href,update=False)
chapter_index = 1
for chapter in chapters:
comicInfo.setChapterIndex(chapter_index)
comicInfo.setChapterName(chapter)
comicInfo.getNewCBZComicChapter()
chapter_index = chapter_index + 1
return None return None
#print(books) #print(books)
@ -55,6 +62,7 @@ class baseComic:
cls.count_chapter = 0 cls.count_chapter = 0
for href in chapter_href: for href in chapter_href:
chapter = chapters[cls.count_chapter] chapter = chapters[cls.count_chapter]
comicInfo.setChapterIndex(cls.count_chapter+1)
comicInfo.setChapterName(chapter) comicInfo.setChapterName(chapter)
if not comicInfo.nextExistsGetPath("done_"): if not comicInfo.nextExistsGetPath("done_"):
cls.comicChapter(href,scramble=True,sleep=random.randint(5,15)) cls.comicChapter(href,scramble=True,sleep=random.randint(5,15))
@ -98,6 +106,7 @@ class baseComic:
# ntfy.sendMsg(f"{comicInfo.getComicName()} 下载出错了") # ntfy.sendMsg(f"{comicInfo.getComicName()} 下载出错了")
# is_next = False # is_next = False
ntfy.sendMsg(f"预计总章节大小:{cls.count_chapter + 1} / "+ str(comicInfo.getLenChapters())) ntfy.sendMsg(f"预计总章节大小:{cls.count_chapter + 1} / "+ str(comicInfo.getLenChapters()))
comicInfo.setChapterIndex(cls.count_chapter + 1)
if sleep != None and is_next == True: if sleep != None and is_next == True:
ntfy.sendMsg(f"{sleep} 秒后开始下载下一个章节") ntfy.sendMsg(f"{sleep} 秒后开始下载下一个章节")
time.sleep(sleep) time.sleep(sleep)
@ -139,7 +148,8 @@ class baseComic:
#保存图像 #保存图像
comicInfo.nextSaveInfoChapter(chapter_name, list_img) comicInfo.nextSaveInfoChapter(chapter_name, list_img)
#验证数据是已存在且是否完整 #验证数据是已存在且是否完整
cbz_path = comicInfo.getDirCBZComicChapter()+".CBZ" #cbz_path = comicInfo.getDirCBZComicChapter()+".CBZ"
cbz_path = comicInfo.getNewCBZComicChapter()+".CBZ"
is_next = True is_next = True
if os.path.exists(cbz_path): if os.path.exists(cbz_path):
try: try: