Spaces:
Running
Running
| """ | |
| pipeline/packager.py | |
| Bundles all reel files + a metadata.json into a timestamped ZIP. | |
| """ | |
| import json | |
| import zipfile | |
| from datetime import datetime | |
| from pathlib import Path | |
| from typing import List | |
| from utils import ReelOutput, log | |
| def package_reels(reel_outputs: List[ReelOutput], output_dir: Path) -> Path: | |
| """ | |
| Create a ZIP archive containing all reel MP4s + metadata.json. | |
| Returns the Path to the .zip file. | |
| """ | |
| timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") | |
| zip_path = output_dir / f"StudioX_Reels_{timestamp}.zip" | |
| metadata = { | |
| "generated_at": datetime.now().isoformat(), | |
| "total_reels" : len(reel_outputs), | |
| "reels" : [r.to_dict() for r in reel_outputs], | |
| } | |
| with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as zf: | |
| for reel in reel_outputs: | |
| zf.write(reel.path, reel.filename) | |
| zf.writestr("metadata.json", json.dumps(metadata, indent=2)) | |
| zip_size_mb = zip_path.stat().st_size / 1_048_576 | |
| log("📦", f"ZIP ready: {zip_path.name} ({zip_size_mb:.1f} MB) " | |
| f"— {len(reel_outputs)} reels") | |
| return zip_path | |