fix
This commit is contained in:
parent
b6608aa7ac
commit
7faddb4ebd
@ -15,7 +15,7 @@ from zipfile import ZipFile, ZIP_DEFLATED
|
||||
from src.common.logging import setup_logging
|
||||
import logging
|
||||
from tempfile import NamedTemporaryFile
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
logger = setup_logging(__name__)
|
||||
|
||||
@ -435,7 +435,29 @@ class CBZUtils:
|
||||
# update_zip_file("data.zip", {
|
||||
# "config.json": new_config # 字节数据
|
||||
# })
|
||||
|
||||
def _clean_old_cbz(self, cbz_path):
|
||||
m_time = datetime.fromtimestamp(os.path.getmtime(cbz_path))
|
||||
str_strftime = '%Y%m%d'
|
||||
zip_time = m_time.strftime(str_strftime)
|
||||
|
||||
with ZipFile(cbz_path, 'r') as zip_ref:
|
||||
old_img = 0
|
||||
for file_info in zip_ref.infolist():
|
||||
# 获取日期时间信息,格式为 (year, month, day, hour, minute, second)
|
||||
date_time = file_info.date_time
|
||||
# 将日期时间元组转换为datetime对象
|
||||
dt = datetime(*date_time)
|
||||
# 格式化输出日期时间,例如:YYYY-MM-DD HH:MM:SS
|
||||
file_date_time = dt.strftime(str_strftime)
|
||||
# 一周内的图片跳过
|
||||
if int(zip_time) - int(file_date_time) > 7:
|
||||
#print(f"Clear Filename: {file_info.filename}, zip: {cbz_path}")
|
||||
old_img += 1
|
||||
|
||||
if old_img > 0:
|
||||
#os.remove(cbz_path)
|
||||
print(f"remove cbz {cbz_path}")
|
||||
|
||||
class ImageUtils:
|
||||
|
||||
@classmethod
|
||||
|
||||
@ -6,7 +6,7 @@ import asyncio
|
||||
import logging
|
||||
from src.config import DEFAULT_HEADERS, TIMEOUT, RETRIES, PROXY_URL, RETRY_PROXY
|
||||
from lxml import etree
|
||||
from src.common.utils import Cache # 导入缓存类
|
||||
from src.common.utils import Cache, CBZUtils # 导入缓存类
|
||||
from src.common.item import Chapter, MangaItem, MangaInfo,CoverItem
|
||||
from src.common.exceptions import SiteError, NetworkError, ParseError
|
||||
from src.common.logging import setup_logging
|
||||
@ -98,9 +98,11 @@ class BaseSite(ABC):
|
||||
if os.path.exists(old_cbz_path):
|
||||
logger.info(f"{chapter.title} Old章节存在")
|
||||
if not os.path.exists(os.path.dirname(cbz_path)): os.makedirs(cbz_path)
|
||||
shutil.copy(old_cbz_path, cbz_path)
|
||||
logger.info(f"{old_cbz_path} ==> {cbz_path} 已复制")
|
||||
chapter.status = "downloaded"
|
||||
CBZUtils()._clean_old_cbz(old_cbz_path)
|
||||
if os.path.exists(old_cbz_path):
|
||||
shutil.copy(old_cbz_path, cbz_path)
|
||||
logger.info(f"{old_cbz_path} ==> {cbz_path} 已复制")
|
||||
chapter.status = "downloaded"
|
||||
down_chapter.append(chapter)
|
||||
return down_chapter
|
||||
except Exception as e:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user