upgrade
This commit is contained in:
parent
03c578f183
commit
d909d67e40
@ -20,11 +20,11 @@ from io import BytesIO
|
||||
logger = setup_logging(__name__)
|
||||
|
||||
class ImageInfo:
|
||||
from src.config import BASE_DIR
|
||||
from src.config import BASE_IMAGES_DIR
|
||||
def _image_path(self, comicinfo, filename):
|
||||
"""生成章节目录"""
|
||||
if filename:
|
||||
return os.path.join(self.BASE_DIR,"images",f"{comicinfo.name}", comicinfo.chapter, filename)
|
||||
return os.path.join(self.BASE_IMAGES_DIR,"images",f"{comicinfo.name}", comicinfo.chapter, filename)
|
||||
|
||||
def get_image_size(self, image_path: str, human_readable: bool = False) -> str:
|
||||
"""
|
||||
|
||||
@ -2,7 +2,7 @@ from pathlib import Path
|
||||
from datetime import datetime
|
||||
from typing import Callable
|
||||
import base64,hashlib,os,re
|
||||
from src.config import BASE_DIR,CBZ_DIR,OLD_CBZ_DIR
|
||||
from src.config import BASE_IMAGES_DIR,CBZ_DIR,OLD_CBZ_DIR
|
||||
from src.common.item import MangaInfo,MangaItem
|
||||
from typing import Generator, Union, List, Optional
|
||||
|
||||
@ -18,9 +18,9 @@ class DirectoryNaming:
|
||||
def chapter_images_dir(cls, manga_info: MangaInfo, chapter: str, filename: str = None) -> Path:
|
||||
"""生成章节目录"""
|
||||
if filename:
|
||||
return Path(BASE_DIR,f"{manga_info.project}","images",f"{manga_info.title}",chapter.title, filename)
|
||||
return Path(BASE_IMAGES_DIR,f"{manga_info.project}","images",f"{manga_info.title}",chapter.title, filename)
|
||||
else:
|
||||
return Path(BASE_DIR,f"{manga_info.project}","images",f"{manga_info.title}",chapter.title)
|
||||
return Path(BASE_IMAGES_DIR,f"{manga_info.project}","images",f"{manga_info.title}",chapter.title)
|
||||
|
||||
@classmethod
|
||||
def chapter_cbz_dir(cls, manga_info: MangaInfo) -> Path:
|
||||
@ -30,16 +30,16 @@ class DirectoryNaming:
|
||||
@classmethod
|
||||
def manga_cover_dir(cls, manga_item: MangaItem) -> Path:
|
||||
"""生成漫画封面目录"""
|
||||
return Path(BASE_DIR,f"{manga_item.info.project}","icons",f"{manga_item.info.title}",f"{manga_item.info.title}.jpg")
|
||||
return Path(BASE_IMAGES_DIR,f"{manga_item.info.project}","icons",f"{manga_item.info.title}",f"{manga_item.info.title}.jpg")
|
||||
|
||||
@classmethod
|
||||
def manga_cover_dir(cls, manga_info: MangaInfo, cache: bool = True, is_dir: bool = False) -> Path:
|
||||
"""生成漫画封面目录"""
|
||||
path = ""
|
||||
if cache:
|
||||
path = Path(BASE_DIR,f"{manga_info.project}","icons",".cache")
|
||||
path = Path(BASE_IMAGES_DIR,f"{manga_info.project}","icons",".cache")
|
||||
else:
|
||||
path = Path(BASE_DIR,f"{manga_info.project}","icons",f"{manga_info.title}")
|
||||
path = Path(BASE_IMAGES_DIR,f"{manga_info.project}","icons",f"{manga_info.title}")
|
||||
if not is_dir:
|
||||
path = os.path.join(path, f"{manga_info.title}.jpg")
|
||||
return Path(path)
|
||||
|
||||
@ -8,7 +8,7 @@ from typing import List, Optional, Callable, Dict, Any
|
||||
from src.common.naming import DirectoryNaming
|
||||
from src.common.naming import FileNaming,PREFIX_SCRAMBLE
|
||||
from src.config import DEFAULT_HEADERS, CONCURRENT_DOWNLOADS, TIMEOUT, RETRY_TIMES, CACHE_DIR, CACHE_IMAGE_DIR
|
||||
from src.config import RETRIES, COMIC_INFO_NAME, PROXY_URL, RETRY_PROXY, RETRY_PROXY_TIMES, XSD_FILE, BASE_DIR
|
||||
from src.config import RETRIES, COMIC_INFO_NAME, PROXY_URL, RETRY_PROXY, RETRY_PROXY_TIMES, BASE_IMAGES_DIR
|
||||
from src.common.exceptions import DownloadError
|
||||
from src.common.item import ImageItem, MangaItem, MangaInfo
|
||||
from zipfile import ZipFile, ZIP_DEFLATED
|
||||
@ -101,7 +101,7 @@ class DownloadStatus:
|
||||
class MangaDownloader:
|
||||
"""漫画下载器类,负责下载漫画及其相关资源"""
|
||||
|
||||
def __init__(self, base_dir: Path = BASE_DIR):
|
||||
def __init__(self, base_dir: Path = BASE_IMAGES_DIR):
|
||||
self.connector = aiohttp.TCPConnector(limit_per_host=CONCURRENT_DOWNLOADS)
|
||||
self.base_dir = Path(base_dir)
|
||||
self.cache_dir = CACHE_IMAGE_DIR # 缓存目录
|
||||
@ -354,7 +354,7 @@ class CBZUtils:
|
||||
print(f"删除 {file} 发生错误 {e},已跳过")
|
||||
return False
|
||||
|
||||
def create_cbz(self, chapter_dir: Path):
|
||||
def create_cbz(self, chapter_dir: Path, clear_chapter: bool = False):
|
||||
if os.path.exists(chapter_dir):
|
||||
dirs = os.listdir(chapter_dir)
|
||||
for file in dirs:
|
||||
@ -365,7 +365,13 @@ class CBZUtils:
|
||||
print(f"删除 {file} 发生错误 {e},已跳过")
|
||||
return False
|
||||
if self._zip_compression(source_dir=chapter_dir, target_file=self.cbz_path, remove=False):
|
||||
logger.info(f"章节 {chapter_dir.name} 打包完成: {self.cbz_path}")
|
||||
logger.info(f"章节 {chapter_dir.name} 打包完成: {self.cbz_path}")
|
||||
if clear_chapter:
|
||||
try:
|
||||
shutil.rmtree(chapter_dir)
|
||||
logger.info(f"{chapter_dir} 章节原图片已删除")
|
||||
except:
|
||||
raise exit(f"{chapter_dir} 章节删除错误")
|
||||
else:
|
||||
raise exit(f"章节 {chapter_dir.name} 打包失败: {self.cbz_path}")
|
||||
|
||||
|
||||
@ -3,11 +3,13 @@ from pathlib import Path
|
||||
from fake_useragent import UserAgent
|
||||
|
||||
# 基础配置
|
||||
BASE_DIR = Path("output")
|
||||
BASE_DIR = ""
|
||||
# BASE_DIR = Path("/mnt/Comics")
|
||||
BASE_IMAGES_DIR = Path(BASE_DIR,"output")
|
||||
CACHE_DIR = Path(".cache")
|
||||
CACHE_IMAGE_DIR = CACHE_DIR / "images"
|
||||
CBZ_DIR = Path("CBZ")
|
||||
OLD_CBZ_DIR = Path("OldCBZ")
|
||||
OLD_CBZ_DIR = Path(BASE_DIR, "OldCBZ")
|
||||
# DEFAULT_SAVE_DIR = Path("output")
|
||||
CONCURRENT_DOWNLOADS = 10
|
||||
RETRY_TIMES = 10
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
from pathlib import Path
|
||||
from typing import Dict, Type, Optional
|
||||
import logging
|
||||
from src.config import BASE_DIR
|
||||
from src.config import BASE_IMAGES_DIR
|
||||
from src.sites.base import BaseSite
|
||||
from src.sites.configs.rouman import RoumanSite
|
||||
from src.common.utils import MangaDownloader, CBZUtils
|
||||
@ -23,7 +23,7 @@ class MangaManager:
|
||||
# 在这里添加更多网站支持
|
||||
}
|
||||
|
||||
def __init__(self, base_dir: Path = BASE_DIR):
|
||||
def __init__(self, base_dir: Path = BASE_IMAGES_DIR):
|
||||
self.downloader = MangaDownloader(base_dir)
|
||||
|
||||
def get_site_handler(self, url: str) -> Optional[Type[BaseSite]]:
|
||||
@ -111,7 +111,7 @@ class MangaManager:
|
||||
CBZUtils(cbz_path)._image_deScrambleByPath(chapter_dir)
|
||||
ComicInfoXml().scrapy_xml_by_json(manga_item.get_comic_info_json(), chapter_dir)
|
||||
# 打包成 CBZ 文件
|
||||
CBZUtils(cbz_path).create_cbz(chapter_dir)
|
||||
CBZUtils(cbz_path).create_cbz(chapter_dir, clear_chapter=True)
|
||||
|
||||
# 章节下载完成后处理流程 end
|
||||
|
||||
@ -159,7 +159,7 @@ class MangaManager:
|
||||
await self.download_manga(str(url))
|
||||
|
||||
@classmethod
|
||||
async def download_manga(cls, url: str, save_dir: Path = BASE_DIR):
|
||||
async def download_manga(cls, url: str, save_dir: Path = BASE_IMAGES_DIR):
|
||||
"""下载漫画"""
|
||||
manager = MangaManager(save_dir)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user