Spaces:
Sleeping
Sleeping
| import sys, shutil, argparse | |
| from pathlib import Path | |
| from datetime import datetime | |
| APP_PATH = Path.home() / "Fenix" / "ltx_service.py" | |
| ANCHOR = " shutil.copy(ruta, destino)\n mat = destino" | |
| REPLACEMENT = """ shutil.copy(ruta, destino) | |
| # --- PARCHE: normalizar clip a H.264 + yuv420p --- | |
| import subprocess | |
| destino_norm = destino.replace(".mp4", "_norm.mp4") | |
| cmd = [ | |
| "ffmpeg", "-y", "-i", destino, | |
| "-c:v", "libx264", | |
| "-pix_fmt", "yuv420p", | |
| "-r", "24", | |
| "-vf", "scale=trunc(iw/2)*2:trunc(ih/2)*2", | |
| "-movflags", "+faststart", | |
| destino_norm | |
| ] | |
| r = subprocess.run(cmd, capture_output=True, text=True) | |
| norm_path = Path(destino_norm) | |
| if r.returncode != 0 or not norm_path.exists() or norm_path.stat().st_size < 10_240: | |
| print(f"[LTX] ERROR normalizando {destino}:\\n{r.stderr}", flush=True) | |
| raise RuntimeError(f"Clip normalizado invalido: {destino_norm}") | |
| print(f"[LTX] Normalizado OK: {destino_norm} ({norm_path.stat().st_size // 1024} KB)", flush=True) | |
| destino = destino_norm | |
| # --- FIN PARCHE --- | |
| mat = destino""" | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("--dry-run", action="store_true") | |
| args = parser.parse_args() | |
| original = APP_PATH.read_text(encoding="utf-8") | |
| if ANCHOR not in original: | |
| print("[ERROR] Anclaje no encontrado.") | |
| sys.exit(1) | |
| if "PARCHE: normalizar clip" in original: | |
| print("[INFO] Parche ya aplicado.") | |
| sys.exit(0) | |
| patched = original.replace(ANCHOR, REPLACEMENT, 1) | |
| if args.dry_run: | |
| print("[DRY RUN] Anclaje encontrado. Listo para aplicar.") | |
| sys.exit(0) | |
| backup = Path(str(APP_PATH) + datetime.now().strftime(".bak_%Y%m%d_%H%M%S")) | |
| shutil.copy2(APP_PATH, backup) | |
| print(f"[OK] Backup: {backup}") | |
| APP_PATH.write_text(patched, encoding="utf-8") | |
| print("[OK] Parche aplicado. Ahora: git add ltx_service.py && git commit -m 'fix: normalizar clips LTX' && git push") | |