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:
@@ -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 };
|
||||
|
||||
Reference in New Issue
Block a user