This commit is contained in:
caiwx86 2023-02-12 13:41:14 +08:00
parent 1199bd46ef
commit 31456addaa
10 changed files with 284 additions and 289 deletions

View File

@ -28,19 +28,16 @@ class comicEntity:
comic_href = base_url+"/books/"+book_id
comicInfo.setUpdateAt(updated)
comicInfo.setComicName(book_name)
href = baseComic.downladsComcis(book_name=book_name,comic_href=comic_href,updated=updated)
if href != None:
cls.oneComic(href)
comicInfo.updateComicDate()
cls.oneComic(baseComic.comics(book_name=book_name,comic_href=comic_href,updated=updated))
@classmethod
def oneComic(cls,c_url,sleep=None):
if c_url == None: return None
#漫画名
title = htmlUtils.xpathData('//div[@class="col"]/h5/text()',url=c_url,num=0,update=True)
#别名
alias = htmlUtils.xpathData('//span[contains(@class,"bookid_alias")]/text()',num=1)
icon = htmlUtils.xpathData('//img[@class="img-thumbnail"]/@src',num=0)
author = htmlUtils.xpathData('//div[contains(@class,"bookid_bookInfo")]/p[1]/text()',num=1)
tags = htmlUtils.xpathData('//div[contains(@class,"bookid_bookInfo")]/p[3]/b/text()',num=0)
action = htmlUtils.xpathData('//div[contains(@class,"bookid_bookInfo")]/p[2]/text()',num=1)
@ -51,4 +48,5 @@ class comicEntity:
baseComic.oneComic(url=c_url,title=title,author=author,
icon=icon,tags=tags,dep=dep,chapters=chapters,chapter_href=chapter_href,
alias=alias,genre="韩漫")
alias=alias,genre="韩漫")
comicInfo.updateComicDate()

20
main.py
View File

@ -1,25 +1,12 @@
import os
import os,skip
from utils.comic.PathStr import pathStr
from utils.comic.ComicInfo import comicInfo
from entity.BaoZi import comicEntity as baoziEntity
from entity.RouMan import comicEntity as roumanEntity
def roumanskip():
# comicInfo.setComicNameSkips("虐美人 1-117話")
# comicInfo.setComicNameSkips("夢遊")
# comicInfo.setComicNameSkips("療癒女孩")
comicInfo.setComicNameSkips("深度交流會")
comicInfo.setComicNameSkips("心機女教授")
comicInfo.setComicNameSkips("天降惡魔 Devil Drop デビルドロップ")
comicInfo.setComicNameSkips("穿越異世界之後救了我的人是個少年殺人犯少年暗殺者×倒黴催的姐姐順水推舟在異世界做起了愛第2話.zip")
comicInfo.setComicNameSkips("幫人家畫嘛 第二季 Cartoonists-NSFW Season2")
# comicInfo.setComicNameSkips("霸道主管要我IN")
# comicInfo.setComicNameSkips("正妹小主管")
comicInfo.setComicNameSkips("反烏托邦遊戲")
def rouman():
pathStr.setComicMainAndPath(pathStr.comic_rm)
roumanskip()
skip.roumanskip()
for x in range(0,52):
roumanEntity.downladsComcis("https://rm01.xyz/books?&page="+str(x))
@ -31,5 +18,4 @@ if __name__ == '__main__':
rouman()
# baozi()
# os.environ["http_proxy"] = "http://127.0.0.1:7890"
# os.environ["https_proxy"] = "http://127.0.0.1:7890"
# comicEntity.oneComic("https://18comic.vip/album/358870/")
# os.environ["https_proxy"] = "http://127.0.0.1:7890"

14
skip.py Normal file
View File

@ -0,0 +1,14 @@
from utils.comic.ComicInfo import comicInfo
def roumanskip():
# comicInfo.setComicNameSkips("虐美人 1-117話")
# comicInfo.setComicNameSkips("夢遊")
# comicInfo.setComicNameSkips("療癒女孩")
comicInfo.setComicNameSkips("深度交流會")
comicInfo.setComicNameSkips("心機女教授")
comicInfo.setComicNameSkips("天降惡魔 Devil Drop デビルドロップ")
comicInfo.setComicNameSkips("穿越異世界之後救了我的人是個少年殺人犯少年暗殺者×倒黴催的姐姐順水推舟在異世界做起了愛第2話.zip")
comicInfo.setComicNameSkips("幫人家畫嘛 第二季 Cartoonists-NSFW Season2")
# comicInfo.setComicNameSkips("霸道主管要我IN")
# comicInfo.setComicNameSkips("正妹小主管")
comicInfo.setComicNameSkips("反烏托邦遊戲")

