Skip to content

利用 AI 大模型和自动化工作流,根据主题或关键词一键生成高清短视频。Generate HD short videos from a topic or keyword with an automated AI workflow.

fix(task): reject unsupported video sources before generation

Rudy Celekli84a8c8032f36
diff --git a/app/services/task.py b/app/services/task.py
index 968e8556..08a586d0 100644
--- a/app/services/task.py
+++ b/app/services/task.py
@@ -91,6 +91,13 @@ _VIDEO_MUSIC_PROVIDERS = {
}
+_SUPPORTED_VIDEO_SOURCES = frozenset({
+ "pexels", "pixabay", "coverr", "local", "wavespeed",
+ "volcengine_seedance", "ofox", "metaso_minimax", "muapi",
+ "loomloom", "openai_image",
+})
+
+
def _get_video_music_prompt(params: VideoParams) -> str:
"""
读取当前视频配乐供应商实际使用的提示词。
@@ -1479,6 +1486,11 @@ def _run_pipeline(
logger.info(f"start task: {task_id}, stop_at: {stop_at}")
sm.state.update_task(task_id, state=const.TASK_STATE_PROCESSING, progress=5)
+ if stop_at in {"materials", "video"} and params.video_source not in _SUPPORTED_VIDEO_SOURCES:
+ return _mark_task_failed(
+ task_id, "preflight", f"unsupported video source: {params.video_source!r}"
+ )
+
if (
stop_at in {"materials", "video"}
and params.video_source == "volcengine_seedance"
diff --git a/test/services/test_material_source_preflight.py b/test/services/test_material_source_preflight.py
new file mode 100644
index 00000000..c30b22bd
--- /dev/null
+++ b/test/services/test_material_source_preflight.py
@@ -0,0 +1,39 @@
+from unittest.mock import patch
+import pytest
+from app.models.schema import TaskVideoRequest
+from app.services import task as tm
+from app.services.state import MemoryState
+
+
[email protected]("source", ["pexel", "unknown-provider", None, ""])
+def test_unknown_material_source_fails_before_llm_or_narration(source):
+ params = TaskVideoRequest(
+ video_subject="Coffee", video_source=source, subtitle_enabled=False
+ )
+ state = MemoryState()
+ with (
+ patch.object(tm.sm, "state", state),
+ patch.object(tm.utils, "check_ffmpeg_ready", return_value=True),
+ patch.object(tm, "generate_script", return_value="Narration") as script,
+ patch.object(tm, "generate_terms", return_value=["coffee"]) as terms,
+ patch.object(tm, "save_script_data"),
+ patch.object(tm, "generate_audio", return_value=(None, None, None)) as audio,
+ ):
+ result = tm.start("invalid-source", params)
+ assert result["failed_stage"] == "preflight"
+ assert "video source" in result["error"].lower()
+ script.assert_not_called()
+ terms.assert_not_called()
+ audio.assert_not_called()
+
+
+def test_script_only_stage_does_not_require_a_material_provider():
+ params = TaskVideoRequest(
+ video_subject="Coffee",
+ video_source="unknown-provider",
+ video_script="Narration",
+ )
+ with patch.object(tm.sm, "state", MemoryState()):
+ assert tm.start("script-only", params, stop_at="script") == {
+ "script": "Narration"
+ }