56 lines
1.5 KiB
Python
56 lines
1.5 KiB
Python
# processors/standardizer.py
|
|
|
|
from processors.cleaner import clean_comic
|
|
from processors.converter import convert_comic
|
|
|
|
class StandardizeResult:
|
|
def __init__(self, original_path):
|
|
self.original_path = original_path
|
|
self.cleaned = None
|
|
self.converted = None
|
|
self.final_path = None
|
|
|
|
def __str__(self):
|
|
msg = f"Estandarización de: {self.original_path}\n"
|
|
if self.cleaned:
|
|
msg += f" Limpieza: OK ({len(self.cleaned.removed_files)} archivos eliminados)\n"
|
|
else:
|
|
msg += " Limpieza: no realizada\n"
|
|
|
|
if self.converted:
|
|
if self.converted["needs_conversion"]:
|
|
msg += f" Conversión: OK → {self.converted['target_path']}\n"
|
|
else:
|
|
msg += " Conversión: no necesaria\n"
|
|
|
|
msg += f" Resultado final: {self.final_path}\n"
|
|
return msg
|
|
|
|
|
|
def standardize_comic(path, desired_format="cbz"):
|
|
"""
|
|
Pipeline básico:
|
|
1. Limpiar
|
|
2. Convertir
|
|
"""
|
|
result = StandardizeResult(path)
|
|
|
|
# 1) Limpiar
|
|
clean_result = clean_comic(path)
|
|
result.cleaned = clean_result
|
|
|
|
# El archivo resultante tras limpiar
|
|
cleaned_path = clean_result.cleaned_path
|
|
|
|
# 2) Convertir
|
|
convert_result = convert_comic(cleaned_path, desired_format)
|
|
result.converted = convert_result
|
|
|
|
# Ruta final
|
|
if convert_result["needs_conversion"]:
|
|
result.final_path = convert_result["target_path"]
|
|
else:
|
|
result.final_path = cleaned_path
|
|
|
|
return result
|