Skip to content

PRINTFILM: AI short-video marketing and AI short-drama creation platform

fix: 流水线任务按 phase 投影状态,分镜时长对齐 @duration

yic790846f270e
diff --git a/backend/app/api/projects.py b/backend/app/api/projects.py
index 70adf89..5073805 100644
--- a/backend/app/api/projects.py
+++ b/backend/app/api/projects.py
@@ -222,7 +222,29 @@ def _project_runtime_view(project: Project) -> tuple[str, int, str | None]:
status = str(getattr(task, "status", "") or "")
progress = int(getattr(task, "progress_percent", 0) or 0)
if task_type == "project_pipeline":
- label = ProjectStatus.SCRIPTING
+ # 勿一律标 SCRIPTING:续跑 videos/assets 时列表会误显示「拆分镜中」
+ payload = getattr(task, "payload", None) or {}
+ phase = str(payload.get("phase") or "").strip().lower() if isinstance(payload, dict) else ""
+ phase_label = {
+ "script": ProjectStatus.SCRIPTING,
+ "assets": ProjectStatus.IMAGING,
+ "videos": ProjectStatus.VIDEOING,
+ "compose": ProjectStatus.COMPOSING,
+ }.get(phase)
+ proj_status = str(project.status or "")
+ if phase_label:
+ label = phase_label
+ elif proj_status in {
+ ProjectStatus.SCRIPTING,
+ ProjectStatus.IMAGING,
+ ProjectStatus.VIDEOING,
+ ProjectStatus.AUDIOING,
+ ProjectStatus.COMPOSING,
+ ProjectStatus.AUDITING,
+ }:
+ label = proj_status
+ else:
+ label = ProjectStatus.SCRIPTING
elif task_type == "shot_regen_image":
label = ProjectStatus.IMAGING
elif task_type == "shot_regen_video":
diff --git a/backend/app/services/pipeline.py b/backend/app/services/pipeline.py
index ea27654..3fe5110 100644
--- a/backend/app/services/pipeline.py
+++ b/backend/app/services/pipeline.py
@@ -717,8 +717,11 @@ async def _script_stage(project_id: int) -> None:
await db.flush()
bible = project.character_bible
for plan in plans:
+ segment_script = (plan.segment_script or plan.video_prompt or "").strip()
+ # 时长以脚本 @duration 合计为准(与列表「逐段分镜」标签一致),勿只用 LLM duration 字段
+ script_total = segplan.sum_duration(segment_script)
dur = clamp_shot_duration(
- plan.duration,
+ float(script_total if script_total > 0 else plan.duration),
pipeline_mode=mode,
tpl_min=tpl.shot_duration_min,
tpl_max=tpl.shot_duration_max,
@@ -732,7 +735,6 @@ async def _script_stage(project_id: int) -> None:
scene = scene.replace(bible, "", 1)
scene = strip_lock_blocks(scene)
img_prompt = ark._sanitize_seedream_prompt(scene)
- segment_script = (plan.segment_script or plan.video_prompt or "").strip()
db.add(
Shot(
project_id=project.id,
diff --git a/backend/tests/test_project_runtime_view.py b/backend/tests/test_project_runtime_view.py
new file mode 100644
index 0000000..42da9dc
--- /dev/null
+++ b/backend/tests/test_project_runtime_view.py
@@ -0,0 +1,51 @@
+"""Unit tests for project list runtime status projection."""
+
+from types import SimpleNamespace
+
+from app.api.projects import _project_runtime_view
+from app.models import ProjectStatus
+
+
+def _proj(**kwargs):
+ return SimpleNamespace(
+ status=kwargs.get("status", ProjectStatus.VIDEOING),
+ progress=kwargs.get("progress", 81),
+ error_msg=kwargs.get("error_msg"),
+ active_tasks=kwargs.get("active_tasks", []),
+ )
+
+
+def _task(*, task_type="project_pipeline", status="running", phase="videos", progress=0):
+ return SimpleNamespace(
+ task_type=task_type,
+ status=status,
+ progress_percent=progress,
+ error_message=None,
+ payload={"phase": phase, "project_id": 404},
+ )
+
+
+def test_pipeline_videos_phase_shows_videoing_not_scripting():
+ p = _proj(active_tasks=[_task(phase="videos")])
+ status, progress, _err = _project_runtime_view(p)
+ assert status == ProjectStatus.VIDEOING
+ assert progress == 81
+
+
+def test_pipeline_assets_phase_shows_imaging():
+ p = _proj(status=ProjectStatus.IMAGING, progress=40, active_tasks=[_task(phase="assets")])
+ status, _, _ = _project_runtime_view(p)
+ assert status == ProjectStatus.IMAGING
+
+
+def test_pipeline_script_phase_shows_scripting():
+ p = _proj(status=ProjectStatus.SCRIPTING, progress=5, active_tasks=[_task(phase="script")])
+ status, _, _ = _project_runtime_view(p)
+ assert status == ProjectStatus.SCRIPTING
+
+
+def test_no_active_task_keeps_project_status():
+ p = _proj(status=ProjectStatus.VIDEOING, progress=81, active_tasks=[])
+ status, progress, _ = _project_runtime_view(p)
+ assert status == ProjectStatus.VIDEOING
+ assert progress == 81
diff --git a/frontend/src/lib/segmentDuration.ts b/frontend/src/lib/segmentDuration.ts
index a66227b..e9f35af 100644
--- a/frontend/src/lib/segmentDuration.ts
+++ b/frontend/src/lib/segmentDuration.ts
@@ -51,6 +51,22 @@ export function sumDuration(content: string): number {
return extractDurations(content).reduce((sum, value) => sum + value, 0)
}
+/**
+ * 分镜列表展示用时长:优先脚本内 @duration 合计,否则回退 shot.duration
+ * (生成时 LLM 的 duration 字段常与逐段标签脱节,列表应对齐用户看到的 3s/4s 标签)
+ */
+export function shotDisplayDurationSec(shot: {
+ duration?: number | null
+ segment_script?: string | null
+ video_prompt?: string | null
+}): number {
+ const script = String(shot.segment_script || shot.video_prompt || '')
+ const tagged = sumDuration(script)
+ if (tagged > 0) return tagged
+ const stored = Number(shot.duration)
+ return Number.isFinite(stored) && stored > 0 ? stored : 0
+}
+
/**
* 校验单个时长是否在科普单段合法区间
* @param seconds 时长秒数
diff --git a/frontend/src/pages/studio/StoryboardPage.tsx b/frontend/src/pages/studio/StoryboardPage.tsx
index a4edc4d..7c254f4 100644
--- a/frontend/src/pages/studio/StoryboardPage.tsx
+++ b/frontend/src/pages/studio/StoryboardPage.tsx
@@ -43,6 +43,8 @@ import {
parseSegmentScript,
replaceFirstVisualInScript,
replaceNarrationInScript,
+ shotDisplayDurationSec,
+ sumDuration,
validateSegmentScriptDuration,
} from '../../lib/segmentDuration'
@@ -62,7 +64,7 @@ function downloadStoryboardCsv(project: Project) {
s.shot_no,
s.narration,
scenePromptForDisplay(s.img_prompt || s.video_prompt || ''),
- s.duration,
+ shotDisplayDurationSec(s),
shotDisplayLabel(shotDisplayKind(s, { pipelineMode: project.pipeline_mode })),
s.overlay_title || '',
]
@@ -193,7 +195,7 @@ export default function StoryboardPage() {
const running = isProjectBusy(project)
const step = project ? kepuStepIndex('board', project) : 2
const totalDuration = useMemo(
- () => (project?.shots || []).reduce((s, x) => s + (Number(x.duration) || 0), 0),
+ () => (project?.shots || []).reduce((s, x) => s + shotDisplayDurationSec(x), 0),
[project?.shots],
)
@@ -569,15 +571,17 @@ export default function StoryboardPage() {
})
}
- // 改脚本时回填旁白与首帧画面
+ // 改脚本时回填旁白与首帧画面,并同步时长为 @duration 合计
function patchEditingScript(value: string) {
if (!editing) return
+ const tagged = sumDuration(value)
setEditing({
...editing,
segment_script: value,
video_prompt: value,
narration: narrationFromScript(value),
img_prompt: firstVisualFromScript(value) || editing.img_prompt,
+ duration: tagged > 0 ? tagged : editing.duration,
})
}
@@ -600,7 +604,7 @@ export default function StoryboardPage() {
img_prompt: editing.img_prompt,
video_prompt: editing.video_prompt,
segment_script: editing.segment_script,
- duration: Number(editing.duration) || 4,
+ duration: durationCheck.total > 0 ? durationCheck.total : Number(editing.duration) || 4,
camera: editing.camera,
})
closeShotEdit()
@@ -1132,7 +1136,7 @@ title="用当前镜头重新拼接"
)}
</button>
</td>
- <td className="col-dur">{formatMmSs(shot.duration)}</td>
+ <td className="col-dur">{formatMmSs(shotDisplayDurationSec(shot))}</td>
<td className="col-status">
<span
className={[
@@ -1310,7 +1314,7 @@ title="用当前镜头重新拼接"
)
}
/>
- 镜头 {String(s.shot_no).padStart(2, '0')} · {formatMmSs(Number(s.duration) || 0)}
+ 镜头 {String(s.shot_no).padStart(2, '0')} · {formatMmSs(shotDisplayDurationSec(s))}
</label>
))}
</div>