This commit is contained in:
cwx committed 2022-12-06 10:16:29 +08:00
1 parent 499cb29fa3
commit a8148ac383
11 files changed
+606 -178

No files matched your search

+270 -17
View File
@@ -1,37 +1,290 @@
from xml.dom.minidom import Document
import os,re
from utils.comic.PathStr import pathStr
import json,shutil
document = Document()
class comicInfoXmlNode():
class comicInfo():
document = Document()
pathComicInfo = None
root = "ComicInfo"
chapter = "Title"
comic_name = "Series"
dep = "Summary"
author = "Writer"
tags = "Genre"
tag = "Genre"
cbs = "Publisher"
lang = "LanguageISO"
comic_names = "SeriesGroup"
tags = "Tag"
str_comicName = None
str_chapter = None
str_icon = None
str_homePage = None
chapter_node = None
comicName_node = None
dep_node = None
author_node = None
tag_node = None
cbs_node = None
lang_node = None
comicNames_node = None
tags_node = None
@classmethod
def setNodeAndValue(cls,node,value):
node = document.createElement(node)
node_text = document.createTextNode(value)
node.appendChild(node_text)
if not value == None:
c_node = cls.document.createElement(node)
node_text = cls.document.createTextNode(value)
c_node.appendChild(node_text)
return c_node
return None
@classmethod
def Root(cls):
return cls.document.createElement(cls.root)
@classmethod
def setChapter(cls,value):
cls.setNodeAndValue(cls.chapter,value)
def setChapterName(cls,value):
cls.str_chapter = cls.fixFileName(value)
cls.chapter_node = cls.setNodeAndValue(cls.chapter,value)
@classmethod
def setComicName(cls,value):
cls.setNodeAndValue(cls.comic_name, value)
cls.str_comicName = cls.fixFileName(value)
cls.comicName_node = cls.setNodeAndValue(cls.comic_name, value)
@classmethod
def getComicInfoXML(cls):
cls.setChapter()
class comicInfo():
def setComicNames(cls,value):
cls.comicNames_node = cls.setNodeAndValue(cls.comic_names,value)
#输出xml
@classmethod
def writeComicInfoXML(cls,c_title,chapter,dep,author,tags="韩漫",c_publisher="韩漫",language="zh"):
#file 预期 CBZ/"comic_name"/chapter
print()
@classmethod
def setDep(cls,value):
cls.dep_node = cls.setNodeAndValue(cls.dep, value)
@classmethod
def setAuthor(cls,value):
cls.author_node = cls.setNodeAndValue(cls.author,value)
@classmethod
def setLang(cls,value):
cls.lang_node = cls.setNodeAndValue(cls.lang, value)
@classmethod
def setTag(cls,value):
cls.tag_node = cls.setNodeAndValue(cls.tag, value)
@classmethod
def setTags(cls,value):
cls.tags_node = cls.setNodeAndValue(cls.tags,value)
@classmethod
def setCBS(cls,value):
cls.cbs_node = cls.setNodeAndValue(cls.cbs,value)
@classmethod
def setIcon(cls,value):
cls.str_icon = value
return cls.str_icon
@classmethod
def setHomePage(cls, value):
cls.str_homePage = value
@classmethod
def getHomePage(cls):
return cls.str_homePage
'''
获取网站主页
'''
@classmethod
def getBaseUrl(cls,url=None):
if url == None:
url = cls.str_homePage
num = 3
index = 0
for x in range(0, num):
index = str(url).find("/",index)+1
return url[0:index-1]
@classmethod
def getIcon(cls):
return cls.str_icon
@classmethod
def getComicName(cls):
return cls.str_comicName
@classmethod
def getChapter(cls):
return cls.str_chapter
@classmethod
def fixFileName(cls,filename,replace=None):
intab = r'[?*/\|.:><]'
str_replace = ""
if not replace == None:
str_replace = replace
filename = re.sub(intab, str_replace, filename)
return filename
@classmethod
def getDirConfComic(cls):
if not cls.str_comicName == None:
return os.path.join(pathStr.base_conf_path, cls.str_comicName)
else:
print("comicName不存在,退出中")
exit()
@classmethod
def getDirCBZComic(cls):
if not cls.str_comicName == None:
return os.path.join(pathStr.base_CBZ, cls.str_comicName)
else:
print("comicName不存在,退出中")
exit()
@classmethod
def getDirCBZComicChapter(cls):
if not cls.str_comicName == None and not cls.str_chapter == None:
return os.path.join(pathStr.base_CBZ,cls.str_comicName,cls.str_chapter)
else:
print("comicName不存在,退出中")
exit()
@classmethod
def getDirComic(cls):
if not cls.str_comicName == None:
return os.path.join(pathStr.base_comic_img, cls.str_comicName)
else:
print("comicName不存在,退出中")
exit()
@classmethod
def getDirComicChapter(cls):
if not cls.str_comicName == None and not cls.str_chapter == None:
return os.path.join(pathStr.base_comic_img,cls.str_comicName,cls.str_chapter)
else:
print("comicName与chapter 不存在,退出中")
exit()
@classmethod
def getPathComicInfoXML(cls):
try:
cls.pathComicInfo = os.path.join(pathStr.base_comic_img,cls.str_comicName,cls.str_chapter,"ComicInfo.xml")
except:
return None
return cls.pathComicInfo
@classmethod
def writeComicInfoXML(cls,chapter):
if cls.chapter == cls.fixFileName(chapter):
wait = input(f"cls.chapter {cls.chapter} 与 chapter {chapter} 不相等,是否继续y/n ")
if wait == "y":
print("继续中...")
else:
print("用户操作取消...")
exit()
root = cls.Root()
newDocument = Document()
newDocument.appendChild(root)
if not cls.chapter_node == None:
root.appendChild(cls.chapter_node)
if not cls.comicName_node == None:
root.appendChild(cls.comicName_node)
if not cls.dep_node == None:
root.appendChild(cls.dep_node)
if not cls.author_node == None:
root.appendChild(cls.author_node)
if not cls.tag_node == None:
root.appendChild(cls.tag_node)
if not cls.cbs_node == None:
root.appendChild(cls.cbs_node)
if not cls.lang_node == None:
root.appendChild(cls.lang_node)
if not cls.comicNames_node == None:
root.appendChild(cls.comicNames_node)
if not cls.tags_node == None:
root.appendChild(cls.tags_node)
cls.getPathComicInfoXML()
base_dir = os.path.dirname(cls.pathComicInfo)
if not os.path.exists(base_dir):
os.makedirs(base_dir)
with open(cls.pathComicInfo , "w", encoding="utf-8") as fo:
newDocument.writexml(fo, indent='', addindent='\t', newl='\n', encoding="utf-8")
fo.close()
print("ComicInfo.xml 已生成 pathd=", cls.pathComicInfo)
#文件保存
@classmethod
def file_save(cls,path,data,mode=None):
result = {}
f = {}
dir_name = os.path.dirname(path)
if not os.path.exists(dir_name):
os.makedirs(dir_name)
save_path = os.path.join(path)
data = json.dumps(data)
if mode == None:
mode = "w+"
try:
f = open(save_path, mode, encoding="utf-8")
f.write(data)
f.close()
print("data=",data)
result = path + "文件写入成功"
except:
result = path + "文件写入失败"
return result
@classmethod
def nextSavePath(cls,next,data=None):
save_path = cls.getDirConfComic()+"/"+next+cls.str_chapter
if not data == None:
cls.file_save(save_path, data)
return save_path
@classmethod
def nextSaveInfoChapter(cls,chapter,data):
if cls.str_chapter == chapter:
cls.nextSavePath("info_",data)
else:
wait = input(f"chapter {cls.str_chapter} 与 {chapter} 不一致,是否继续 y/n")
if wait == "y":
print("继续中")
else:
exit()
@classmethod
def nextInfoToImgChapter(cls):
info = cls.nextSavePath("info_")
img = cls.nextSavePath("img_")
shutil.move(info,img)
@classmethod
def nextImgToDownloadChapter(cls):
img = cls.nextSavePath("img_")
download = cls.nextSavePath("down_")
shutil.move(img, download)
@classmethod
def nextDownloadToCBZChapter(cls):
download = cls.nextSavePath("down_")
cbz = cls.nextSavePath("cbz_")
shutil.move(download, cbz)
@classmethod
def nextCBZToDoneChapter(cls):
cbz = cls.nextSavePath("cbz_")
done = cls.nextSavePath("done_")
shutil.move(cbz,done)
@classmethod
def nextExistsGetPath(cls,msg):
path = cls.nextSavePath(msg)
return os.path.exists(path)
+2 -1
View File
@@ -3,4 +3,5 @@ import os
class pathStr:
base_comic_out = "COMICOUT"
base_CBZ = os.path.join(base_comic_out,"CBZ")
base_comic_img = os.path.join(base_comic_out,"outputComic")
base_comic_img = os.path.join(base_comic_out,"outputComic")
base_conf_path = ".conf"