conformtools 0.6.4 → 0.6.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. package/README.md +3 -3
  2. package/dist/account-HDXVTS5T.js +3 -0
  3. package/dist/avid-panel/MANIFEST.json +11 -0
  4. package/dist/avid-panel/avid-manifest.json +46 -0
  5. package/dist/avid-panel/icon.svg +4 -0
  6. package/dist/avid-panel/icons/conformtools.svg +4 -0
  7. package/dist/avid-panel/index.html +26 -0
  8. package/dist/avid-panel/panel.css +12 -0
  9. package/dist/avid-panel/panel.js +7 -0
  10. package/dist/bridge-D5KPIUSY.js +3 -0
  11. package/dist/browser/timeline_core_bg.wasm +0 -0
  12. package/dist/chunk-3OCQA33E.js +3 -0
  13. package/dist/chunk-3XD6NC4G.js +10 -0
  14. package/dist/chunk-5JBUCVRI.js +20 -0
  15. package/dist/chunk-5RSNFPED.js +8 -0
  16. package/dist/{chunk-BW2NQ54J.js → chunk-5SUGU2YR.js} +1 -1
  17. package/dist/{chunk-HKP4P6JN.js → chunk-6ML26TIK.js} +1 -1
  18. package/dist/chunk-7MC7M2Y5.js +3 -0
  19. package/dist/chunk-AS7IXHYM.js +19 -0
  20. package/dist/chunk-BL6L5ZBP.js +39 -0
  21. package/dist/chunk-C5IX63YF.js +3 -0
  22. package/dist/chunk-EJGVNQ3E.js +8 -0
  23. package/dist/{chunk-EPZ6NWE4.js → chunk-HGDO3OED.js} +1 -1
  24. package/dist/chunk-JV7TZDKJ.js +3 -0
  25. package/dist/chunk-LFJLRLEP.js +3 -0
  26. package/dist/chunk-NFJHWZJX.js +3 -0
  27. package/dist/{chunk-WT6NIJCB.js → chunk-NQHQKEP5.js} +1 -1
  28. package/dist/chunk-NU3X7P4N.js +3 -0
  29. package/dist/chunk-OJWIBQK4.js +376 -0
  30. package/dist/chunk-OVUCL3YY.js +5 -0
  31. package/dist/chunk-PFISREY4.js +3 -0
  32. package/dist/chunk-PFZVET7S.js +3 -0
  33. package/dist/chunk-PLRB2YXJ.js +3 -0
  34. package/dist/chunk-RFIPLBQ4.js +5 -0
  35. package/dist/chunk-SZD4C5MB.js +6 -0
  36. package/dist/chunk-TXQR2HI2.js +4 -0
  37. package/dist/chunk-UKKRZ574.js +7 -0
  38. package/dist/{chunk-EO5NIBOV.js → chunk-VS3MKKJ5.js} +1 -1
  39. package/dist/{chunk-42QQI3WX.js → chunk-X53BNWNV.js} +1 -1
  40. package/dist/{chunk-QTPCU2TF.js → chunk-XNR7M4VX.js} +1 -1
  41. package/dist/{claude-setup-BM3AAUKR.js → claude-setup-IIWUB4CE.js} +1 -1
  42. package/dist/cli.js +8 -8
  43. package/dist/conformtools-analyze +0 -0
  44. package/dist/conformtools-decode +0 -0
  45. package/dist/{cr3-wasm-WKWMEK3V.js → cr3-wasm-L2LFY3LM.js} +1 -1
  46. package/dist/{dng-wasm-Z5OVO4UI.js → dng-wasm-U6NC3MDK.js} +1 -1
  47. package/dist/{dpx-wasm-QNYXAOAJ.js → dpx-wasm-RMKEUKED.js} +1 -1
  48. package/dist/engine-P6H5P6HP.js +5 -0
  49. package/dist/{exr-wasm-BHSBJLQH.js → exr-wasm-LBAOMOZD.js} +1 -1
  50. package/dist/flame/hook/conformtools_flame/__init__.py +10 -0
  51. package/dist/flame/hook/conformtools_flame/building.py +191 -0
  52. package/dist/flame/hook/conformtools_flame/hook.py +177 -0
  53. package/dist/flame/hook/conformtools_flame/render.py +622 -0
  54. package/dist/flame/hook/conformtools_flame/util.py +33 -0
  55. package/dist/flame/hook/conformtools_flame/verbs.py +1037 -0
  56. package/dist/flame/hook/conformtools_flame_hook.py +42 -0
  57. package/dist/fonts/gfx/BarlowCondensed-Bold.ttf +0 -0
  58. package/dist/fonts/gfx/BarlowCondensed-Regular.ttf +0 -0
  59. package/dist/fonts/gfx/InstrumentSerif-Regular.ttf +0 -0
  60. package/dist/fonts/gfx/Inter-Bold.ttf +0 -0
  61. package/dist/fonts/gfx/Inter-Regular.ttf +0 -0
  62. package/dist/fonts/gfx/JetBrainsMono-Bold.ttf +0 -0
  63. package/dist/fonts/gfx/JetBrainsMono-Regular.ttf +0 -0
  64. package/dist/fonts/gfx/OFL.txt +100 -0
  65. package/dist/framing-SRCJKAYO.js +3 -0
  66. package/dist/gfx-worker.js +3 -0
  67. package/dist/h264-3ESGVT6G.js +3 -0
  68. package/dist/{h264-mxf-MWS7DDV7.js → h264-mxf-NPFS7NGH.js} +1 -1
  69. package/dist/host-relink-D6CB2VOQ.js +10 -0
  70. package/dist/hosts-W4AD2MYH.js +3 -0
  71. package/dist/http.js +3 -2
  72. package/dist/i2o-transfer +0 -0
  73. package/dist/inspect-7ASUPU73.js +68 -0
  74. package/dist/isobmff-SIOE67WL.js +3 -0
  75. package/dist/mcp.js +7 -8
  76. package/dist/media-7AUNRKHF.js +3 -0
  77. package/dist/media_core-Q2PIEV7D.js +9 -0
  78. package/dist/{media_core_bg-FGAR5KA5.js → media_core_bg-FDL7GJZP.js} +1 -1
  79. package/dist/mxf-74TTDICM.js +3 -0
  80. package/dist/nuke/panel/python/Startup/conformtools_nuke_startup.py +44 -0
  81. package/dist/nuke/panel/python/conformtools_nuke/__init__.py +10 -0
  82. package/dist/nuke/panel/python/conformtools_nuke/panel.py +217 -0
  83. package/dist/nuke/panel/python/conformtools_nuke/verbs.py +837 -0
  84. package/dist/{ops-73NR3X6R.js → ops-FSOOBXMV.js} +1 -1
  85. package/dist/peer-kit/ctpeer/__init__.py +21 -0
  86. package/dist/peer-kit/ctpeer/client.py +247 -0
  87. package/dist/peer-kit/ctpeer/neutral.py +178 -0
  88. package/dist/peer-kit/ctpeer/pairing.py +139 -0
  89. package/dist/peer-kit/ctpeer/protocol.py +209 -0
  90. package/dist/peer-kit/ctpeer/websocket.py +289 -0
  91. package/dist/premiere-uxp/index.js +5 -5
  92. package/dist/premiere-uxp/lib/clipmeta.js +6 -6
  93. package/dist/premiere-uxp/lib/ctx.js +30 -24
  94. package/dist/premiere-uxp/lib/edit.js +516 -0
  95. package/dist/premiere-uxp/lib/markers.js +5 -5
  96. package/dist/premiere-uxp/lib/pairing.js +14 -5
  97. package/dist/premiere-uxp/lib/premiere.js +10 -1
  98. package/dist/premiere-uxp/lib/probe.js +102 -0
  99. package/dist/premiere-uxp/lib/render.js +15 -8
  100. package/dist/premiere-uxp/lib/session.js +1 -1
  101. package/dist/premiere-uxp/lib/sizing.js +30 -17
  102. package/dist/premiere-uxp/lib/time.js +7 -1
  103. package/dist/premiere-uxp/lib/timeline.js +2 -2
  104. package/dist/premiere-uxp/lib/verbs.js +3 -2
  105. package/dist/premiere-uxp/lib/write.js +3 -3
  106. package/dist/premiere-uxp/manifest.json +1 -1
  107. package/dist/probe-F7WQHMIA.js +3 -0
  108. package/dist/r3d-YTLOMC7C.js +3 -0
  109. package/dist/{r3d-VUOYU2KQ.js → r3d-ZDJ3WURS.js} +1 -1
  110. package/dist/resolve-bridge.py +1262 -13
  111. package/dist/{still-4G25EYN5.js → still-ZG2RUQAL.js} +1 -1
  112. package/dist/store-ZHXLQCGN.js +3 -0
  113. package/dist/{tiff-wasm-QJPCR7JT.js → tiff-wasm-D2FJ3L56.js} +1 -1
  114. package/dist/timeline-6DYFDVEH.js +3 -0
  115. package/dist/timeline_core-IOENXK4Z.js +3 -0
  116. package/dist/wasm/media_core_bg.wasm +0 -0
  117. package/dist/wasm-threads/media_core_bg.wasm +0 -0
  118. package/dist/wav-OWMUGQMM.js +3 -0
  119. package/package.json +6 -4
  120. package/dist/chunk-6FVGUJ6L.js +0 -3
  121. package/dist/chunk-6TM32YIJ.js +0 -7
  122. package/dist/chunk-BUEIRRNY.js +0 -3
  123. package/dist/chunk-CL26XMDO.js +0 -3
  124. package/dist/chunk-DRHOPOC7.js +0 -3
  125. package/dist/chunk-GXEVALBL.js +0 -3
  126. package/dist/chunk-JB7PR2TQ.js +0 -3
  127. package/dist/chunk-QDWB7QU7.js +0 -3
  128. package/dist/chunk-QTKRMXL5.js +0 -363
  129. package/dist/chunk-SP5RGDAM.js +0 -3
  130. package/dist/chunk-TEZP6VEQ.js +0 -3
  131. package/dist/chunk-Y2BEEOPB.js +0 -3
  132. package/dist/h264-LIZVHN2W.js +0 -3
  133. package/dist/inspect-DZF537QL.js +0 -46
  134. package/dist/isobmff-HM3UPWPZ.js +0 -3
  135. package/dist/media_core-R5PPN3AY.js +0 -9
  136. package/dist/mxf-K465SWBN.js +0 -3
  137. package/dist/onnxruntime-web-stub-PKJ2NZBF.js +0 -3
  138. package/dist/r3d-RR3FUM6H.js +0 -3
  139. package/dist/sscd-embed-DHFTEIOC.js +0 -3
  140. package/dist/sscd-sweep-OYS4XAID.js +0 -3
  141. package/dist/timeline_core-VK2ZWPCO.js +0 -3
  142. package/dist/wav-63QF6SCT.js +0 -3
  143. /package/dist/{arriraw-3GKCR6K2.js → arriraw-YIJ3BYNN.js} +0 -0
  144. /package/dist/{chunk-WHY3DVXS.js → chunk-D6YDLKSA.js} +0 -0
  145. /package/dist/{media_core_bg-YK63OUDM.js → media_core_bg-XRBVKQZH.js} +0 -0
  146. /package/dist/{prores-L4JZZWGH.js → prores-RIG37OIH.js} +0 -0
  147. /package/dist/{timeline_core_bg-2TYWZ35G.js → timeline_core_bg-JW42YM3G.js} +0 -0
  148. /package/dist/{udf_bg-A4WEMSAX.js → udf_bg-B37GKRIH.js} +0 -0
