This commit is contained in:
cwx
2023-03-30 02:01:06 +08:00
parent eaf15969f0
commit 25be464102
8 changed files with 119 additions and 121 deletions
+27 -30
View File
@@ -10,19 +10,21 @@ from entity.down.RouMan import comicCommon as RouManComicCommon
from entity.down.JM import comicCommon as JMComicCommon
from entity.down.BaoZi import comicCommon as BaoZiComicCommon
from utils.comic.PathStr import pathStr
from utils.FileUtils import fileUtils
from utils.FileUtils import fileUtils as fu
class baseComic:
count_chapter = 0
#校验该漫画是否为最新
# Y/跳过 N/下载 返回下载链接
@classmethod
def comics(cls,book_name,comic_href,updated=None):
#不判断是否为空,ComicInfo方法内会自动判断
ci.setComicInfo(comicname=book_name,update_at=updated)
def updateComics(cls):
(book_name,comic_href,updated) = [ci.getComicName(),ci.getCurrentChapterImg(),ci.getUpdateAt()]
#白名单跳过
if ci.getIsComicNameSkips(book_name): return None
if not os.path.exists(ci.getDirConfComic()): ntfy.sendMsg(f"{random.randint(5,20)}秒后开始下载 漫画:{book_name}")
else: ntfy.sendMsg(f"已存在 漫画:{book_name}")
if not ci.isUpdateComic(): return comic_href
if not ci.isUpdateComic():
ntfy.sendMsg(f"开始下载 漫画:{book_name}")
return comic_href
else:
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)
@@ -49,13 +51,10 @@ class baseComic:
for href in chapter_href:
ci.setChapterName(chapters[cls.count_chapter])
ci.setChapterIndex(cls.count_chapter+1)
if ci.isProgress(ci.PROGRESS_DONE) and not os.path.exists(ci.getNewCBZComicChapter("file")): ci.isProgress(ci.PROGRESS_DONE,remove=True)
if not ci.isProgress(ci.PROGRESS_DONE): cls.comicChapter(href,scramble=True,sleep=random.randint(5,15))
#存在就校验CBZ包是否完整
#if ci.nextExistsGetPath("done_"):
# verUtils.verCBZ()
#if ci.isProgress(ci.PROGRESS_DONE):
# CBZUtils.verCBZComic()
#存在完成配置文件 但文件不存在 将清空完成配置文件
if ci.isProgress(ci.PROGRESS_DONE) and not fu.exists(ci.getNewCBZComicChapter("file")): ci.isProgress(ci.PROGRESS_DONE,remove=True)
#存在完成配置文件 则允许下载
if not ci.isProgress(ci.PROGRESS_DONE): cls.comicChapters(href,scramble=True,sleep=random.randint(5,15))
cls.count_chapter += 1
#一本漫画下载后等待
#清空文件夹
@@ -67,9 +66,9 @@ class baseComic:
读取某章节下所有图片
'''
@classmethod
def comicChapter(cls,chapter_url,scramble=None,sleep=None,is_next=True):
def comicChapters(cls,chapter_url,scramble=None,sleep=None):
try:
is_next = cls.Onechapter(chapter_url,scramble)
cls.Onechapter(chapter_url,scramble)
#进入下个阶段
#章节图片全部下载后,调用下载封面
if ci.isProgress(ci.PROGRESS_DOWN): download_comic_icon()
@@ -80,15 +79,14 @@ class baseComic:
ci.setChapterIndex(cls.count_chapter + 1)
if sleep != None and is_next: ntfy.sendMsg(f"{sleep} 秒后开始下载下一个章节",sleep=sleep)
#根据章节地址下载全部图片,并将文件名scramble开头的图片进行解密
@classmethod
def Onechapter(cls,chapter_url,scramble=None):
is_next = True
if not str(chapter_url).startswith("http"): chapter_url = ci.getBaseUrl() + chapter_url
try:
is_next = cls.comicChapterDownload(chapter_url)
except:
htmlUtils.remove_HtmlCache(chapter_url)
#下载图片
try: is_next = cls.comicChapterDownload(chapter_url)
except: htmlUtils.remove_HtmlCache(chapter_url)
ci.nextInfoToImgChapter()
#下载完成后, 开始解密图片
chapter_dir = ci.getDirComicChapter()
@@ -103,33 +101,32 @@ class baseComic:
@classmethod
def comicChapterDownload(cls,url,is_next=True):
#获取本次工程的HOME目录
comic_main = pathStr.getComicMain()
if comic_main == pathStr.comic_jm: JMComicCommon.comicChapterDownload(url)
if comic_main == pathStr.comic_bz: BaoZiComicCommon.comicChapterDownload(url)
if comic_main == pathStr.comic_rm: RouManComicCommon.comicChapterDownload(url)
if comic_main == None: print("comic_main为空,退出中...") & exit()
list_img = ci.getChapterListImg()
files_name = ci.getChapterFilesName()
chapter_name = ci.getChapter()
book_name = ci.getComicName()
(list_img,files_name,chapter_name,book_name) = [ci.getChapterListImg(),ci.getChapterFilesName(),ci.getChapter(),ci.getComicName()]
ci.setChapterImgs(list_img)
#保存信息
ci.nextSaveInfoChapter(chapter_name, list_img)
#验证数据是已存在且是否完整
#cbz_path = ci.getDirCBZComicChapter()+".CBZ"
cbz_path = ci.getNewCBZComicChapter()+".CBZ"
cbz_file = ci.getNewFileCBZComicChapter()
#更新Icon
ci.getNewIconComicChapter()
if os.path.exists(cbz_path): CBZUtils.verCBZComic(cbz_path)
#检验CBZ文件
CBZUtils.verCBZComic(cbz_file)
is_unzip = CBZUtils.existsUnzipCBZ(files_name)
if is_next and not os.path.exists(ci.getPathComicInfoXML()):
if is_next and fu.notExists(ci.getPathComicInfoXML()):
#print("不存在ComicInfo.xml 生成中...")
ci.setPages(files_name)
ci.writeComicInfoXML(chapter_name)
is_next = CBZUtils.nextCBZ(list_img)
repeat = 1
while is_next and repeat <= 2 and not is_unzip:
while is_next and repeat <= 2 and not CBZUtils.updateOldCBZ(files_name):
ntfy.sendMsg(f"{book_name} {chapter_name} 下载中")
download_images(list_img,ci.getDirComicChapter(), files_name=files_name,concurrency=10,timeout=60)
equ_next = len(",".join(os.listdir(ci.getDirComicChapter())).split(".jpg"))-1 == len(list_img)