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="
|
||||
|
||||
@ -79,6 +80,19 @@ class FileNaming:
|
||||
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:
|
||||
"""默认文件名生成器:使用数字序号"""
|
||||
@ -217,6 +231,7 @@ class FileNaming:
|
||||
|
||||
return _scandir(folder_path)
|
||||
|
||||
|
||||
class NamingStrategy:
|
||||
"""命名策略集合类"""
|
||||
|
||||
|
||||
@ -143,6 +143,7 @@ class BaseSite(ABC):
|
||||
for cbz_path in list_cbz:
|
||||
first_cover_path = str(cbz_path).split(".")[0]+".jpg"
|
||||
if len(list_cover) == 1:
|
||||
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
|
||||
@ -151,6 +152,7 @@ class BaseSite(ABC):
|
||||
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)
|
||||
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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user