"use client"; // The video's transcript, read on demand, with the small track switcher when it // has more than one English track whose words differ (lib/captionTracks.ts). // Switching is a reader's choice and changes nothing on disk — "Set as // transcript" in the Transcript source card is how the primary changes. import { useState, useTransition } from "react"; import type { AltTrack } from "yt-dlp-transcript-common/lib/captionTracks"; import { trackLabels } from "yt-dlp-transcript-common/lib/captionTracks"; import { formatTimestamp } from "yt-dlp-transcript-common/lib/vtt"; import { readTranscriptTracksAction } from "../../videoActions"; export function TranscriptTracksReader({ slug, videoId, }: { slug: string; videoId: string; }) { const [pending, startTransition] = useTransition(); const [tracks, setTracks] = useState(null); const [shown, setShown] = useState(null); const [error, setError] = useState(null); const load = () => { setError(null); startTransition(async () => { const res = await readTranscriptTracksAction(slug, videoId); if (!res.ok) { setError(res.error); return; } setTracks(res.tracks); setShown(res.tracks[0]?.track ?? null); }); }; if (!tracks) { return (
{error && ( {error} )}
); } const current = tracks.find((t) => t.track === shown) ?? tracks[0]; return (
{tracks.length > 1 && ( )} {current.cues.length === 0 ? (

No cues in this track.

) : (
    {current.cues.map((c, i) => (
  1. {formatTimestamp(c.start)} {c.text}
  2. ))}
)}
); }