// The clip kit's QR (lane clip-kit, slice B): the corner, the link at the clip's second, a short's code, the notes -- // and, with none of the new keys, the corner code exactly as it always was. import { test } from "node:test"; import assert from "node:assert/strict"; import { clipKitErrors, clipQrUrl, cornerOverlayXY, cornerQrOf, expiringLinkNote, momentLinkOf, namesRecording, qrSettingsErrors, validateClipKit, verticalQrBox, verticalQrOf, } from "./clip-kit.mjs"; import { archiveMomentUrl } from "./site-links.mjs"; import { qrsOf, lintManifest } from "./lint.mjs"; import { safeArea, clipGeometry, validateVerticalRender, verticalKnobs } from "./vertical.mjs"; const KICK = "https://kick.com/somechan/videos/01a1d292-6d30-7092-867d-d46a2db2f3e8"; const clip = (o = {}) => ({ type: "clip", id: "w01", video: "01a1d292-6d30-7092-867d-d46a2db2f3e8", start: 10643.6, end: 10764, ...o }); test("no new keys: the corner code is where it always was, with the link it always had", () => { // The overlay the build drew before the kit, byte for byte. const VW = 1920, FH = 0, qrM = 28; assert.equal(cornerOverlayXY("br", { VW, FH, HH: 56, m: qrM }), `x=${VW}-w-${qrM}:y=H-h-${FH + qrM}`); assert.equal(cornerOverlayXY("br", { VW: 1600, FH: 40, m: 20 }), "x=1600-w-20:y=H-h-60"); assert.deepEqual(cornerQrOf(clip(), {}), { corner: "br", links: "cite" }); const prov = { siteOrigin: "https://archive.example", channelSlug: "chan" }; const e = clip({ channel: "chan" }); assert.equal(clipQrUrl(e, prov), archiveMomentUrl(e, prov, e.start)); assert.equal(clipQrUrl(clip({ citeUrl: KICK }), prov), KICK); assert.equal(clipQrUrl(clip({ citeUrl: null, src: "a.mp4" }), prov, { local: true }), null); // The lint's corner codes: the same links as before. const m = { render: { width: 1920, height: 1080 }, provenance: prov, timeline: [e, clip({ id: "w02", citeUrl: KICK })] }; assert.deepEqual(qrsOf(m).map((q) => [q.url, "links" in q]), [[archiveMomentUrl(e, prov, e.start), false], [KICK, false]]); assert.deepEqual(validateClipKit(m), []); // A short asks for no code: none (the vertical knobs' default). assert.equal(verticalKnobs({ format: "vertical" }).qr, false); assert.equal(verticalQrOf(clip(), { format: "vertical" }), null); }); test("the corners, a clip's own over the cut's, off for one clip", () => { assert.equal(cornerOverlayXY("tl", { VW: 1920, HH: 56, m: 28 }), "x=28:y=84"); assert.equal(cornerOverlayXY("tr", { VW: 1920, HH: 0, m: 28 }), "x=1920-w-28:y=28"); assert.equal(cornerOverlayXY("bl", { VW: 1920, FH: 0, m: 28 }), "x=28:y=H-h-28"); assert.deepEqual(cornerQrOf(clip({ qr: { corner: "tl" } }), { qr: { corner: "bl", links: "moment" } }), { corner: "tl", links: "moment" }); assert.equal(cornerQrOf(clip({ qr: false }), {}), null); assert.equal(cornerQrOf(clip(), { qr: false }), null); }); test("a moment link: this recording's citeUrl retimed; a mirror kept; else the record's page; the channel", () => { // The citeUrl names this recording (its id is in it): retimed to the second the clip plays from. assert.equal(momentLinkOf(clip({ citeUrl: KICK }), 10643.9), `${KICK}?t=10643`); assert.equal(momentLinkOf(clip({ citeUrl: `${KICK}?t=10600` }), 10643.9), `${KICK}?t=10643`); // A mirror (another recording): as written. assert.equal(momentLinkOf(clip({ citeUrl: "https://www.youtube.com/watch?v=mirror1&t=5s" }), 99), "https://www.youtube.com/watch?v=mirror1&t=5s"); // No citeUrl: the record's page at the second. assert.equal(momentLinkOf(clip(), 61.2, "https://www.youtube.com/watch?v=abc"), "https://www.youtube.com/watch?v=abc&t=61s"); assert.equal(momentLinkOf(clip(), 61.2, null), null); assert.ok(namesRecording(KICK, "01a1d292-6d30-7092-867d-d46a2db2f3e8")); assert.equal(namesRecording(KICK, "abc"), false, "an id too short to tell is not taken as a match"); const prov = { siteOrigin: "https://archive.example", channelSlug: "chan" }; assert.equal(clipQrUrl(clip({ citeUrl: KICK }), prov, { links: "moment", at: 10650 }), `${KICK}?t=10650`); // No moment to link: the cite as before. assert.equal(clipQrUrl(clip({ channel: "chan" }), prov, { links: "moment", at: 5 }), archiveMomentUrl(clip({ channel: "chan" }), prov, 10643.6)); assert.equal(clipQrUrl(clip({ citeUrl: KICK }), prov, { links: "channel", channelUrl: "https://kick.com/somechan" }), "https://kick.com/somechan"); }); test("the rules refuse what cannot be drawn, by name", () => { assert.deepEqual(qrSettingsErrors({ scale: 4, corner: "tl", links: "moment" }), []); assert.match(qrSettingsErrors({ corner: "middle" }).join(), /render\.qr\.corner is one of br, bl, tr, tl/); assert.match(qrSettingsErrors({ links: "site" }).join(), /render\.qr\.links is one of cite, moment, channel/); assert.match(clipKitErrors({ type: "clip", qr: { corner: "tl", size: 2 } }, "w01").join(), /w01\.qr\.size is not a key/); assert.match(clipKitErrors({ type: "clip", qr: "yes" }, "w01").join(), /w01\.qr is false/); assert.match(clipKitErrors({ type: "clip", name: "x".repeat(61) }, "w01").join(), /w01\.name is a file name of 1 to 60/); assert.match(clipKitErrors({ type: "post", qr: false }, "p1").join(), /qr, name, promo, zooms, coldOpen and censor are a clip's/); assert.match(validateClipKit({ render: { qr: { links: "channel" } }, timeline: [] }).join(), /set render\.promo\.url/); assert.deepEqual(validateClipKit({ render: { qr: { links: "channel" }, promo: { url: "https://kick.com/somechan" } }, timeline: [] }), []); // A short's code: at the top only (its captions run along the foot), a size in bounds. assert.deepEqual(validateVerticalRender({ render: { vertical: { qr: { corner: "tl", size: 0.2, links: "moment" } } } }), []); assert.match(validateVerticalRender({ render: { vertical: { qr: { corner: "br" } } } }).join(), /corner is tr or tl/); assert.match(validateVerticalRender({ render: { vertical: { qr: { size: 0.5 } } } }).join(), /size is 0\.1–0\.3/); }); test("a short's code: on, the moment by default, at the top of the safe area, never over the tag", () => { const render = { format: "vertical", vertical: { qr: true } }; assert.deepEqual(verticalQrOf(clip(), render), { corner: "tr", size: 0.16, links: "moment" }); assert.deepEqual(verticalQrOf(clip({ qr: { corner: "tl", links: "cite" } }), render), { corner: "tl", size: 0.16, links: "cite" }); assert.equal(verticalQrOf(clip({ qr: false }), render), null); // A clip's bottom corner is the landscape code's: a short keeps its own corner. assert.equal(verticalQrOf(clip({ qr: { corner: "br" } }), render).corner, "tr"); const W = 1080, H = 1920; const safe = safeArea(render, W, H); for (const layout of ["full", "framed", "quote", "split"]) { const geo = clipGeometry(layout, render, W, H); for (const corner of ["tr", "tl"]) { const b = verticalQrBox({ corner, size: 0.16 }, { W, safe, tag: geo.tag }); assert.ok(b.x >= safe.x0 && b.x + b.size <= safe.x1 && b.y >= safe.y0 && b.y + b.size <= safe.y1, `${layout} ${corner} inside the safe area`); if (corner === "tl" && geo.tag) assert.ok(b.y >= geo.tag.y + geo.tag.size, `${layout}: under the tag`); } } }); test("a moment code to a Kick or Twitch VOD is a NOTE naming the expiry; a channel page or YouTube is not", () => { assert.match(expiringLinkNote(`${KICK}?t=10643`, "w01"), /w01: its QR links a Kick VOD .* about 30 days/); assert.match(expiringLinkNote("https://www.twitch.tv/videos/123?t=1h0m0s", "w01"), /Twitch deletes VODs about 14 days/); assert.equal(expiringLinkNote("https://kick.com/somechan", "w01"), null); assert.equal(expiringLinkNote("https://www.youtube.com/watch?v=abc&t=5s", "w01"), null); // In the lint: a warning for a moment code, none for the same link cited as it always was. const base = { render: { width: 1920, height: 1080 }, provenance: { siteOrigin: "https://archive.example" } }; const moment = lintManifest({ ...base, render: { ...base.render, qr: { links: "moment" } }, timeline: [clip({ citeUrl: KICK })] }, { validators: false }); assert.ok(moment.warnings.some((w) => /Kick deletes VODs/.test(w)), moment.warnings.join("\n")); assert.equal(moment.errors.length, 0, moment.errors.join("\n")); // A citeUrl that is itself a Kick VOD is noted too (review); an archive link is not. const cite = lintManifest({ ...base, timeline: [clip({ citeUrl: KICK })] }, { validators: false }); assert.ok(cite.warnings.some((w) => /Kick deletes VODs/.test(w)), cite.warnings.join("\n")); const archive = lintManifest({ ...base, provenance: { siteOrigin: "https://archive.example", channelSlug: "chan" }, timeline: [clip({ channel: "chan" })] }, { validators: false }); assert.ok(!archive.warnings.some((w) => /deletes VODs/.test(w))); // A stacked-deck 9:16 cut draws no vertical code: none is listed. const stacked = { ...base, render: { width: 1080, height: 1920, format: "vertical", vertical: { qr: true, deck: "stacked" }, chrome: { engine: "hyperframes", layout: "deck", deck: { qr: { show: false } } } }, timeline: [clip({ citeUrl: KICK })] }; assert.ok(!qrsOf(stacked).some((q) => /\(its QR\)/.test(q.where))); // A short's code is measured and noted too. const short = lintManifest({ ...base, render: { width: 1080, height: 1920, format: "vertical", qr: false, vertical: { qr: true } }, timeline: [clip({ citeUrl: KICK })] }, { validators: false }); assert.ok(short.warnings.some((w) => /timeline w01 \(its QR\): its QR links a Kick VOD/.test(w)), short.warnings.join("\n")); }); // ---- slice C: the desktop clip -------------------------------------------------------------------------------------- import { desktopGeometry, desktopRender, desktopSafeArea, verticalAss } from "./vertical.mjs"; import { DESKTOP_DEFAULTS, desktopKnobs, validateDesktopRender } from "yt-dlp-transcript-common/lib/report/vertical.mjs"; import { desktopQrBox, desktopQrOf } from "./clip-kit.mjs"; import { knobsForFormat } from "../lib/report/shortsBatch.mjs"; import { desktopKnobsOf } from "../lib/report/verticalCli.mjs"; test("desktop: the knobs' defaults are minimal chrome; the rules refuse by name", () => { assert.deepEqual(desktopKnobs({}), { ...DESKTOP_DEFAULTS, captions: { ...DESKTOP_DEFAULTS.captions }, safe: { ...DESKTOP_DEFAULTS.safe } }); assert.equal(desktopKnobs({}).qr, false); assert.equal(desktopKnobs({}).maxSeconds, 140, "X's 2:20"); assert.deepEqual(validateDesktopRender({ render: { desktop: { qr: { corner: "bl", size: 0.1, links: "moment" }, captions: { size: "m", lines: 1 }, hook: "title" } } }), []); assert.match(validateDesktopRender({ render: { desktop: { qr: { corner: "middle" } } } }).join(), /render\.desktop\.qr\.corner is one of br, bl, tr, tl/); assert.match(validateDesktopRender({ render: { desktop: { wide: true } } }).join(), /render\.desktop\.wide is not a desktop knob/); assert.match(validateDesktopRender({ render: { desktop: { safe: { top: 0.5 } } } }).join(), /safe\.top must be a fraction/); assert.deepEqual(validateDesktopRender({ render: {} }), []); // The render: 1920x1080, nothing over the picture but what the clip draws, the desktop's loudness; marked a desktop build. const r = desktopRender({ width: 1280, height: 720, headerHeight: 56, qr: { corner: "tl" }, chrome: { deck: {} }, intro: "boot", desktop: { loudness: -16 } }); assert.deepEqual([r.width, r.height, r.headerHeight, r.footerHeight, r.qr, r.chrome, r.intro, r.desktopBuild], [1920, 1080, 0, 0, false, undefined, undefined, true]); assert.deepEqual(r.loudness, { target: -16 }); }); test("desktop: every text inside the safe area; a bottom code narrows the captions both sides; a top-left code moves the source line", () => { const W = 1920, H = 1080; const a = desktopSafeArea({}, W, H); const g = desktopGeometry({}, W, H); assert.deepEqual(g.video, { x: 0, y: 0, w: W, h: H, aspect: W / H, fill: "fit" }, "the picture full frame, never cropped"); assert.ok(g.tag.x >= a.x0 && g.tag.y >= a.y0); assert.equal(g.captions.marginV, H - a.y1); assert.equal(g.captions.marginL, a.x0); const qr = desktopQrBox({ corner: "br", size: 0.09 }, { W, safe: a }); assert.ok(qr.x + qr.size <= a.x1 && qr.y + qr.size <= a.y1 && qr.x >= a.x0); const gq = desktopGeometry({}, W, H, { qr }); assert.equal(gq.captions.marginL - g.captions.marginL, gq.captions.marginR - g.captions.marginR, "centred"); assert.ok(W - gq.captions.marginR <= qr.x, "the captions end before the code"); const tl = desktopQrBox({ corner: "tl", size: 0.09 }, { W, safe: a }); assert.ok(desktopGeometry({}, W, H, { qr: tl }).tag.x >= tl.x + tl.size, "the source line beside the code"); // A clip's own corner over the cut's; the moment by default; off unless asked. assert.equal(desktopQrOf({ type: "clip" }, {}), null); assert.deepEqual(desktopQrOf({ type: "clip", qr: { corner: "tl" } }, { desktop: { qr: true } }), { corner: "tl", size: 0.09, links: "moment" }); assert.equal(desktopQrOf({ type: "clip", qr: false }, { desktop: { qr: true } }), null); }); test("desktop: the ASS reads the desktop's lines and tag; the vertical's are unchanged without knobs", () => { const words = [{ text: "one", start: 0.1, end: 0.4 }, { text: "two", start: 0.5, end: 0.8 }]; const g = desktopGeometry({}, 1920, 1080); const doc = verticalAss({ geo: g, render: {}, words, seconds: 2, tag: "Synth · 2 Jan 2024", W: 1920, H: 1080, knobs: desktopKnobs({ desktop: { tag: false } }) }); assert.match(doc, /PlayResX: 1920\nPlayResY: 1080/); assert.ok(!/,tag,,0,0,0,,Synth/.test(doc), "the desktop's tag: false is read"); assert.match(verticalAss({ geo: g, render: {}, words, seconds: 2, tag: "Synth", W: 1920, H: 1080, knobs: desktopKnobs({}) }), /,tag,,0,0,0,,Synth/); // Without knobs: the vertical's, exactly the document it always wrote. const vg = clipGeometry("full", {}, 1080, 1920); assert.equal(verticalAss({ geo: vg, render: {}, words, seconds: 2, tag: "Synth" }), verticalAss({ geo: vg, render: {}, words, seconds: 2, tag: "Synth", knobs: null })); }); test("desktop: the flags' knobs; a batch keeps a short's code at the top", () => { assert.deepEqual(desktopKnobsOf({ clip: "framed", hook: "title", captions: { size: "xl", lines: 1 }, loudness: -16, maxSeconds: 140, qr: { corner: "bl" } }), { hook: "title", captions: { size: "xl", lines: 1 }, loudness: -16, maxSeconds: 140, qr: { corner: "bl" } }); assert.deepEqual(knobsForFormat({ qr: { corner: "bl" } }, "desktop"), { knobs: { qr: { corner: "bl" } }, note: null }); const v = knobsForFormat({ qr: { corner: "bl" }, clip: "framed" }, "vertical"); assert.deepEqual(v.knobs, { qr: true, clip: "framed" }); assert.match(v.note, /top right/); assert.deepEqual(knobsForFormat({ qr: { corner: "tl" } }, "vertical").knobs, { qr: { corner: "tl" } }); });