diff --git a/src/common/ComicInfo.py b/src/common/ComicInfo.py index e5c4819..1d4705b 100644 --- a/src/common/ComicInfo.py +++ b/src/common/ComicInfo.py @@ -16,7 +16,6 @@ from concurrent.futures import ThreadPoolExecutor import hashlib from io import BytesIO - logger = setup_logging(__name__) class ImageInfo: @@ -171,7 +170,7 @@ class ImageInfo: ('.png', '.jpg', '.jpeg', '.gif', '.bmp') ): continue - + try: with zf.open(file_info) as file: # 读取前 chunk_size 字节用于解析元数据 @@ -182,13 +181,13 @@ class ImageInfo: page = ComicPageInfo() page.Key = self.get_image_hash_advanced(img_buffer) - + # 使用 Pillow 解析图像信息 with Image.open(img_buffer) as img: page.Image = file_info.filename.split(".")[0] page.ImageSize = file_info.file_size ImageWidth, ImageHeight = zip(img.size) - page.ImageWidth, page.ImageHeight = [ImageWidth[0], ImageHeight[0]] + page.ImageWidth, page.ImageHeight = [ImageWidth[0], ImageHeight[0]] #metadata = { # "filename": file_info.filename, # "compressed_size": file_info.compress_size, @@ -342,6 +341,8 @@ class ComicInfoXml: cpi.ImageSize = page.ImageSize cpi.Key = page.Key cpi.ImageWidth = page.ImageWidth + if page.ImageWidth != 720: + print(cpi) cpi.ImageHeight = page.ImageHeight page_elem = ET.SubElement(pages_elem, 'Page', cpi.toString()) else: diff --git a/test.py b/test.py index 6e08da0..873bed8 100644 --- a/test.py +++ b/test.py @@ -1,13 +1,54 @@ from src.common.naming import FileNaming +from src.common.ComicInfo import ImageInfo +from zipfile import ZipFile +from datetime import datetime import os -dir_path = "/mnt/Comics/CBZ/rm_comic" -for dir in os.listdir(dir_path): - c_dir = os.path.join(dir_path, dir) - if os.path.isdir(c_dir): - files = list(FileNaming.get_filenames_optimized(c_dir, ext_filter=['.CBZ'])) - for file in files: - size = os.path.getsize(file) - if size < 3000: - os.remove(file) - print(f"已删除{file}") \ No newline at end of file +class test: + + def clean_cbz(self): + dir_path = "/mnt/Comics/CBZ/rm_comic" + for dir in os.listdir(dir_path): + c_dir = os.path.join(dir_path, dir) + if os.path.isdir(c_dir): + files = list(FileNaming.get_filenames_optimized(c_dir, ext_filter=['.CBZ'])) + for file in files: + size = os.path.getsize(file) + if size < 3000: + os.remove(file) + print(f"已删除{file}") + + 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) > 10: + 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}") + + def clean_old_cbz(self): + dir_path = "/mnt/Comics/CBZ/rm_comic" + for dir in os.listdir(dir_path): + c_dir = os.path.join(dir_path, dir) + if os.path.isdir(c_dir): + files = list(FileNaming.get_filenames_optimized(c_dir, ext_filter=['.CBZ'])) + for file in files: + self._clean_old_cbz(file) + +if __name__ == "__main__": + test().clean_old_cbz() \ No newline at end of file