- Refactor codebase into src/ (preprocessing, translation, assembly) - Add pipeline/ scripts for individual stages - Externalize configuration to config/config.yaml - Fix Cover Image preservation - Update documentation and manuals
48 lines
1.4 KiB
Python
48 lines
1.4 KiB
Python
import sys
|
|
from pathlib import Path
|
|
import traceback
|
|
|
|
# Add src to path
|
|
sys.path.insert(0, str(Path(__file__).parent.parent))
|
|
|
|
from src.epub_cleaner import EpubCleaner
|
|
from src.bilingual_builder import BilingualBuilder
|
|
from src.utils import setup_logger
|
|
from src.data_model import BookStructure
|
|
|
|
logger = setup_logger("verify_toc")
|
|
|
|
def verify_fix():
|
|
INPUT_EPUB = Path("input/Empire of AI Dreams and Nightmares in Sam Altmans OpenAI (Karen Hao).epub")
|
|
OUTPUT_EPUB = Path("output/verify_toc.epub")
|
|
WORK_DIR = Path("tmp/verify_toc")
|
|
|
|
if not INPUT_EPUB.exists():
|
|
logger.error(f"Input not found: {INPUT_EPUB}")
|
|
return
|
|
|
|
# Clean
|
|
logger.info("Step 1: Cleaning EPUB...")
|
|
cleaner = EpubCleaner(INPUT_EPUB, WORK_DIR)
|
|
json_path = cleaner.clean()
|
|
|
|
# Load structure
|
|
with open(json_path, 'r') as f:
|
|
structure = BookStructure.model_validate_json(f.read())
|
|
|
|
# Build
|
|
logger.info("Step 2: Building EPUB with TOC preservation...")
|
|
builder = BilingualBuilder(WORK_DIR, original_epub_path=INPUT_EPUB)
|
|
builder.build(structure, OUTPUT_EPUB)
|
|
|
|
logger.info(f"Step 3: EPUB generated at {OUTPUT_EPUB}")
|
|
|
|
if __name__ == "__main__":
|
|
print("Starting verification script...")
|
|
try:
|
|
verify_fix()
|
|
print("Verification script finished.")
|
|
except Exception as e:
|
|
traceback.print_exc()
|
|
print(f"CRITICAL ERROR: {e}")
|