AI-video-lifeplan-demo/backend/fix_ids.py

38 lines
1.2 KiB
Python

import json
from pathlib import Path
def fix_script_ids():
"""
Specifically re-indexes all script segments in render_props.json
and updates audioPath to match the new ID.
"""
props_path = Path("assets/1_processed/render_props.json")
if not props_path.exists():
print("❌ Error: render_props.json not found.")
return
print(f"📖 Reading {props_path}...")
with open(props_path, "r", encoding="utf-8") as f:
data = json.load(f)
print("🔢 Re-indexing and updating audio paths...")
for i, segment in enumerate(data["script"]):
new_id = i + 1
segment["id"] = new_id
# Only update audioPath if it's not a video clip (which uses original audio)
if segment.get("visualType") != "video":
segment["audioPath"] = f"public/segment_{new_id:03d}.mp3"
else:
# Video clips don't have audioPath in the same way (they use the video asset)
if "audioPath" in segment:
del segment["audioPath"]
with open(props_path, "w", encoding="utf-8") as f:
json.dump(data, f, ensure_ascii=False, indent=2)
print(f"✅ IDs and audio paths fixed in {props_path}.")
if __name__ == "__main__":
fix_script_ids()