// THE JOIN PREVIEW, umtool's half (release 38 lane E): `/out/join- // preview.mp4`, the first few joins of the cut in its current look // (report-to-video/join-preview.mjs; build-video.mjs `--join-preview`, which // runs in the machine's heavy slot), as ONE job on the app's runner // (lib/jobs.ts: one at a time, a log, Cancel) -- the Look panel's and the Ask // box's Preview join. Its record (`out/join-preview.json`) says what it was // made from, so the page can say when the look has moved since. import { readFile, stat } from "node:fs/promises"; import path from "node:path"; import { lookOf } from "yt-dlp-transcript-common/lib/report/look.mjs"; import { JOIN_PREVIEW_FILE, JOIN_PREVIEW_RECORD } from "umtool-report-to-video/join-preview"; import { PIPELINE_DIR } from "./driver.mjs"; /** A preview is a few seconds of four clips: minutes at most. */ export const JOIN_PREVIEW_TIMEOUT_MS = 15 * 60_000; const CLIP_ID = /^[A-Za-z0-9][A-Za-z0-9._-]{0,80}$/; const outOf = (dir) => path.join(/* turbopackIgnore: true */ dir, "out"); export const joinPreviewFile = (dir) => path.join(/* turbopackIgnore: true */ outOf(dir), JOIN_PREVIEW_FILE); /** * The job's one step: build-video `--join-preview` (from `from`, else the * first clip), NDJSON progress. No path or argv from a client. * @param {{ dir: string }} project * @param {string | null} [from] */ export function joinPreviewSteps(project, from = null) { if (from !== null && !CLIP_ID.test(from)) throw new Error(`not a clip id: ${from}`); return [ { cwd: PIPELINE_DIR, env: {}, label: `preview the joins${from ? ` from ${from}` : ""}`, argv: [ "node", path.join(/* turbopackIgnore: true */ PIPELINE_DIR, "build-video.mjs"), path.join(/* turbopackIgnore: true */ project.dir, "video.manifest.json"), "--out", outOf(project.dir), "--join-preview", ...(from ? ["--join-from", from] : []), "--progress", "ndjson", ], ndjson: true, timeoutMs: JOIN_PREVIEW_TIMEOUT_MS, }, ]; } /** * The preview on disk, or null: `{ size, mtimeMs, record, stale }` -- * `stale` when the look (lookOf the render) is not what it was made with. * @param {string} dir * @param {any} [manifest] */ export async function readJoinPreview(dir, manifest = null) { const st = await stat(joinPreviewFile(dir)).catch(() => null); if (!st?.isFile()) return null; const record = await readFile(path.join(/* turbopackIgnore: true */ outOf(dir), JOIN_PREVIEW_RECORD), "utf8").then(JSON.parse, () => null); const stale = !!manifest && !!record && JSON.stringify(record.look ?? {}) !== JSON.stringify(lookOf(manifest.render ?? {})); return { size: st.size, mtimeMs: Math.round(st.mtimeMs), record, stale }; }