From 5d52abe8530c5364e27c15147180fc23cd5a2c09 Mon Sep 17 00:00:00 2001 From: Dreaming Computers Date: Wed, 11 Feb 2026 11:06:30 +0700 Subject: [PATCH] kling3: support 'shot 1 | 4 seconds | prompt' multi-shot format --- kie_api/kling3_video.py | 27 ++++++++++++++++----------- nodes.py | 19 ++++++++++--------- web/docs/KIE_Kling3_Preflight.md | 1 + web/docs/KIE_Kling3_Video.md | 14 +++++++------- 4 files changed, 34 insertions(+), 27 deletions(-) diff --git a/kie_api/kling3_video.py b/kie_api/kling3_video.py index e895e76..055321b 100644 --- a/kie_api/kling3_video.py +++ b/kie_api/kling3_video.py @@ -58,21 +58,26 @@ def _parse_multi_prompt_text(shots_text: str) -> list[dict[str, Any]]: shots: list[dict[str, Any]] = [] for idx, line in enumerate(lines, start=1): parts = [part.strip() for part in line.split("|")] - if len(parts) == 2: - duration_str, prompt = parts - elif len(parts) >= 3: - duration_str, prompt = parts[1], "|".join(parts[2:]).strip() - else: + if len(parts) < 3: raise _validation_error( f"Invalid shots_text format on line {idx}. " - "Use 'duration | prompt' or 'label | duration | prompt'. " - "Example: '3 | A dog runs through fog' or 'shot1 | 3 | A dog runs through fog'." + "Use 'shot_label | duration | prompt'. " + "Example: 'shot 1 | 3 seconds | A dog runs through fog'." ) + shot_label = parts[0] + duration_str = parts[1] + prompt = "|".join(parts[2:]).strip() - try: - duration = int(duration_str) - except ValueError as exc: - raise _validation_error(f"Invalid shot duration '{duration_str}' on line {idx}.") from exc + if not shot_label: + raise _validation_error(f"Missing shot label on line {idx}.") + + duration_match = re.match(r"^(\\d+)(?:\\s*seconds?)?$", duration_str, flags=re.IGNORECASE) + if not duration_match: + raise _validation_error( + f"Invalid shot duration '{duration_str}' on line {idx}. " + "Use values like '4' or '4 seconds'." + ) + duration = int(duration_match.group(1)) if duration < MULTI_SHOT_MIN or duration > MULTI_SHOT_MAX: raise _validation_error( diff --git a/nodes.py b/nodes.py index 86c0a5e..a763b71 100644 --- a/nodes.py +++ b/nodes.py @@ -775,9 +775,8 @@ Inputs: - multi_shots: enable multi-shot mode - prompt: Used in single-shot mode - shots_text: Used in multi-shot mode, format: - duration | prompt - or - label | duration | prompt + shot_label | duration | prompt + duration can be like: 4 or 4 seconds - first_frame: Optional start frame image - last_frame: Optional end frame image (single-shot only) - sound: Single-shot only @@ -796,9 +795,10 @@ Outputs: - VIDEO: ComfyUI video output compatible with SaveVideo """ SHOTS_TEXT_PLACEHOLDER = ( - "shot1 | 4 | Wide cinematic opening with @element_name\n" - "shot2 | 3 | Medium tracking shot with @element_name\n" - "shot3 | 3 | Close-up emotional finale with @element_name" + "multi-prompt section:\n" + "shot 1 | 4 seconds | Wide cinematic opening with @element_name\n" + "shot 2 | 3 seconds | Medium tracking shot with @element_name\n" + "shot 3 | 3 seconds | Close-up emotional finale with @element_name" ) @classmethod @@ -908,9 +908,10 @@ Outputs: - STRING: notes """ SHOTS_TEXT_PLACEHOLDER = ( - "shot1 | 4 | Wide cinematic opening with @element_name\n" - "shot2 | 3 | Medium tracking shot with @element_name\n" - "shot3 | 3 | Close-up emotional finale with @element_name" + "multi-prompt section:\n" + "shot 1 | 4 seconds | Wide cinematic opening with @element_name\n" + "shot 2 | 3 seconds | Medium tracking shot with @element_name\n" + "shot 3 | 3 seconds | Close-up emotional finale with @element_name" ) @classmethod diff --git a/web/docs/KIE_Kling3_Preflight.md b/web/docs/KIE_Kling3_Preflight.md index dc0682d..8ba1613 100644 --- a/web/docs/KIE_Kling3_Preflight.md +++ b/web/docs/KIE_Kling3_Preflight.md @@ -20,6 +20,7 @@ Validate Kling 3.0 inputs and build the exact payload JSON without submitting a ## Notes - This node still uploads required input media to produce valid URLs in payload. - In multi-shot mode, duration is auto-calculated from shot durations. +- Multi-shot `shots_text` must use: `shot_label | duration | prompt` (duration supports `4` or `4 seconds`). - `notes` returns a `VALID` summary when checks pass, including: - mode, single/multi-shot status, resolved duration - frame count and aspect-ratio handling diff --git a/web/docs/KIE_Kling3_Video.md b/web/docs/KIE_Kling3_Video.md index ce210a3..806dbc2 100644 --- a/web/docs/KIE_Kling3_Video.md +++ b/web/docs/KIE_Kling3_Video.md @@ -12,8 +12,8 @@ Generate Kling 3.0 videos in single-shot or multi-shot mode. - `multi_shots` (BOOLEAN): enables multi-shot mode - `prompt` (STRING): single-shot prompt - `shots_text` (STRING, optional): multi-shot lines: - - `duration | prompt` - - or `label | duration | prompt` + - `shot_label | duration | prompt` + - duration accepts `4` or `4 seconds` - `first_frame` (IMAGE, optional): start frame - `last_frame` (IMAGE, optional): end frame (single-shot only) - `sound` (BOOLEAN, optional): single-shot only @@ -37,12 +37,12 @@ Generate Kling 3.0 videos in single-shot or multi-shot mode. - Single-shot (`multi_shots=false`): use `prompt`. - Multi-shot (`multi_shots=true`): use `shots_text` only. - `shots_text` format: - - `duration | prompt` - - or `label | duration | prompt` + - `shot_label | duration | prompt` + - duration accepts `4` or `4 seconds` - Example: - - `shot1 | 4 | A woman exits a spaceship with @dog` - - `shot2 | 3 | Medium tracking shot of @dog running` - - `shot3 | 3 | Emotional close-up of @dog and @old_woman` + - `shot 1 | 4 seconds | A woman exits a spaceship with @dog` + - `shot 2 | 3 seconds | Medium tracking shot of @dog running` + - `shot 3 | 3 seconds | Emotional close-up of @dog and @old_woman` ## Element Naming and References - Define elements upstream with `KIE Kling Elements`.