@@ -0,0 +1,837 @@
1
+ """The Nuke Studio / Hiero verb table: the capability verbs of
2
+ `hosts/base.py`, answered from `hiero.core` / `hiero.ui`.
3
+
4
+ Everything here runs on the application's MAIN thread (the client marshals
5
+ each call through `hiero.core.executeInMainThreadWithResult`: Foundry - any
6
+ method on an object attached to a project throws off the main thread). The
7
+ `hiero` package is injected, so the tests drive this file with a fake.
8
+
9
+ Conventions (docs/INTERNAL_HOST_BRIDGE.md "Nuke Studio / Hiero" has the
10
+ evidence for each):
11
+
12
+ * **Timelines** are the project's Sequences, walking `clipsBin()` depth first
13
+ (`Bin.sequences()` then `Bin.bins()`); current = `hiero.ui.activeSequence()`.
14
+ * **Frames** are ABSOLUTE: `Sequence.timecodeStart()` + the sequence-relative
15
+ frame. `TrackItem.timelineOut()` is INCLUSIVE (Foundry's own examples set
16
+ `timelineOut = duration - 1`), so the neutral exclusive end is `+ 1`.
17
+ `sourceIn()` is already frames from the media's first frame - Resolve's
18
+ left offset.
19
+ * **Markers are Tags.** A sequence tag's in/out is its range (sequence
20
+ frames, relative to the start); a track-item tag is a clip marker, its
21
+ in/out in source frames (`TrackItem.addTagToRange` is documented that way).
22
+ A tag with no range is not a marker and is not listed. Name and note are
23
+ the tag's own; the exact neutral colour and the custom data live in the
24
+ tag's metadata (`ct.color`, `ct.custom_data`), so they round-trip exactly;
25
+ the ICON shows the colour in Hiero and is lossy (six colours).
26
+ * **Undo**: every write is one `Project.beginUndo` / `endUndo` group; a
27
+ batch rename is one group.
28
+ """
29
+
30
+ from __future__ import annotations
31
+
32
+ import os
33
+ from typing import Any, Callable, Dict, List, Optional, Tuple
34
+
35
+ from ctpeer import Handles, PeerError
36
+ from ctpeer import neutral as N
37
+
38
+ MODEL_SCHEMA = 1
39
+ CAPABILITIES = ["session", "timeline_read", "markers", "clip_meta", "timeline_write"]
40
+ #: The optional verbs (`hosts/base.py` OPTIONAL) Hiero really answers.
41
+ OPTIONAL_VERBS = [
42
+ "session.project_names",
43
+ "timeline_read.set_current_frame", "timeline_read.item_media", "timeline_read.end_frame",
44
+ "timeline_read.start_timecode", "timeline_read.item_enabled", "timeline_read.track_enabled",
45
+ "timeline_read.track_name", "timeline_read.item_source_end", "timeline_read.item_right_offset",
46
+ "timeline_read.item_track", "timeline_read.item_clip", "timeline_read.linked_items",
47
+ "timeline_read.selected_items", "timeline_read.item_speed",
48
+ "clip_meta.set_clip_properties", "clip_meta.clip_info", "clip_meta.metadata",
49
+ "timeline_write.import_file",
50
+ ]
51
+
52
+ #: Hiero's built-in colour tag icons (the shipped tag presets).
53
+ ICONS = {"Red": "icons:TagRed.png", "Green": "icons:TagGreen.png", "Blue": "icons:TagBlue.png",
54
+ "Cyan": "icons:TagCyan.png", "Magenta": "icons:TagMagenta.png", "Yellow": "icons:TagYellow.png"}
55
+ #: Neutral name -> the nearest Hiero icon colour (lossy: 16 names, 6 icons).
56
+ NEUTRAL_TO_ICON = {"Blue": "Blue", "Cyan": "Cyan", "Green": "Green", "Yellow": "Yellow", "Red": "Red", "Pink": "Magenta",
57
+ "Purple": "Magenta", "Fuchsia": "Magenta", "Rose": "Red", "Lavender": "Blue", "Sky": "Cyan", "Mint": "Green",
58
+ "Lemon": "Yellow", "Sand": "Yellow", "Cocoa": "Red", "Cream": "Yellow"}
59
+ #: An icon colour read back when the tag carries no `ct.color` (a user's tag).
60
+ ICON_TO_NEUTRAL = {"Red": "Red", "Green": "Green", "Blue": "Blue", "Cyan": "Cyan", "Magenta": "Pink", "Yellow": "Yellow"}
61
+ MD_COLOR = "ct.color"
62
+ MD_CUSTOM = "ct.custom_data"
63
+
64
+ #: Sequence files `Bin.importSequence` reads (Foundry: EDL, XML = Final Cut
65
+ #: Pro 7 XML, AAF, OTIO). FCPXML is not among them.
66
+ IMPORTABLE = (".xml", ".edl", ".aaf", ".otio")
67
+ WRITABLE_CLIP_PROPS = ("Clip Name",)
68
+
69
+
70
+ def icon_color(icon: str) -> str:
71
+ """`"icons:TagRed.png"` -> `"Red"`, anything else -> `""`."""
72
+ base = os.path.basename(str(icon or ""))
73
+ if base.startswith("icons:"):
74
+ base = base[len("icons:"):]
75
+ if base.startswith("Tag") and base.endswith(".png"):
76
+ return base[3:-4]
77
+ return ""
78
+
79
+
80
+ class NukePeer:
81
+ def __init__(self, hiero: Any):
82
+ self.hiero = hiero
83
+ self.core = hiero.core
84
+ self.ui = getattr(hiero, "ui", None)
85
+ self.handles = Handles()
86
+ #: item handle id -> (its Sequence - the clock its frames are on -, kind, track index)
87
+ self._owner: Dict[str, Tuple[Any, str, int]] = {}
88
+
89
+ # ── plumbing ────────────────────────────────────────────────────────
90
+ def verbs(self) -> Dict[str, Callable[..., Any]]:
91
+ table: Dict[str, Callable[..., Any]] = {}
92
+ for name in dir(self):
93
+ if name.startswith("v_"):
94
+ cap, _, verb = name[2:].partition("__")
95
+ table[f"{cap}.{verb}"] = getattr(self, name)
96
+ return table
97
+
98
+ @staticmethod
99
+ def _guid(obj: Any) -> str:
100
+ try:
101
+ g = obj.guid()
102
+ return str(g) if g else ""
103
+ except Exception:
104
+ return ""
105
+
106
+ def _wrap(self, kind: str, obj: Any) -> Any:
107
+ g = self._guid(obj)
108
+ return self.handles.wrap(kind, obj, ("guid", g) if g else None)
109
+
110
+ def _is_sequence(self, obj: Any) -> bool:
111
+ return isinstance(obj, self.core.Sequence)
112
+
113
+ def _undo(self, project: Any, label: str):
114
+ return _Undo(project, f"CONFORM.TOOLS: {label}")
115
+
116
+ # ── projects and sequences ──────────────────────────────────────────
117
+ def _projects(self) -> List[Any]:
118
+ return list(self.core.projects() or [])
119
+
120
+ def _active_sequence(self) -> Optional[Any]:
121
+ try:
122
+ return self.ui.activeSequence() if self.ui is not None else None
123
+ except Exception:
124
+ return None
125
+
126
+ def _bin_sequences(self, b: Any) -> List[Any]:
127
+ out = []
128
+ for bi in b.sequences() or []:
129
+ item = bi.activeItem()
130
+ if item is not None and self._is_sequence(item):
131
+ out.append(item)
132
+ for sub in b.bins() or []:
133
+ out += self._bin_sequences(sub)
134
+ return out
135
+
136
+ def _sequences(self, project: Any) -> List[Any]:
137
+ return self._bin_sequences(project.clipsBin())
138
+
139
+ def _project_of(self, seq: Any) -> Optional[Any]:
140
+ g = self._guid(seq)
141
+ for p in self._projects():
142
+ if any(s is seq or (g and self._guid(s) == g) for s in self._sequences(p)):
143
+ return p
144
+ return None
145
+
146
+ def _current_project(self) -> Optional[Any]:
147
+ seq = self._active_sequence()
148
+ if seq is not None:
149
+ p = self._project_of(seq)
150
+ if p is not None:
151
+ return p
152
+ projects = self._projects()
153
+ return projects[-1] if projects else None
154
+
155
+ def _project(self, handle: Any = None) -> Any:
156
+ if handle:
157
+ return self.handles.get(handle, "project")
158
+ p = self._current_project()
159
+ if p is None:
160
+ raise PeerError("no_project", "No project open")
161
+ return p
162
+
163
+ def _seq(self, handle: Any) -> Any:
164
+ return self.handles.get(handle, "seq")
165
+
166
+ # ── time ────────────────────────────────────────────────────────────
167
+ @staticmethod
168
+ def _fps(obj: Any) -> float:
169
+ try:
170
+ return float(obj.framerate().toFloat())
171
+ except Exception:
172
+ return 24.0
173
+
174
+ @staticmethod
175
+ def _drop(seq: Any) -> bool:
176
+ try:
177
+ return bool(seq.dropFrame())
178
+ except Exception:
179
+ return False
180
+
181
+ @staticmethod
182
+ def _start(seq: Any) -> int:
183
+ try:
184
+ return int(seq.timecodeStart())
185
+ except Exception:
186
+ return 0
187
+
188
+ def _viewer_time(self, seq: Any) -> Optional[int]:
189
+ """The playhead (sequence-relative) when the current viewer shows `seq`."""
190
+ try:
191
+ viewer = self.ui.currentViewer()
192
+ shown = viewer.player(0).sequence()
193
+ if shown is not seq and self._guid(shown) != self._guid(seq):
194
+ return None
195
+ return int(viewer.time())
196
+ except Exception:
197
+ return None
198
+
199
+ # ── items ───────────────────────────────────────────────────────────
200
+ def _tracks(self, seq: Any, kind: str) -> List[Any]:
201
+ return list(seq.audioTracks() if str(kind or "video").lower() == "audio" else seq.videoTracks())
202
+
203
+ def _track_items(self, track: Any) -> List[Any]:
204
+ return [it for it in (track.items() or []) if isinstance(it, self.core.TrackItem)]
205
+
206
+ def _item(self, seq: Any, kind: str, ti: int, it: Any) -> Any:
207
+ h = self._wrap("item", it)
208
+ self._owner[self.handles.id_of(h)] = (seq, "audio" if str(kind).lower() == "audio" else "video", int(ti))
209
+ return h
210
+
211
+ def _it(self, handle: Any) -> Tuple[Any, Any]:
212
+ it = self.handles.get(handle, "item")
213
+ owner = self._owner.get(self.handles.id_of(handle))
214
+ seq = owner[0] if owner else None
215
+ if seq is None:
216
+ try:
217
+ seq = it.parentSequence()
218
+ except Exception:
219
+ seq = None
220
+ return it, seq
221
+
222
+ def _times(self, it: Any, seq: Any) -> Dict[str, Any]:
223
+ start = self._start(seq) if seq is not None else 0
224
+ t_in, t_out = int(it.timelineIn()), int(it.timelineOut())
225
+ speed = float(it.playbackSpeed() or 1.0)
226
+ s_in, s_out = float(it.sourceIn()), float(it.sourceOut())
227
+ lo = s_out if speed < 0 else s_in
228
+ return {"start": start + t_in, "end": start + t_out + 1, "src_in": int(round(lo)), "src_out": int(round(max(s_in, s_out))) + 1,
229
+ "speed": speed}
230
+
231
+ def _media(self, it: Any) -> Dict[str, Any]:
232
+ out: Dict[str, Any] = {}
233
+ try:
234
+ clip = it.source()
235
+ except Exception:
236
+ clip = None
237
+ if clip is None:
238
+ return out
239
+ if self._is_sequence(clip):
240
+ return {"id": self._guid(clip), "name": _call(clip, "name", ""), "type": "compound", "fps": self._fps(clip)}
241
+ ms = None
242
+ try:
243
+ ms = clip.mediaSource()
244
+ except Exception:
245
+ ms = None
246
+ out["name"] = _call(clip, "name", "")
247
+ out["id"] = self._guid(clip) or out["name"]
248
+ out["fps"] = self._fps(clip)
249
+ if ms is not None:
250
+ out["file_path"] = _call(ms, "firstpath", "") or _call(ms, "filename", "")
251
+ tcs = _call(ms, "timecodeStart", None)
252
+ out["start_tc"] = int(tcs) if tcs is not None else None
253
+ dur = _call(ms, "duration", None)
254
+ if dur is not None:
255
+ out["frames"] = int(dur)
256
+ out["offline"] = bool(out.get("file_path")) and bool(_call(ms, "isOffline", False))
257
+ out["reel"] = self._reel(ms) or self._reel(clip)
258
+ w, h = _call(ms, "width", 0), _call(ms, "height", 0)
259
+ if w and h:
260
+ out["resolution"] = f"{int(w)}x{int(h)}"
261
+ out["type"] = "still" if out.get("frames") == 1 else "video"
262
+ return {k: v for k, v in out.items() if v not in (None, "")}
263
+
264
+ @staticmethod
265
+ def _reel(obj: Any) -> str:
266
+ try:
267
+ md = obj.metadata()
268
+ for key in ("foundry.source.reelID", "foundry.edl.sourceReel"):
269
+ if md.hasKey(key):
270
+ return str(md.value(key) or "")
271
+ except Exception:
272
+ pass
273
+ return ""
274
+
275
+ # ── session ─────────────────────────────────────────────────────────
276
+ def v_session__current_project(self) -> Any:
277
+ p = self._current_project()
278
+ return self._wrap("project", p) if p is not None else None
279
+
280
+ def v_session__current_timeline(self, project: Any = None) -> Any:
281
+ p = self._project(project)
282
+ seqs = self._sequences(p)
283
+ active = self._active_sequence()
284
+ if active is not None:
285
+ g = self._guid(active)
286
+ for s in seqs:
287
+ if s is active or (g and self._guid(s) == g):
288
+ return self._wrap("seq", s)
289
+ return self._wrap("seq", seqs[0]) if seqs else None
290
+
291
+ def v_session__timeline_count(self, project: Any = None) -> int:
292
+ return len(self._sequences(self._project(project)))
293
+
294
+ def v_session__timeline_by_index(self, project: Any = None, index: int = 1) -> Any:
295
+ seqs = self._sequences(self._project(project))
296
+ i = int(index)
297
+ return self._wrap("seq", seqs[i - 1]) if 1 <= i <= len(seqs) else None
298
+
299
+ def v_session__set_current_timeline(self, project: Any = None, timeline: Any = None) -> bool:
300
+ seq = self._seq(timeline)
301
+ opened = False
302
+ opener = getattr(self.ui, "openInTimeline", None)
303
+ if callable(opener):
304
+ try:
305
+ opener(seq.binItem())
306
+ opened = True
307
+ except Exception:
308
+ opened = False
309
+ if not opened:
310
+ try:
311
+ self.ui.currentViewer().setSequence(seq)
312
+ opened = True
313
+ except Exception:
314
+ return False
315
+ active = self._active_sequence()
316
+ return active is seq or (active is not None and self._guid(active) == self._guid(seq))
317
+
318
+ def v_session__name(self, handle: Any) -> str:
319
+ obj = self.handles.get(handle)
320
+ return str(_call(obj, "name", "") or "")
321
+
322
+ def v_session__set_name(self, handle: Any, name: str) -> bool:
323
+ kind = self.handles.kind_of(handle)
324
+ obj = self.handles.get(handle)
325
+ if kind == "project":
326
+ return False # a project's name is its file name in Hiero
327
+ project = self._current_project()
328
+ with self._undo(project, f"rename to {name}"):
329
+ obj.setName(str(name))
330
+ if kind == "clip":
331
+ active = _call(obj, "activeItem", None)
332
+ if active is not None:
333
+ active.setName(str(name))
334
+ return str(obj.name()) == str(name)
335
+
336
+ def v_session__project_names(self) -> List[str]:
337
+ return [str(_call(p, "name", "") or "") for p in self._projects()]
338
+
339
+ def v_session__unique_id(self, handle: Any) -> str:
340
+ obj = self.handles.get(handle)
341
+ return self._guid(obj) or self.handles.id_of(handle)
342
+
343
+ # ── timeline_read ───────────────────────────────────────────────────
344
+ def v_timeline_read__model(self, timeline: Any, project: Any = None) -> Dict[str, Any]:
345
+ seq = self._seq(timeline)
346
+ fps, drop, start = self._fps(seq), self._drop(seq), self._start(seq)
347
+ fmt = _call(seq, "format", None)
348
+ raster = [int(_call(fmt, "width", 0) or 0), int(_call(fmt, "height", 0) or 0)] if fmt is not None else [0, 0]
349
+ items, tracks, states = [], [], {}
350
+ for ti, track in enumerate(self._tracks(seq, "video"), 1):
351
+ enabled = bool(_call(track, "isEnabled", True))
352
+ states[str(ti)] = enabled
353
+ rows = []
354
+ for it in self._track_items(track):
355
+ row = self._row(seq, ti, it, enabled)
356
+ if row["end"] > row["start"]:
357
+ rows.append(row)
358
+ items.append(row)
359
+ tracks.append({"index": ti, "enabled": enabled, "items": rows, "name": str(_call(track, "name", "") or "")})
360
+ audio = []
361
+ for ai, track in enumerate(self._tracks(seq, "audio"), 1):
362
+ for it in self._track_items(track):
363
+ t = self._times(it, seq)
364
+ audio.append({"track": ai, "name": str(it.name()), "start": t["start"], "end": t["end"],
365
+ "file_path": self._media(it).get("file_path", "")})
366
+ items.sort(key=lambda r: (r["start"], r["track"]))
367
+ return {
368
+ "model_schema": MODEL_SCHEMA, "timeline": str(seq.name()), "start_frame": start, "fps": fps, "drop_frame": drop,
369
+ "items": items, "tracks": tracks, "track_states": states, "transitions": [], "audio_items": audio,
370
+ "audio_track_count": len(self._tracks(seq, "audio")), "playhead": self._playhead_abs(seq),
371
+ "source": "nuke", "format": "nuke", "raster": raster, "sizing_basis": None, "markers": {},
372
+ "timelines": [], "timeline_index": None,
373
+ }
374
+
375
+ def _row(self, seq: Any, ti: int, it: Any, track_enabled: bool) -> Dict[str, Any]:
376
+ t = self._times(it, seq)
377
+ media = self._media(it)
378
+ dur = max(1, t["end"] - t["start"])
379
+ src_len = max(1, t["src_out"] - t["src_in"])
380
+ speed = t["speed"]
381
+ handle = self._item(seq, "video", ti, it)
382
+ start_tc = media.get("start_tc")
383
+ src_fps = float(media.get("fps") or self._fps(seq))
384
+ path = media.get("file_path", "")
385
+ return {
386
+ "clip_id": handle["$h"], "name": str(it.name()), "mpi_id": media.get("id", ""), "track": ti,
387
+ "start": t["start"], "end": t["end"], "enabled": bool(_call(it, "isEnabled", True)), "track_enabled": track_enabled,
388
+ "src_in": t["src_in"], "src_out": t["src_in"] + src_len, "src_relative": True,
389
+ "src_abs_in": start_tc + t["src_in"] if start_tc is not None else None,
390
+ "src_abs_out": start_tc + t["src_in"] + src_len if start_tc is not None else None,
391
+ "speed": round(abs(speed), 4), "speed_derived": round(src_len / dur, 4),
392
+ "fps_factor": round(src_fps / self._fps(seq), 6) if self._fps(seq) else 1.0,
393
+ "speed_reported": round(abs(speed), 4), "speed_is_variable": False, "speed_listed": True, "reversed": speed < 0,
394
+ "sizing": None, "nodes": None, "markers": {}, "flags": [], "color": "",
395
+ "reel": media.get("reel", ""), "file_name": os.path.basename(path) if path else "", "file_path": path,
396
+ "start_tc": start_tc, "source_id": media.get("id", ""), "nested": self._is_sequence(_call(it, "source", None)),
397
+ "item": None, "src_fps": src_fps, "offline": bool(media.get("offline", False)), "handle": handle,
398
+ }
399
+
400
+ def _playhead_abs(self, seq: Any) -> Optional[int]:
401
+ t = self._viewer_time(seq)
402
+ return None if t is None else self._start(seq) + t
403
+
404
+ def v_timeline_read__start_frame(self, timeline: Any) -> int:
405
+ return self._start(self._seq(timeline))
406
+
407
+ def v_timeline_read__setting(self, handle: Any, key: str) -> Any:
408
+ seq = self._seq(handle)
409
+ fps = self._fps(seq)
410
+ fmt = _call(seq, "format", None)
411
+ w, h = (int(_call(fmt, "width", 0) or 0), int(_call(fmt, "height", 0) or 0)) if fmt is not None else (0, 0)
412
+ table = {"timelineFrameRate": fps, "timelineResolutionWidth": w, "timelineResolutionHeight": h,
413
+ "timelineOutputResolutionWidth": w, "timelineOutputResolutionHeight": h,
414
+ "timelineDropFrameTimecode": "1" if self._drop(seq) else "0", "timelinePlaybackFrameRate": fps}
415
+ return table.get(str(key))
416
+
417
+ def v_timeline_read__track_count(self, timeline: Any, kind: str = "video") -> int:
418
+ return len(self._tracks(self._seq(timeline), kind))
419
+
420
+ def v_timeline_read__items_in_track(self, timeline: Any, kind: str = "video", index: int = 1) -> List[Any]:
421
+ seq = self._seq(timeline)
422
+ tracks = self._tracks(seq, kind)
423
+ i = int(index)
424
+ if not 1 <= i <= len(tracks):
425
+ return []
426
+ return [self._item(seq, kind, i, it) for it in self._track_items(tracks[i - 1])]
427
+
428
+ def v_timeline_read__item_start(self, item: Any) -> int:
429
+ it, seq = self._it(item)
430
+ return self._times(it, seq)["start"]
431
+
432
+ def v_timeline_read__item_end(self, item: Any) -> int:
433
+ it, seq = self._it(item)
434
+ return self._times(it, seq)["end"]
435
+
436
+ def v_timeline_read__item_left_offset(self, item: Any) -> int:
437
+ it, seq = self._it(item)
438
+ return self._times(it, seq)["src_in"]
439
+
440
+ def v_timeline_read__item_source_start(self, item: Any) -> int:
441
+ it, seq = self._it(item)
442
+ tc = self._media(it).get("start_tc")
443
+ return (int(tc) if tc is not None else 0) + self._times(it, seq)["src_in"]
444
+
445
+ def v_timeline_read__item_media(self, item: Any) -> Dict[str, Any]:
446
+ it, _ = self._it(item)
447
+ return self._media(it)
448
+
449
+ def v_timeline_read__current_timecode(self, timeline: Any) -> str:
450
+ seq = self._seq(timeline)
451
+ ph = self._playhead_abs(seq)
452
+ return N.frames_to_tc(ph if ph is not None else self._start(seq), self._fps(seq), self._drop(seq))
453
+
454
+ def _set_playhead(self, seq: Any, frame: int) -> bool:
455
+ try:
456
+ viewer = self.ui.currentViewer()
457
+ shown = viewer.player(0).sequence()
458
+ if shown is not seq and self._guid(shown) != self._guid(seq):
459
+ viewer.setSequence(seq)
460
+ viewer.setTime(int(frame) - self._start(seq))
461
+ except Exception:
462
+ return False
463
+ return self._playhead_abs(seq) == int(frame)
464
+
465
+ def v_timeline_read__set_current_timecode(self, timeline: Any, timecode: str) -> bool:
466
+ seq = self._seq(timeline)
467
+ try:
468
+ frame = N.tc_to_frames(timecode, self._fps(seq), self._drop(seq))
469
+ except ValueError as e:
470
+ raise PeerError("bad_params", str(e))
471
+ return self._set_playhead(seq, frame)
472
+
473
+ def v_timeline_read__set_current_frame(self, timeline: Any, frame: int) -> bool:
474
+ return self._set_playhead(self._seq(timeline), int(frame))
475
+
476
+ def v_timeline_read__current_video_item(self, timeline: Any) -> Any:
477
+ seq = self._seq(timeline)
478
+ ph = self._playhead_abs(seq)
479
+ if ph is None:
480
+ return None
481
+ tracks = self._tracks(seq, "video")
482
+ for ti in range(len(tracks), 0, -1):
483
+ for it in self._track_items(tracks[ti - 1]):
484
+ t = self._times(it, seq)
485
+ if t["start"] <= ph < t["end"]:
486
+ return self._item(seq, "video", ti, it)
487
+ return None
488
+
489
+ def v_timeline_read__end_frame(self, timeline: Any) -> Optional[int]:
490
+ seq = self._seq(timeline)
491
+ dur = _call(seq, "duration", None)
492
+ return self._start(seq) + int(dur) if dur is not None else None
493
+
494
+ def v_timeline_read__start_timecode(self, timeline: Any) -> str:
495
+ seq = self._seq(timeline)
496
+ return N.frames_to_tc(self._start(seq), self._fps(seq), self._drop(seq))
497
+
498
+ def v_timeline_read__item_enabled(self, item: Any) -> bool:
499
+ it, _ = self._it(item)
500
+ return bool(_call(it, "isEnabled", True))
501
+
502
+ def _track_at(self, timeline: Any, kind: str, index: int) -> Optional[Any]:
503
+ tracks = self._tracks(self._seq(timeline), kind)
504
+ i = int(index)
505
+ return tracks[i - 1] if 1 <= i <= len(tracks) else None
506
+
507
+ def v_timeline_read__track_enabled(self, timeline: Any, kind: str = "video", index: int = 1) -> Optional[bool]:
508
+ track = self._track_at(timeline, kind, index)
509
+ return None if track is None else bool(_call(track, "isEnabled", True))
510
+
511
+ def v_timeline_read__track_name(self, timeline: Any, kind: str = "video", index: int = 1) -> str:
512
+ track = self._track_at(timeline, kind, index)
513
+ return str(_call(track, "name", "") or "") if track is not None else ""
514
+
515
+ def v_timeline_read__item_source_end(self, item: Any) -> Optional[int]:
516
+ it, seq = self._it(item)
517
+ tc = self._media(it).get("start_tc")
518
+ return (int(tc) if tc is not None else 0) + self._times(it, seq)["src_out"]
519
+
520
+ def v_timeline_read__item_right_offset(self, item: Any) -> Optional[int]:
521
+ it, seq = self._it(item)
522
+ frames = self._media(it).get("frames")
523
+ return max(0, int(frames) - self._times(it, seq)["src_out"]) if frames is not None else None
524
+
525
+ def v_timeline_read__item_track(self, item: Any) -> Optional[List[Any]]:
526
+ self.handles.get(item, "item")
527
+ owner = self._owner.get(self.handles.id_of(item))
528
+ return [owner[1], owner[2]] if owner else None
529
+
530
+ def v_timeline_read__item_clip(self, item: Any) -> Any:
531
+ """The bin item behind a track item - the `clip_meta` handle."""
532
+ it, _ = self._it(item)
533
+ clip = _call(it, "source", None)
534
+ bi = _call(clip, "binItem", None) if clip is not None else None
535
+ return self._wrap("clip", bi) if bi is not None else None
536
+
537
+ def _wrap_any_item(self, it: Any) -> Any:
538
+ seq = _call(it, "parentSequence", None)
539
+ track = _call(it, "parent", None)
540
+ kind = "audio" if isinstance(track, getattr(self.core, "AudioTrack", ())) else "video"
541
+ ti = 0
542
+ if seq is not None and track is not None:
543
+ tracks = self._tracks(seq, kind)
544
+ ti = next((i for i, t in enumerate(tracks, 1) if t is track or self._guid(t) == self._guid(track)), 0)
545
+ return self._item(seq, kind, ti, it)
546
+
547
+ def v_timeline_read__linked_items(self, item: Any) -> List[Any]:
548
+ it, _ = self._it(item)
549
+ fn = getattr(it, "linkedItems", None)
550
+ return [self._wrap_any_item(x) for x in (fn() if callable(fn) else []) or []]
551
+
552
+ def v_timeline_read__selected_items(self, timeline: Any) -> List[Any]:
553
+ """The selection in the sequence's timeline editor
554
+ (`hiero.ui.getTimelineEditor(seq).selection()`)."""
555
+ seq = self._seq(timeline)
556
+ get_editor = getattr(self.ui, "getTimelineEditor", None)
557
+ if not callable(get_editor):
558
+ return []
559
+ try:
560
+ selection = get_editor(seq).selection() or []
561
+ except Exception:
562
+ return []
563
+ return [self._wrap_any_item(x) for x in selection if isinstance(x, self.core.TrackItem)]
564
+
565
+ def v_timeline_read__item_speed(self, item: Any, timeline_fps: Optional[float] = None) -> Dict[str, Any]:
566
+ it, _ = self._it(item)
567
+ speed = float(_call(it, "playbackSpeed", 1.0) or 0.0)
568
+ return {"factor": speed, "reversed": speed < 0, "variable": False}
569
+
570
+ # ── markers (tags) ──────────────────────────────────────────────────
571
+ def _marker_target(self, target: Any) -> Tuple[Any, Any, str]:
572
+ kind = self.handles.kind_of(target)
573
+ if kind == "seq":
574
+ seq = self._seq(target)
575
+ return seq, seq, "timeline"
576
+ if kind == "item":
577
+ it, seq = self._it(target)
578
+ return it, seq, "clip"
579
+ raise PeerError("bad_handle", f"tags live on a sequence or a track item, not a {kind or 'non-handle'}")
580
+
581
+ @staticmethod
582
+ def _range(tag: Any) -> Optional[Tuple[int, int]]:
583
+ try:
584
+ a, b = tag.inTime(), tag.outTime()
585
+ except Exception:
586
+ return None
587
+ if a is None or b is None or int(a) < 0 or int(b) < int(a):
588
+ return None
589
+ return int(a), int(b)
590
+
591
+ @staticmethod
592
+ def _md(tag: Any, key: str) -> str:
593
+ try:
594
+ md = tag.metadata()
595
+ return str(md.value(key)) if md.hasKey(key) else ""
596
+ except Exception:
597
+ return ""
598
+
599
+ def _tag_record(self, tag: Any, scope: str) -> Optional[Dict[str, Any]]:
600
+ r = self._range(tag)
601
+ if r is None:
602
+ return None
603
+ color = self._md(tag, MD_COLOR) or ICON_TO_NEUTRAL.get(icon_color(_call(tag, "icon", "")), "")
604
+ return {"frame": r[0], "color": color, "name": str(_call(tag, "name", "") or ""), "note": str(_call(tag, "note", "") or ""),
605
+ "duration": r[1] - r[0] + 1, "custom_data": self._md(tag, MD_CUSTOM), "scope": scope,
606
+ "keywords": icon_color(_call(tag, "icon", ""))}
607
+
608
+ def v_markers__list(self, target: Any) -> List[Dict[str, Any]]:
609
+ holder, _, scope = self._marker_target(target)
610
+ out = [r for r in (self._tag_record(t, scope) for t in (holder.tags() or [])) if r is not None]
611
+ out.sort(key=lambda r: r["frame"])
612
+ return out
613
+
614
+ def _find_tag(self, holder: Any, frame: int) -> Optional[Any]:
615
+ for tag in holder.tags() or []:
616
+ r = self._range(tag)
617
+ if r is not None and r[0] == int(frame):
618
+ return tag
619
+ return None
620
+
621
+ def v_markers__add(self, target: Any, frame: int, color: str = "", name: str = "", note: str = "", duration: int = 1, custom_data: str = "") -> bool:
622
+ holder, seq, scope = self._marker_target(target)
623
+ if self._find_tag(holder, frame) is not None:
624
+ return False
625
+ frame, dur = int(frame), max(1, int(duration or 1))
626
+ if scope == "clip":
627
+ t = self._times(holder, seq)
628
+ if not t["src_in"] <= frame < t["src_out"]:
629
+ return False # a clip tag is kept inside the visible source range
630
+ canon = N.canonical_color(color)
631
+ icon = ICONS.get(NEUTRAL_TO_ICON.get(canon, ""), "icons:TagNote.png")
632
+ tag = self.core.Tag(str(name or "Marker"), icon)
633
+ tag.setNote(str(note or ""))
634
+ self._stamp(tag, canon, custom_data)
635
+ project = self._project_of(seq) if seq is not None else self._current_project()
636
+ with self._undo(project, f"add marker {name}"):
637
+ added = holder.addTagToRange(tag, frame, frame + dur - 1)
638
+ if added is not None and added is not tag:
639
+ self._stamp(added, canon, custom_data) # Hiero may store a copy
640
+ return self._find_tag(holder, frame) is not None
641
+
642
+ @staticmethod
643
+ def _stamp(tag: Any, color: str, custom: str) -> None:
644
+ md = tag.metadata()
645
+ if color:
646
+ md.setValue(MD_COLOR, color)
647
+ if custom:
648
+ md.setValue(MD_CUSTOM, str(custom))
649
+
650
+ def v_markers__delete_at(self, target: Any, frame: int) -> bool:
651
+ holder, seq, _ = self._marker_target(target)
652
+ tag = self._find_tag(holder, frame)
653
+ if tag is None:
654
+ return False
655
+ project = self._project_of(seq) if seq is not None else self._current_project()
656
+ with self._undo(project, "delete marker"):
657
+ holder.removeTag(tag)
658
+ return self._find_tag(holder, frame) is None
659
+
660
+ # ── clip_meta ───────────────────────────────────────────────────────
661
+ def v_clip_meta__media_pool(self, project: Any = None) -> Any:
662
+ p = self._project(project)
663
+ return self._wrap("project", p)
664
+
665
+ def v_clip_meta__root_folder(self, media_pool: Any) -> Any:
666
+ p = self.handles.get(media_pool, "project")
667
+ return self._wrap("bin", p.clipsBin())
668
+
669
+ def v_clip_meta__current_folder(self, media_pool: Any) -> Any:
670
+ return self.v_clip_meta__root_folder(media_pool) # Hiero has no "current bin" in the API; the root stands in
671
+
672
+ def v_clip_meta__subfolders(self, folder: Any) -> List[Any]:
673
+ b = self.handles.get(folder, "bin")
674
+ return [self._wrap("bin", sub) for sub in (b.bins() or [])]
675
+
676
+ def v_clip_meta__clips(self, folder: Any) -> List[Any]:
677
+ b = self.handles.get(folder, "bin")
678
+ out = [self._wrap("clip", bi) for bi in (b.clips() or [])]
679
+ out += [self._wrap("clip", bi) for bi in (b.sequences() or [])]
680
+ return out
681
+
682
+ def _clip_props(self, bi: Any) -> Dict[str, Any]:
683
+ item = _call(bi, "activeItem", None)
684
+ is_seq = item is not None and self._is_sequence(item)
685
+ props: Dict[str, Any] = {"Clip Name": str(bi.name()), "Type": "Timeline" if is_seq else "Video", "File Path": ""}
686
+ if item is not None and not is_seq:
687
+ ms = _call(item, "mediaSource", None)
688
+ fps = self._fps(item)
689
+ props["FPS"] = fps
690
+ if ms is not None:
691
+ props["File Path"] = _call(ms, "firstpath", "") or _call(ms, "filename", "")
692
+ tcs = _call(ms, "timecodeStart", None)
693
+ if tcs is not None:
694
+ props["Start TC"] = N.frames_to_tc(int(tcs), fps)
695
+ w, h = _call(ms, "width", 0), _call(ms, "height", 0)
696
+ if w and h:
697
+ props["Resolution"] = f"{int(w)}x{int(h)}"
698
+ dur = _call(ms, "duration", None)
699
+ if dur is not None:
700
+ props["Frames"] = int(dur)
701
+ props["Reel Name"] = self._reel(ms) or self._reel(item)
702
+ if not ms or _call(ms, "isOffline", False):
703
+ props["Offline"] = True
704
+ return props
705
+
706
+ def v_clip_meta__clip_info(self, clip: Any) -> Dict[str, Any]:
707
+ """`base.MEDIA_KEYS` + `used` (a track item of some sequence in the
708
+ project shows this clip)."""
709
+ bi = self.handles.get(clip, "clip")
710
+ item = _call(bi, "activeItem", None)
711
+ out: Dict[str, Any] = {"id": self._guid(item) or self._guid(bi), "name": str(_call(bi, "name", "") or "")}
712
+ if item is not None and self._is_sequence(item):
713
+ out.update({"type": "compound", "fps": self._fps(item), "used": False})
714
+ return out
715
+ ms = _call(item, "mediaSource", None) if item is not None else None
716
+ out["fps"] = self._fps(item) if item is not None else None
717
+ if ms is not None:
718
+ path = _call(ms, "firstpath", "") or _call(ms, "filename", "")
719
+ frames = _call(ms, "duration", None)
720
+ w, h = _call(ms, "width", 0), _call(ms, "height", 0)
721
+ out.update({"file_path": path, "start_tc": _call(ms, "timecodeStart", None), "frames": frames,
722
+ "reel": self._reel(ms) or self._reel(item), "resolution": f"{int(w)}x{int(h)}" if w and h else None,
723
+ "type": "still" if frames == 1 else "video", "offline": bool(path) and bool(_call(ms, "isOffline", False))})
724
+ out["used"] = self._used(item)
725
+ return {k: v for k, v in out.items() if v not in (None, "")}
726
+
727
+ def _used(self, clip: Any) -> bool:
728
+ if clip is None:
729
+ return False
730
+ g = self._guid(clip)
731
+ for p in self._projects():
732
+ for seq in self._sequences(p):
733
+ for kind in ("video", "audio"):
734
+ for track in self._tracks(seq, kind):
735
+ for it in self._track_items(track):
736
+ src = _call(it, "source", None)
737
+ if src is clip or (g and self._guid(src) == g):
738
+ return True
739
+ return False
740
+
741
+ def v_clip_meta__metadata(self, clip: Any, key: Optional[str] = None) -> Any:
742
+ """The clip's metadata (`Clip.metadata()`, read-only here: Foundry
743
+ returns a copy, so writing it would change nothing)."""
744
+ bi = self.handles.get(clip, "clip")
745
+ item = _call(bi, "activeItem", None)
746
+ md = _call(item, "metadata", None) if item is not None else None
747
+ if md is None:
748
+ return None if key is not None else {}
749
+ try:
750
+ table = {str(k): md.value(k) for k in md.keys()}
751
+ except Exception:
752
+ table = {}
753
+ return table if key is None else table.get(str(key))
754
+
755
+ def v_clip_meta__clip_property(self, clip: Any, key: Optional[str] = None) -> Any:
756
+ props = self._clip_props(self.handles.get(clip, "clip"))
757
+ return props if key is None else props.get(str(key))
758
+
759
+ def _rename(self, bi: Any, value: Any) -> bool:
760
+ bi.setName(str(value))
761
+ item = _call(bi, "activeItem", None)
762
+ if item is not None:
763
+ item.setName(str(value))
764
+ return str(bi.name()) == str(value)
765
+
766
+ def v_clip_meta__set_clip_property(self, clip: Any, key: str, value: Any) -> bool:
767
+ bi = self.handles.get(clip, "clip")
768
+ if key not in WRITABLE_CLIP_PROPS:
769
+ return False
770
+ with self._undo(self._current_project(), f"rename {bi.name()}"):
771
+ return self._rename(bi, value)
772
+
773
+ def v_clip_meta__set_clip_properties(self, items: List[Dict[str, Any]]) -> List[bool]:
774
+ """A batch rename as ONE undo step in Hiero."""
775
+ out: List[bool] = []
776
+ with self._undo(self._current_project(), f"rename {len(items)} clips"):
777
+ for row in items or []:
778
+ try:
779
+ bi = self.handles.get(row.get("clip"), "clip")
780
+ out.append(row.get("key") in WRITABLE_CLIP_PROPS and self._rename(bi, row.get("value")))
781
+ except PeerError:
782
+ out.append(False)
783
+ return out
784
+
785
+ # ── timeline_write ──────────────────────────────────────────────────
786
+ def v_timeline_write__import_file(self, project: Any = None, path: str = "", sequences: Any = None) -> Dict[str, Any]:
787
+ p = self._project(project)
788
+ path = str(path or "")
789
+ ext = os.path.splitext(path)[1].lower()
790
+ if ext not in IMPORTABLE:
791
+ raise PeerError("unsupported_format", f"Nuke Studio imports FCP 7 XML, EDL, AAF and OTIO sequences, not {ext or 'this file'}")
792
+ if not os.path.isfile(path):
793
+ raise PeerError("not_found", f"no file at {path}")
794
+ with self._undo(p, f"import {os.path.basename(path)}"):
795
+ seq = p.clipsBin().importSequence(path)
796
+ if seq is None:
797
+ return {"ok": False, "imported": [], "issues": [f"Nuke Studio imported nothing from {os.path.basename(path)}"]}
798
+ return {"ok": True, "imported": [{"name": str(seq.name()), "handle": self._wrap("seq", seq)}], "issues": []}
799
+
800
+
801
+ class _Undo:
802
+ """`Project.beginUndo(name)` / `endUndo()` around a write; a failed write
803
+ cancels the group instead of leaving half an undo step."""
804
+
805
+ def __init__(self, project: Any, label: str):
806
+ self.project, self.label = project, label
807
+
808
+ def __enter__(self):
809
+ if self.project is not None:
810
+ try:
811
+ self.project.beginUndo(self.label)
812
+ except Exception:
813
+ self.project = None
814
+ return self
815
+
816
+ def __exit__(self, exc_type, exc, tb):
817
+ if self.project is None:
818
+ return False
819
+ try:
820
+ if exc_type is None:
821
+ self.project.endUndo()
822
+ else:
823
+ cancel = getattr(self.project, "cancelUndo", None)
824
+ (cancel or self.project.endUndo)()
825
+ except Exception:
826
+ pass
827
+ return False
828
+
829
+
830
+ def _call(obj: Any, name: str, default: Any = None) -> Any:
831
+ fn = getattr(obj, name, None) if obj is not None else None
832
+ if not callable(fn):
833
+ return default
834
+ try:
835
+ return fn()
836
+ except Exception:
837
+ return default