Skip to content

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

fix(cli): validate saved subtitle background colour, scope README claim

Jeff Block39fd54aca8e9
diff --git a/README-en.md b/README-en.md
index 3bb08a11..c33bf64f 100644
--- a/README-en.md
+++ b/README-en.md
@@ -347,9 +347,11 @@ command line. The simplest complete generation command is:
uv run python cli.py --video-subject "How AI is changing everyday life"
```
-Subtitle style and voice options you do not pass explicitly fall back to the WebUI
-settings stored under `[ui]` in `config.toml`, so both entry points produce
-consistent videos.
+Subtitle style and voiceover options resolve in this order: **explicit CLI option >
+saved `[ui]` value in `config.toml` > built-in default**. Other generation settings,
+such as background music, video count, and paragraph count, are not inherited from
+the WebUI. If the WebUI is set to use uploaded audio, pass `--custom-audio-file`
+explicitly, since the uploaded path is not persisted.
For the complete command reference, parameter descriptions, and usage instructions,
run:
diff --git a/README.md b/README.md
index 6d31d20c..32a736eb 100644
--- a/README.md
+++ b/README.md
@@ -358,8 +358,10 @@ python main.py
uv run python cli.py --video-subject "人工智能如何改变日常生活"
```
-未在命令行显式指定的字幕样式和语音参数,会沿用 WebUI 保存在 `config.toml`
-`[ui]` 中的设置,因此两种方式生成的视频保持一致。
+字幕样式和配音参数按以下优先级取值:**命令行显式参数 > `config.toml` 中
+`[ui]` 保存的 WebUI 设置 > 内置默认值**。其余生成设置(如背景音乐、视频数量、
+段落数量等)不会自动沿用 WebUI 的保存值。若 WebUI 中选择了上传自备音频,
+命令行需要显式传入 `--custom-audio-file`,因为音频路径不会被保存。
如需查看完整命令、参数说明和使用方法,可以执行:
diff --git a/cli.py b/cli.py
index af8e797e..732e75bd 100644
--- a/cli.py
+++ b/cli.py
@@ -724,7 +724,10 @@ def build_video_params(args: argparse.Namespace) -> VideoParams:
# 用户只开启了背景而没有覆盖颜色,因此优先沿用 WebUI 保存的颜色,
# 只有在没有可用保存值时才回退到默认背景。
params_kwargs["text_background_color"] = (
- _ui_config_value(ui_config, "subtitle_background_color", str) or True
+ _ui_config_value(
+ ui_config, "subtitle_background_color", str, _hex_color
+ )
+ or True
)
else:
# “关闭背景”加上颜色作为命令行组合是参数错误;但作为保存的设置,
@@ -732,7 +735,9 @@ def build_video_params(args: argparse.Namespace) -> VideoParams:
ui_enabled = _ui_config_value(
ui_config, "subtitle_background_enabled", bool
)
- ui_color = _ui_config_value(ui_config, "subtitle_background_color", str)
+ ui_color = _ui_config_value(
+ ui_config, "subtitle_background_color", str, _hex_color
+ )
if ui_enabled is False:
params_kwargs["text_background_color"] = False
if args.rounded_subtitle_background is None:
diff --git a/test/services/test_cli.py b/test/services/test_cli.py
index 93306edb..8f845c3b 100644
--- a/test/services/test_cli.py
+++ b/test/services/test_cli.py
@@ -993,6 +993,51 @@ class TestCliUiDefaults(unittest.TestCase):
self.assertEqual(params.subtitle_position, "bottom")
self.assertEqual(params.custom_position, 70.0)
+ def test_invalid_saved_background_color_with_saved_enable_flag(self):
+ """
+ 保存的背景颜色同样要按 #RRGGBB 校验。非法值若留在 VideoParams 中,
+ 渲染时会变成黑色,而同色检测比较的仍是原始非法字符串,导致黑底黑字
+ 无法被发现。
+ """
+ ui_config = {
+ "subtitle_background_enabled": True,
+ "subtitle_background_color": "not-a-color",
+ }
+
+ args = cli.parse_args(["--video-subject", "test"])
+
+ with patch.dict(app_config.ui, ui_config, clear=True):
+ params = cli.build_video_params(args)
+
+ self.assertIs(params.text_background_color, True)
+
+ def test_invalid_saved_background_color_with_explicit_enable_flag(self):
+ """显式开启背景时,非法的保存颜色同样回退到默认背景。"""
+ ui_config = {"subtitle_background_color": "not-a-color"}
+
+ args = cli.parse_args(
+ ["--video-subject", "test", "--subtitle-background-enabled"]
+ )
+
+ with patch.dict(app_config.ui, ui_config, clear=True):
+ params = cli.build_video_params(args)
+
+ self.assertIs(params.text_background_color, True)
+
+ def test_invalid_saved_background_color_without_enable_flag(self):
+ """
+ 只保存了非法颜色且没有开关时,不应据此推断出需要背景,
+ 因此保持 VideoParams 的默认关闭状态。
+ """
+ ui_config = {"subtitle_background_color": "not-a-color"}
+
+ args = cli.parse_args(["--video-subject", "test"])
+
+ with patch.dict(app_config.ui, ui_config, clear=True):
+ params = cli.build_video_params(args)
+
+ self.assertFalse(params.text_background_color)
+
if __name__ == "__main__":
unittest.main()