D5: empty VTT captions fall back to whisper transcription

When youtube-transcript fetchTranscript() returns empty segments array
(parse succeeded but zero captions), treat as fallback trigger instead of
returning empty transcript.

- tryGetCaptions(): return CaptionResult with empty segments (not null)
  when segments array is empty. Distinguishes 'no captions available'
  (null) from 'captions exist but empty' (CaptionResult with [])
- downloadYouTube(): check captions.segments.length > 0 before taking
  fast path. Empty segments fall through to audio download + whisper
- Tests: empty array fallback, whitespace-only entries fallback,
  non-empty segments still use fast path
This commit is contained in:
Giancarmine Salucci
2026-07-09 05:01:55 +02:00
parent 7c19af2d80
commit 0d4f58310f
2 changed files with 74 additions and 3 deletions
+1 -3
View File
@@ -53,8 +53,6 @@ async function tryGetCaptions(url: string, _outDir: string): Promise<CaptionResu
try {
const transcript = await fetchTranscript(url, { lang: 'en' });
const segments = transcriptEntriesToSegments(transcript);
if (segments.length === 0) return null;
const title = await getYouTubeTitle(url);
return { type: 'captions', segments, title };
} catch {
@@ -109,7 +107,7 @@ export async function downloadYouTube(url: string, jobId: string): Promise<Downl
await mkdir(outDir, { recursive: true });
const captions = await tryGetCaptions(url, outDir);
if (captions) return captions;
if (captions && captions.segments.length > 0) return captions;
const { audioPath, title } = await downloadAudio(url, outDir);
return { type: 'audio', audioPath, title };