From e36431adf629abd867f26a19ab1b10b276180a0a Mon Sep 17 00:00:00 2001 From: caiwx86 Date: Wed, 5 Apr 2023 13:55:20 +0800 Subject: [PATCH] fix --- common/ComicInfo.py | 6 +----- common/Constant.py | 9 ++++++++- utils/ComicUtils.py | 2 +- utils/NetUtils.py | 20 +++++++++----------- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/common/ComicInfo.py b/common/ComicInfo.py index 2a325e4..24e5261 100644 --- a/common/ComicInfo.py +++ b/common/ComicInfo.py @@ -1,9 +1,6 @@ import json,os -from typing import Any from xml.dom.minidom import Document -from common.Constant import pathStr from utils.FileUtils import dbUtils as db -from utils.FileUtils import fileUtils from common.Comic import Comic from common.Constant import ComicPath @@ -22,7 +19,6 @@ class ComicInfoEntity: Comic.dict_cbs,Comic.dict_genre,Comic.dict_tags,Comic.dict_page_count, Comic.dict_language,Comic.dict_agerating,Comic.dict_pages,Comic.dict_chapter_imgs] class ComicInfo: - COMIC_ICON_NAME = "000" IS_NEW_ICON = False document = Document() path_comic_info = None @@ -61,7 +57,7 @@ class ComicInfo: if cls.IS_NEW_ICON: #添加封面 icon_node = cls.document.createElement("Page") - icon_node.setAttribute("Image",cls.COMIC_ICON_NAME) + icon_node.setAttribute("Image",ComicPath.COMIC_ICON_NAME) icon_node.setAttribute("Type","FrontCover") root_node.appendChild(icon_node) for page in values: diff --git a/common/Constant.py b/common/Constant.py index a36cce4..0c2ecfb 100644 --- a/common/Constant.py +++ b/common/Constant.py @@ -75,6 +75,7 @@ class pathStr: return week class ComicPath: + COMIC_ICON_NAME = "000" DEFAULT_PATH = "default" PROGRESS_PATH = "progress" ICONS_PATH = "icons" @@ -110,6 +111,9 @@ class ComicPath: #章节配置json文件路径 @classmethod def getPathConfComicChapterJson(cls,mkdir=True): return cls.setDirConf([Comic.getOriginComicName(),Comic.getOriginChapterName()],suffix="json",mkdir=mkdir) + #漫画Icon路径 + @classmethod + def getPathConfComicIcon(cls,mkdir=True,suffix="jpg"): return cls.setDirConf([Comic.getOriginComicName(),cls.COMIC_ICON_NAME],suffix=suffix,mkdir=mkdir) #Icons json文件路径 @classmethod def getDirConfDefault(cls,path=None,suffix=None,mkdir=True): return cls.setDirConf([cls.DEFAULT_PATH,path],suffix=suffix,mkdir=mkdir) @@ -121,7 +125,10 @@ class ComicPath: def getDirCBZComic(cls): return cls.setDirCBZ(Comic.getComicName()) #漫画章节CBZ路径 @classmethod - def getDirCBZComicChapter(cls): return cls.setDirCBZ([Comic.getComicName(),Comic.getChapterName()]) + def getDirCBZComicChapter(cls,suffix=None): return cls.setDirCBZ([Comic.getComicName(),Comic.getChapterName()],suffix=suffix) + #漫画章节CBZ同根下封面 + @classmethod + def getPathCBZComicChapterIcon(cls,suffix="jpg"): return cls.setDirCBZ([Comic.getComicName(),Comic.getChapterName()],suffix=suffix) #旧版本漫画章节CBZ路径 @classmethod def getPathOldCBZComicChapter(cls): return cls.setDirOld([Comic.getOriginComicName(),Comic.getOriginChapterName()],suffix="CBZ") diff --git a/utils/ComicUtils.py b/utils/ComicUtils.py index 118175f..37898bb 100644 --- a/utils/ComicUtils.py +++ b/utils/ComicUtils.py @@ -121,7 +121,7 @@ class CBZUtils: with ZipFile(path, "r") as zip_file: result = zip_file.namelist() if filter: - filter_icon = ci.COMIC_ICON_NAME+".jpg" + filter_icon = ComicPath.COMIC_ICON_NAME+".jpg" filter_info_xml = ComicPath.COMIC_INFO_XML if filter_icon in result: result.remove(filter_icon) if filter_info_xml in result: result.remove(filter_info_xml) diff --git a/utils/NetUtils.py b/utils/NetUtils.py index 51e2f0d..4325138 100644 --- a/utils/NetUtils.py +++ b/utils/NetUtils.py @@ -248,16 +248,13 @@ class downloadUtils: if icon_url == None: print("icon 不存在,已跳过") return None - save_name = ci.COMIC_ICON_NAME - icon_suffix = "."+str(icon_url).split(".")[-1] - icon_suffix = icon_suffix.split("?")[0] + icon_suffix = str(icon_url).split(".")[-1] #判断漫画名路径是否已存在comicname/cover.jpg, 存在跳过 - 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) + path_comic_icon = ComicPath.getPathConfComicIcon() + 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_suffix]) - save_path = os.path.join(ComicPath.getDirCBZComic(),Comic.getChapterName()+icon_suffix) + cls.download_images([icon_url],ComicPath.getDirConfComic(),files_name=[ComicPath.COMIC_ICON_NAME+"."+icon_suffix]) + save_path = ComicPath.getPathCBZComicChapterIcon(icon_suffix) if is_new: #历史版本ICON if os.path.exists(save_path): @@ -265,11 +262,12 @@ 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_suffix)) + shutil.copy(path_comic_icon,os.path.join(base_dir,ComicPath.COMIC_ICON_NAME+icon_suffix)) else: if fu.notExists(ComicPath.getDirCBZComic()): os.makedirs(ComicPath.getDirCBZComic()) - shutil.copy(path_comic_icon,save_path) - print(f"{path_comic_icon} 已复制至: {save_path}") + if fu.notExists(save_path): + shutil.copy(path_comic_icon,save_path) + print(f"{path_comic_icon} 已复制至: {save_path}") #保存icon信息 ciUtils.iconDB() ciUtils.setProgressCBZ() \ No newline at end of file