View File

@ -15,6 +15,21 @@ class CBZUtils:
@classmethod
def getCBZ_Path(cls): return cls.getCBZ_Dir()+".CBZ"
@classmethod
def PackCBZAndequZipLength(cls):
try:
size_zip = len(cls.zip_compression(comicInfo.getDirComicChapter(), cls.getCBZ_Path()))
size_imgs = len(comicInfo.getChapterImgs())
if size_zip == size_imgs:
ntfy.sendMsg(f"打包校验成功: {cls.getCBZ_Path()}")
comicInfo.nextCBZToDoneChapter()
return True
else:
ntfy.sendMsg(f"打包检验不完整:{cls.getCBZ_Path()}")
return False
except:
print("CBZ打包ERROR")
@classmethod
def readDirsOrFiles(cls,dir,type):
data = []
@ -28,12 +43,11 @@ class CBZUtils:
return data
@classmethod
def zip_compression(cls,source_dir, target_file):
def zip_compression(cls,source_dir=None, target_file=None, remove=True):
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):
if not os.path.exists(target_file) and source_dir != None:
with ZipFile(target_file, mode='w') as zf:
for path, dir_names, filenames in os.walk(source_dir):
path = Path(path)
@ -45,12 +59,15 @@ class CBZUtils:
zf.write(path.joinpath(filename), arc_dir.joinpath(filename))
zf.close()
ntfy.sendMsg(f"打包完成:{target_file}")
#md5_file = md5(target_file)
#print("md5:", md5_file)
#msg[target_file] = md5_file
else:
with ZipFile(target_file, "r") as zfile:
filenames = zfile.namelist()
zfile.close()
print("文件已存在:", target_file)
return len(filenames)
if remove:
filenames.remove(comicInfo.COMIC_ICON_NAME+".jpg")
filenames.remove(comicInfo.COMIC_INFO_XML)
return filenames
@classmethod
def packAutoComicChapterCBZ(cls):
@ -63,31 +80,10 @@ class CBZUtils:
os.remove(file)
except:
print(f"删除 {file} 发生错误,已跳过")
try:
size_zip = cls.zip_compression(chapter_path, cls.getCBZ_Path())
size_imgs = len(comicInfo.getChapterImgs())
if size_zip -1 == size_imgs:
ntfy.sendMsg(f"打包校验成功: {cls.getCBZ_Path()}")
comicInfo.nextCBZToDoneChapter()
return True
else:
ntfy.sendMsg(f"打包检验不完整:{cls.getCBZ_Path()}")
return False
except:
print("")
#ntfy.sendMsg("CBZ打包失败")
@classmethod
def zip_info(cls,zip_path=None):
if zip_path == None:
zip_path = cls.getCBZ_Path()
data = None
if os.path.exists(zip_path):
with ZipFile(zip_path, "r") as zfile:
data = zfile.namelist()
zfile.close()
return data
cls.zip_compression(comicInfo.getDirComicChapter(), cls.getCBZ_Path())
time.sleep(0.1)
fileUtils.remove(comicInfo.getDirComicChapter())
return cls.PackCBZAndequZipLength()
@classmethod
def replaceZip(cls,filepath,unpack_dir=None):
@ -128,39 +124,6 @@ class CBZUtils:
return False
class verUtils:
@classmethod
def verCBZ(cls,data=None):
zip_info = CBZUtils.zip_info()
if zip_info != None:
len_zip = len(zip_info) - 1
else:
len_zip = 0
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):
#验证数据是已存在且是否完整
@ -168,7 +131,7 @@ class verUtils:
is_next = False
if os.path.exists(cbz_path):
try:
cbz_size = len(CBZUtils.zip_info(cbz_path)) - 1
cbz_size = len(CBZUtils.zip_info(cbz_path))
except:
cbz_size = 0
if len(list_img) == cbz_size:

View File

