-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathemitter.py
More file actions
59 lines (48 loc) · 2.04 KB
/
Copy pathemitter.py
File metadata and controls
59 lines (48 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python3
"""Story Forge emitter — resolved IR -> .storyplan.json shape."""
from __future__ import annotations
import json
from pathlib import Path
from typing import Any
SCHEMA_VERSION = "0.1"
def emit_storyplan(resolved: dict[str, Any]) -> dict[str, Any]:
"""Convert the resolver output into the canonical .storyplan.json dict."""
film = resolved["film"]
attrs = film.get("attrs", {})
plan: dict[str, Any] = {
"schema_version": SCHEMA_VERSION,
"film_meta": {
"title": film.get("title", "Untitled"),
"slug": attrs.get("slug", "untitled"),
"target": attrs.get("target", "m5"),
"scene_duration": float(attrs.get("scene_dur", 8.5)),
"extras": {k: v for k, v in attrs.items()
if k not in ("slug", "target", "scene_dur")},
},
"voice_presets": resolved.get("voice_presets", {}),
"music_presets": resolved.get("music_presets", {}),
"sfx_presets": resolved.get("sfx_presets", {}),
"transitions": resolved.get("transitions", []),
"mixes": resolved.get("mixes", []),
"vars": resolved.get("vars", {}),
"scenes": {},
}
for s in resolved.get("scenes", []):
plan["scenes"][s["name"]] = {
"still_spec": s.get("still"),
"motion_spec": s.get("motion"),
# Back-compat: singular narration_spec is the first narrate block
# (or None if the scene has no narration). All narrate blocks live
# in the plural narration_specs list, in declaration order.
"narration_spec": s.get("narrate"),
"narration_specs": s.get("narrates", []),
"music_spec": s.get("music"),
"sfx_specs": s.get("sfx", []),
"attrs": s.get("attrs", {}),
"extras": s.get("extras", {}),
}
return plan
def write_storyplan(plan: dict[str, Any], out_path: Path) -> Path:
out_path = Path(out_path)
out_path.write_text(json.dumps(plan, indent=2, default=str))
return out_path