// THE CLIP EDITOR's seam onto the clip finder (release 35 C2 → C1). // // `/reactions.json` is the clip finder's (lane C1, `common/lib/clips/`; // the shape is plans/release-35/clip-finder.md). The clip editor READS it and // writes exactly one thing into it -- a speaker's role, when the operator says // "This is the host" on the strip -- through C1's exported `setSpeakerRole`. // // `readReactions` here is lenient and says WHY a file is unreadable (the // clip finder's own reader answers null); the role writer is the clip // finder's. Every caller in umtool imports from here. import { readFile } from "node:fs/promises"; import path from "node:path"; export const REACTIONS_FILE = "reactions.json"; export const SPEAKER_ROLES = Object.freeze(["host", "subject", "other"]); const isObj = (v) => !!v && typeof v === "object" && !Array.isArray(v); /** * The project's reactions.json: `{ doc, error }`. No file is `{ doc: null, * error: null }` (a report video the clip finder never ran on); a file that * does not parse, or is not version 1, is an error and never read as empty. * @param {string} dir */ export async function readReactions(dir) { let text; try { text = await readFile(path.join(/* turbopackIgnore: true */ dir, REACTIONS_FILE), "utf8"); } catch (err) { if (/** @type {NodeJS.ErrnoException} */ (err)?.code === "ENOENT") return { doc: null, error: null }; return { doc: null, error: String(err) }; } try { const doc = JSON.parse(text); if (!isObj(doc) || doc.version !== 1) return { doc: null, error: `${REACTIONS_FILE} is not version 1` }; return { doc, error: null }; } catch (e) { return { doc: null, error: `${REACTIONS_FILE} does not parse: ${e instanceof Error ? e.message : String(e)}` }; } } /** * Set one speaker's role, the operator's -- THE CLIP FINDER'S WRITER * (common/lib/clips/reactions.mjs): marking a host or a subject takes that * role off any other speaker that held it; `null` hands the speaker back to * the analysis; `rolesChangedAt` is stamped, so the page offers Re-propose * while it is later than `proposedAt`. Returns the document as written. */ export { setSpeakerRole } from "yt-dlp-transcript-common/lib/clips/reactions.mjs"; /** * A person's name for one speaker (release 36): THE CLIP FINDER'S FILE, the * one other write the editor makes into it -- what the speaker captions head * that voice's lines with. Empty gives the default back. */ export { setSpeakerLabel } from "yt-dlp-transcript-common/lib/clips/reactions.mjs"; /** Re-propose is the clip finder's proposal pass: POST /api/report/clips {project, mode: "propose"} (`umtool clips propose`, a job). */ export const reproposeAvailable = true; export const REPROPOSE_UNAVAILABLE = null;