@ -2,6 +2,8 @@ import base64,hashlib,os,shutil
import math
import numpy as np
from PIL import Image
from tinydb import TinyDB, Query
from utils.comic.PathStr import pathStr
class imageUtils:
@ -197,7 +199,11 @@ class imageUtils:
os.remove(imgpath)
print("remove=",imgpath)
class fileUtils:
class fileUtils:
@classmethod
def exists(cls,path):
return os.path.exists(path)
@classmethod
def ver_file(cls,file_path,type):
if type == "image":
@ -210,4 +216,56 @@ class fileUtils:
if os.path.exists(file_path):
os.remove(file_path)
print(f"{file_path}已损坏 type:{type},删除重试中")
return False
return False
@classmethod
def remove(cls,path):
if not os.path.exists(path):
return None
try:
if os.path.isfile(path):
os.remove(path)
if os.path.isdir(path):
shutil.rmtree(path)
print(f"已删除:{path}")
except:
print(f"删除错误:{path}")
class dbUtils:
@classmethod
def base_path(cls,path):
base_dir = pathStr.base_db()
if not os.path.exists(base_dir):
os.makedirs(base_dir)
return os.path.join(base_dir,path)
@classmethod
def init_db(cls,db_name=None):
if db_name != None: db_name = cls.base_path(db_name)+".json"
else: db_name = "Comics.json"
return TinyDB(cls.base_path(db_name))
@classmethod
def setComic(cls,name,progress,db_name=None):
db = cls.init_db(db_name)
comic = Query()
if len(db.search(comic.name == name)) == 0: db.insert({"name":name,"progress":progress})
else: db.update({"progress":progress},comic.name== name)
print(db.all())
@classmethod
def query(cls,name,progress=None,db_name=None):
db = cls.init_db(db_name)
result = db.search(Query().name == name)
if progress != None:
try:
if len(db.search((Query().name == name) & (Query().progress == progress))) != 0: result = True
else: result = False
except Exception as e:
print(e)
return result
@classmethod
def remove(cls,name,db_name=None):
db = cls.init_db(db_name)
db.remove(Query().name == name)

View File

@ -1,12 +1,19 @@
import requests
import requests,time
class ntfy:
@classmethod
def sendMsg(cls, msg,alert=True):
def sendMsg(cls, msg,alert=True,sleep=None,error=None):
try:
print(f"#ntfy: {msg}")
if alert:
requests.post("https://ntfy.caiwenxiu.cn/PyComic",
data=msg.encode(encoding='utf-8'))
except:
print(f"#ntfy error: {msg}")
print(f"#ntfy error: {msg}")
if sleep != None:
time.sleep(int(sleep))
if error != None:
print(f"#ntfy Error: {error}")
return False
else:
return True

View File

