// `archilyzer frames rederive /` (release 30): a frame scan's // `derived` worked out again from the readings its sidecar holds — zero model // calls, no frame, no editor. The same rederiveRecord the editor's // `frame-scan {rederive: true}` runs; this one cannot see the editor's jobs, so // it is not for a video whose scan is running. import path from "node:path"; import { getPaths } from "../lib/paths"; import { frameScanSidecar } from "../lib/frameScan-server"; import { isFrameProfile } from "../lib/frames/profiles"; import { rederiveRecord } from "../lib/frames/scan"; import { loadCues, rederivedSummary } from "../controller/frameScan"; import { isSafeChannelSegment, isSafeIdSegment } from "../lib/citations/moments"; export async function framesRederiveRow({ positionals, flags }: { positionals: string[]; flags: Record }): Promise { const [ref] = positionals; const [slug, id] = (ref ?? "").split("/"); const profile = typeof flags.profile === "string" ? flags.profile : "poker"; if (!isSafeChannelSegment(slug) || !isSafeIdSegment(id) || !isFrameProfile(profile)) { console.error("frames rederive: give / [--profile poker] [--hero ] [--dry]"); return 2; } const videoDir = path.join(getPaths().channelsDir, slug, "data", id); const sidecar = frameScanSidecar(profile); const rec = await sidecar.load(videoDir); if (!rec) { console.error(`frames rederive: ${slug}/${id} has no ${sidecar.filename}`); return 1; } const cues = await loadCues(videoDir); const hero = typeof flags.hero === "string" && flags.hero.trim() ? flags.hero.trim() : undefined; const out = rederiveRecord(rec, { ...(cues ? { cues } : {}), ...(hero ? { hero } : {}) }); const summary = rederivedSummary(rec, out, sidecar.filename); if (flags.dry !== true) await sidecar.write(videoDir, out); if (flags.json === true) console.log(JSON.stringify({ ...summary, written: flags.dry !== true })); else { const b = summary.before; const a = summary.after; console.log(`${slug}/${id} ${sidecar.filename}: ${summary.readings} readings${flags.dry === true ? " (dry: nothing written)" : ""}`); console.log(` tournaments ${b.tournaments} → ${a.tournaments}, events ${b.events} → ${a.events}, flags ${b.flags} → ${a.flags}, misreads ${b.misreads} → ${a.misreads}`); for (const t of summary.tournaments) console.log(` ${t.key}${t.name ? ` (${t.name})` : ""} ${Math.round(t.from)}–${Math.round(t.to)} s`); console.log(` events: ${Object.entries(summary.eventsByKind).map(([k, n]) => `${k} ${n}`).join(", ") || "none"}`); } return 0; }