davinci-resolve-mcp 2.23.0

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 (92) hide show
  1. package/AGENTS.md +85 -0
  2. package/CHANGELOG.md +802 -0
  3. package/CLAUDE.md +15 -0
  4. package/LICENSE +21 -0
  5. package/README.md +159 -0
  6. package/SECURITY.md +53 -0
  7. package/bin/davinci-resolve-mcp.mjs +376 -0
  8. package/docs/README.md +56 -0
  9. package/docs/SKILL.md +1145 -0
  10. package/docs/authoring/fuse-dctl-authoring.md +242 -0
  11. package/docs/authoring/script-plugin-authoring.md +195 -0
  12. package/docs/contributing.md +82 -0
  13. package/docs/guides/color-decision-guide.md +387 -0
  14. package/docs/guides/editorial-decision-guide.md +136 -0
  15. package/docs/guides/media-analysis-guide.md +615 -0
  16. package/docs/guides/multicam-setup-guide.md +138 -0
  17. package/docs/install.md +198 -0
  18. package/docs/integrations/workflow-integrations.md +120 -0
  19. package/docs/kernels/README.md +28 -0
  20. package/docs/kernels/audio-fairlight-kernel.md +86 -0
  21. package/docs/kernels/color-grade-kernel.md +103 -0
  22. package/docs/kernels/extension-authoring-kernel.md +101 -0
  23. package/docs/kernels/fusion-composition-kernel.md +91 -0
  24. package/docs/kernels/media-pool-ingest-kernel.md +147 -0
  25. package/docs/kernels/project-lifecycle-kernel.md +120 -0
  26. package/docs/kernels/render-deliver-kernel.md +92 -0
  27. package/docs/kernels/review-annotation-kernel.md +110 -0
  28. package/docs/kernels/timeline-conform-interchange-kernel.md +99 -0
  29. package/docs/kernels/timeline-edit-kernel.md +189 -0
  30. package/docs/notes/codec-plugin-notes.md +136 -0
  31. package/docs/notes/dctl-notes.md +234 -0
  32. package/docs/notes/fusion-template-notes.md +136 -0
  33. package/docs/notes/lut-notes.md +136 -0
  34. package/docs/notes/openfx-notes.md +120 -0
  35. package/docs/process/release-process.md +152 -0
  36. package/docs/reference/api-coverage.md +488 -0
  37. package/docs/reference/resolve_scripting_api.txt +1012 -0
  38. package/examples/README.md +53 -0
  39. package/examples/markers/README.md +81 -0
  40. package/examples/media/README.md +94 -0
  41. package/examples/timeline/README.md +98 -0
  42. package/install.py +1196 -0
  43. package/package.json +52 -0
  44. package/scripts/audit_api_parity.py +275 -0
  45. package/scripts/live_media_analysis_polish_probe.py +65 -0
  46. package/src/__init__.py +3 -0
  47. package/src/analysis_dashboard.py +4936 -0
  48. package/src/control_panel.py +13 -0
  49. package/src/granular/__init__.py +17 -0
  50. package/src/granular/common.py +727 -0
  51. package/src/granular/folder.py +287 -0
  52. package/src/granular/gallery.py +306 -0
  53. package/src/granular/graph.py +309 -0
  54. package/src/granular/media_pool.py +679 -0
  55. package/src/granular/media_pool_item.py +852 -0
  56. package/src/granular/media_storage.py +179 -0
  57. package/src/granular/project.py +1594 -0
  58. package/src/granular/resolve_control.py +521 -0
  59. package/src/granular/timeline.py +1074 -0
  60. package/src/granular/timeline_item.py +2251 -0
  61. package/src/resolve_mcp_server.py +43 -0
  62. package/src/server.py +15691 -0
  63. package/src/utils/__init__.py +3 -0
  64. package/src/utils/app_control.py +319 -0
  65. package/src/utils/audio_fairlight_live_probe.py +263 -0
  66. package/src/utils/cdl.py +20 -0
  67. package/src/utils/cloud_operations.py +192 -0
  68. package/src/utils/color_grade_live_probe.py +444 -0
  69. package/src/utils/dctl_templates.py +368 -0
  70. package/src/utils/extension_authoring_live_probe.py +292 -0
  71. package/src/utils/fuse_templates.py +1968 -0
  72. package/src/utils/fusion_composition_live_probe.py +284 -0
  73. package/src/utils/layout_presets.py +333 -0
  74. package/src/utils/mcp_stdio.py +32 -0
  75. package/src/utils/media_analysis.py +3618 -0
  76. package/src/utils/media_analysis_jobs.py +796 -0
  77. package/src/utils/media_pool_ingest_live_probe.py +592 -0
  78. package/src/utils/multicam.py +393 -0
  79. package/src/utils/object_inspection.py +287 -0
  80. package/src/utils/platform.py +157 -0
  81. package/src/utils/project_lifecycle_live_probe.py +376 -0
  82. package/src/utils/project_properties.py +601 -0
  83. package/src/utils/render_deliver_live_probe.py +384 -0
  84. package/src/utils/resolve_connection.py +77 -0
  85. package/src/utils/review_annotation_live_probe.py +352 -0
  86. package/src/utils/script_templates.py +1193 -0
  87. package/src/utils/sync_detection.py +887 -0
  88. package/src/utils/timeline_conform_live_probe.py +280 -0
  89. package/src/utils/timeline_kernel_live_probe.py +1091 -0
  90. package/src/utils/timeline_kernel_probe.py +185 -0
  91. package/src/utils/timeline_title_text.py +87 -0
  92. package/src/utils/update_check.py +610 -0