@ -1,103 +1,65 @@
import json,os,time,random,shutil
from utils.HtmlUtils import htmlUtils
from utils.FileUtils import imageUtils
from utils.comic.ComicInfo import comicInfo
from utils.comic.ComicInfo import comicInfo as ci
from utils.CBZUtils import CBZUtils
from utils.CBZUtils import verUtils
from utils.downloader import download_images
from utils.downloader import download_comic_icon
from utils.Ntfy import ntfy
from utils.CBZUtils import verUtils
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
class baseComic:
count_chapter = 0
@classmethod
def downladsComcis(cls,book_name,comic_href,updated=None):
comicInfo.setComicName(book_name)
if updated != None:
comicInfo.setUpdateAt(updated)
random_int = random.randint(5,20)
comicInfo.setComicName(book_name)
dir_conf_comic = comicInfo.getDirConfComic()
if comicInfo.getIsComicNameSkips(book_name):
print(f"{book_name} 在白名单中,已跳过")
return None
if not os.path.exists(dir_conf_comic):
ntfy.sendMsg(f"{random_int}秒后开始下载 漫画:{book_name}")
time.sleep(random_int)
else:
ntfy.sendMsg(f"已存在 漫画:{book_name}")
if comicInfo.isUpdateComic():
return comic_href
def comics(cls,book_name,comic_href,updated=None):
#不判断是否为空ComicInfo方法内会自动判断
ci.setComicInfo(comicname=book_name,update_at=updated)
#白名单跳过
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 ci.isUpdateComic(): 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)
chapter_index = 1
for chapter in chapters:
comicInfo.setChapterIndex(chapter_index)
comicInfo.setChapterName(chapter)
cbz_path = comicInfo.getNewCBZComicChapter("file")
icon_path = comicInfo.getNewIconComicChapter("file")
ci.setChapterIndex(chapter_index)
ci.setChapterName(chapter)
cbz_path = ci.getNewCBZComicChapter("file")
icon_path = ci.getNewIconComicChapter("file")
CBZUtils.replaceZip(cbz_path)
if comicInfo.nextExistsGetPath("done_") and not os.path.exists(cbz_path):
comicInfo.nextExistsGetPath("done_",remove=True)
#判断漫画是否完成
if ci.isProgress(ci.PROGRESS_DONE) and not os.path.exists(cbz_path): ci.isProgress(ci.PROGRESS_DONE,remove=True)
if not os.path.exists(cbz_path):
comicInfo.updateComicDate("0")
ci.updateComicDate("0")
return comic_href
else:
cover_icon_path = os.path.join(comicInfo.getDirConfComic(),"cover.jpg")
if not os.path.exists(icon_path) and os.path.exists(cover_icon_path):
shutil.copy(cover_icon_path,icon_path)
print(f"{cover_icon_path} copy 至:{icon_path}")
chapter_index = chapter_index + 1
return None
#print(books)
#for comicHref in comicsHref:
# cls.oneComic(comicHref,random.uniform(10,20))
@classmethod
def oneComic(cls,url,title,author,icon,tags,dep,chapters,chapter_href,alias=None,genre=None,lang="zh",sleep=None):
author = str(author).replace("&",",").replace(" ",",")
comicInfo.setHomePage(url)
comicInfo.setComicName(str(title))
if alias != None:
comicInfo.setComicNames(title+","+alias)
comicInfo.setAuthor(author)
comicInfo.setIcon(icon)
comicInfo.setTags(tags)
comicInfo.setDep(dep)
#comicInfo.setCBS("韩漫")
if genre != None:
comicInfo.setGenre(genre)
comicInfo.setLang(lang)
comicInfo.setListChapter(chapters)
#comicUtils.setComic(title,alias,icon,author,tags,action,dep,update_date,chapters,chapter_href)
ci.setComicInfo(homepage=url,comicname=title,alias=ci.setComicNames(title+","+alias),
author=author,icon=icon,tags=tags,dep=dep,genre=genre,lang=lang,chapters=chapters)
cls.count_chapter = 0
for href in chapter_href:
chapter = chapters[cls.count_chapter]
comicInfo.setChapterIndex(cls.count_chapter+1)
comicInfo.setChapterName(chapter)
if comicInfo.nextExistsGetPath("done_") and not os.path.exists(comicInfo.getNewCBZComicChapter("file")):
comicInfo.nextExistsGetPath("done_",remove=True)
if not comicInfo.nextExistsGetPath("done_"):
cls.comicChapter(href,scramble=True,sleep=random.randint(5,15))
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 comicInfo.nextExistsGetPath("done_"):
verUtils.verCBZ()
#if ci.nextExistsGetPath("done_"):
# verUtils.verCBZ()
cls.count_chapter += 1
#一本漫画下载后等待
#清空文件夹
path_dir_comic = comicInfo.getDirComic()
if os.path.exists(path_dir_comic):
shutil.rmtree(path_dir_comic)
if sleep != None:
time.sleep(sleep)
if os.path.exists(ci.getDirComic()): shutil.rmtree(ci.getDirComic())
if sleep != None: time.sleep(sleep)
'''
@ -109,116 +71,81 @@ class baseComic:
try:
is_next = cls.Onechapter(chapter_url,scramble)
#进入下个阶段
if comicInfo.nextExistsGetPath("down_"):
#章节图片全部下载后,调用下载封面
download_comic_icon()
if ci.isProgress(ci.PROGRESS_DOWN): download_comic_icon()
#下个阶段
if comicInfo.nextExistsGetPath("cbz_"):
time.sleep(0.1)
#下载后自动打包
is_next = CBZUtils.packAutoComicChapterCBZ()
#完成删除原文件
remove_path = comicInfo.getDirComicChapter()
if os.path.exists(remove_path):
shutil.rmtree(remove_path)
print(f"文件已删除: {remove_path}")
except Exception as e:
print(e)
ntfy.sendMsg(f"{comicInfo.getComicName()} 下载出错了")
is_next = False
ntfy.sendMsg(f"预计总章节大小:{cls.count_chapter + 1} / "+ str(comicInfo.getLenChapters()))
comicInfo.setChapterIndex(cls.count_chapter + 1)
if sleep != None and is_next == True:
ntfy.sendMsg(f"{sleep} 秒后开始下载下一个章节")
time.sleep(sleep)
if ci.isProgress(ci.PROGRESS_CBZ): is_next = CBZUtils.packAutoComicChapterCBZ()
except Exception as e: is_next = ntfy.sendMsg(f"{ci.getComicName()} 下载出错了",error=e)
ntfy.sendMsg(f"预计总章节大小:{cls.count_chapter + 1} / "+ str(ci.getLenChapters()))
ci.setChapterIndex(cls.count_chapter + 1)
if sleep != None and is_next == True: ntfy.sendMsg(f"{sleep} 秒后开始下载下一个章节",sleep=sleep)
@classmethod
def Onechapter(cls,chapter_url,scramble=None):
is_next = True
if not str(chapter_url).startswith("http"):
chapter_url = comicInfo.getBaseUrl() + chapter_url
try:
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)
comicInfo.nextInfoToImgChapter()
ci.nextInfoToImgChapter()
#下载完成后, 开始解密图片
chapter_dir = comicInfo.getDirComicChapter()
if scramble and os.path.exists(chapter_dir):
#获取章节图片路径
chapter_dir = ci.getDirComicChapter()
if scramble and os.path.exists(chapter_dir): #获取章节图片路径
dirs = os.listdir(chapter_dir)
for img in dirs:
if img.startswith("scramble="):
c_path = os.path.join(chapter_dir, img)
#imageUtils.getScrambleImage(c_path)
imageUtils.encode_scramble_image(c_path)
imageUtils.encode_scramble_image(os.path.join(chapter_dir,img))
#进入下一阶段
comicInfo.nextImgToDownloadChapter()
ci.nextImgToDownloadChapter()
return is_next
@classmethod
def comicChapterDownload(cls,url):
def comicChapterDownload(cls,url,is_next=True):
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 = comicInfo.getChapterListImg()
files_name = comicInfo.getChapterFilesName()
#netUtils.downloadComicChapterImages(list_img,scrambles=list_scramble)
chapter_name = comicInfo.getChapter()
book_name = comicInfo.getComicName()
comicInfo.setChapterImgs(list_img)
#保存图像
comicInfo.nextSaveInfoChapter(chapter_name, list_img)
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()
ci.setChapterImgs(list_img)
#保存信息
ci.nextSaveInfoChapter(chapter_name, list_img)
#验证数据是已存在且是否完整
#cbz_path = comicInfo.getDirCBZComicChapter()+".CBZ"
cbz_path = comicInfo.getNewCBZComicChapter()+".CBZ"
#cbz_path = ci.getDirCBZComicChapter()+".CBZ"
cbz_path = ci.getNewCBZComicChapter()+".CBZ"
#更新Icon
comicInfo.getNewIconComicChapter()
is_next = True
ci.getNewIconComicChapter()
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:
if CBZUtils.PackCBZAndequZipLength:
ntfy.sendMsg(f"{book_name} {chapter_name} 数据完整,已跳过")
comicInfo.nextDoneSave(list_img)
ci.nextDoneSave(list_img)
is_next = False
else:
ntfy.sendMsg(f"{book_name} {chapter_name} 数据不完整尝试删除配置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 = False
if os.path.getsize(cbz_path) < 300000: fileUtils.remove(cbz_path)
else: is_next = False
except:
ntfy(f"删除失败 {cbz_path}")
if is_next:
path_comic_info = comicInfo.getPathComicInfoXML()
if not os.path.exists(path_comic_info):
if not os.path.exists(ci.getPathComicInfoXML()):
#print("不存在ComicInfo.xml 生成中...")
comicInfo.setPages(files_name)
comicInfo.writeComicInfoXML(chapter_name)
ci.setPages(files_name)
ci.writeComicInfoXML(chapter_name)
ntfy.sendMsg(f"{book_name} {chapter_name} 下载中")
is_next = verUtils.verNextCBZ(list_img)
repeat = 1
while not is_next and repeat <= 2:
download_images(list_img,comicInfo.getDirComicChapter(), files_name=files_name,timeout=20)
file_imgs = os.listdir(comicInfo.getDirComicChapter())
count_jpg = ",".join(file_imgs).split(".jpg")
is_next = len(count_jpg)-1 == len(list_img)
download_images(list_img,ci.getDirComicChapter(), files_name=files_name,timeout=20)
is_next = len(",".join(os.listdir(ci.getDirComicChapter())).split(".jpg"))-1 == len(list_img)
if not is_next:
sleep_time = 3+int(repeat)*2
time.sleep(sleep_time)
ntfy.sendMsg(f"下载数据({len(count_jpg)-1}/{len(list_img)})不完整,{sleep_time}秒钟后尝试第{repeat}")
ntfy.sendMsg(f"下载数据(不完整,{sleep_time}秒钟后尝试第{repeat}")
repeat += 1
return is_next

View File

@ -2,9 +2,17 @@ from xml.dom.minidom import Document
import os,re
from utils.comic.PathStr import pathStr
import json,shutil
from utils.FileUtils import dbUtils
class comicInfo():
COMIC_ICON_NAME = "cover"
COMIC_INFO_XML = "ComicInfo.xml"
PROGRESS_INFO = "info"
PROGRESS_DOWN = "download"
PROGRESS_IMG = "download"
PROGRESS_CBZ = "cbz"
PROGRESS_DONE = "done"
document = Document()
path_comic_info = None
@ -75,11 +83,18 @@ class comicInfo():
def setChapterName(cls,value):
cls.str_chapter = cls.fixFileName(value)
cls.chapter_node = cls.setNodeAndValue(cls.chapter,value)
@classmethod
def setListChapter(cls, value): cls.str_list_chapter = value
def setComicValue(cls,value):
result = None
if value != None or value != "":
result = value
return result
@classmethod
def setChapterImgs(cls, value): cls.str_chapter_imgs = value
def setListChapter(cls, value): cls.str_list_chapter = cls.setComicValue(value)
@classmethod
def setChapterImgs(cls, value): cls.str_chapter_imgs = cls.setComicValue(value)
@classmethod
def getChapterImgs(cls): return cls.str_chapter_imgs
@classmethod
@ -106,11 +121,11 @@ class comicInfo():
@classmethod
def setWeb(cls,value):
cls.str_web = value
cls.web_node = cls.setNodeAndValue(cls.web,value)
cls.str_web = cls.setComicValue(value)
cls.web_node = cls.setNodeAndValue(cls.web,cls.setComicValue(value))
@classmethod
def setChapterListImg(cls,value): cls.str_list_img=value
def setChapterListImg(cls,value): cls.str_list_img=cls.setComicValue(value)
@classmethod
def setValue1(cls,value): cls.str_value1 = value
@classmethod
@ -118,7 +133,7 @@ class comicInfo():
@classmethod
def getChapterListImg(cls): return cls.str_list_img
@classmethod
def setChapterFilesName(cls,value): cls.str_files_img=value
def setChapterFilesName(cls,value): cls.str_files_img=cls.setComicValue(value)
@classmethod
def getChapterFilesName(cls): return cls.str_files_img
@classmethod
@ -126,8 +141,8 @@ class comicInfo():
@classmethod
def setPageCount(cls,value):
cls.str_page_count = value
cls.page_count_node = cls.setNodeAndValue(cls.page_count,value)
cls.str_page_count = cls.setComicValue(int(value)+1)
cls.page_count_node = cls.setNodeAndValue(cls.page_count,cls.str_page_count)
@classmethod
def setPages(cls,value):
@ -137,6 +152,11 @@ class comicInfo():
value = join_list.split(",")
cls.setPageCount(str(len(value)))
root_node = cls.document.createElement(cls.pages)
#添加封面
icon_node = cls.document.createElement("Page")
icon_node.setAttribute("Image","cover")
icon_node.setAttribute("Type","FrontCover")
root_node.appendChild(icon_node)
for page in value:
c_node = cls.document.createElement("Page")
page = page.split("_")[-1]
@ -157,15 +177,15 @@ class comicInfo():
@classmethod
def setIcon(cls,value):
cls.str_icon = value
cls.str_icon = cls.setComicValue(value)
return cls.str_icon
@classmethod
def setHomePage(cls, value): cls.str_homepage = value
def setHomePage(cls, value): cls.str_homepage = cls.setComicValue(value)
@classmethod
def getHomePage(cls): return cls.str_homepage
@classmethod
def setUpdateAt(cls, value): cls.str_update_at = value
def setUpdateAt(cls, value): cls.str_update_at = cls.setComicValue(value)
@classmethod
def getUpdateAt(cls): return cls.str_update_at
@classmethod
@ -176,7 +196,7 @@ class comicInfo():
return value
@classmethod
def setChapterIndex(cls,value): cls.str_chapter_index = value
def setChapterIndex(cls,value): cls.str_chapter_index = cls.setComicValue(value)
@classmethod
def getChapterIndex(cls): return cls.str_chapter_index
@classmethod
@ -286,7 +306,7 @@ class comicInfo():
@classmethod
def getPathComicInfoXML(cls):
try:
cls.path_comic_info = os.path.join(pathStr.base_comic_img(),cls.str_comic_name,cls.str_chapter,"ComicInfo.xml")
cls.path_comic_info = os.path.join(pathStr.base_comic_img(),cls.str_comic_name,cls.str_chapter, cls.COMIC_INFO_XML)
except:
return None
return cls.path_comic_info
@ -311,16 +331,16 @@ class comicInfo():
if cls.page_count_node != None: root.appendChild(cls.page_count_node)
if cls.pages_node != None: root.appendChild(cls.pages_node)
cls.getPathComicInfoXML()
if path != None: cls.path_comic_info = os.path.join(path,"ComicInfo.xml")
if path != None: cls.path_comic_info = os.path.join(path,cls.COMIC_INFO_XML)
base_dir = os.path.dirname(cls.path_comic_info)
if not os.path.exists(base_dir): os.makedirs(base_dir)
if os.path.exists(cls.path_comic_info):
print("ComicInfo.xml 已存在")
print(f"{cls.COMIC_INFO_XML} 已存在")
return None
with open(cls.path_comic_info , "w", encoding="utf-8") as fo:
new_document.writexml(fo, indent='', addindent='\t', newl='\n', encoding="utf-8")
fo.close()
print("ComicInfo.xml 已生成 pathd=", cls.path_comic_info)
print(f"{cls.COMIC_INFO_XML} 已生成 pathd=", cls.path_comic_info)
#文件保存
@classmethod
@ -359,47 +379,37 @@ class comicInfo():
def nextSaveInfoChapter(cls,chapter,data):
if cls.str_chapter != chapter:
print(f"chapter {cls.str_chapter}{chapter} 不一致,已自动跳过")
cls.setProgress(cls.PROGRESS_INFO)
cls.nextSavePath("info_",data)
@classmethod
def nextInfoToImgChapter(cls):
info = cls.nextSavePath("info_")
img = cls.nextSavePath("img_")
shutil.move(info,img)
def nextInfoToImgChapter(cls): cls.setProgress(cls.PROGRESS_IMG)
@classmethod
def nextImgToDownloadChapter(cls):
img = cls.nextSavePath("img_")
download = cls.nextSavePath("down_")
shutil.move(img, download)
def nextImgToDownloadChapter(cls): cls.setProgress(cls.PROGRESS_DOWN)
@classmethod
def nextDownloadToCBZChapter(cls):
download = cls.nextSavePath("down_")
cbz = cls.nextSavePath("cbz_")
shutil.move(download, cbz)
def nextDownloadToCBZChapter(cls): cls.setProgress(cls.PROGRESS_CBZ)
@classmethod
def nextCBZToDoneChapter(cls):
cbz = cls.nextSavePath("cbz_")
done = cls.nextSavePath("done_")
shutil.move(cbz,done)
def nextCBZToDoneChapter(cls): cls.setProgress(cls.PROGRESS_DONE)
@classmethod
def nextDoneSave(cls,data): cls.nextSavePath("done_",data)
@classmethod
def setProgress(cls,progress):
dbUtils.setComic(cls.str_chapter,progress,cls.str_comic_name)
@classmethod
def nextExistsGetPath(cls,msg,remove=False):
path = cls.nextSavePath(msg)
is_exists = os.path.exists(path)
if remove and is_exists:
os.remove(path)
return is_exists
def isProgress(cls,progress,remove=None):
if remove: cls.setProgress("None")
return dbUtils.query(cls.str_chapter,progress,cls.str_comic_name)
@classmethod
def iconDB(cls): dbUtils.setComic(cls.str_comic_name,cls.str_icon,"icons")
@classmethod
def equIcon(cls): return dbUtils.query(cls.str_comic_name,cls.str_icon,"icons")
@classmethod
def setConfDirComicPath(cls,file_name,comic_name=None):
if comic_name != None:
cls.setComicName(comic_name)
if comic_name != None: cls.setComicName(comic_name)
return os.path.join(cls.getDirConfComic(),file_name)
@classmethod
@ -451,4 +461,21 @@ class comicInfo():
@classmethod
def comicChapterDownload(cls,imgs,names):
cls.setChapterListImg(imgs)
cls.setChapterFilesName(names)
cls.setChapterFilesName(names)
@classmethod
def setComicInfo(cls,comicname=None,homepage=None,alias=None,author=None,icon=None,tags=None,
dep=None,genre=None,lang=None,chapters=None,update_at=None):
author = str(author).replace("&",",").replace(" ",",")
cls.setHomePage(homepage)
cls.setComicName(str(comicname))
if alias != None: comicInfo.setComicNames(alias)
cls.setAuthor(author)
cls.setIcon(icon)
cls.setTags(tags)
cls.setDep(dep)
#comicInfo.setCBS("韩漫")
if genre != None: cls.setGenre(genre)
cls.setLang(lang)
cls.setListChapter(chapters)
cls.setUpdateAt(update_at)

View File

@ -8,7 +8,7 @@ class pathStr:
comic_rm="RM"
comic_url_main = None
base_comic_out = os.path.join("/mnt", "bigTComics")
base_comic_out = os.path.join("/mnt", "Comics")
@classmethod
def base_cbz(cls): return cls.getBaseComicPath("CBZ")
@ -22,6 +22,8 @@ class pathStr:
def base_html_chapter(cls): return cls.getBaseComicPath("html_updated")
@classmethod
def base_comic_update(cls): return cls.getBaseComicPath("comic_update")
@classmethod
def base_db(cls): return cls.getBaseComicPath("db")
@classmethod
def getBaseComicPath(cls,join_path): return os.path.join(cls.base_comic_out,join_path)
@ -39,7 +41,8 @@ class pathStr:
@classmethod
def setComicMainPath(cls,value):
if value != cls.comic_rm: cls.base_comic_out = os.path.join(cls.base_comic_out, value)
#if value != cls.comic_rm: cls.base_comic_out = os.path.join(cls.base_comic_out, value)
cls.base_comic_out = os.path.join(cls.base_comic_out, value)
@classmethod
def base_html_week(cls):

View File

@ -98,20 +98,32 @@ def download_comic_icon():
if icon_url == None:
print("icon 不存在,已跳过")
return None
save_name = "cover"
save_name = comicInfo.COMIC_ICON_NAME
icon_prefix = "."+str(icon_url).split(".")[-1]
icon_prefix = icon_prefix.split("?")[0]
#判断漫画名路径是否已存在comicname/cover.jpg, 存在跳过
path_comic_icon = os.path.join(comicInfo.getDirConfComic(),save_name+icon_prefix)
if not comicInfo.equIcon() and os.path.exists(path_comic_icon):
os.remove(path_comic_icon)
if not os.path.exists(path_comic_icon):
download(icon_url, path_comic_icon)
path_cbz_comic = comicInfo.getDirCBZComic()
if not os.path.exists(path_cbz_comic):
os.makedirs(path_cbz_comic)
save_path = os.path.join(path_cbz_comic,comicInfo.getChapter()+icon_prefix)
shutil.copy(path_comic_icon, save_path)
print(f"{path_comic_icon} 已复制至: {save_path}")
#if not os.path.exists(path_cbz_comic):
# os.makedirs(path_cbz_comic)
save_path = os.path.join(comicInfo.getDirCBZComic(),comicInfo.getChapter()+icon_prefix)
#历史版本ICON
if os.path.exists(save_path):
os.remove(save_path)
#shutil.copy(path_comic_icon, save_path)
#print(f"{path_comic_icon} 已复制至: {save_path}")
if os.path.exists(path_comic_icon):
base_dir = comicInfo.getDirComicChapter()
if not os.path.exists(base_dir):
os.makedirs(base_dir)
shutil.copy(path_comic_icon,os.path.join(base_dir,save_name+icon_prefix))
#保存icon信息
comicInfo.iconDB()
comicInfo.nextDownloadToCBZChapter()
comicInfo.setProgress(comicInfo.PROGRESS_CBZ)
# 定义下载函数
def download(url,path,file_type=None):