import os import rarfile import zipfile import shutil import difflib import UtilPack as util import subprocess as ps from PIL import Image m_ImgExts = [".jpg",".png",".jpeg",".webp"] m_CalLibPath = "/Volumes/NewDataStor/calibre_lib/" def Start(): pathTrg = os.path.abspath(m_CalLibPath) if False == os.path.exists(pathTrg): util.DbgOut("Error : Invalid Path") listPaths = util.ListSubDirectories(pathTrg) print(f"Input : {len(listPaths)} \r\n") nIdx = 0; listWorked = [] listSkiped = [] strCoverName = "cover.jpg" for path in listPaths: nIdx += 1 # 조건은 커버파일이 있고 크기가 0 일 경우가 문제가 되는데... pathCover = os.path.join(path, strCoverName) if True == os.path.exists(pathCover) and 0 < os.path.getsize(pathCover): continue # 조건에 맞는 폴더에서 cbz 파일을 찾아낸다. nameCBZFile = "" contents = os.listdir(path) for item in contents: extTmp = util.GetExtStr(item, False) if extTmp.lower() == "cbz": nameCBZFile = item break # cbz 없으면 일단 넘어간다. if nameCBZFile == "": continue # # 압축을 풀고 pathCBZFull = os.path.join(path, nameCBZFile) util.ExtractZIP(pathCBZFull, path) # 하위 폴더를 훑어서 이미지 파일을 가져온다. 일단 webp 만... listTrgFiles = util.ListFileExtRcr(path, "webp") if 0 >= len(listTrgFiles): continue # CBZ 파일 삭제 os.remove(pathCBZFull) # 다시 압축을 한다 if False == util.CreateZIPShell(pathCBZFull, listTrgFiles): print(f"error : {pathCBZFull}") break # 크기가 0 인 커버 지운다. if True == os.path.exists(pathCover): os.remove(pathCover) # 원본 WebP 이미지 파일 경로 webp_file = listTrgFiles[0] # JPEG로 변환할 이미지를 엽니다 try: with Image.open(webp_file) as img: # 새로운 파일명과 확장자를 지정하여 저장합니다 img.save(pathCover, "JPEG") except Exception as e: listSkiped.append(pathCBZFull) print(f"커버 변환중 에러 : {e}") continue # webp 파일들 삭제 for fileTrg in listTrgFiles: if True == os.path.isfile(fileTrg): os.remove(fileTrg) # 성공 로그! print(f"Success : {nIdx} : {pathCBZFull}\r\n") listWorked.append(pathCBZFull) print(f"complete : {len(listWorked)}") print(f"Something Wrong : {listSkiped}")