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