fix(asr): use content_dir for subtitle output instead of video_path
PR Test / lint (pull_request) Successful in 2s
PR Test / lint (pull_request) Successful in 2s
- Add content_dir field to ASRInput schema
- Pass content_dir from pipeline when creating ASRInput
- Modify _try_official_subtitle to use content_dir for output
- Modify _run_whisper_basic to use content_dir for output
- Add validation for empty video_path in Whisper fallback
Root cause: DownloadProcessor sets content_file="" for video types,
causing Path("").parent to resolve to current directory instead of
content directory. Subtitle files were written to wrong location.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -31,7 +31,8 @@ class TestASRInputSchema:
|
||||
input_data = ASRInput(
|
||||
content_id="BV1xx",
|
||||
platform="bilibili",
|
||||
video_path="/path/to/video.mp4"
|
||||
video_path="/path/to/video.mp4",
|
||||
content_dir="/path/to/content"
|
||||
)
|
||||
|
||||
# 验证继承
|
||||
@@ -46,7 +47,8 @@ class TestASRInputSchema:
|
||||
input_data = ASRInput(
|
||||
content_id="BV1xx",
|
||||
platform="bilibili",
|
||||
video_path="/path/to/video.mp4"
|
||||
video_path="/path/to/video.mp4",
|
||||
content_dir="/path/to/content"
|
||||
)
|
||||
|
||||
assert hasattr(input_data, "video_path")
|
||||
@@ -59,7 +61,8 @@ class TestASRInputSchema:
|
||||
input_data = ASRInput(
|
||||
content_id="BV1xx",
|
||||
platform="bilibili",
|
||||
video_path="/path/to/video.mp4"
|
||||
video_path="/path/to/video.mp4",
|
||||
content_dir="/path/to/content"
|
||||
)
|
||||
|
||||
assert input_data.content_type == "video"
|
||||
@@ -222,7 +225,8 @@ class TestOfficialSubtitle:
|
||||
input_data = ASRInput(
|
||||
content_id="BV1xx",
|
||||
platform="bilibili",
|
||||
video_path=str(video_path)
|
||||
video_path=str(video_path),
|
||||
content_dir=str(tmp_path)
|
||||
)
|
||||
|
||||
result = await processor._try_official_subtitle(input_data)
|
||||
@@ -256,7 +260,8 @@ class TestOfficialSubtitle:
|
||||
input_data = ASRInput(
|
||||
content_id="BV1xx",
|
||||
platform="bilibili",
|
||||
video_path=str(video_path)
|
||||
video_path=str(video_path),
|
||||
content_dir=str(tmp_path)
|
||||
)
|
||||
|
||||
result = await processor._try_official_subtitle(input_data)
|
||||
@@ -283,7 +288,8 @@ class TestOfficialSubtitle:
|
||||
input_data = ASRInput(
|
||||
content_id="BV1xx",
|
||||
platform="bilibili",
|
||||
video_path=str(video_path)
|
||||
video_path=str(video_path),
|
||||
content_dir=str(tmp_path)
|
||||
)
|
||||
|
||||
await processor.process(input_data)
|
||||
@@ -325,7 +331,8 @@ class TestWhisperBasic:
|
||||
input_data = ASRInput(
|
||||
content_id="BV1xx",
|
||||
platform="bilibili",
|
||||
video_path=str(video_path)
|
||||
video_path=str(video_path),
|
||||
content_dir=str(tmp_path)
|
||||
)
|
||||
|
||||
result = await processor._run_whisper_basic(input_data)
|
||||
@@ -368,7 +375,8 @@ class TestWhisperBasic:
|
||||
input_data = ASRInput(
|
||||
content_id="BV1xx",
|
||||
platform="bilibili",
|
||||
video_path=str(video_path)
|
||||
video_path=str(video_path),
|
||||
content_dir=str(tmp_path)
|
||||
)
|
||||
|
||||
await processor._run_whisper_basic(input_data)
|
||||
@@ -392,7 +400,8 @@ class TestWhisperBasic:
|
||||
input_data = ASRInput(
|
||||
content_id="BV1xx",
|
||||
platform="bilibili",
|
||||
video_path=str(video_path)
|
||||
video_path=str(video_path),
|
||||
content_dir=str(tmp_path)
|
||||
)
|
||||
|
||||
with pytest.raises(RuntimeError):
|
||||
@@ -435,7 +444,8 @@ class TestDiarization:
|
||||
input_data = ASRInput(
|
||||
content_id="BV1xx",
|
||||
platform="bilibili",
|
||||
video_path=str(video_path)
|
||||
video_path=str(video_path),
|
||||
content_dir=str(tmp_path)
|
||||
)
|
||||
|
||||
result = await processor._run_whisper(input_data)
|
||||
@@ -470,7 +480,8 @@ class TestDiarization:
|
||||
input_data = ASRInput(
|
||||
content_id="BV1xx",
|
||||
platform="bilibili",
|
||||
video_path=str(video_path)
|
||||
video_path=str(video_path),
|
||||
content_dir=str(tmp_path)
|
||||
)
|
||||
|
||||
result = await processor._run_whisper(input_data)
|
||||
@@ -550,7 +561,8 @@ class TestStateRecording:
|
||||
input_data = ASRInput(
|
||||
content_id="BV1xx",
|
||||
platform="bilibili",
|
||||
video_path=str(video_path)
|
||||
video_path=str(video_path),
|
||||
content_dir=str(tmp_path)
|
||||
)
|
||||
|
||||
await processor.process(input_data)
|
||||
@@ -581,7 +593,8 @@ class TestStateRecording:
|
||||
input_data = ASRInput(
|
||||
content_id="BV1xx",
|
||||
platform="bilibili",
|
||||
video_path=str(video_path)
|
||||
video_path=str(video_path),
|
||||
content_dir=str(tmp_path)
|
||||
)
|
||||
|
||||
with pytest.raises(Exception, match="Whisper error"):
|
||||
@@ -611,7 +624,8 @@ class TestStateRecording:
|
||||
input_data = ASRInput(
|
||||
content_id="BV1xx",
|
||||
platform="bilibili",
|
||||
video_path=str(video_path)
|
||||
video_path=str(video_path),
|
||||
content_dir=str(tmp_path)
|
||||
)
|
||||
|
||||
# 应该不抛异常
|
||||
|
||||
Reference in New Issue
Block a user