// A recording's cues as the run's corpus has them (release 27, S6): read // through the corpus tools' `get_transcript` with timestamps — the same build // the agent quoted from, so convert widens and the strict check reads the // words it saw. A cue ends where the next begins (the transcript shows starts). import type { CuesOf } from "../../convertShared"; import type { CorpusToolsLike } from "./types"; const LINE = /^\[\[((?:\d+:)?\d+:\d+)\]\([^)]*\)\]\s?(.*)$/; const seconds = (stamp: string) => stamp.split(":").reduce((s, p) => s * 60 + Number(p), 0); export function parseTimestampedTranscript(text: string): { start: number; end: number; text: string }[] { const starts: { start: number; text: string }[] = []; for (const raw of text.split("\n")) { const m = LINE.exec(raw.trim()); if (m) starts.push({ start: seconds(m[1]!), text: m[2]!.trim() }); } return starts.map((c, i) => ({ start: c.start, end: Math.max(c.start + 0.5, (starts[i + 1]?.start ?? c.start + 5) - 0.01), text: c.text })); } export function corpusCuesOf(corpus: Pick): CuesOf { const cache = new Map>(); return (channel, id) => { const key = `${channel}/${id}`; let p = cache.get(key); if (!p) { p = corpus .call("get_transcript", { video_id: id, channel, timestamps: true }) .then((t) => { const cues = parseTimestampedTranscript(t); return cues.length ? cues : null; }) .catch(() => null); cache.set(key, p); } return p; }; }