update version
This commit is contained in:
@@ -0,0 +1,144 @@
|
||||
import json,os,time,random,shutil
|
||||
from utils.NetUtils import htmlUtils
|
||||
from utils.FileUtils import imageUtils
|
||||
from utils.ComicUtils import CBZUtils
|
||||
from utils.NetUtils import downloadUtils
|
||||
from utils.ComicUtils import ntfy
|
||||
from utils.FileUtils import fileUtils as fu
|
||||
from domain.Domains import domains
|
||||
from common.ComicInfo import ComicInfoUtils as ciUtils
|
||||
from common.ComicInfo import ComicInfo as ci
|
||||
from common.Comic import Comic
|
||||
from common.Comic import ListComic
|
||||
from common.Constant import ComicPath
|
||||
|
||||
class baseComic:
|
||||
count_chapter = 0
|
||||
|
||||
#校验该漫画是否为最新
|
||||
# Y/跳过 N/下载 返回下载链接
|
||||
@classmethod
|
||||
def updateComics(cls,chapters_xpath):
|
||||
comics = ListComic.getListComicsLinksUpdateAt()
|
||||
try:
|
||||
(book_name,comic_href,updated) = [comics[0],comics[1],comics[2]]
|
||||
except:
|
||||
return False
|
||||
cls.updateOneComic(book_name,comic_href,updated,chapters_xpath)
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def updateOneComic(cls,book_name,comic_href,update_at,chapters_xpath):
|
||||
#白名单跳过
|
||||
if ciUtils.getIsComicNameSkips(book_name): return None
|
||||
if not ciUtils.isUpdateComic():
|
||||
ntfy.sendMsg(f"开始下载 漫画:{book_name}")
|
||||
Comic.setCurrentDownLink(comic_href)
|
||||
else:
|
||||
ntfy.sendMsg(f"{book_name} 已是最新")
|
||||
chapters = htmlUtils.xpathData(chapters_xpath,url=comic_href,update=False)
|
||||
chapter_index = 1
|
||||
for chapter in chapters:
|
||||
Comic.setNumber(chapter_index)
|
||||
Comic.setChapter(chapter)
|
||||
cbz_path = ComicPath.getNewCBZComicChapter("file")
|
||||
icon_path = ComicPath.getNewIconComicChapter("file")
|
||||
CBZUtils.replaceZip(cbz_path)
|
||||
#判断漫画是否完成
|
||||
if ciUtils.isProgress(ciUtils.PROGRESS_DONE) and not os.path.exists(cbz_path): ciUtils.isProgress(ciUtils.PROGRESS_DONE,remove=True)
|
||||
if not os.path.exists(cbz_path):
|
||||
ciUtils.updateLastDate("0")
|
||||
Comic.setCurrentDownLink(comic_href)
|
||||
chapter_index = chapter_index + 1
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def oneComic(cls,url,title,author,icon,tags,dep,chapters,chapter_href,alias=None,genre=None,lang="zh",age_rating=None,sleep=None):
|
||||
ci.setComicInfo(homepage=url,comicname=title,author=author,icon=icon,tags=tags,dep=dep,genre=genre,lang=lang,age_rating=age_rating,chapters=chapters)
|
||||
cls.count_chapter = 0
|
||||
for href in chapter_href:
|
||||
Comic.setChapterName(chapters[cls.count_chapter])
|
||||
Comic.setNumber(cls.count_chapter+1)
|
||||
#存在完成配置文件 但文件不存在 将清空完成配置文件
|
||||
if ciUtils.isProgress(ciUtils.PROGRESS_DONE) and not fu.exists(ComicPath.getNewCBZComicChapter("file")):
|
||||
ciUtils.isProgress(ciUtils.PROGRESS_DONE,remove=True)
|
||||
#不存在完成配置文件 则允许下载
|
||||
if not ciUtils.isProgress(ciUtils.PROGRESS_DONE):
|
||||
cls.comicChapters(href,scramble=True,sleep=random.randint(1,5))
|
||||
cls.count_chapter += 1
|
||||
#一本漫画下载后等待
|
||||
#清空文件夹
|
||||
if os.path.exists(ComicPath.getDirComic()): shutil.rmtree(ComicPath.getDirComic())
|
||||
if sleep != None: time.sleep(sleep)
|
||||
#完成 更新最近一次时间
|
||||
ciUtils.updateLastDate()
|
||||
|
||||
'''
|
||||
|
||||
读取某章节下所有图片
|
||||
'''
|
||||
@classmethod
|
||||
def comicChapters(cls,chapter_url,scramble=None,sleep=None):
|
||||
is_next = False
|
||||
#try:
|
||||
cls.Onechapter(chapter_url,scramble)
|
||||
#进入下个阶段
|
||||
#章节图片全部下载后,调用下载封面
|
||||
if ciUtils.isProgress(ciUtils.PROGRESS_DOWN): downloadUtils.download_comic_icon()
|
||||
#下个阶段
|
||||
if ciUtils.isProgress(ciUtils.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(Comic.getLenChapters()))
|
||||
Comic.setNumber(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
|
||||
#下载图片
|
||||
is_next = cls.comicChapterDownload(chapter_url)
|
||||
ciUtils.nextInfoToImgChapter()
|
||||
#下载完成后, 开始解密图片
|
||||
chapter_dir = ComicPath.getDirComicChapter()
|
||||
if scramble and os.path.exists(chapter_dir): #获取章节图片路径
|
||||
dirs = os.listdir(chapter_dir)
|
||||
for img in dirs:
|
||||
if img.startswith("scramble="):
|
||||
imageUtils.encode_scramble_image(os.path.join(chapter_dir,img))
|
||||
#进入下一阶段
|
||||
ciUtils.nextImgToDownloadChapter()
|
||||
return is_next
|
||||
|
||||
@classmethod
|
||||
def comicChapterDownload(cls,url,is_next=True):
|
||||
#获取本次工程的HOME目录
|
||||
try:
|
||||
domains.setdomain(url)
|
||||
except:
|
||||
htmlUtils.remove_HtmlCache(url)
|
||||
cls.comicChapterDownload(url,is_next)
|
||||
|
||||
(list_img,files_name,chapter_name,book_name) = [Comic.chapter_imgs,Comic.file_chapter_imgs,
|
||||
Comic.chapter,Comic.comic_name]
|
||||
#保存信息
|
||||
ciUtils.nextSaveInfoChapter(chapter_name,list_img)
|
||||
#验证数据是已存在且是否完整
|
||||
cbz_file = ComicPath.getNewFileCBZComicChapter()
|
||||
#更新Icon
|
||||
ComicPath.getNewIconComicChapter()
|
||||
#检验CBZ文件
|
||||
CBZUtils.verCBZComic(cbz_file)
|
||||
is_next = CBZUtils.nextCBZ()
|
||||
is_old=CBZUtils.updateOldCBZ(files_name)
|
||||
#不存在ComicInfo.xml则生成
|
||||
if is_next and fu.notExists(ci.getPathComicInfoXML()): ci.writeComicInfoXML(chapter_name)
|
||||
if is_next:
|
||||
# ntfy.sendMsg(f"{book_name} {chapter_name} 下载中")
|
||||
downloadUtils.download_images(list_img,ComicPath.getDirComicChapter(),files_name=files_name,concurrency=None,timeout=8)
|
||||
# ntfy.sendMsg("等待数据检验中...",sleep=0.5)
|
||||
is_next = fu.equImages(ComicPath.getDirComicChapter(),list_img)
|
||||
# if not is_next: ntfy.sendMsg(msg=f"下载数据(不完整,{int(repeat*2)}秒钟后尝试第{repeat}次",sleep=int(repeat*2))
|
||||
# repeat += 1
|
||||
return is_next
|
||||
+206
@@ -0,0 +1,206 @@
|
||||
import json,re
|
||||
from opencc import OpenCC
|
||||
from queue import Queue
|
||||
from utils.OldUtils import OldUtils
|
||||
|
||||
class Comic:
|
||||
#章节名 漫画名 编号 概述 作者
|
||||
(chapter,comic_name,number,dep,author) = [None,None,None,None,None]
|
||||
#流派 语言 年龄分级 标签 总页数
|
||||
(genre,language,agerating,tags,page_count) = [None,None,None,None,None]
|
||||
#页数 出版社 年 月 日
|
||||
(pages,cbs,year,month,day) = [None,None,None,None,None]
|
||||
#主页 别名
|
||||
(homepage,comic_names) = [None,None]
|
||||
CURRENT_DOWN_LINK = None
|
||||
|
||||
#繁体中文转简体中文
|
||||
@classmethod
|
||||
def ChineseConvert(cls, text,convert='t2s'): return OpenCC(convert).convert(str(text))
|
||||
#处理成符合规定的文件名
|
||||
@classmethod
|
||||
def fixFileName(cls,filename,replace=None):
|
||||
if not isinstance(filename,str): return filename
|
||||
intab = r'[?*/\|.:><]'
|
||||
str_replace = ""
|
||||
if replace != None: str_replace = replace
|
||||
filename = re.sub(intab, str_replace, filename)
|
||||
count = 1
|
||||
while True:
|
||||
str_file = filename[0-count]
|
||||
if str_file == " ": count += 1
|
||||
else:
|
||||
filename = filename[0:len(filename)+1-count]
|
||||
break
|
||||
return filename
|
||||
|
||||
@classmethod
|
||||
def setValue(cls,value):
|
||||
if value != None: value = cls.ChineseConvert(value)
|
||||
return value
|
||||
@classmethod
|
||||
def getValue(cls,dict,exec=None):
|
||||
if exec != None: return cls.parseExec(dict,exec=exec)
|
||||
return dict
|
||||
@classmethod
|
||||
def getChapter(cls): return cls.chapter
|
||||
@classmethod
|
||||
def getComicName(cls): return cls.comic_name
|
||||
@classmethod
|
||||
def getNumber(cls): return cls.number
|
||||
#章节名
|
||||
@classmethod
|
||||
def setChapterName(cls,value,exec=None):
|
||||
value = cls.fixFileName(cls.parseExec(value,exec=exec))
|
||||
OldUtils.setOldChapter(value)
|
||||
cls.chapter = cls.setValue(value)
|
||||
@classmethod
|
||||
def getChapterName(cls): return cls.getValue(cls.chapter)
|
||||
|
||||
#漫画名
|
||||
@classmethod
|
||||
def setComicName(cls,value,exec=None):
|
||||
value = cls.fixFileName(cls.parseExec(value,exec=exec))
|
||||
OldUtils.setOldComicName(value)
|
||||
cls.comic_name = cls.setValue(value)
|
||||
@classmethod
|
||||
def getComicName(cls): return cls.getValue(cls.comic_name)
|
||||
#编号
|
||||
@classmethod
|
||||
def setNumber(cls,value): cls.number = cls.setValue(value)
|
||||
@classmethod
|
||||
def getNumber(cls): return cls.getValue(cls.number)
|
||||
#概述
|
||||
@classmethod
|
||||
def setDep(cls,value,exec=None):
|
||||
cls.dep = cls.setValue(cls.parseExec(value,exec=exec))
|
||||
@classmethod
|
||||
def getDep(cls): return cls.getValue(cls.dep)
|
||||
#作者
|
||||
@classmethod
|
||||
def setAuthor(cls,value): cls.author = cls.setValue(value)
|
||||
@classmethod
|
||||
def getAuthor(cls): return cls.getValue(cls.author)
|
||||
#流派
|
||||
@classmethod
|
||||
def setGenre(cls,value): cls.genre = cls.setValue(value)
|
||||
@classmethod
|
||||
def getGenre(cls): return cls.getValue(Comic.genre)
|
||||
#语言
|
||||
@classmethod
|
||||
def setLanguage(cls,value): cls.language = cls.setValue(value)
|
||||
@classmethod
|
||||
def getLanguage(cls): return cls.getValue(Comic.language)
|
||||
#年龄分级
|
||||
@classmethod
|
||||
def setAgeRating(cls,value): cls.agerating = cls.setValue(value)
|
||||
@classmethod
|
||||
def getAgeRating(cls): return cls.getValue(Comic.agerating)
|
||||
#标签
|
||||
@classmethod
|
||||
def setTags(cls,value): cls.tags = cls.setValue(value)
|
||||
@classmethod
|
||||
def getTags(cls): return cls.getValue(Comic.tags)
|
||||
#总页数
|
||||
@classmethod
|
||||
def setPageCount(cls,value): cls.page_count = cls.setValue(value)
|
||||
@classmethod
|
||||
def getPageCount(cls): return cls.getValue(Comic.page_count)
|
||||
#主页
|
||||
(homepage,icon,list_chapter,chapter_imgs,
|
||||
update_at,current_chapter_img,file_chapter_imgs) = [None,None,None,None,None,None,None]
|
||||
|
||||
@classmethod
|
||||
def parseExec(cls,data,exec,item=True):
|
||||
if data !=None and exec != None:
|
||||
dots = str(exec).split(".")
|
||||
if not isinstance(data,dict): data = json.loads(data)
|
||||
for dot in dots:
|
||||
data = data.get(dot)
|
||||
return data
|
||||
@classmethod
|
||||
def setHomePage(cls,value): cls.homepage = value
|
||||
@classmethod
|
||||
def getHomePage(cls): return cls.homepage
|
||||
@classmethod
|
||||
def setIcon(cls,value): cls.icon = value
|
||||
@classmethod
|
||||
def getIcon(cls): return cls.icon
|
||||
@classmethod
|
||||
def setListChapter(cls,value): cls.list_chapter = value
|
||||
@classmethod
|
||||
def getListChapter(cls): return cls.list_chapter
|
||||
@classmethod
|
||||
def getLenChapters(cls): return len(cls.list_chapter)
|
||||
@classmethod
|
||||
def setChapterImgs(cls,value,exec=None,item=None): cls.chapter_imgs = cls.parseExec(value,exec=exec,item=item)
|
||||
@classmethod
|
||||
def getChapterImgs(cls): return cls.chapter_imgs
|
||||
@classmethod
|
||||
def setUpdateAt(cls,value): cls.update_at = value
|
||||
@classmethod
|
||||
def getUpdateAt(cls): return cls.update_at
|
||||
@classmethod
|
||||
def setCurrentChapterImg(cls,value): cls.current_chapter_img = value
|
||||
@classmethod
|
||||
def getCurrentChapterImg(cls): return cls.current_chapter_img
|
||||
@classmethod
|
||||
def setChapterFilesName(cls,value): cls.file_chapter_imgs= value
|
||||
@classmethod
|
||||
def getChapterFilesName(cls): return cls.file_chapter_imgs
|
||||
@classmethod
|
||||
def setCurrentDownLink(cls,value): cls.CURRENT_DOWN_LINK = value
|
||||
@classmethod
|
||||
def getCurrentDownLink(cls): return cls.CURRENT_DOWN_LINK
|
||||
|
||||
class ListComic:
|
||||
LIST_COMIC_QUEUE = Queue()
|
||||
(LIST_COMIC_NAME,LIST_COMIC_LINK,LIST_COMIC_UPDATEAT) = [None,None,None]
|
||||
|
||||
@classmethod
|
||||
def setListComicsLinksUpdateAt(cls,names,links,update_at):
|
||||
if isinstance(names,list) and isinstance(links,list) and isinstance(update_at,list):
|
||||
for x in range(0,len(names)):
|
||||
cls.LIST_COMIC_QUEUE.put([names[x],links[x],update_at[x]])
|
||||
@classmethod
|
||||
def getListComicsLinksUpdateAt(cls):
|
||||
if cls.LIST_COMIC_NAME != None and cls.LIST_COMIC_LINK != None:
|
||||
cls.setListComicsLinksUpdateAt(cls.LIST_COMIC_NAME,cls.LIST_COMIC_LINK,cls.LIST_COMIC_UPDATEAT)
|
||||
(cls.LIST_COMIC_NAME,cls.LIST_COMIC_LINK,cls.LIST_COMIC_UPDATEAT) = [None,None,None]
|
||||
return cls.LIST_COMIC_QUEUE.get(False)
|
||||
|
||||
@classmethod
|
||||
def addListComicChapterLink(cls,name,link,update_at):
|
||||
if name != None and link != None:
|
||||
cls.LIST_COMIC_QUEUE.put(name,link,update_at)
|
||||
|
||||
@classmethod
|
||||
def getListValue(cls,result,type,start_add=None,result_type="list"):
|
||||
if result == None: return None
|
||||
if type == None: return result
|
||||
if result_type == "list" and type != None:
|
||||
data = []
|
||||
for x in range(0, len(result)):
|
||||
if start_add != None:
|
||||
data.append(start_add+result[x].get(type))
|
||||
else:
|
||||
data.append(result[x].get(type))
|
||||
return data
|
||||
return result
|
||||
|
||||
@classmethod
|
||||
def setListComicName(cls,value,type=None): cls.LIST_COMIC_NAME = cls.getListValue(value,type)
|
||||
@classmethod
|
||||
def getListComicName(cls): return cls.LIST_COMIC_NAME
|
||||
@classmethod
|
||||
def setListComicChapterLink(cls,value,type=None,start_add=None): cls.LIST_COMIC_LINK = cls.getListValue(value,type,start_add)
|
||||
@classmethod
|
||||
def getListComicChapterLink(cls): return cls.LIST_COMIC_LINK
|
||||
@classmethod
|
||||
def setListComicUpdateAt(cls,value,type=None): cls.LIST_COMIC_UPDATEAT = cls.getListValue(value,type)
|
||||
@classmethod
|
||||
def getListComicUpdateAt(cls): return cls.LIST_COMIC_UPDATEAT
|
||||
@classmethod
|
||||
def getListComicChapterLink(cls): return cls.LIST_COMIC_QUEUE.get(False)
|
||||
|
||||
#domain end....
|
||||
@@ -0,0 +1,254 @@
|
||||
import json,os
|
||||
from xml.dom.minidom import Document
|
||||
from common.Constant import pathStr
|
||||
from utils.FileUtils import dbUtils
|
||||
from utils.FileUtils import fileUtils
|
||||
from common.Comic import Comic
|
||||
from common.Constant import ComicPath
|
||||
|
||||
class ComicInfoEntity:
|
||||
#章节名 value node child
|
||||
@classmethod
|
||||
def getNodes(cls):
|
||||
#web [Comic.homepage,"Web"]
|
||||
nodes = []
|
||||
#章节名
|
||||
nodes.append([Comic.chapter,"Title"])
|
||||
#漫画名
|
||||
nodes.append([Comic.comic_name,"Series"])
|
||||
#编号
|
||||
nodes.append([Comic.number,"Number"])
|
||||
#别名
|
||||
nodes.append([Comic.comic_names,"SeriesGroup"])
|
||||
#概述
|
||||
nodes.append([Comic.dep,"Summary"])
|
||||
#年
|
||||
nodes.append([Comic.year,"Year"])
|
||||
#月
|
||||
nodes.append([Comic.month,"Month"])
|
||||
#日
|
||||
nodes.append([Comic.day,"Day"])
|
||||
#作者
|
||||
nodes.append([Comic.author,"Writer"])
|
||||
#出版社
|
||||
nodes.append([Comic.cbs,"Publisher"])
|
||||
#流派
|
||||
nodes.append([Comic.genre,"Genre"])
|
||||
#标签
|
||||
nodes.append([Comic.tags,"Tags"])
|
||||
#主页
|
||||
#nodes.append([Comic.homepage,"Web"])
|
||||
#总页数
|
||||
nodes.append([Comic.page_count,"PageCount"])
|
||||
#语言
|
||||
nodes.append([Comic.language,"LanguageISO"])
|
||||
#年龄分级
|
||||
nodes.append([Comic.agerating,"AgeRating"])
|
||||
#页码
|
||||
nodes.append([Comic.pages,"Pages"])
|
||||
return nodes
|
||||
|
||||
class ComicInfo:
|
||||
COMIC_ICON_NAME = "000"
|
||||
COMIC_INFO_XML = "ComicInfo.xml"
|
||||
IS_NEW_ICON = False
|
||||
document = Document()
|
||||
path_comic_info = None
|
||||
|
||||
@classmethod
|
||||
def parseExec(cls,data,exec,start_add=None,item=True):
|
||||
if data !=None and exec != None:
|
||||
dots = str(exec).split(".")
|
||||
if not isinstance(data,dict): data = json.loads(data)
|
||||
for dot in dots:
|
||||
data = data.get(dot)
|
||||
if start_add != None and data != None:
|
||||
data = start_add+data
|
||||
return data
|
||||
|
||||
@classmethod
|
||||
def setNodeAndValue(cls,node,value):
|
||||
if value != None:
|
||||
if isinstance(value,str):
|
||||
c_node = cls.document.createElement(node)
|
||||
child_node = cls.document.createTextNode(value)
|
||||
c_node.appendChild(child_node)
|
||||
return c_node
|
||||
else: return value
|
||||
return None
|
||||
|
||||
#页数
|
||||
@classmethod
|
||||
def setPages(cls,values):
|
||||
if values != None and isinstance(values,list):
|
||||
suffix = "."+str(values[0]).split(".")[-1]
|
||||
join_list=",".join(values).replace(suffix,"")
|
||||
values = join_list.split(",")
|
||||
Comic.setPageCount(len(values)+1 if cls.IS_NEW_ICON else len(values))
|
||||
root_node = cls.document.createElement("Pages")
|
||||
if cls.IS_NEW_ICON:
|
||||
#添加封面
|
||||
icon_node = cls.document.createElement("Page")
|
||||
icon_node.setAttribute("Image",cls.COMIC_ICON_NAME)
|
||||
icon_node.setAttribute("Type","FrontCover")
|
||||
root_node.appendChild(icon_node)
|
||||
for page in values:
|
||||
c_node = cls.document.createElement("Page")
|
||||
page = page.split("_")[-1]
|
||||
c_node.setAttribute("Image",page)
|
||||
root_node.appendChild(c_node)
|
||||
Comic.pages = root_node
|
||||
|
||||
@classmethod
|
||||
def getBaseUrl(cls,url=None):
|
||||
if url == None:
|
||||
url = Comic.homepage
|
||||
(num,index) = [3,0]
|
||||
for x in range(0, num):
|
||||
index = str(url).find("/",index)+1
|
||||
return url[0:index-1]
|
||||
|
||||
@classmethod
|
||||
def getPathComicInfoXML(cls):
|
||||
try:
|
||||
cls.path_comic_info = os.path.join(pathStr.base_comic_img(),
|
||||
Comic.comic_name,Comic.chapter, cls.COMIC_INFO_XML)
|
||||
except:
|
||||
return None
|
||||
return cls.path_comic_info
|
||||
|
||||
#XML根文档
|
||||
@classmethod
|
||||
def root_node(cls,root_value): return cls.document.createElement(root_value)
|
||||
|
||||
@classmethod
|
||||
def add_nodes(cls,root,list_value):
|
||||
if len(list_value) == 0: return list_value
|
||||
for value in list_value:
|
||||
#Comic.chapter
|
||||
if value[0] != None: root.appendChild(cls.setNodeAndValue(value[1],value[0]))
|
||||
|
||||
@classmethod
|
||||
def writeComicInfoXML(cls,chapter=None,path=None,overlay=False):
|
||||
root = cls.root_node("ComicInfo")
|
||||
new_document = Document()
|
||||
new_document.appendChild(root)
|
||||
cls.add_nodes(root,ComicInfoEntity.getNodes())
|
||||
cls.getPathComicInfoXML()
|
||||
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) and not overlay:
|
||||
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(f"{cls.COMIC_INFO_XML} 已生成 pathd=", cls.path_comic_info)
|
||||
|
||||
@classmethod
|
||||
def setComicInfo(cls,comicname=None,homepage=None,alias=None,author=None,icon=None,tags=None,
|
||||
dep=None,genre=None,lang=None,age_rating=None,chapters=None,update_at=None,current_chapter_img=None):
|
||||
author = ",".join(set(str(str(author).replace("&",",").replace(" ",",")).split(",")))
|
||||
Comic.setHomePage(homepage)
|
||||
Comic.setIcon(icon)
|
||||
Comic.setListChapter(chapters)
|
||||
Comic.setUpdateAt(update_at)
|
||||
Comic.setComicName(str(comicname))
|
||||
#if alias != None: comicInfo.setComicNames(alias)
|
||||
Comic.setAuthor(author)
|
||||
Comic.setTags(tags)
|
||||
Comic.setDep(dep)
|
||||
#comicInfo.setCBS("韩漫")
|
||||
if genre != None: Comic.setGenre(genre)
|
||||
Comic.setLanguage(lang)
|
||||
Comic.setAgeRating(age_rating)
|
||||
Comic.setCurrentChapterImg(current_chapter_img)
|
||||
|
||||
|
||||
class ComicInfoUtils:
|
||||
PROGRESS_INFO = "info"
|
||||
PROGRESS_DOWN = "download"
|
||||
PROGRESS_IMG = "download"
|
||||
PROGRESS_CBZ = "cbz"
|
||||
PROGRESS_DONE = "done"
|
||||
PROGRESS_NONE = "none"
|
||||
IS_NEW_ICON = False
|
||||
list_skip = []
|
||||
|
||||
|
||||
@classmethod
|
||||
def getListToString(cls,to_list):
|
||||
value = to_list
|
||||
if isinstance(to_list,list):
|
||||
value = ",".join(to_list)
|
||||
return value
|
||||
@classmethod
|
||||
def setComicNameSkips(cls,value): return cls.list_skip.append(value)
|
||||
@classmethod
|
||||
def getIsComicNameSkips(cls,value): return value in ",".join(cls.list_skip)
|
||||
@classmethod
|
||||
def nextSavePath(cls,next,data=None):
|
||||
save_path = ComicPath.getDirConfComic()+"/"+next+Comic.getChapterName()
|
||||
if data != None: fileUtils.file_save(save_path, data)
|
||||
return save_path
|
||||
|
||||
@classmethod
|
||||
def nextSaveInfoChapter(cls,chapter,data=None):
|
||||
if data == None: data = Comic.getChapterImgs()
|
||||
if Comic.getChapterName() != chapter:
|
||||
print(f"chapter {Comic.getChapterName()} 与 {chapter} 不一致,已自动跳过")
|
||||
cls.setProgress(cls.PROGRESS_INFO)
|
||||
cls.nextSavePath("info_",data)
|
||||
|
||||
@classmethod
|
||||
def nextInfoToImgChapter(cls): cls.setProgress(cls.PROGRESS_IMG)
|
||||
@classmethod
|
||||
def nextImgToDownloadChapter(cls): cls.setProgress(cls.PROGRESS_DOWN)
|
||||
@classmethod
|
||||
def nextDownloadToCBZChapter(cls): cls.setProgress(cls.PROGRESS_CBZ)
|
||||
@classmethod
|
||||
def nextCBZToDoneChapter(cls): cls.setProgress(cls.PROGRESS_DONE)
|
||||
@classmethod
|
||||
def nextDoneSave(cls,data): cls.nextSavePath("done_",data)
|
||||
@classmethod
|
||||
def setProgress(cls,progress):
|
||||
dbUtils.setComic(Comic.getChapterName(),progress,Comic.getComicName())
|
||||
|
||||
@classmethod
|
||||
def isProgress(cls,progress,remove=None):
|
||||
if remove: cls.setProgress("None")
|
||||
return dbUtils.query(Comic.getChapter(),progress,Comic.getComicName())
|
||||
|
||||
@classmethod
|
||||
def iconDB(cls): dbUtils.setComic(Comic.getComicName(),Comic.getIcon(),"icons")
|
||||
|
||||
@classmethod
|
||||
def equIcon(cls): return dbUtils.query(Comic.getComicName(),Comic.getIcon(),"icons")
|
||||
|
||||
@classmethod
|
||||
def setConfDirComicPath(cls,file_name,comic_name=None):
|
||||
if comic_name != None: Comic.setComicName(comic_name)
|
||||
return os.path.join(ComicPath.getDirConfComic(),file_name)
|
||||
|
||||
@classmethod
|
||||
def saveConfComicData(cls,file_name,data,comic_name=None): fileUtils.file_save(cls.setConfDirComicPath(file_name,comic_name), data)
|
||||
@classmethod
|
||||
def getPathInitConfComicData(cls,file_name,comic_name=None): return cls.setConfDirComicPath(file_name,comic_name)
|
||||
|
||||
@classmethod
|
||||
def updateLastDate(cls,date=None):
|
||||
update_at = Comic.getUpdateAt()
|
||||
if date != None: update_at = date
|
||||
dbUtils.setComic(Comic.getComicName(), update_at, "update")
|
||||
|
||||
@classmethod
|
||||
def isUpdateComic(cls):
|
||||
return dbUtils.query(Comic.getComicName(), Comic.getUpdateAt(),"update")
|
||||
|
||||
@classmethod
|
||||
def comicChapterDownload(cls,imgs,names):
|
||||
Comic.setChapterImgs(imgs)
|
||||
#Comic.setChapterListImg(imgs)
|
||||
ComicInfo.setPages(names)
|
||||
Comic.setChapterFilesName(names)
|
||||
@@ -0,0 +1,133 @@
|
||||
import os,datetime,shutil
|
||||
from time import strftime
|
||||
from common.Comic import Comic
|
||||
|
||||
class pathStr:
|
||||
comic_name = None
|
||||
comic_jm="JM"
|
||||
comic_bz="BZ"
|
||||
comic_rm="RM"
|
||||
|
||||
comic_url_main = None
|
||||
base_comic_out = os.path.join("/mnt", "Comics")
|
||||
old_cbz_path = os.path.join("/mnt","OldComics")
|
||||
@classmethod
|
||||
def base_cbz(cls): return cls.getBaseComicPath("CBZ")
|
||||
@classmethod
|
||||
def base_comic_img(cls): return cls.getBaseComicPath("outputComic")
|
||||
@classmethod
|
||||
def base_conf_path(cls): return cls.getBaseComicPath(".conf")
|
||||
@classmethod
|
||||
def base_html_cache(cls): return cls.getBaseComicPath("html_cache")
|
||||
@classmethod
|
||||
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 getBaseUrl(cls,url=None):
|
||||
if url == None:
|
||||
url = Comic.homepage
|
||||
num = 3
|
||||
index = 0
|
||||
for x in range(0, num):
|
||||
index = str(url).find("/",index)+1
|
||||
return url[0:index-1]
|
||||
@classmethod
|
||||
def getBaseComicPath(cls,join_path): return os.path.join(cls.base_comic_out,join_path)
|
||||
|
||||
@classmethod
|
||||
def setComicMainAndPath(cls,value):
|
||||
cls.setComicMain(value)
|
||||
cls.setComicMainPath(value)
|
||||
|
||||
@classmethod
|
||||
def setComicMain(cls,value): cls.comic_name = value
|
||||
|
||||
@classmethod
|
||||
def getComicMain(cls): return cls.comic_name
|
||||
|
||||
@classmethod
|
||||
def setComicMainPath(cls,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):
|
||||
date_path = cls.getDatePath()
|
||||
return os.path.join(cls.base_comic_out,"html_"+str(date_path))
|
||||
|
||||
@classmethod
|
||||
def getDatePath(cls):
|
||||
date = datetime.datetime.now()
|
||||
year = int(date.strftime("%Y"))
|
||||
month = int(date.strftime("%m"))
|
||||
day = int(date.strftime("%d"))
|
||||
week = cls.get_week_of_month(year, month, day)
|
||||
return f"{year}{month}{week}"
|
||||
|
||||
@classmethod
|
||||
def get_week_of_month(cls, year, month, day):
|
||||
begin = int(datetime.date(year, month, 1).strftime("%W"))
|
||||
end = int(datetime.date(year, month, day).strftime("%W"))
|
||||
week = "{:0>2d}".format(end - begin + 1)
|
||||
return week
|
||||
|
||||
class ComicPath:
|
||||
#顶级路径
|
||||
@classmethod
|
||||
def setJoinPathDir(cls,path,dir="",prefix=None):
|
||||
result = dir
|
||||
if isinstance(path,dict) or isinstance(path,list):
|
||||
for x in path:
|
||||
result = os.path.join(result,x)
|
||||
else: result = os.path.join(result,path)
|
||||
if prefix != None: result += "."+prefix
|
||||
return result
|
||||
|
||||
@classmethod
|
||||
def setDirConf(cls,path,prefix=None): return cls.setJoinPathDir(path,pathStr.base_conf_path(),prefix=prefix)
|
||||
@classmethod
|
||||
def setDirCBZ(cls,path,prefix=None): return cls.setJoinPathDir(path,pathStr.base_cbz(),prefix=prefix)
|
||||
@classmethod
|
||||
def setDirImg(cls,path,prefix=None): return cls.setJoinPathDir(path,pathStr.base_comic_img(),prefix=prefix)
|
||||
#漫画配置文件路径
|
||||
@classmethod
|
||||
def getDirConfComic(cls): return cls.setDirConf(Comic.comic_name)
|
||||
#漫画CBZ路径
|
||||
@classmethod
|
||||
def getDirCBZComic(cls): return cls.setDirCBZ(Comic.comic_name)
|
||||
#漫画章节CBZ路径
|
||||
@classmethod
|
||||
def getDirCBZComicChapter(cls): return cls.setDirCBZ([Comic.comic_name,Comic.chapter])
|
||||
#排序
|
||||
@classmethod
|
||||
def getSortDirCBZComicChapter(cls): return cls.setDirCBZ([Comic.comic_name],str(Comic.number)+" "+Comic.chapter)
|
||||
@classmethod
|
||||
def getNewCBZComicChapter(cls,type="dir"): return cls.getNewToComicChapter(".CBZ", type)
|
||||
@classmethod
|
||||
def getNewIconComicChapter(cls,type="dir"): return cls.getNewToComicChapter(".jpg", type)
|
||||
@classmethod
|
||||
def getNewFileCBZComicChapter(cls,type="file"): return cls.getNewToComicChapter(".CBZ", type)
|
||||
@classmethod
|
||||
def getNewFileIconComicChapter(cls,type="file"): return cls.getNewToComicChapter(".jpg", type)
|
||||
|
||||
@classmethod
|
||||
def getNewToComicChapter(cls,su,type="dir"):
|
||||
c_dir = cls.getDirCBZComicChapter()
|
||||
s_dir = cls.getSortDirCBZComicChapter()
|
||||
c_path = cls.getDirCBZComicChapter()+su
|
||||
s_path = cls.getSortDirCBZComicChapter()+su
|
||||
if os.path.exists(s_path) and s_path != None:
|
||||
shutil.move(s_path, c_path)
|
||||
print("文件已移动至:", c_path)
|
||||
if type == "file":
|
||||
return c_path
|
||||
return c_dir
|
||||
|
||||
@classmethod
|
||||
def getDirComic(cls): return cls.setDirImg(Comic.comic_name)
|
||||
|
||||
@classmethod
|
||||
def getDirComicChapter(cls): return cls.setJoinPathDir(Comic.chapter,cls.getDirComic())
|
||||
Reference in New Issue
Block a user