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.config import BASE_IMAGES_DIR,CBZ_DIR,OLD_CBZ_DIR
|
||||||
from src.common.item import MangaInfo,MangaItem
|
from src.common.item import MangaInfo,MangaItem
|
||||||
from typing import Generator, Union, List, Optional
|
from typing import Generator, Union, List, Optional
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
PREFIX_SCRAMBLE = "scramble="
|
PREFIX_SCRAMBLE = "scramble="
|
||||||
|
|
||||||
@ -78,7 +79,20 @@ class FileNaming:
|
|||||||
filename = filename[0:len(filename)+1-count]
|
filename = filename[0:len(filename)+1-count]
|
||||||
break
|
break
|
||||||
return filename
|
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
|
@classmethod
|
||||||
def default_filename(cls,url: str, idx: int) -> str:
|
def default_filename(cls,url: str, idx: int) -> str:
|
||||||
"""默认文件名生成器:使用数字序号"""
|
"""默认文件名生成器:使用数字序号"""
|
||||||
@ -216,7 +230,8 @@ class FileNaming:
|
|||||||
yield entry.path if full_path else entry.name
|
yield entry.path if full_path else entry.name
|
||||||
|
|
||||||
return _scandir(folder_path)
|
return _scandir(folder_path)
|
||||||
|
|
||||||
|
|
||||||
class NamingStrategy:
|
class NamingStrategy:
|
||||||
"""命名策略集合类"""
|
"""命名策略集合类"""
|
||||||
|
|
||||||
|
|||||||
@ -143,17 +143,19 @@ class BaseSite(ABC):
|
|||||||
for cbz_path in list_cbz:
|
for cbz_path in list_cbz:
|
||||||
first_cover_path = str(cbz_path).split(".")[0]+".jpg"
|
first_cover_path = str(cbz_path).split(".")[0]+".jpg"
|
||||||
if len(list_cover) == 1:
|
if len(list_cover) == 1:
|
||||||
shutil.copy(list_cover[0].path, first_cover_path)
|
if FileNaming().file_update_by_date(first_cover_path):
|
||||||
logger.info(f"{list_cover[0].path} ==> {first_cover_path} 已复制")
|
shutil.copy(list_cover[0].path, first_cover_path)
|
||||||
|
logger.info(f"{list_cover[0].path} ==> {first_cover_path} 已复制")
|
||||||
continue
|
continue
|
||||||
cover_count = 1
|
cover_count = 1
|
||||||
for cover in list_cover:
|
for cover in list_cover:
|
||||||
cover_path = cover.path
|
cover_path = cover.path
|
||||||
if os.path.exists(first_cover_path): os.remove(first_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)
|
new_cover_path = FileNaming().cover_format_path(str(cbz_path).split(".")[0]+".jpg", count=cover_count)
|
||||||
shutil.copy(cover_path, new_cover_path)
|
if FileNaming().file_update_by_date(new_cover_path):
|
||||||
logger.info(f"{cover_path} ==> {new_cover_path} 已复制")
|
shutil.copy(cover_path, new_cover_path)
|
||||||
cover_count += 1
|
logger.info(f"{cover_path} ==> {new_cover_path} 已复制")
|
||||||
|
cover_count += 1
|
||||||
|
|
||||||
async def download_manga(self, manga_url: str) -> AsyncGenerator[Dict, None]:
|
async def download_manga(self, manga_url: str) -> AsyncGenerator[Dict, None]:
|
||||||
"""下载整部漫画"""
|
"""下载整部漫画"""
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user