156 lines
6.1 KiB
Python
156 lines
6.1 KiB
Python
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.getHomePage()
|
|
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:
|
|
DEFAULT_PATH = "default"
|
|
PROGRESS_PATH = "progress"
|
|
ICONS_PATH = "icons"
|
|
COMIC_INFO_XML = "ComicInfo.xml"
|
|
|
|
#顶级路径
|
|
@classmethod
|
|
def setJoinPathDir(cls,path,dir="",prefix=None,mkdir=False):
|
|
result = dir
|
|
if isinstance(path,dict) or isinstance(path,list):
|
|
for x in path:
|
|
if x != None: result = os.path.join(result,x)
|
|
else: result = os.path.join(result,path)
|
|
if mkdir:
|
|
base_dir = os.path.dirname(result)
|
|
if not os.path.exists(base_dir):
|
|
os.makedirs(base_dir)
|
|
print(f"新路径 {result} mkdir={mkdir}")
|
|
if prefix != None: result += "."+prefix
|
|
return result
|
|
|
|
@classmethod
|
|
def setDirConf(cls,path,prefix=None,mkdir=False): return cls.setJoinPathDir(path,pathStr.base_conf_path(),prefix=prefix,mkdir=mkdir)
|
|
@classmethod
|
|
def setDirCBZ(cls,path,prefix=None,mkdir=False): return cls.setJoinPathDir(path,pathStr.base_cbz(),prefix=prefix,mkdir=mkdir)
|
|
@classmethod
|
|
def setDirImg(cls,path,prefix=None,mkdir=False): return cls.setJoinPathDir(path,pathStr.base_comic_img(),prefix=prefix,mkdir=mkdir)
|
|
#漫画配置文件路径
|
|
@classmethod
|
|
def getDirConfComic(cls): return cls.setDirConf(Comic.getOriginComicName())
|
|
#章节配置json文件路径
|
|
@classmethod
|
|
def getPathConfComicChapterJson(cls,mkdir=True): return cls.setDirConf([Comic.getOriginComicName(),Comic.getOriginChapterName()],prefix="json",mkdir=mkdir)
|
|
#Icons json文件路径
|
|
@classmethod
|
|
def getDirConfDefault(cls,path=None,prefix=None,mkdir=True): return cls.setDirConf([cls.DEFAULT_PATH,path],prefix=prefix,mkdir=mkdir)
|
|
#漫画进度文件
|
|
@classmethod
|
|
def getPathProgressJson(cls,mkdir=True): return cls.setDirConf([cls.PROGRESS_PATH,Comic.getOriginComicName()],prefix="json",mkdir=mkdir)
|
|
#漫画CBZ路径
|
|
@classmethod
|
|
def getDirCBZComic(cls): return cls.setDirCBZ(Comic.getComicName())
|
|
#漫画章节CBZ路径
|
|
@classmethod
|
|
def getDirCBZComicChapter(cls): return cls.setDirCBZ([Comic.getComicName(),Comic.getChapterName()])
|
|
#排序
|
|
@classmethod
|
|
def getSortDirCBZComicChapter(cls): return cls.setDirCBZ([Comic.getComicName()],str(Comic.getNumber())+" "+Comic.getChapterName())
|
|
@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.getComicName())
|
|
|
|
@classmethod
|
|
def getDirComicChapter(cls): return cls.setJoinPathDir(Comic.getChapterName(),cls.getDirComic())
|
|
|
|
@classmethod
|
|
def getPathComicInfoXML(cls,mkdir=True): return cls.setDirImg([Comic.getComicName(),Comic.getChapterName()
|
|
,cls.COMIC_INFO_XML],mkdir=mkdir) |