@@ -0,0 +1,393 @@
1
+ """Helpers for source-safe multicam setup timelines.
2
+
3
+ Resolve's public scripting API does not expose native multicam clip creation.
4
+ These helpers build append plans for a stacked prep timeline that can be
5
+ converted to a native multicam clip in Resolve's UI.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import re
11
+ from typing import Any, Callable, Dict, List, Optional, Tuple
12
+
13
+
14
+ FindClip = Callable[[Any, str], Any]
15
+
16
+
17
+ _SOURCE_TIMECODE_KEYS = (
18
+ "Start TC",
19
+ "Start Timecode",
20
+ "Start Time Code",
21
+ "Source Start TC",
22
+ "Source Start Timecode",
23
+ )
24
+
25
+ _FPS_KEYS = ("FPS", "Frame Rate", "Video Frame Rate")
26
+ _FRAME_COUNT_KEYS = ("Frames", "Frame Count", "Video Frames")
27
+ _DURATION_KEYS = ("Duration", "Video Duration")
28
+
29
+
30
+ def _err(message: str) -> Dict[str, str]:
31
+ return {"error": message}
32
+
33
+
34
+ def _frame_int(value: Any) -> Optional[int]:
35
+ if value is None or value == "":
36
+ return None
37
+ if isinstance(value, str):
38
+ match = re.search(r"-?\d+(?:\.\d+)?", value.strip())
39
+ if not match:
40
+ return None
41
+ value = match.group(0)
42
+ try:
43
+ return int(round(float(value)))
44
+ except (TypeError, ValueError):
45
+ return None
46
+
47
+
48
+ def parse_frame_rate(value: Any) -> Optional[float]:
49
+ if value is None or value == "":
50
+ return None
51
+ if isinstance(value, (int, float)):
52
+ return float(value) if float(value) > 0 else None
53
+ match = re.search(r"\d+(?:\.\d+)?", str(value))
54
+ if not match:
55
+ return None
56
+ fps = float(match.group(0))
57
+ return fps if fps > 0 else None
58
+
59
+
60
+ def _nominal_timecode_rate(fps: float) -> int:
61
+ if abs(fps - 23.976) < 0.02:
62
+ return 24
63
+ if abs(fps - 29.97) < 0.02:
64
+ return 30
65
+ if abs(fps - 47.952) < 0.05:
66
+ return 48
67
+ if abs(fps - 59.94) < 0.05:
68
+ return 60
69
+ return int(round(fps))
70
+
71
+
72
+ def timecode_to_frames(timecode: Any, fps: Any, *, drop_frame: Optional[bool] = None) -> Optional[int]:
73
+ """Convert HH:MM:SS:FF timecode to a frame count.
74
+
75
+ Semicolon timecode implies drop-frame. When drop_frame is not specified,
76
+ 29.97/59.94 colon timecode is treated as non-drop-frame.
77
+ """
78
+ rate = parse_frame_rate(fps)
79
+ if rate is None:
80
+ return None
81
+ text = str(timecode or "").strip()
82
+ match = re.match(r"^(\d{1,2}):(\d{2}):(\d{2})([:;])(\d{2})$", text)
83
+ if not match:
84
+ return None
85
+ hours, minutes, seconds, sep, frames = match.groups()
86
+ hh = int(hours)
87
+ mm = int(minutes)
88
+ ss = int(seconds)
89
+ ff = int(frames)
90
+ nominal = _nominal_timecode_rate(rate)
91
+ if mm > 59 or ss > 59 or ff >= nominal:
92
+ return None
93
+ total = ((hh * 3600 + mm * 60 + ss) * nominal) + ff
94
+ use_drop = (sep == ";") if drop_frame is None else bool(drop_frame)
95
+ if use_drop and nominal in (30, 60):
96
+ drop_frames = 2 if nominal == 30 else 4
97
+ total_minutes = hh * 60 + mm
98
+ total -= drop_frames * (total_minutes - total_minutes // 10)
99
+ return total
100
+
101
+
102
+ def _get_clip_property_map(clip: Any) -> Dict[str, Any]:
103
+ try:
104
+ props = clip.GetClipProperty()
105
+ except Exception:
106
+ props = None
107
+ return dict(props) if isinstance(props, dict) else {}
108
+
109
+
110
+ def _prop_from_map(props: Dict[str, Any], key: str) -> Any:
111
+ if key in props:
112
+ return props[key]
113
+ key_norm = key.strip().lower()
114
+ for existing, value in props.items():
115
+ if str(existing).strip().lower() == key_norm:
116
+ return value
117
+ return None
118
+
119
+
120
+ def _clip_property(clip: Any, props: Dict[str, Any], keys: Tuple[str, ...]) -> Any:
121
+ for key in keys:
122
+ value = _prop_from_map(props, key)
123
+ if value not in (None, ""):
124
+ return value
125
+ for key in keys:
126
+ try:
127
+ value = clip.GetClipProperty(key)
128
+ except Exception:
129
+ value = None
130
+ if value not in (None, ""):
131
+ return value
132
+ return None
133
+
134
+
135
+ def _clip_name(clip: Any, fallback: str) -> str:
136
+ try:
137
+ name = clip.GetName()
138
+ except Exception:
139
+ name = None
140
+ return str(name or fallback)
141
+
142
+
143
+ def _clip_duration_frames(clip: Any, props: Dict[str, Any], fps: Optional[float]) -> Optional[int]:
144
+ frames = _frame_int(_clip_property(clip, props, _FRAME_COUNT_KEYS))
145
+ if frames is not None and frames > 0:
146
+ return frames
147
+ try:
148
+ duration = clip.GetDuration()
149
+ except Exception:
150
+ duration = None
151
+ frames = _frame_int(duration)
152
+ if frames is not None and frames > 0:
153
+ return frames
154
+ if duration and ":" in str(duration) and fps is not None:
155
+ frames = timecode_to_frames(duration, fps)
156
+ if frames is not None and frames > 0:
157
+ return frames
158
+ duration_value = _clip_property(clip, props, _DURATION_KEYS)
159
+ frames = _frame_int(duration_value)
160
+ if frames is not None and frames > 0 and ":" not in str(duration_value):
161
+ return frames
162
+ if fps is None:
163
+ return None
164
+ return timecode_to_frames(duration_value, fps)
165
+
166
+
167
+ def _angle_source_range(angle: Dict[str, Any], clip: Any, props: Dict[str, Any], fps: Optional[float], index: int):
168
+ start = _frame_int(angle.get("start_frame", angle.get("startFrame", 0)))
169
+ if start is None or start < 0:
170
+ return None, None, _err(f"angles[{index}] start_frame must be a non-negative frame number")
171
+ end = _frame_int(angle.get("end_frame", angle.get("endFrame")))
172
+ if end is None:
173
+ duration = _frame_int(angle.get("duration_frames", angle.get("durationFrames")))
174
+ if duration is None:
175
+ duration = _clip_duration_frames(clip, props, fps)
176
+ if duration is not None:
177
+ end = start + duration
178
+ if end is None:
179
+ return None, None, _err(
180
+ f"angles[{index}] requires end_frame/duration_frames, or clip properties with Frames/Duration"
181
+ )
182
+ if end <= start:
183
+ return None, None, _err(f"angles[{index}] end_frame must be greater than start_frame")
184
+ return start, end, None
185
+
186
+
187
+ def _normalize_sync_mode(value: Any) -> Optional[str]:
188
+ raw = str(value or "stack_start").strip().lower().replace("-", "_").replace(" ", "_")
189
+ aliases = {
190
+ "none": "stack_start",
191
+ "start": "stack_start",
192
+ "stack": "stack_start",
193
+ "stack_start": "stack_start",
194
+ "common_start": "stack_start",
195
+ "manual": "record_frame",
196
+ "record": "record_frame",
197
+ "record_frame": "record_frame",
198
+ "record_frames": "record_frame",
199
+ "timecode": "source_timecode",
200
+ "source_timecode": "source_timecode",
201
+ "source_tc": "source_timecode",
202
+ }
203
+ return aliases.get(raw)
204
+
205
+
206
+ def _normalize_audio_mode(value: Any, include_audio: bool) -> Optional[str]:
207
+ if not include_audio:
208
+ return "none"
209
+ raw = str(value or "matching").strip().lower().replace("-", "_").replace(" ", "_")
210
+ aliases = {
211
+ "none": "none",
212
+ "off": "none",
213
+ "matching": "matching",
214
+ "match": "matching",
215
+ "per_angle": "matching",
216
+ "first": "first",
217
+ "first_angle": "first",
218
+ "scratch": "first",
219
+ }
220
+ return aliases.get(raw)
221
+
222
+
223
+ def _selected_record_frame(
224
+ *,
225
+ angle: Dict[str, Any],
226
+ clip: Any,
227
+ props: Dict[str, Any],
228
+ fps: Optional[float],
229
+ sync_mode: str,
230
+ timeline_start_timecode: str,
231
+ record_frame_start: int,
232
+ index: int,
233
+ ):
234
+ offset = _frame_int(angle.get("record_offset", angle.get("recordOffset", 0)))
235
+ if offset is None:
236
+ return None, _err(f"angles[{index}] record_offset must be numeric")
237
+ if sync_mode == "source_timecode":
238
+ tc = (
239
+ angle.get("source_timecode")
240
+ or angle.get("sourceTimecode")
241
+ or angle.get("start_timecode")
242
+ or angle.get("startTimecode")
243
+ or _clip_property(clip, props, _SOURCE_TIMECODE_KEYS)
244
+ )
245
+ if not tc:
246
+ return None, _err(f"angles[{index}] has no source_timecode or readable clip Start TC")
247
+ tc_frames = timecode_to_frames(tc, fps)
248
+ start_frames = timecode_to_frames(timeline_start_timecode, fps)
249
+ if tc_frames is None or start_frames is None:
250
+ return None, _err(f"angles[{index}] could not parse source/timeline timecode at fps={fps!r}")
251
+ return record_frame_start + (tc_frames - start_frames) + offset, None
252
+ if sync_mode == "record_frame":
253
+ manual = _frame_int(angle.get("record_frame", angle.get("recordFrame")))
254
+ if manual is None:
255
+ manual = record_frame_start
256
+ return manual + offset, None
257
+ return record_frame_start + offset, None
258
+
259
+
260
+ def build_multicam_setup_plan(root: Any, params: Dict[str, Any], find_clip: FindClip):
261
+ """Build a stacked multicam setup plan from media pool clip IDs."""
262
+ params = params or {}
263
+ name = str(params.get("name") or "Multicam Setup")
264
+ raw_angles = params.get("angles")
265
+ if raw_angles is None:
266
+ clip_ids = params.get("clip_ids") or params.get("clipIds")
267
+ if not isinstance(clip_ids, list) or not clip_ids:
268
+ return None, _err("setup_multicam_timeline requires angles or clip_ids")
269
+ raw_angles = [{"clip_id": clip_id} for clip_id in clip_ids]
270
+ if not isinstance(raw_angles, list) or not raw_angles:
271
+ return None, _err("angles must be a non-empty list")
272
+
273
+ sync_mode = _normalize_sync_mode(params.get("sync_mode", params.get("syncMode")))
274
+ if not sync_mode:
275
+ return None, _err("sync_mode must be stack_start, record_frame, or source_timecode")
276
+
277
+ include_video = bool(params.get("include_video", params.get("includeVideo", True)))
278
+ include_audio = bool(params.get("include_audio", params.get("includeAudio", False)))
279
+ if not include_video and not include_audio:
280
+ return None, _err("At least one of include_video or include_audio must be true")
281
+ audio_mode = _normalize_audio_mode(params.get("audio_track_mode", params.get("audioTrackMode")), include_audio)
282
+ if not audio_mode:
283
+ return None, _err("audio_track_mode must be matching, first, or none")
284
+
285
+ default_fps = parse_frame_rate(params.get("frame_rate", params.get("frameRate")))
286
+ timeline_start_timecode = str(
287
+ params.get("timeline_start_timecode")
288
+ or params.get("timelineStartTimecode")
289
+ or params.get("start_timecode")
290
+ or params.get("startTimecode")
291
+ or "01:00:00:00"
292
+ )
293
+ record_frame_start = _frame_int(params.get("record_frame_start", params.get("recordFrameStart", 0)))
294
+ if record_frame_start is None:
295
+ return None, _err("record_frame_start must be numeric")
296
+
297
+ rows: List[Dict[str, Any]] = []
298
+ angles: List[Dict[str, Any]] = []
299
+ max_video_track = 0
300
+ max_audio_track = 0
301
+ allow_negative = bool(params.get("allow_negative_record_frame", params.get("allowNegativeRecordFrame", False)))
302
+ record_frame_mode = params.get("record_frame_mode", params.get("recordFrameMode", "relative"))
303
+
304
+ for index, raw in enumerate(raw_angles):
305
+ if not isinstance(raw, dict):
306
+ return None, _err(f"angles[{index}] must be an object")
307
+ clip_id = raw.get("clip_id") or raw.get("media_pool_item_id") or raw.get("clipId")
308
+ if not clip_id:
309
+ return None, _err(f"angles[{index}] requires clip_id or media_pool_item_id")
310
+ clip = find_clip(root, str(clip_id))
311
+ if not clip:
312
+ return None, _err(f"angles[{index}]: media pool clip not found: {clip_id}")
313
+ props = _get_clip_property_map(clip)
314
+ fps = parse_frame_rate(raw.get("frame_rate", raw.get("frameRate"))) or parse_frame_rate(
315
+ _clip_property(clip, props, _FPS_KEYS)
316
+ ) or default_fps
317
+ source_start, source_end, range_err = _angle_source_range(raw, clip, props, fps, index)
318
+ if range_err:
319
+ return None, range_err
320
+ record_frame, record_err = _selected_record_frame(
321
+ angle=raw,
322
+ clip=clip,
323
+ props=props,
324
+ fps=fps,
325
+ sync_mode=sync_mode,
326
+ timeline_start_timecode=timeline_start_timecode,
327
+ record_frame_start=record_frame_start,
328
+ index=index,
329
+ )
330
+ if record_err:
331
+ return None, record_err
332
+ if record_frame is None or (record_frame < 0 and not allow_negative):
333
+ return None, _err(f"angles[{index}] resolved to a negative record frame")
334
+
335
+ video_track = _frame_int(raw.get("track_index", raw.get("trackIndex", index + 1)))
336
+ if video_track is None or video_track < 1:
337
+ return None, _err(f"angles[{index}] track_index must be a positive integer")
338
+ audio_track = _frame_int(raw.get("audio_track_index", raw.get("audioTrackIndex", video_track)))
339
+ if audio_track is None or audio_track < 1:
340
+ return None, _err(f"angles[{index}] audio_track_index must be a positive integer")
341
+ angle_name = str(raw.get("angle_name") or raw.get("angleName") or _clip_name(clip, str(clip_id)))
342
+
343
+ angle_summary = {
344
+ "angle_index": index + 1,
345
+ "angle_name": angle_name,
346
+ "clip_id": str(clip_id),
347
+ "clip_name": _clip_name(clip, str(clip_id)),
348
+ "source_start": source_start,
349
+ "source_end": source_end,
350
+ "record_frame": record_frame,
351
+ "video_track_index": video_track,
352
+ "audio_track_index": audio_track if audio_mode != "none" else None,
353
+ "fps": fps,
354
+ }
355
+ angles.append(angle_summary)
356
+ common = {
357
+ "clip_id": str(clip_id),
358
+ "start_frame": source_start,
359
+ "end_frame": source_end,
360
+ "record_frame": record_frame,
361
+ "record_frame_mode": raw.get("record_frame_mode", raw.get("recordFrameMode", record_frame_mode)),
362
+ "angle_index": index + 1,
363
+ "angle_name": angle_name,
364
+ }
365
+ if include_video:
366
+ rows.append({**common, "track_index": video_track, "media_type": 1, "role": "video"})
367
+ max_video_track = max(max_video_track, video_track)
368
+ if audio_mode == "matching" or (audio_mode == "first" and index == 0):
369
+ rows.append({**common, "track_index": audio_track, "media_type": 2, "role": "audio"})
370
+ max_audio_track = max(max_audio_track, audio_track)
371
+
372
+ return {
373
+ "success": True,
374
+ "name": name,
375
+ "sync_mode": sync_mode,
376
+ "start_timecode": params.get("start_timecode") or params.get("startTimecode"),
377
+ "timeline_start_timecode": timeline_start_timecode,
378
+ "include_video": include_video,
379
+ "include_audio": include_audio,
380
+ "audio_track_mode": audio_mode,
381
+ "angles": angles,
382
+ "append_rows": rows,
383
+ "max_video_track": max_video_track,
384
+ "max_audio_track": max_audio_track,
385
+ "native_multicam_created": False,
386
+ "native_multicam_api": False,
387
+ "manual_reference": "DaVinci Resolve 20 Manual, Edit > Chapter 42, Multicam Editing",
388
+ "next_step": (
389
+ "Resolve's public scripting API does not expose native multicam clip creation. "
390
+ "Use the created prep timeline directly, or in Resolve convert the timeline/"
391
+ "compound clip to a multicam clip from the Media Pool context menu."
392
+ ),
393
+ }, None
@@ -0,0 +1,287 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ DaVinci Resolve MCP Server - Object Inspection Utilities
4
+
5
+ This module provides functions for inspecting DaVinci Resolve API objects:
6
+ - Exploring available methods and properties
7
+ - Generating structured documentation
8
+ - Inspecting nested objects
9
+ - Converting between Python and Lua objects if needed
10
+ """
11
+
12
+ import sys
13
+ import inspect
14
+ from typing import Any, Dict, List, Optional, Union, Callable
15
+
16
+
17
+ def get_object_methods(obj: Any) -> Dict[str, Dict[str, Any]]:
18
+ """
19
+ Get all methods of a DaVinci Resolve object with their documentation.
20
+
21
+ Args:
22
+ obj: A DaVinci Resolve API object
23
+
24
+ Returns:
25
+ A dictionary of method names and their details
26
+ """
27
+ if obj is None:
28
+ return {"error": "Cannot inspect None object"}
29
+
30
+ methods = {}
31
+
32
+ # Get all object attributes
33
+ for attr_name in dir(obj):
34
+ # Skip private/internal attributes
35
+ if attr_name.startswith('_'):
36
+ continue
37
+
38
+ try:
39
+ attr = getattr(obj, attr_name)
40
+
41
+ # Check if it's a callable method
42
+ if callable(attr):
43
+ # Get the method signature if possible
44
+ try:
45
+ signature = str(inspect.signature(attr))
46
+ except (ValueError, TypeError):
47
+ signature = "()"
48
+
49
+ # Get the docstring if available
50
+ doc = inspect.getdoc(attr) or ""
51
+
52
+ methods[attr_name] = {
53
+ "signature": signature,
54
+ "doc": doc,
55
+ "type": "method"
56
+ }
57
+ except Exception as e:
58
+ methods[attr_name] = {
59
+ "error": str(e),
60
+ "type": "error"
61
+ }
62
+
63
+ return methods
64
+
65
+
66
+ def get_object_properties(obj: Any) -> Dict[str, Dict[str, Any]]:
67
+ """
68
+ Get all properties (non-callable attributes) of a DaVinci Resolve object.
69
+
70
+ Args:
71
+ obj: A DaVinci Resolve API object
72
+
73
+ Returns:
74
+ A dictionary of property names and their details
75
+ """
76
+ if obj is None:
77
+ return {"error": "Cannot inspect None object"}
78
+
79
+ properties = {}
80
+
81
+ # Get all object attributes
82
+ for attr_name in dir(obj):
83
+ # Skip private/internal attributes
84
+ if attr_name.startswith('_'):
85
+ continue
86
+
87
+ try:
88
+ attr = getattr(obj, attr_name)
89
+
90
+ # Skip if it's a method
91
+ if callable(attr):
92
+ continue
93
+
94
+ # Get the property value and type
95
+ properties[attr_name] = {
96
+ "value": str(attr),
97
+ "type": type(attr).__name__,
98
+ "type_category": "property"
99
+ }
100
+ except Exception as e:
101
+ properties[attr_name] = {
102
+ "error": str(e),
103
+ "type_category": "error"
104
+ }
105
+
106
+ return properties
107
+
108
+
109
+ def inspect_object(obj: Any, max_depth: int = 1) -> Dict[str, Any]:
110
+ """
111
+ Inspect a DaVinci Resolve API object and return its methods and properties.
112
+
113
+ Args:
114
+ obj: A DaVinci Resolve API object
115
+ max_depth: Maximum depth for nested object inspection
116
+
117
+ Returns:
118
+ A dictionary containing the object's methods and properties
119
+ """
120
+ if obj is None:
121
+ return {"error": "Cannot inspect None object"}
122
+
123
+ result = {
124
+ "type": type(obj).__name__,
125
+ "methods": get_object_methods(obj),
126
+ "properties": get_object_properties(obj),
127
+ }
128
+
129
+ # Add string representation
130
+ try:
131
+ result["str"] = str(obj)
132
+ except Exception as e:
133
+ result["str_error"] = str(e)
134
+
135
+ # Add repr representation
136
+ try:
137
+ result["repr"] = repr(obj)
138
+ except Exception as e:
139
+ result["repr_error"] = str(e)
140
+
141
+ return result
142
+
143
+
144
+ def get_lua_table_keys(lua_table: Any) -> List[str]:
145
+ """
146
+ Get all keys from a Lua table object (if the object supports Lua table iteration).
147
+
148
+ Args:
149
+ lua_table: A Lua table object from DaVinci Resolve API
150
+
151
+ Returns:
152
+ A list of keys from the Lua table
153
+ """
154
+ if lua_table is None:
155
+ return []
156
+
157
+ keys = []
158
+
159
+ # Check for DaVinci-specific Lua table iteration methods
160
+ if hasattr(lua_table, 'GetKeyList'):
161
+ try:
162
+ # Some DaVinci Resolve objects have a GetKeyList() method
163
+ return lua_table.GetKeyList()
164
+ except Exception:
165
+ logger.debug("Lua table GetKeyList() lookup failed", exc_info=True)
166
+
167
+ # Try different iteration methods that might work with Lua tables
168
+ try:
169
+ # Some Lua tables can be iterated directly
170
+ for key in lua_table:
171
+ keys.append(key)
172
+ return keys
173
+ except Exception:
174
+ logger.debug("Lua table direct iteration failed", exc_info=True)
175
+
176
+ # Try manual iteration with pairs-like behavior (if available)
177
+ # This is a fallback for APIs that don't support Python-style iteration
178
+ return []
179
+
180
+
181
+ def convert_lua_to_python(lua_obj: Any) -> Any:
182
+ """
183
+ Convert a Lua object from DaVinci Resolve API to a Python object.
184
+
185
+ Args:
186
+ lua_obj: A Lua object from DaVinci Resolve API
187
+
188
+ Returns:
189
+ The converted Python object
190
+ """
191
+ # Handle None
192
+ if lua_obj is None:
193
+ return None
194
+
195
+ # Handle primitive types
196
+ if isinstance(lua_obj, (str, int, float, bool)):
197
+ return lua_obj
198
+
199
+ # Try to convert Lua tables to Python dicts or lists
200
+ if hasattr(lua_obj, 'GetKeyList') or hasattr(lua_obj, '__iter__'):
201
+ keys = get_lua_table_keys(lua_obj)
202
+
203
+ # If we found keys, convert to dict
204
+ if keys:
205
+ result = {}
206
+ for key in keys:
207
+ try:
208
+ # Get the value for this key
209
+ value = lua_obj[key]
210
+ # Recursively convert nested Lua objects
211
+ result[key] = convert_lua_to_python(value)
212
+ except Exception:
213
+ logger.debug("Failed to convert Lua table key %r", key, exc_info=True)
214
+ result[key] = None
215
+ return result
216
+
217
+ # Try to convert to list if it appears numeric-indexed
218
+ try:
219
+ # Common Lua pattern for numeric arrays (1-indexed)
220
+ result = []
221
+ index = 1 # Lua arrays typically start at 1
222
+ while True:
223
+ try:
224
+ value = lua_obj[index]
225
+ result.append(convert_lua_to_python(value))
226
+ index += 1
227
+ except Exception:
228
+ logger.debug("Lua numeric iteration stopped at index %s", index, exc_info=True)
229
+ break
230
+
231
+ # If we found items, return as list
232
+ if result:
233
+ return result
234
+ except Exception:
235
+ logger.debug("Lua numeric-indexed conversion failed", exc_info=True)
236
+
237
+ # If conversion failed, return string representation
238
+ return str(lua_obj)
239
+
240
+
241
+ def print_object_help(obj: Any) -> str:
242
+ """
243
+ Generate a human-readable help string for a DaVinci Resolve API object.
244
+
245
+ Args:
246
+ obj: A DaVinci Resolve API object
247
+
248
+ Returns:
249
+ A formatted help string describing the object's methods and properties
250
+ """
251
+ if obj is None:
252
+ return "Cannot provide help for None object"
253
+
254
+ obj_type = type(obj).__name__
255
+ methods = get_object_methods(obj)
256
+ properties = get_object_properties(obj)
257
+
258
+ help_text = [f"Help for {obj_type} object:"]
259
+ help_text.append("\n" + "=" * 40 + "\n")
260
+
261
+ # Add methods
262
+ if methods:
263
+ help_text.append("METHODS:")
264
+ help_text.append("-" * 40)
265
+ for name, info in sorted(methods.items()):
266
+ if "error" in info:
267
+ continue
268
+ signature = info.get("signature", "()")
269
+ doc = info.get("doc", "").strip()
270
+ help_text.append(f"{name}{signature}")
271
+ if doc:
272
+ help_text.append(f" {doc}\n")
273
+ else:
274
+ help_text.append("")
275
+
276
+ # Add properties
277
+ if properties:
278
+ help_text.append("\nPROPERTIES:")
279
+ help_text.append("-" * 40)
280
+ for name, info in sorted(properties.items()):
281
+ if "error" in info:
282
+ continue
283
+ value = info.get("value", "")
284
+ type_name = info.get("type", "")
285
+ help_text.append(f"{name}: {type_name} = {value}")
286
+
287
+ return "\n".join(help_text)