利用 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(material): address review — pending status, mirror_urls priority, rebase onto grouped source selector
celeste19006991d98816fa
diff --git a/app/services/ofox.py b/app/services/ofox.pyindex d18cf5c3..a9d2389a 100644--- a/app/services/ofox.py+++ b/app/services/ofox.py@@ -29,7 +29,8 @@ TERMINAL_SUCCESS_STATUSES = frozenset({"completed", "succeeded"})TERMINAL_FAILURE_STATUSES = frozenset({"failed", "error", "cancelled", "canceled", "expired"})-ACTIVE_STATUSES = frozenset({"queued", "in_progress"})+# 官方成功路径: pending(收单待上游提交) → queued → in_progress → completed+ACTIVE_STATUSES = frozenset({"pending", "queued", "in_progress"})class OFoxError(RuntimeError):@@ -302,13 +303,19 @@ def generate_videos(if task is None:return []- # 产物地址在 unsigned_urls 里,是会过期的临时直链,必须整体保留并- # 立即用于下载,不能写入长期的 source_info。- unsigned_urls = task.get("unsigned_urls")+ # 官方推荐优先使用 mirror_urls(OFox CDN 持久签名地址,仅在上游开启镜像+ # 时返回),缺失时回退到 unsigned_urls(上游临时直链,可能 24 小时内过+ # 期)。两者都必须整体保留并立即用于下载,不写入长期的 source_info。video_url = ""- for candidate in unsigned_urls if isinstance(unsigned_urls, list) else []:- if isinstance(candidate, str) and candidate.startswith(("http://", "https://")):- video_url = candidate+ for field in ("mirror_urls", "unsigned_urls"):+ urls = task.get(field)+ for candidate in urls if isinstance(urls, list) else []:+ if isinstance(candidate, str) and candidate.startswith(+ ("http://", "https://")+ ):+ video_url = candidate+ break+ if video_url:breakif not video_url:raise OFoxError(diff --git a/test/services/test_ofox.py b/test/services/test_ofox.pyindex db5f1418..91675c0b 100644--- a/test/services/test_ofox.py+++ b/test/services/test_ofox.py@@ -276,6 +276,74 @@ class TestOFoxService(unittest.TestCase):ofox.generate_videos("sunrise", 5)self.assertEqual(post.call_count, 1)+ def test_pending_status_is_active_and_polling_continues(self):+ # 官方成功路径为 pending → queued → in_progress → completed;首次轮询+ # 拿到 pending 属于正常在途状态,不能当作未知状态终止任务。+ submit = self._response({"id": "vid-pending", "status": "queued"}, 202)+ polls = [+ self._response({"id": "vid-pending", "status": "pending"}),+ self._response({"id": "vid-pending", "status": "queued"}),+ self._response({"id": "vid-pending", "status": "in_progress"}),+ self._response(+ {+ "id": "vid-pending",+ "status": "completed",+ "unsigned_urls": ["https://cdn.example.com/pending.mp4"],+ }+ ),+ ]+ with (+ patch.object(ofox.requests, "post", return_value=submit),+ patch.object(ofox.requests, "get", side_effect=polls) as get,+ patch.object(ofox.time, "sleep"),+ ):+ result = ofox.generate_videos("sunrise", 5)++ self.assertEqual(len(result), 1)+ self.assertEqual(get.call_count, 4)++ def test_mirror_urls_are_preferred_over_unsigned_urls(self):+ submit = self._response({"id": "vid-mirror", "status": "queued"}, 202)+ completed = self._response(+ {+ "id": "vid-mirror",+ "status": "completed",+ "mirror_urls": ["https://cdn.ofox.ai/videos/vid-mirror.mp4?sig=abc"],+ "unsigned_urls": ["https://upstream.example.com/tmp.mp4"],+ }+ )+ with (+ patch.object(ofox.requests, "post", return_value=submit),+ patch.object(ofox.requests, "get", return_value=completed),+ ):+ result = ofox.generate_videos("sunrise", 5)++ self.assertEqual(+ result[0].url, "https://cdn.ofox.ai/videos/vid-mirror.mp4?sig=abc"+ )++ def test_missing_or_invalid_mirror_urls_fall_back_to_unsigned_urls(self):+ # mirror_urls 仅在上游开启镜像时返回;缺失、为空或不含合法直链时都+ # 必须回退到 unsigned_urls,不能让任务失败。+ for mirror in (None, [], ["not-a-url", 123]):+ with self.subTest(mirror=mirror):+ submit = self._response({"id": "vid-fallback", "status": "queued"}, 202)+ body = {+ "id": "vid-fallback",+ "status": "completed",+ "unsigned_urls": ["https://upstream.example.com/ok.mp4"],+ }+ if mirror is not None:+ body["mirror_urls"] = mirror+ completed = self._response(body)+ with (+ patch.object(ofox.requests, "post", return_value=submit),+ patch.object(ofox.requests, "get", return_value=completed),+ ):+ result = ofox.generate_videos("sunrise", 5)++ self.assertEqual(result[0].url, "https://upstream.example.com/ok.mp4")+def test_poll_retries_transient_errors_on_same_task(self):submit = self._response({"id": "vid-retry", "status": "queued"}, 202)rate_limited = self._response({}, status_code=429)diff --git a/test/services/test_webui_generation_defaults.py b/test/services/test_webui_generation_defaults.pyindex 22955abd..6754686d 100644--- a/test/services/test_webui_generation_defaults.py+++ b/test/services/test_webui_generation_defaults.py@@ -358,7 +358,7 @@ def test_ofox_source_shows_unchecked_paid_task_confirmation():):app = _new_app()- assert _widget_by_key(app.selectbox, "video_source_select").value == "ofox"+ assert app.session_state["video_source_select_en"] == "ofox"assert _widget_by_key(app.checkbox, "ofox_confirm_charge").value is Falsediff --git a/test/services/test_webui_grouped_select.py b/test/services/test_webui_grouped_select.pyindex 4e13c47c..f7e7bda1 100644--- a/test/services/test_webui_grouped_select.py+++ b/test/services/test_webui_grouped_select.py@@ -120,6 +120,7 @@ def test_grouped_video_source_keeps_groups_and_accessible_label_binding():"coverr","wavespeed","volcengine_seedance",+ "ofox","loomloom","openai_image","local",diff --git a/test/services/test_webui_ofox.py b/test/services/test_webui_ofox.pyindex b79846f5..650c29c8 100644--- a/test/services/test_webui_ofox.py+++ b/test/services/test_webui_ofox.py@@ -42,7 +42,8 @@ def test_ofox_source_requires_confirmation_then_submits_without_secret_in_params_widget_by_key(app.text_area, "video_terms").set_value("office worker, AI assistant").run()- _widget_by_key(app.selectbox, "video_source_select").select("ofox").run()+ app.session_state["video_source_select_en"] = "ofox"+ app.run()_widget_by_key(app.button, "generate_video_button").click().run()assert submit_generation.call_count == 0