This commit is contained in:
caiwx86 2025-02-04 17:29:11 +08:00
parent 4927a40c31
commit 244c1b8c39
2 changed files with 8 additions and 2 deletions

View File

@ -81,7 +81,7 @@ class FileNaming:
return filename
@classmethod
def file_update_by_date(cls, path, day: int = 7) -> bool:
def file_update_by_date(cls, path, day: int = 7, remove: bool = False) -> bool:
is_update = False
if not os.path.exists(path): return False
now = datetime.now()
@ -89,8 +89,13 @@ class FileNaming:
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):
if int(now_time) - int(file_time) > int(day):
is_update = True
if is_update and remove:
try:
os.remove(path)
except:
raise exit(f"file_update_by_date() {path} 删除失败")
return is_update
@classmethod

View File

@ -198,6 +198,7 @@ class MangaDownloader:
async def download_image(self, session: aiohttp.ClientSession, url: str, save_path: Path, retries: int = RETRIES, timeout: int = TIMEOUT, use_proxy: bool = RETRY_PROXY) -> bool:
"""下载单个图片,增加重试机制、超时等待和文件缓存机制"""
FileNaming().file_update_by_date(save_path, remove=True)
if os.path.exists(FileNaming.getFileScrambleImageSave(save_path)): # 检查文件是否已存在
logger.info(f"文件已存在,跳过下载: {save_path}")
return True