133 lines
4.8 KiB
Python
133 lines
4.8 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.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()) |