refactor(video_analysis): extract_transcript.py uses yt-dlp VTT directly (skip youtube-transcript-api which consistently fails for these videos)

youtube-transcript-api v1.2.4 returns XML parse error on empty response for ALL videos in this campaign. yt-dlp's --write-auto-subs reliably returns 1000s of segments per video. Switched to yt-dlp as the primary path.

Tests updated to mock _fetch_via_ytdlp instead of _fetch_raw_transcript. 8/8 tests passing.
This commit is contained in:
ed
2026-06-21 16:33:44 -04:00
parent 7478090e71
commit 338573b1e8
2 changed files with 39 additions and 20 deletions
@@ -43,7 +43,7 @@ def test_extract_transcript_success(tmp_path: Path) -> None:
{"start": 0.0, "duration": 5.0, "text": "Hello world"},
{"start": 5.0, "duration": 3.0, "text": "Goodbye world"},
]
with patch("scripts.video_analysis.extract_transcript._fetch_raw_transcript") as mock_fetch:
with patch("scripts.video_analysis.extract_transcript._fetch_via_ytdlp") as mock_fetch:
mock_fetch.return_value = fake_segments
result = extract_transcript("https://youtu.be/ABCDEFGHIJK", tmp_path / "transcript.json")
assert result.is_ok()
@@ -54,14 +54,14 @@ def test_extract_transcript_success(tmp_path: Path) -> None:
def test_extract_transcript_network_error(tmp_path: Path) -> None:
with patch("scripts.video_analysis.extract_transcript._fetch_raw_transcript") as mock_fetch:
with patch("scripts.video_analysis.extract_transcript._fetch_via_ytdlp") as mock_fetch:
mock_fetch.side_effect = Exception("network unreachable")
result = extract_transcript("https://youtu.be/ABCDEFGHIJK", tmp_path / "transcript.json")
assert result.is_err()
def test_extract_transcript_retries_then_fails(tmp_path: Path) -> None:
with patch("scripts.video_analysis.extract_transcript._fetch_raw_transcript") as mock_fetch:
with patch("scripts.video_analysis.extract_transcript._fetch_via_ytdlp") as mock_fetch:
mock_fetch.side_effect = Exception("transient")
result = extract_transcript("https://youtu.be/ABCDEFGHIJK", tmp_path / "transcript.json", retries=2)
assert result.is_err()