davinci-resolve-mcp 5.2.8 → 5.2.10
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.
- package/CHANGELOG.md +39 -0
- package/README.md +2 -2
- package/README.zh-CN.md +3 -3
- package/README.zh-TW.md +423 -0
- package/docs/process/release-process.md +6 -1
- package/install.py +1 -1
- package/package.json +1 -1
- package/src/granular/common.py +16 -3
- package/src/granular/media_pool.py +4 -2
- package/src/granular/timeline.py +13 -1
- package/src/server.py +369 -19
- package/src/utils/clip_info_tracks.py +133 -0
- package/src/utils/mcp_arg_guard.py +79 -0
- package/src/utils/mcp_error_flag.py +24 -0
- package/src/utils/subtitle_live.py +111 -2
|
@@ -210,7 +210,8 @@ def append_to_timeline(
|
|
|
210
210
|
timeline_start = _timeline_start_frame(current_timeline)
|
|
211
211
|
built = []
|
|
212
212
|
for i, ci in enumerate(clip_infos):
|
|
213
|
-
row, row_err = _build_append_clip_info_dict(
|
|
213
|
+
row, row_err = _build_append_clip_info_dict(
|
|
214
|
+
root, ci, i, timeline_start, timeline=current_timeline)
|
|
214
215
|
if row_err:
|
|
215
216
|
return row_err
|
|
216
217
|
built.append(row)
|
|
@@ -343,7 +344,8 @@ def setup_multicam_timeline(
|
|
|
343
344
|
append_rows = plan.get("append_rows") or []
|
|
344
345
|
append_infos = []
|
|
345
346
|
for index, row in enumerate(append_rows):
|
|
346
|
-
clip_info, clip_err = _build_append_clip_info_dict(
|
|
347
|
+
clip_info, clip_err = _build_append_clip_info_dict(
|
|
348
|
+
root, row, index, timeline_start, timeline=timeline)
|
|
347
349
|
if clip_err:
|
|
348
350
|
return clip_err
|
|
349
351
|
append_infos.append(clip_info)
|
package/src/granular/timeline.py
CHANGED
|
@@ -1056,6 +1056,11 @@ def create_timeline_from_clips(
|
|
|
1056
1056
|
_, row_err = _build_create_clip_info_dict(root, ci, i)
|
|
1057
1057
|
if row_err:
|
|
1058
1058
|
return row_err
|
|
1059
|
+
# Rows that name a track past the new timeline's would land on track 1
|
|
1060
|
+
# with success (issue #370): validate first, then add those tracks.
|
|
1061
|
+
needed_tracks, track_err = clip_info_tracks.needed_tracks(clip_infos)
|
|
1062
|
+
if track_err:
|
|
1063
|
+
return {"error": track_err, "code": "INVALID_TRACK_INDEX"}
|
|
1059
1064
|
tl = mp.CreateEmptyTimeline(name)
|
|
1060
1065
|
if not tl:
|
|
1061
1066
|
return {"success": False, "error": "Failed to create timeline"}
|
|
@@ -1068,12 +1073,19 @@ def create_timeline_from_clips(
|
|
|
1068
1073
|
"error": describe_switch_failure(switch_detail,
|
|
1069
1074
|
"appending the clip_infos"),
|
|
1070
1075
|
"switch": switch_detail}
|
|
1076
|
+
ensure_err = clip_info_tracks.ensure_tracks(tl, needed_tracks)
|
|
1077
|
+
if ensure_err:
|
|
1078
|
+
return {"success": False,
|
|
1079
|
+
"error": f"Timeline {name!r} was created but the tracks the clip_infos "
|
|
1080
|
+
f"name could not be added: {ensure_err}",
|
|
1081
|
+
"code": "ADD_TRACK_FAILED"}
|
|
1071
1082
|
timeline_start = _timeline_start_frame(tl)
|
|
1072
1083
|
built = []
|
|
1073
1084
|
for i, ci in enumerate(clip_infos):
|
|
1074
1085
|
append_ci = dict(ci)
|
|
1075
1086
|
append_ci.setdefault("track_index", append_ci.get("trackIndex", 1))
|
|
1076
|
-
row, row_err = _build_append_clip_info_dict(
|
|
1087
|
+
row, row_err = _build_append_clip_info_dict(
|
|
1088
|
+
root, append_ci, i, timeline_start, timeline=tl)
|
|
1077
1089
|
if row_err:
|
|
1078
1090
|
return row_err
|
|
1079
1091
|
built.append(row)
|
package/src/server.py
CHANGED
|
@@ -11,7 +11,7 @@ Usage:
|
|
|
11
11
|
python src/server.py --full # Start the 377-tool granular server instead
|
|
12
12
|
"""
|
|
13
13
|
|
|
14
|
-
VERSION = "5.2.
|
|
14
|
+
VERSION = "5.2.10"
|
|
15
15
|
|
|
16
16
|
import base64
|
|
17
17
|
import os
|
|
@@ -65,6 +65,7 @@ from src.utils.cdl import normalize_cdl_payload
|
|
|
65
65
|
from src.utils.media_paths import media_exists as _media_exists
|
|
66
66
|
from src.utils.preset_files import preset_export_file as _preset_export_file
|
|
67
67
|
from src.utils.render_target import missing_target_dir_error as _missing_target_dir_error
|
|
68
|
+
from src.utils import clip_info_tracks as _clip_info_tracks
|
|
68
69
|
from src.utils import archive_guard
|
|
69
70
|
from src.utils import subtitle_append_guard
|
|
70
71
|
from src.utils import typed_api_search
|
|
@@ -4013,12 +4014,18 @@ def _build_append_clip_info_dict(
|
|
|
4013
4014
|
index: int,
|
|
4014
4015
|
timeline_start_frame: Optional[int] = None,
|
|
4015
4016
|
pack: bool = False,
|
|
4017
|
+
timeline=None,
|
|
4016
4018
|
):
|
|
4017
4019
|
"""Build one MediaPool.AppendToTimeline clipInfo map (Python API uses camelCase keys).
|
|
4018
4020
|
|
|
4019
4021
|
See docs/reference/resolve_scripting_api.txt: mediaPoolItem, startFrame, endFrame,
|
|
4020
4022
|
optional mediaType, trackIndex, recordFrame. With pack=True, recordFrame is omitted
|
|
4021
4023
|
so Resolve appends each clip contiguously at the end of its track.
|
|
4024
|
+
|
|
4025
|
+
trackIndex must be a 1-based int and mediaType 1 or 2. With `timeline`, the
|
|
4026
|
+
index must also name an existing track: Resolve puts an unknown index on
|
|
4027
|
+
track 1 and reports success (issue #370). Callers that add tracks after
|
|
4028
|
+
building the rows leave `timeline` unset.
|
|
4022
4029
|
"""
|
|
4023
4030
|
if not isinstance(ci, dict):
|
|
4024
4031
|
return None, _err(f"clip_infos[{index}] must be an object")
|
|
@@ -4049,6 +4056,12 @@ def _build_append_clip_info_dict(
|
|
|
4049
4056
|
return None, _err(
|
|
4050
4057
|
f"clip_infos[{index}] requires track_index/trackIndex (1-based track index)"
|
|
4051
4058
|
)
|
|
4059
|
+
ti, ti_err = _clip_info_tracks.coerce_track_index(ti, index)
|
|
4060
|
+
if ti_err:
|
|
4061
|
+
return None, _err(ti_err, code="INVALID_TRACK_INDEX", category="invalid_input")
|
|
4062
|
+
mt, mt_err = _clip_info_tracks.coerce_media_type(ci.get("mediaType", ci.get("media_type")), index)
|
|
4063
|
+
if mt_err:
|
|
4064
|
+
return None, _err(mt_err, code="INVALID_MEDIA_TYPE", category="invalid_input")
|
|
4052
4065
|
out: Dict[str, Any] = {
|
|
4053
4066
|
"mediaPoolItem": mp_item,
|
|
4054
4067
|
"startFrame": sf,
|
|
@@ -4057,12 +4070,18 @@ def _build_append_clip_info_dict(
|
|
|
4057
4070
|
}
|
|
4058
4071
|
if not pack:
|
|
4059
4072
|
out["recordFrame"] = rf
|
|
4060
|
-
mt = ci.get("mediaType", ci.get("media_type"))
|
|
4061
4073
|
if mt is not None:
|
|
4062
4074
|
out["mediaType"] = mt
|
|
4063
4075
|
blocked = _subtitle_append_block(out, index=index)
|
|
4064
4076
|
if blocked:
|
|
4065
4077
|
return None, blocked
|
|
4078
|
+
# A subtitle item's trackIndex names a subtitle track, which the
|
|
4079
|
+
# video/audio range check does not measure.
|
|
4080
|
+
if not subtitle_append_guard.is_subtitle_item(mp_item):
|
|
4081
|
+
range_refusal = _clip_info_tracks.track_range_error(timeline, ti, mt, index)
|
|
4082
|
+
if range_refusal:
|
|
4083
|
+
message = range_refusal.pop("message")
|
|
4084
|
+
return None, _err(message, **range_refusal)
|
|
4066
4085
|
return out, None
|
|
4067
4086
|
|
|
4068
4087
|
|
|
@@ -6407,15 +6426,23 @@ def _timeline_ripple_insert_impl(proj, tl, p: Dict[str, Any], *, resolve=None) -
|
|
|
6407
6426
|
ci = dict(raw_ci)
|
|
6408
6427
|
ci.pop("record_frame", None)
|
|
6409
6428
|
ci.pop("recordFrame", None)
|
|
6410
|
-
track_index =
|
|
6411
|
-
|
|
6429
|
+
track_index, ti_err = _clip_info_tracks.coerce_track_index(
|
|
6430
|
+
ci.get("trackIndex", ci.get("track_index", 1)), idx)
|
|
6431
|
+
if ti_err:
|
|
6432
|
+
return _err(ti_err, code="INVALID_TRACK_INDEX", category="invalid_input")
|
|
6433
|
+
media_type, mt_err = _clip_info_tracks.coerce_media_type(
|
|
6434
|
+
ci.get("mediaType", ci.get("media_type", 1)), idx)
|
|
6435
|
+
if mt_err:
|
|
6436
|
+
return _err(mt_err, code="INVALID_MEDIA_TYPE", category="invalid_input")
|
|
6437
|
+
ci.pop("trackIndex", None)
|
|
6438
|
+
ci.pop("mediaType", None)
|
|
6412
6439
|
ci["track_index"] = track_index
|
|
6413
6440
|
ci["media_type"] = media_type
|
|
6414
|
-
key = (
|
|
6441
|
+
key = (media_type, track_index)
|
|
6415
6442
|
record = cursor_by_track.get(key, insert_frame)
|
|
6416
6443
|
ci["record_frame"] = record
|
|
6417
6444
|
ci["record_frame_mode"] = "absolute"
|
|
6418
|
-
info, ierr = _build_append_clip_info_dict(root, ci, idx, tl_start)
|
|
6445
|
+
info, ierr = _build_append_clip_info_dict(root, ci, idx, tl_start, timeline=tl)
|
|
6419
6446
|
if ierr:
|
|
6420
6447
|
return ierr
|
|
6421
6448
|
duration = int(info["endFrame"]) - int(info["startFrame"])
|
|
@@ -8042,7 +8069,11 @@ def _timeline_create_variant_from_ranges(proj, source_tl, p: Dict[str, Any]) ->
|
|
|
8042
8069
|
media_type = _timeline_media_type(track_type)
|
|
8043
8070
|
if media_type not in (1, 2):
|
|
8044
8071
|
return _err(f"ranges[{index}] track_type/media_type must resolve to video or audio")
|
|
8045
|
-
track_index =
|
|
8072
|
+
track_index, ti_err = _clip_info_tracks.coerce_track_index(
|
|
8073
|
+
row.get("track_index", row.get("trackIndex", 1)), index)
|
|
8074
|
+
if ti_err:
|
|
8075
|
+
return _err(ti_err.replace("clip_infos[", "ranges[", 1),
|
|
8076
|
+
code="INVALID_TRACK_INDEX", category="invalid_input")
|
|
8046
8077
|
if media_type == 1:
|
|
8047
8078
|
max_tracks["video"] = max(max_tracks["video"], track_index)
|
|
8048
8079
|
else:
|
|
@@ -11069,7 +11100,8 @@ def _setup_multicam_timeline(proj, mp, p: Dict[str, Any]):
|
|
|
11069
11100
|
append_infos = []
|
|
11070
11101
|
append_rows = plan.get("append_rows") or []
|
|
11071
11102
|
for index, row in enumerate(append_rows):
|
|
11072
|
-
clip_info, clip_err = _build_append_clip_info_dict(
|
|
11103
|
+
clip_info, clip_err = _build_append_clip_info_dict(
|
|
11104
|
+
root, row, index, timeline_start, timeline=new_tl)
|
|
11073
11105
|
if clip_err:
|
|
11074
11106
|
return clip_err
|
|
11075
11107
|
append_infos.append(clip_info)
|
|
@@ -15727,6 +15759,225 @@ def _timeline_append_readback_snapshot(proj):
|
|
|
15727
15759
|
}
|
|
15728
15760
|
|
|
15729
15761
|
|
|
15762
|
+
def _created_clip_property(clip, key):
|
|
15763
|
+
try:
|
|
15764
|
+
getter = getattr(clip, "GetClipProperty", None)
|
|
15765
|
+
value = getter(key) if callable(getter) else None
|
|
15766
|
+
return value if isinstance(value, str) else None
|
|
15767
|
+
except Exception:
|
|
15768
|
+
return None
|
|
15769
|
+
|
|
15770
|
+
|
|
15771
|
+
def _normalized_subtitle_text(value):
|
|
15772
|
+
return " ".join(str(value or "").split())
|
|
15773
|
+
|
|
15774
|
+
|
|
15775
|
+
def _read_srt_cue_texts(path):
|
|
15776
|
+
with open(path, "r", encoding="utf-8-sig") as handle:
|
|
15777
|
+
content = handle.read()
|
|
15778
|
+
cues = []
|
|
15779
|
+
for block in re.split(r"(?:\r?\n){2,}", content.strip()):
|
|
15780
|
+
lines = block.splitlines()
|
|
15781
|
+
timing_index = next(
|
|
15782
|
+
(index for index, line in enumerate(lines)
|
|
15783
|
+
if re.match(r"^\s*\d{1,2}:\d{2}:\d{2}[,.]\d{1,3}\s*-->\s*"
|
|
15784
|
+
r"\d{1,2}:\d{2}:\d{2}[,.]\d{1,3}(?:\s+.*)?$", line)),
|
|
15785
|
+
None,
|
|
15786
|
+
)
|
|
15787
|
+
if timing_index is None:
|
|
15788
|
+
raise ValueError("SRT cue has no valid timing line")
|
|
15789
|
+
text = _normalized_subtitle_text("\n".join(lines[timing_index + 1:]))
|
|
15790
|
+
if not text:
|
|
15791
|
+
raise ValueError("SRT cue has empty text")
|
|
15792
|
+
cues.append(text)
|
|
15793
|
+
if not cues:
|
|
15794
|
+
raise ValueError("SRT contains no cues")
|
|
15795
|
+
return cues
|
|
15796
|
+
|
|
15797
|
+
|
|
15798
|
+
def _created_timeline_readback(proj, created, clips):
|
|
15799
|
+
"""Read back media IDs, subtitle cues, and source-less generator entries."""
|
|
15800
|
+
expected_ids, subtitle_ids, expected_generators = [], [], []
|
|
15801
|
+
subtitle_sources = []
|
|
15802
|
+
source_errors = []
|
|
15803
|
+
generator_warnings = []
|
|
15804
|
+
for clip in clips:
|
|
15805
|
+
clip_id = _safe_media_pool_item_id(clip)
|
|
15806
|
+
file_path = _created_clip_property(clip, "File Path")
|
|
15807
|
+
if (subtitle_append_guard.is_subtitle_item(clip)
|
|
15808
|
+
or (file_path and file_path.lower().endswith(".srt"))):
|
|
15809
|
+
if clip_id:
|
|
15810
|
+
subtitle_ids.append(clip_id)
|
|
15811
|
+
subtitle_sources.append(clip)
|
|
15812
|
+
continue
|
|
15813
|
+
clip_type = (_created_clip_property(clip, "Type") or "").strip().casefold()
|
|
15814
|
+
if clip_type in {"generator", "title", "fusion generator", "fusion composition"}:
|
|
15815
|
+
name = _safe_media_pool_item_name(clip)
|
|
15816
|
+
if name:
|
|
15817
|
+
expected_generators.append((clip_id, name))
|
|
15818
|
+
else:
|
|
15819
|
+
generator_warnings.append("Generator/title source has no readable name")
|
|
15820
|
+
elif clip_id:
|
|
15821
|
+
expected_ids.append(clip_id)
|
|
15822
|
+
else:
|
|
15823
|
+
name = _safe_media_pool_item_name(clip) or "<unnamed>"
|
|
15824
|
+
source_errors.append(f"Media source {name} has no readable unique ID")
|
|
15825
|
+
expected_ids = list(dict.fromkeys(expected_ids))
|
|
15826
|
+
subtitle_ids = list(dict.fromkeys(subtitle_ids))
|
|
15827
|
+
timeline_id = _safe_timeline_item_id(created)
|
|
15828
|
+
readback = {
|
|
15829
|
+
"timeline_id": timeline_id,
|
|
15830
|
+
"project_timeline_found": False,
|
|
15831
|
+
"item_count": 0,
|
|
15832
|
+
"media_pool_item_ids": [],
|
|
15833
|
+
"missing_clip_ids": list(expected_ids),
|
|
15834
|
+
"missing_generator_clip_ids": [clip_id for clip_id, _ in expected_generators if clip_id],
|
|
15835
|
+
"generator_item_names": [],
|
|
15836
|
+
"subtitle_readback": {
|
|
15837
|
+
"source_clip_ids": subtitle_ids,
|
|
15838
|
+
"sources": [],
|
|
15839
|
+
"mode": "source_srt" if subtitle_sources else None,
|
|
15840
|
+
"expected_cue_count": None,
|
|
15841
|
+
"cue_count": 0,
|
|
15842
|
+
"invalid_cue_count": 0,
|
|
15843
|
+
"text_mismatches": [],
|
|
15844
|
+
"verified": not subtitle_sources,
|
|
15845
|
+
},
|
|
15846
|
+
"errors": list(source_errors),
|
|
15847
|
+
"warnings": list(generator_warnings),
|
|
15848
|
+
"certain": False,
|
|
15849
|
+
"verified": False,
|
|
15850
|
+
}
|
|
15851
|
+
if not timeline_id:
|
|
15852
|
+
readback["errors"].append("Created timeline has no readable unique ID")
|
|
15853
|
+
return readback
|
|
15854
|
+
try:
|
|
15855
|
+
timeline_count = int(proj.GetTimelineCount() or 0)
|
|
15856
|
+
project_timeline = None
|
|
15857
|
+
for index in range(1, timeline_count + 1):
|
|
15858
|
+
candidate = proj.GetTimelineByIndex(index)
|
|
15859
|
+
if candidate and _safe_timeline_item_id(candidate) == timeline_id:
|
|
15860
|
+
project_timeline = candidate
|
|
15861
|
+
break
|
|
15862
|
+
except Exception as exc:
|
|
15863
|
+
readback["errors"].append(f"Project timeline enumeration failed: {exc}")
|
|
15864
|
+
return readback
|
|
15865
|
+
if project_timeline is None:
|
|
15866
|
+
readback["errors"].append("Created timeline unique ID is absent from the current project")
|
|
15867
|
+
return readback
|
|
15868
|
+
readback["project_timeline_found"] = True
|
|
15869
|
+
|
|
15870
|
+
observed_ids, generator_names, subtitle_texts = [], [], []
|
|
15871
|
+
for track_type in ("video", "audio", "subtitle"):
|
|
15872
|
+
try:
|
|
15873
|
+
track_count = int(project_timeline.GetTrackCount(track_type) or 0)
|
|
15874
|
+
except Exception as exc:
|
|
15875
|
+
readback["errors"].append(f"GetTrackCount({track_type}) failed: {exc}")
|
|
15876
|
+
continue
|
|
15877
|
+
for track_index in range(1, track_count + 1):
|
|
15878
|
+
try:
|
|
15879
|
+
items = project_timeline.GetItemListInTrack(track_type, track_index) or []
|
|
15880
|
+
except Exception as exc:
|
|
15881
|
+
readback["errors"].append(
|
|
15882
|
+
f"GetItemListInTrack({track_type}, {track_index}) failed: {exc}"
|
|
15883
|
+
)
|
|
15884
|
+
continue
|
|
15885
|
+
readback["item_count"] += len(items)
|
|
15886
|
+
for item in items:
|
|
15887
|
+
if track_type == "subtitle" and subtitle_sources:
|
|
15888
|
+
readback["subtitle_readback"]["cue_count"] += 1
|
|
15889
|
+
text = _normalized_subtitle_text(_safe_timeline_item_name(item))
|
|
15890
|
+
subtitle_texts.append(text)
|
|
15891
|
+
try:
|
|
15892
|
+
start, end = item.GetStart(), item.GetEnd()
|
|
15893
|
+
if not text or start is None or end is None or end <= start:
|
|
15894
|
+
readback["subtitle_readback"]["invalid_cue_count"] += 1
|
|
15895
|
+
except Exception:
|
|
15896
|
+
readback["subtitle_readback"]["invalid_cue_count"] += 1
|
|
15897
|
+
try:
|
|
15898
|
+
media_item = item.GetMediaPoolItem()
|
|
15899
|
+
media_id = _safe_media_pool_item_id(media_item)
|
|
15900
|
+
except Exception as exc:
|
|
15901
|
+
readback["errors"].append(f"Timeline item Media Pool readback failed: {exc}")
|
|
15902
|
+
continue
|
|
15903
|
+
if media_id and media_id not in observed_ids:
|
|
15904
|
+
observed_ids.append(media_id)
|
|
15905
|
+
if media_item is None and track_type != "subtitle" and expected_generators:
|
|
15906
|
+
try:
|
|
15907
|
+
name = item.GetName()
|
|
15908
|
+
start, end = item.GetStart(), item.GetEnd()
|
|
15909
|
+
if name and start is not None and end is not None and end > start:
|
|
15910
|
+
generator_names.append(name)
|
|
15911
|
+
except Exception:
|
|
15912
|
+
continue
|
|
15913
|
+
readback["media_pool_item_ids"] = observed_ids
|
|
15914
|
+
readback["missing_clip_ids"] = [clip_id for clip_id in expected_ids if clip_id not in observed_ids]
|
|
15915
|
+
readback["generator_item_names"] = list(dict.fromkeys(generator_names))
|
|
15916
|
+
readback["missing_generator_clip_ids"] = [
|
|
15917
|
+
clip_id for clip_id, name in expected_generators
|
|
15918
|
+
if clip_id and name not in generator_names
|
|
15919
|
+
]
|
|
15920
|
+
subtitle_readback = readback["subtitle_readback"]
|
|
15921
|
+
expected_texts = []
|
|
15922
|
+
source_comparison = bool(subtitle_sources)
|
|
15923
|
+
for clip in subtitle_sources:
|
|
15924
|
+
path = _created_clip_property(clip, "File Path")
|
|
15925
|
+
source = {
|
|
15926
|
+
"name": _safe_media_pool_item_name(clip),
|
|
15927
|
+
"file_path": path,
|
|
15928
|
+
"cue_count": None,
|
|
15929
|
+
}
|
|
15930
|
+
subtitle_readback["sources"].append(source)
|
|
15931
|
+
if not path:
|
|
15932
|
+
source_comparison = False
|
|
15933
|
+
continue
|
|
15934
|
+
try:
|
|
15935
|
+
cue_texts = _read_srt_cue_texts(path)
|
|
15936
|
+
except (OSError, ValueError) as exc:
|
|
15937
|
+
# An SRT this parser cannot read (not UTF-8, unusual layout) says
|
|
15938
|
+
# nothing about the timeline: compare the timeline's own cues
|
|
15939
|
+
# instead of failing a create that worked (#373).
|
|
15940
|
+
source["read_error"] = f"{type(exc).__name__}: {exc}"
|
|
15941
|
+
source_comparison = False
|
|
15942
|
+
continue
|
|
15943
|
+
source["cue_count"] = len(cue_texts)
|
|
15944
|
+
expected_texts.extend(cue_texts)
|
|
15945
|
+
if source_comparison:
|
|
15946
|
+
subtitle_readback["expected_cue_count"] = len(expected_texts)
|
|
15947
|
+
subtitle_readback["text_mismatches"] = [
|
|
15948
|
+
{"index": index, "expected": expected, "observed": observed}
|
|
15949
|
+
for index, (expected, observed) in enumerate(zip(expected_texts, subtitle_texts))
|
|
15950
|
+
if expected != observed
|
|
15951
|
+
]
|
|
15952
|
+
cue_count_matches = len(expected_texts) == len(subtitle_texts)
|
|
15953
|
+
else:
|
|
15954
|
+
subtitle_readback["mode"] = "timeline_cues" if subtitle_sources else None
|
|
15955
|
+
cue_count_matches = bool(subtitle_texts)
|
|
15956
|
+
subtitle_readback["verified"] = bool(
|
|
15957
|
+
not subtitle_sources
|
|
15958
|
+
or (subtitle_texts
|
|
15959
|
+
and cue_count_matches
|
|
15960
|
+
and not subtitle_readback["text_mismatches"]
|
|
15961
|
+
and subtitle_readback["invalid_cue_count"] == 0)
|
|
15962
|
+
)
|
|
15963
|
+
# Certain: the timeline is in the project, holds items, and every ordinary
|
|
15964
|
+
# media ID is on it. Heuristic: subtitle cue text (that GetName() equals
|
|
15965
|
+
# the cue text) and generator Type strings are not measured live, so a
|
|
15966
|
+
# miss there is reported, not turned into a failed call (#373).
|
|
15967
|
+
readback["certain"] = bool(
|
|
15968
|
+
(expected_ids or subtitle_sources or expected_generators)
|
|
15969
|
+
and not readback["missing_clip_ids"]
|
|
15970
|
+
and not readback["errors"]
|
|
15971
|
+
and readback["item_count"] > 0
|
|
15972
|
+
)
|
|
15973
|
+
readback["verified"] = bool(
|
|
15974
|
+
readback["certain"]
|
|
15975
|
+
and not readback["missing_generator_clip_ids"]
|
|
15976
|
+
and subtitle_readback["verified"]
|
|
15977
|
+
)
|
|
15978
|
+
return readback
|
|
15979
|
+
|
|
15980
|
+
|
|
15730
15981
|
def _compare_timeline_append_readback(before, observed, expected_count: int):
|
|
15731
15982
|
before_count = before.get("item_count") if isinstance(before, dict) and before.get("available") else None
|
|
15732
15983
|
after_count = observed.get("item_count") if isinstance(observed, dict) and observed.get("available") else None
|
|
@@ -17152,14 +17403,32 @@ def _timeline_frame_of(tl, timecode) -> Optional[int]:
|
|
|
17152
17403
|
return None if err else frame
|
|
17153
17404
|
|
|
17154
17405
|
|
|
17406
|
+
def _same_timecode_label(a, b) -> bool:
|
|
17407
|
+
"""True when two timecodes name the same HH:MM:SS:FF label.
|
|
17408
|
+
|
|
17409
|
+
Separators and padding are ignored: Resolve reports a drop-frame
|
|
17410
|
+
timeline's playhead with ';' even when the seek was asked with ':', and
|
|
17411
|
+
the frame parser reads the two separators as different frame counts.
|
|
17412
|
+
"""
|
|
17413
|
+
def parts(tc):
|
|
17414
|
+
if not isinstance(tc, str):
|
|
17415
|
+
return None
|
|
17416
|
+
fields = re.split(r"[:;.,]", tc.strip())
|
|
17417
|
+
if len(fields) != 4 or not all(f.isdigit() for f in fields):
|
|
17418
|
+
return None
|
|
17419
|
+
return tuple(int(f) for f in fields)
|
|
17420
|
+
pa = parts(a)
|
|
17421
|
+
return pa is not None and pa == parts(b)
|
|
17422
|
+
|
|
17423
|
+
|
|
17155
17424
|
def _seek_and_confirm(tl, target: str, *, attempts: int = 8, delay: float = 0.1):
|
|
17156
17425
|
"""SetCurrentTimecode(target) and read the playhead back until it lands.
|
|
17157
17426
|
|
|
17158
17427
|
Returns (landed_timecode, error). The return value of SetCurrentTimecode is
|
|
17159
17428
|
not the evidence: a True that left the playhead where it was has been
|
|
17160
17429
|
measured on Studio 19.1.3.7 straight after a page switch. The readback is
|
|
17161
|
-
compared by FRAME,
|
|
17162
|
-
|
|
17430
|
+
compared by FRAME, and by label with separators and padding ignored, so a
|
|
17431
|
+
drop-frame ';' or an unpadded hour cannot fail a seek that landed.
|
|
17163
17432
|
"""
|
|
17164
17433
|
want = _timeline_frame_of(tl, target)
|
|
17165
17434
|
try:
|
|
@@ -17179,7 +17448,7 @@ def _seek_and_confirm(tl, target: str, *, attempts: int = 8, delay: float = 0.1)
|
|
|
17179
17448
|
landed = tl.GetCurrentTimecode()
|
|
17180
17449
|
except Exception:
|
|
17181
17450
|
landed = None
|
|
17182
|
-
if want is None or _timeline_frame_of(tl, landed) == want:
|
|
17451
|
+
if want is None or _timeline_frame_of(tl, landed) == want or _same_timecode_label(target, landed):
|
|
17183
17452
|
return landed, None
|
|
17184
17453
|
if attempt < attempts - 1:
|
|
17185
17454
|
time.sleep(delay)
|
|
@@ -23602,6 +23871,12 @@ def media_pool(action: str, params: Optional[Dict[str, Any]] = None) -> Dict[str
|
|
|
23602
23871
|
_, row_err = _build_create_clip_info_dict(root, ci, i)
|
|
23603
23872
|
if row_err:
|
|
23604
23873
|
return row_err
|
|
23874
|
+
# Validate track_index/media_type before the timeline exists, then
|
|
23875
|
+
# add the tracks the rows name: an index past the new timeline's
|
|
23876
|
+
# tracks would land on track 1 with success (issue #370).
|
|
23877
|
+
needed_tracks, track_err = _clip_info_tracks.needed_tracks(raw)
|
|
23878
|
+
if track_err:
|
|
23879
|
+
return _err(track_err, code="INVALID_TRACK_INDEX", category="invalid_input")
|
|
23605
23880
|
tl = mp.CreateEmptyTimeline(create_name)
|
|
23606
23881
|
if not tl:
|
|
23607
23882
|
return _err("Failed to create timeline from clip_infos")
|
|
@@ -23609,12 +23884,21 @@ def media_pool(action: str, params: Optional[Dict[str, Any]] = None) -> Dict[str
|
|
|
23609
23884
|
proj, tl, what="appending the clip_infos")
|
|
23610
23885
|
if switch_err:
|
|
23611
23886
|
return switch_err
|
|
23887
|
+
ensure_err = _clip_info_tracks.ensure_tracks(tl, needed_tracks)
|
|
23888
|
+
if ensure_err:
|
|
23889
|
+
return _err(
|
|
23890
|
+
f"Timeline {tl.GetName()!r} was created but the tracks the clip_infos "
|
|
23891
|
+
f"name could not be added: {ensure_err}",
|
|
23892
|
+
code="ADD_TRACK_FAILED", category="api_error",
|
|
23893
|
+
state={"timeline": tl.GetName(), "needed": needed_tracks},
|
|
23894
|
+
)
|
|
23612
23895
|
timeline_start = _timeline_start_frame(tl)
|
|
23613
23896
|
built = []
|
|
23614
23897
|
for i, ci in enumerate(raw):
|
|
23615
23898
|
append_ci = dict(ci)
|
|
23616
23899
|
append_ci.setdefault("track_index", append_ci.get("trackIndex", 1))
|
|
23617
|
-
row, row_err = _build_append_clip_info_dict(
|
|
23900
|
+
row, row_err = _build_append_clip_info_dict(
|
|
23901
|
+
root, append_ci, i, timeline_start, timeline=tl)
|
|
23618
23902
|
if row_err:
|
|
23619
23903
|
return row_err
|
|
23620
23904
|
built.append(row)
|
|
@@ -23635,13 +23919,34 @@ def media_pool(action: str, params: Optional[Dict[str, Any]] = None) -> Dict[str
|
|
|
23635
23919
|
if clips_err:
|
|
23636
23920
|
return clips_err
|
|
23637
23921
|
tl = mp.CreateTimelineFromClips(create_name, clips)
|
|
23922
|
+
if not tl:
|
|
23923
|
+
return _err("Failed to create timeline", code="CREATE_TIMELINE_FAILED")
|
|
23924
|
+
readback = _created_timeline_readback(proj, tl, clips)
|
|
23925
|
+
if not readback["certain"]:
|
|
23926
|
+
out = _err(
|
|
23927
|
+
"CreateTimelineFromClips returned a timeline, but its project or clip readback failed",
|
|
23928
|
+
code="CREATE_TIMELINE_READBACK_FAILED", category="resolve_api_failed",
|
|
23929
|
+
retryable=False,
|
|
23930
|
+
remediation=("Inspect the current project for the returned timeline ID before retrying; "
|
|
23931
|
+
"the native call may already have created a timeline."),
|
|
23932
|
+
state=readback,
|
|
23933
|
+
)
|
|
23934
|
+
out.update({"success": False, "verified": False, "readback": readback})
|
|
23935
|
+
return out
|
|
23638
23936
|
return _ok(
|
|
23639
23937
|
name=tl.GetName(),
|
|
23640
23938
|
id=tl.GetUniqueId(),
|
|
23641
23939
|
requested_name=p.get("name"),
|
|
23642
23940
|
created_new=True,
|
|
23643
23941
|
versioned_name=bool(existing and create_name != p.get("name")),
|
|
23644
|
-
|
|
23942
|
+
verified=readback["verified"],
|
|
23943
|
+
readback=readback,
|
|
23944
|
+
**({"warnings": readback["warnings"] + [
|
|
23945
|
+
"The timeline and its media were confirmed, but the subtitle-cue or "
|
|
23946
|
+
"generator read-back did not match. Those checks rest on behaviour "
|
|
23947
|
+
"not yet measured live; inspect the timeline."
|
|
23948
|
+
]} if not readback["verified"] else {}),
|
|
23949
|
+
)
|
|
23645
23950
|
elif action == "create_multicam_clip":
|
|
23646
23951
|
missing = _requires_method(mp, "CreateMulticamClip", "21.1")
|
|
23647
23952
|
if missing:
|
|
@@ -23705,10 +24010,12 @@ def media_pool(action: str, params: Optional[Dict[str, Any]] = None) -> Dict[str
|
|
|
23705
24010
|
return _err("clip_infos must be a list")
|
|
23706
24011
|
if not raw:
|
|
23707
24012
|
return _err("clip_infos must be a non-empty list")
|
|
23708
|
-
|
|
24013
|
+
current_tl = proj.GetCurrentTimeline()
|
|
24014
|
+
timeline_start = _timeline_start_frame(current_tl)
|
|
23709
24015
|
built = []
|
|
23710
24016
|
for i, ci in enumerate(raw):
|
|
23711
|
-
row, row_err = _build_append_clip_info_dict(
|
|
24017
|
+
row, row_err = _build_append_clip_info_dict(
|
|
24018
|
+
root, ci, i, timeline_start, timeline=current_tl)
|
|
23712
24019
|
if row_err:
|
|
23713
24020
|
return row_err
|
|
23714
24021
|
built.append(row)
|
|
@@ -27187,7 +27494,8 @@ def edit_engine(action: str, params: Optional[Dict[str, Any]] = None) -> Dict[st
|
|
|
27187
27494
|
# Sequential assembly: each select lands after the previous one.
|
|
27188
27495
|
append_ci.setdefault("record_frame", record_cursor)
|
|
27189
27496
|
append_ci.setdefault("track_index", 1)
|
|
27190
|
-
row, row_err = _build_append_clip_info_dict(
|
|
27497
|
+
row, row_err = _build_append_clip_info_dict(
|
|
27498
|
+
root_folder, append_ci, i, timeline_start, timeline=tl)
|
|
27191
27499
|
if row_err:
|
|
27192
27500
|
build_errors.append({"index": i, "error": row_err.get("error")})
|
|
27193
27501
|
continue
|
|
@@ -27594,7 +27902,7 @@ def edit_engine(action: str, params: Optional[Dict[str, Any]] = None) -> Dict[st
|
|
|
27594
27902
|
"record_frame_mode": "absolute",
|
|
27595
27903
|
"track_index": int(item_block.get("track_index") or 1),
|
|
27596
27904
|
}
|
|
27597
|
-
row, row_err = _build_append_clip_info_dict(root_folder, ci, 0, timeline_start)
|
|
27905
|
+
row, row_err = _build_append_clip_info_dict(root_folder, ci, 0, timeline_start, timeline=tl)
|
|
27598
27906
|
if row_err:
|
|
27599
27907
|
return {"success": False, "error": f"swap append failed: {row_err.get('error')}", "lifted": lift}
|
|
27600
27908
|
# No mediaType on the clip info: the replacement appends video+audio
|
|
@@ -28754,7 +29062,7 @@ def timeline_markers(action: str, params: Optional[Dict[str, Any]] = None) -> An
|
|
|
28754
29062
|
delete_at_frame(frame|frame_id|frameId|timecode) -> {success}
|
|
28755
29063
|
delete_by_custom_data(custom_data) -> {success}
|
|
28756
29064
|
get_current_timecode() -> {timecode}
|
|
28757
|
-
set_current_timecode(timecode) -> {success}
|
|
29065
|
+
set_current_timecode(timecode) -> {success, requested, target, before, actual, api_success, verified}
|
|
28758
29066
|
get_current_video_item() -> {name, id}
|
|
28759
29067
|
get_thumbnail() -> {thumbnail}
|
|
28760
29068
|
get_thumbnail_image() -> MCP image content for the current Color-page frame
|
|
@@ -28855,7 +29163,49 @@ def timeline_markers(action: str, params: Optional[Dict[str, Any]] = None) -> An
|
|
|
28855
29163
|
elif action == "get_current_timecode":
|
|
28856
29164
|
return {"timecode": tl.GetCurrentTimecode()}
|
|
28857
29165
|
elif action == "set_current_timecode":
|
|
28858
|
-
|
|
29166
|
+
# The read-back goes through _seek_and_confirm: it compares by FRAME
|
|
29167
|
+
# (a drop-frame ';' or an unpadded hour is the same playhead) and
|
|
29168
|
+
# retries, since a True that had not moved the playhead yet has been
|
|
29169
|
+
# measured straight after a page switch (#373).
|
|
29170
|
+
requested = p["timecode"]
|
|
29171
|
+
target = _playhead_absolute_timecode(tl, requested)
|
|
29172
|
+
try:
|
|
29173
|
+
before = tl.GetCurrentTimecode()
|
|
29174
|
+
except Exception:
|
|
29175
|
+
before = None
|
|
29176
|
+
landed, seek_err = _seek_and_confirm(tl, target)
|
|
29177
|
+
api_success = seek_err is None or seek_err["error"].get("code") == "SEEK_UNCONFIRMED"
|
|
29178
|
+
if seek_err is None:
|
|
29179
|
+
actual = landed
|
|
29180
|
+
else:
|
|
29181
|
+
try:
|
|
29182
|
+
actual = tl.GetCurrentTimecode()
|
|
29183
|
+
except Exception:
|
|
29184
|
+
actual = None
|
|
29185
|
+
result = {
|
|
29186
|
+
"success": seek_err is None,
|
|
29187
|
+
"requested": requested,
|
|
29188
|
+
"target": target,
|
|
29189
|
+
"before": before,
|
|
29190
|
+
"actual": actual,
|
|
29191
|
+
"api_success": api_success,
|
|
29192
|
+
"verified": seek_err is None,
|
|
29193
|
+
}
|
|
29194
|
+
if seek_err is not None:
|
|
29195
|
+
message = (
|
|
29196
|
+
f"SetCurrentTimecode returned True but the playhead reads {actual!r}, not {target!r}"
|
|
29197
|
+
if api_success else seek_err["error"]["message"]
|
|
29198
|
+
)
|
|
29199
|
+
error = _err(
|
|
29200
|
+
message,
|
|
29201
|
+
code="TIMECODE_READBACK_MISMATCH" if api_success else "SET_CURRENT_TIMECODE_FAILED",
|
|
29202
|
+
category="resolve_api_failed" if api_success else seek_err["error"].get("category", "api_error"),
|
|
29203
|
+
retryable=True,
|
|
29204
|
+
remediation=seek_err["error"].get("remediation"),
|
|
29205
|
+
state={key: value for key, value in result.items() if key != "success"},
|
|
29206
|
+
)
|
|
29207
|
+
result.update(error)
|
|
29208
|
+
return result
|
|
28859
29209
|
elif action == "get_current_video_item":
|
|
28860
29210
|
it = tl.GetCurrentVideoItem()
|
|
28861
29211
|
return {"name": it.GetName(), "id": it.GetUniqueId()} if it else {"name": None, "id": None}
|