add cover date copy
This commit is contained in:
parent
7faddb4ebd
commit
2ad55af141
@ -5,6 +5,7 @@ import base64,hashlib,os,re
|
||||
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
|
||||
from datetime import datetime
|
||||
|
||||
PREFIX_SCRAMBLE = "scramble="
|
||||
|
||||
@ -78,7 +79,20 @@ class FileNaming:
|
||||
filename = filename[0:len(filename)+1-count]
|
||||
break
|
||||
return filename
|
||||
|
||||
|
||||
@classmethod
|
||||
def file_update_by_date(cls, path, day: int = 7) -> bool:
|
||||
is_update = False
|
||||
if not os.path.exists(path): return False
|
||||
now = datetime.now()
|
||||
str_strftime = '%Y%m%d'
|
||||
now_time = now.strftime(str_strftime)
|
||||
m_time = datetime.fromtimestamp(os.path.getmtime(path))
|
||||
file_time = m_time.strftime(str_strftime)
|
||||
if int(now_time) - int(file_time) > int(day):
|
||||
is_update = True
|
||||
return is_update
|
||||
|
||||
@classmethod
|
||||
def default_filename(cls,url: str, idx: int) -> str:
|
||||
"""默认文件名生成器:使用数字序号"""
|
||||
@ -216,7 +230,8 @@ class FileNaming:
|
||||
yield entry.path if full_path else entry.name
|
||||
|
||||
return _scandir(folder_path)
|
||||
|
||||
|
||||
|
||||
class NamingStrategy:
|
||||
"""命名策略集合类"""
|
||||
|
||||
|
||||
@ -143,17 +143,19 @@ class BaseSite(ABC):
|
||||
for cbz_path in list_cbz:
|
||||
first_cover_path = str(cbz_path).split(".")[0]+".jpg"
|
||||
if len(list_cover) == 1:
|
||||
shutil.copy(list_cover[0].path, first_cover_path)
|
||||
logger.info(f"{list_cover[0].path} ==> {first_cover_path} 已复制")
|
||||
if FileNaming().file_update_by_date(first_cover_path):
|
||||
shutil.copy(list_cover[0].path, first_cover_path)
|
||||
logger.info(f"{list_cover[0].path} ==> {first_cover_path} 已复制")
|
||||
continue
|
||||
cover_count = 1
|
||||
for cover in list_cover:
|
||||
cover_path = cover.path
|
||||
if os.path.exists(first_cover_path): os.remove(first_cover_path)
|
||||
new_cover_path = FileNaming().cover_format_path(str(cbz_path).split(".")[0]+".jpg", count=cover_count)
|
||||
shutil.copy(cover_path, new_cover_path)
|
||||
logger.info(f"{cover_path} ==> {new_cover_path} 已复制")
|
||||
cover_count += 1
|
||||
if FileNaming().file_update_by_date(new_cover_path):
|
||||
shutil.copy(cover_path, new_cover_path)
|
||||
logger.info(f"{cover_path} ==> {new_cover_path} 已复制")
|
||||
cover_count += 1
|
||||
|
||||
async def download_manga(self, manga_url: str) -> AsyncGenerator[Dict, None]:
|
||||
"""下载整部漫画"""
|
||||
|
||||
Loading…
Reference in New Issue
Block a user