mirror of
https://github.com/linyqh/NarratoAI.git
synced 2026-07-04 13:25:03 +00:00
- 为VideoClipParams新增原字幕路径配置字段,支持单条/多条字幕路径 - 完善webui参数获取逻辑,处理字幕路径兼容性并对接前端选择 - 重构后端字幕处理流程,支持自动匹配视频对应原字幕,合并原声字幕 - 优化视频合并逻辑,新增ffmpeg无损copy合并判断,自动回退重编码提升效率 - 新增ffmpeg快速素材合并路径,支持自定义字幕样式与多音轨混合 - 新增多个单元测试覆盖字幕匹配、合并及视频合并场景
47 lines
1.6 KiB
Python
47 lines
1.6 KiB
Python
import tempfile
|
|
import time
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
from app.models.schema import VideoClipParams
|
|
from app.services import task
|
|
|
|
|
|
class TaskSubtitleResolutionTests(unittest.TestCase):
|
|
def test_get_original_subtitle_paths_falls_back_to_matching_video_name(self):
|
|
original_subtitle_dir = task.utils.subtitle_dir
|
|
|
|
with tempfile.TemporaryDirectory() as temp_dir:
|
|
temp_path = Path(temp_dir)
|
|
older = temp_path / "01_1080p_fun_asr.srt"
|
|
newer = temp_path / "01_1080p_fun_asr_20260608010240.srt"
|
|
unrelated = temp_path / "other_fun_asr.srt"
|
|
older.write_text("older", encoding="utf-8")
|
|
unrelated.write_text("other", encoding="utf-8")
|
|
time.sleep(0.01)
|
|
newer.write_text("newer", encoding="utf-8")
|
|
|
|
task.utils.subtitle_dir = lambda: str(temp_path)
|
|
params = VideoClipParams(
|
|
video_origin_path="/tmp/01_1080p_20260608113314.mp4",
|
|
)
|
|
|
|
try:
|
|
subtitle_paths = task._get_original_subtitle_paths(params)
|
|
finally:
|
|
task.utils.subtitle_dir = original_subtitle_dir
|
|
|
|
self.assertEqual([str(newer)], subtitle_paths)
|
|
|
|
def test_get_original_subtitle_paths_keeps_explicit_params(self):
|
|
params = VideoClipParams(
|
|
video_origin_path="/tmp/01_1080p_20260608113314.mp4",
|
|
original_subtitle_paths=["/tmp/provided.srt"],
|
|
)
|
|
|
|
self.assertEqual(["/tmp/provided.srt"], task._get_original_subtitle_paths(params))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|