diff --git a/common/Constant.py b/common/Constant.py index fcd4a5c..a36cce4 100644 --- a/common/Constant.py +++ b/common/Constant.py @@ -82,7 +82,7 @@ class ComicPath: #顶级路径 @classmethod - def setJoinPathDir(cls,path,dir="",prefix=None,mkdir=False): + def setJoinPathDir(cls,path,dir="",suffix=None,mkdir=False): result = dir if isinstance(path,dict) or isinstance(path,list): for x in path: @@ -93,33 +93,38 @@ class ComicPath: if not os.path.exists(base_dir): os.makedirs(base_dir) print(f"新路径 {result} mkdir={mkdir}") - if prefix != None: result += "."+prefix + if suffix != None: result += "."+suffix return result @classmethod - def setDirConf(cls,path,prefix=None,mkdir=False): return cls.setJoinPathDir(path,pathStr.base_conf_path(),prefix=prefix,mkdir=mkdir) + def setDirConf(cls,path,suffix=None,mkdir=False): return cls.setJoinPathDir(path,pathStr.base_conf_path(),suffix=suffix,mkdir=mkdir) @classmethod - def setDirCBZ(cls,path,prefix=None,mkdir=False): return cls.setJoinPathDir(path,pathStr.base_cbz(),prefix=prefix,mkdir=mkdir) + def setDirCBZ(cls,path,suffix=None,mkdir=False): return cls.setJoinPathDir(path,pathStr.base_cbz(),suffix=suffix,mkdir=mkdir) @classmethod - def setDirImg(cls,path,prefix=None,mkdir=False): return cls.setJoinPathDir(path,pathStr.base_comic_img(),prefix=prefix,mkdir=mkdir) + def setDirImg(cls,path,suffix=None,mkdir=False): return cls.setJoinPathDir(path,pathStr.base_comic_img(),suffix=suffix,mkdir=mkdir) + @classmethod + def setDirOld(cls,path,suffix=None,mkdir=False): return cls.setJoinPathDir(path,pathStr.old_cbz_path,suffix=suffix,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) + def getPathConfComicChapterJson(cls,mkdir=True): return cls.setDirConf([Comic.getOriginComicName(),Comic.getOriginChapterName()],suffix="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) + def getDirConfDefault(cls,path=None,suffix=None,mkdir=True): return cls.setDirConf([cls.DEFAULT_PATH,path],suffix=suffix,mkdir=mkdir) #漫画进度文件 @classmethod - def getPathProgressJson(cls,mkdir=True): return cls.setDirConf([cls.PROGRESS_PATH,Comic.getOriginComicName()],prefix="json",mkdir=mkdir) + def getPathProgressJson(cls,mkdir=True): return cls.setDirConf([cls.PROGRESS_PATH,Comic.getOriginComicName()],suffix="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()]) + #旧版本漫画章节CBZ路径 + @classmethod + def getPathOldCBZComicChapter(cls): return cls.setDirOld([Comic.getOriginComicName(),Comic.getOriginChapterName()],suffix="CBZ") #排序 @classmethod def getSortDirCBZComicChapter(cls): return cls.setDirCBZ([Comic.getComicName()],str(Comic.getNumber())+" "+Comic.getChapterName()) diff --git a/domain/down/RouMan.py b/domain/down/RouMan.py index 2864401..b4aa97b 100644 --- a/domain/down/RouMan.py +++ b/domain/down/RouMan.py @@ -34,11 +34,11 @@ class DomainDown: (image_src,scramble) = [image.get("src"),image.get("scramble")] count_image = "{:0>3d}".format(count) list_img.append(image_src) - image_src_prefix = "."+str(image_src).split(".")[-1] + image_src_suffix = "."+str(image_src).split(".")[-1] if scramble: - de_str = str(image_src).split("/")[-1].replace(image_src_prefix,"==") + de_str = str(image_src).split("/")[-1].replace(image_src_suffix,"==") blocks_num = imageUtils.encodeImage(de_str) count_image = "scramble="+str(blocks_num)+"_"+count_image - list_file_name.append(count_image+image_src_prefix) + list_file_name.append(count_image+image_src_suffix) count+=1 ciUtils.comicChapterDownload(list_img,list_file_name) \ No newline at end of file diff --git a/utils/ComicUtils.py b/utils/ComicUtils.py index 5ec07dc..118175f 100644 --- a/utils/ComicUtils.py +++ b/utils/ComicUtils.py @@ -156,8 +156,8 @@ class CBZUtils: @classmethod def updateOldCBZ(cls,filesname,result=False): - old_zipfile_path = ComicPath.setJoinPathDir([OldUtils.getOldComicName(),OldUtils.getOldChapter()], - pathStr.old_cbz_path,prefix="CBZ") + old_zipfile_path = ComicPath.getPathOldCBZComicChapter() + #判断是否存在已下载CBZ文件 if fu.exists(old_zipfile_path) and fu.notExists(CBZUtils.getCBZ_Path()): print(f"存在CBZ文件{old_zipfile_path},解压中...") diff --git a/utils/FileUtils.py b/utils/FileUtils.py index 4cc692a..98e3967 100644 --- a/utils/FileUtils.py +++ b/utils/FileUtils.py @@ -55,7 +55,7 @@ class imageUtils: block_height = int(height / blocks) block_width = int(width / blocks) print("blockHeight=",block_height) - prefix = str(file_path).split(".")[-1] + suffix = str(file_path).split(".")[-1] split_path = os.path.join(base_dir,save_name_delesu+"split") if image_su == "downloads": return None @@ -242,7 +242,7 @@ class fileUtils: return False @classmethod - def dirFilesName(cls,path,type="file",prefix=None): + def dirFilesName(cls,path,type="file",suffix=None): result = [] if cls.exists(path): for file_or_dir in os.listdir(path): @@ -251,11 +251,11 @@ class fileUtils: return result @classmethod - def equImages(cls,dir,files,prefix=".jpg"): + def equImages(cls,dir,files,suffix=".jpg"): len_count = 0 file_names = cls.dirFilesName(dir,"file") for file in file_names: - if str(file).endswith(prefix): len_count += 1 + if str(file).endswith(suffix): len_count += 1 return len_count == len(files) @classmethod @@ -304,7 +304,7 @@ class fileUtils: class dbUtils: @classmethod def init_db(cls,db_name): - return TinyDB(ComicPath.getDirConfDefault(db_name,prefix="json")) + return TinyDB(ComicPath.getDirConfDefault(db_name,suffix="json")) @classmethod def set(cls,name,progress,db_name): diff --git a/utils/NetUtils.py b/utils/NetUtils.py index 6b8c10c..51e2f0d 100644 --- a/utils/NetUtils.py +++ b/utils/NetUtils.py @@ -223,7 +223,7 @@ class downloadUtils: :param proxy_type: :param image_urls: list of image urls :param dst_dir: output the downloaded images to dst_dir - :param file_prefix: if set to "img", files will be in format "img_xxx.jpg" + :param file_suffix: if set to "img", files will be in format "img_xxx.jpg" :param concurrency: number of requests process simultaneously :return: none """ @@ -249,15 +249,15 @@ class downloadUtils: print("icon 不存在,已跳过") return None save_name = ci.COMIC_ICON_NAME - icon_prefix = "."+str(icon_url).split(".")[-1] - icon_prefix = icon_prefix.split("?")[0] + icon_suffix = "."+str(icon_url).split(".")[-1] + icon_suffix = icon_suffix.split("?")[0] #判断漫画名路径是否已存在comicname/cover.jpg, 存在跳过 - path_comic_icon = os.path.join(ComicPath.getDirConfComic(),save_name+icon_prefix) + path_comic_icon = os.path.join(ComicPath.getDirConfComic(),save_name+icon_suffix) if not ciUtils.equIcon() and fu.exists(path_comic_icon): os.remove(path_comic_icon) if fu.notExists(path_comic_icon): - cls.download_images([icon_url],ComicPath.getDirConfComic(),files_name=[save_name+icon_prefix]) - save_path = os.path.join(ComicPath.getDirCBZComic(),Comic.getChapterName()+icon_prefix) + cls.download_images([icon_url],ComicPath.getDirConfComic(),files_name=[save_name+icon_suffix]) + save_path = os.path.join(ComicPath.getDirCBZComic(),Comic.getChapterName()+icon_suffix) if is_new: #历史版本ICON if os.path.exists(save_path): @@ -265,7 +265,7 @@ class downloadUtils: if os.path.exists(path_comic_icon): base_dir = ComicPath.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)) + shutil.copy(path_comic_icon,os.path.join(base_dir,save_name+icon_suffix)) else: if fu.notExists(ComicPath.getDirCBZComic()): os.makedirs(ComicPath.getDirCBZComic()) shutil.copy(path_comic_icon,save_path)