Skip to content

Commit 6b0d646

Browse files
committed
chore(transcripts): log innertube diagnostics in debug block
1 parent cf3ed4d commit 6b0d646

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

‎apps/site/src/pages/api/transcript.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,16 @@ async function fetchYouTubeCaptions(videoId: string): Promise<{
6262
});
6363

6464
if (!response.ok) {
65-
return { cues: [], fullText: "", status: "no_caption_available" };
65+
return { cues: [], fullText: "", status: "no_caption_available", error: `innertube_http_${response.status}` };
6666
}
6767

6868
const data: any = await response.json();
69+
const playability = data?.playabilityStatus?.status;
6970
const captionTracks =
7071
data?.captions?.playerCaptionsTracklistRenderer?.captionTracks;
7172

7273
if (!Array.isArray(captionTracks) || captionTracks.length === 0) {
73-
return { cues: [], fullText: "", status: "no_caption_available" };
74+
return { cues: [], fullText: "", status: "no_caption_available", error: `no_tracks_playability_${playability}` };
7475
}
7576

7677
// Prefer English track or default to first
@@ -82,15 +83,18 @@ async function fetchYouTubeCaptions(videoId: string): Promise<{
8283
) || captionTracks[0];
8384

8485
if (!track?.baseUrl) {
85-
return { cues: [], fullText: "", status: "no_caption_available" };
86+
return { cues: [], fullText: "", status: "no_caption_available", error: "missing_track_baseUrl" };
8687
}
8788

8889
const captionResp = await fetch(track.baseUrl);
8990
if (!captionResp.ok) {
90-
return { cues: [], fullText: "", status: "no_caption_available" };
91+
return { cues: [], fullText: "", status: "no_caption_available", error: `caption_fetch_http_${captionResp.status}` };
9192
}
9293

9394
const xml = await captionResp.text();
95+
if (!xml || xml.length === 0) {
96+
return { cues: [], fullText: "", status: "no_caption_available", error: "caption_xml_empty" };
97+
}
9498
const cues: Cue[] = [];
9599

96100
// Try srv3 format (<p t="ms" d="ms">text</p>)

0 commit comments

Comments
 (0)