利用 AI 大模型和自动化工作流,根据主题或关键词一键生成高清短视频。Generate HD short videos from a topic or keyword with an automated AI workflow.
Python ai-video-generatorcontent-creationffmpeginstagram-reelsllmpythonshort-videosubtitlestext-to-speechtiktokvideo-automationvideo-workflowworkflow-automationyoutube-shorts
fix(loomloom): avoid synthesizing narration from nontext results
Rudy Celeklibbe7eb9ae3e7
diff --git a/app/services/loomloom.py b/app/services/loomloom.pyindex e4216b61..18565070 100644--- a/app/services/loomloom.py+++ b/app/services/loomloom.py@@ -627,8 +627,8 @@ class LoomLoomScriptBackend:if not isinstance(value, dict):raise LoomLoomAPIError("result artifact JSON must be an object")- script = str(value.get("script", "")).strip()- if not script:+ script = value.get("script")+ if not isinstance(script, str) or not script.strip():raise LoomLoomAPIError("result artifact script is required")video_terms = value.get("videoTerms")if not isinstance(video_terms, list) or not video_terms:@@ -636,13 +636,13 @@ class LoomLoomScriptBackend:"result artifact videoTerms must be a non-empty list")normalized_terms = tuple(- str(term).strip() for term in video_terms if str(term).strip()+ term.strip() for term in video_terms if isinstance(term, str) and term.strip())if not normalized_terms:raise LoomLoomAPIError("result artifact videoTerms must not be empty")return LoomLoomScriptCandidate(row_index=row_index,- script=script,+ script=script.strip(),video_terms=normalized_terms,)diff --git a/test/services/test_loomloom_script_result_types.py b/test/services/test_loomloom_script_result_types.pynew file mode 100644index 00000000..6967c78f--- /dev/null+++ b/test/services/test_loomloom_script_result_types.py@@ -0,0 +1,35 @@+import json+from unittest.mock import patch++import pytest++from app.services.loomloom import LoomLoomScriptBackend, LoomLoomSettings++[email protected]("field,value", [+ ("script", None), ("script", False), ("script", 42), ("script", {"text": "Hello"}),+ ("videoTerms", [None]), ("videoTerms", [False]), ("videoTerms", [42]),+ ("videoTerms", [{"term": "ocean"}]),+])+def test_nontext_script_results_become_row_errors(field, value):+ backend = LoomLoomScriptBackend(LoomLoomSettings.from_mapping({"loomloom_api_token": "fixture"}))+ payload = {"script": "Ocean narration", "videoTerms": ["ocean waves"]}+ payload[field] = value+ row = {"rowIndex": 0, "status": "completed", "artifacts": [+ {"portName": "output", "inlineText": json.dumps(payload)}+ ]}+ with patch.object(backend, "_list_all_result_rows", return_value=[row]):+ result = backend.get_script_results("fixture-run")+ assert result.candidates == ()+ assert len(result.errors) == 1+ assert result.errors[0].row_index == 0+++def test_valid_text_script_and_search_terms_remain_usable():+ backend = LoomLoomScriptBackend(LoomLoomSettings.from_mapping({"loomloom_api_token": "fixture"}))+ row = {"artifacts": [{"portName": "output", "inlineText": json.dumps({+ "script": " Ocean narration ", "videoTerms": [" ocean waves ", ""]+ })}]}+ candidate = backend._parse_candidate(0, row)+ assert candidate.script == "Ocean narration"+ assert candidate.video_terms == ("ocean waves",)