Files
CollectMangaInfo/MgrCalibreLibs.py
15000rpm d5f2d82bc9 Update .gitignore, DataClass.py, and 19 more files...
오랜만에 서버 정리하고 커밋. 파일 위치를 정리했다.
캘리버 DB 를 열고 정보를 열람. Pupil 을 통해 다운받은 정보를 관리하기 위해 새로운 클래스 추가
2025-08-01 14:57:40 +09:00

99 lines
2.9 KiB
Python

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}")