// The channel promo (lane clip-kit, slice D): its rules, its colours, its page, its timing in the segment's graph, // and the captions moved into its band. import { test } from "node:test"; import assert from "node:assert/strict"; import { PROMO_TIMING, clipPromoErrors, linkColourOf, nameLines, promoBand, promoCardHtml, promoErrors, promoFilterParts, promoOf, promoPalette, urlParts, validatePromo, } from "./promo-card.mjs"; import { captionGroups, clipGeometry, desktopGeometry, verticalAss } from "./vertical.mjs"; import { parseBox, parsePortraitFrom } from "../lib/report/promoCli.mjs"; const PROMO = { name: ["Example Channel", "Live"], url: "https://kick.com/synth" }; test("the rules: name and url needed, a portrait of the project's, timing in bounds, the fade inside the lead", () => { assert.deepEqual(promoErrors(PROMO), []); assert.deepEqual(promoErrors({ ...PROMO, qr: false, portrait: { file: "shots/a.png", box: [0.5, 0, 0.3, 0.5] }, kicker: "Clipped from", palette: { ground: "#101010", link: "#53fc18" }, lead: 4.5, fade: 0.7, hold: 1.5, captions: false }), []); const no = (v, re) => assert.match(promoErrors(v).join("\n"), re, JSON.stringify(v)); no({ url: PROMO.url }, /name is the channel's name/); no({ ...PROMO, name: ["a", "b", "c"] }, /one or two lines/); no({ ...PROMO, name: "x".repeat(60) }, /at most 24/); no({ ...PROMO, url: "kick.com/synth" }, /url is the channel's page/); no({ ...PROMO, portrait: { file: "/etc/a.png" } }, /portrait is \{file, box\?\}/); no({ ...PROMO, portrait: { file: "../a.png" } }, /portrait is \{file, box\?\}/); no({ ...PROMO, portrait: { file: "a.png", box: [0.9, 0, 0.3, 1] } }, /box is \[x, y, w, h\]/); no({ ...PROMO, palette: { ground: "black" } }, /palette\.ground is #rrggbb/); no({ ...PROMO, palette: { sky: "#000000" } }, /palette\.sky is not a colour/); no({ ...PROMO, lead: 20 }, /lead is 1–10 seconds/); no({ ...PROMO, lead: 1, fade: 1.5 }, /fade \(1\.5 s\) is longer than its lead/); no({ ...PROMO, wiggle: true }, /wiggle is not a key/); assert.deepEqual(clipPromoErrors(false), []); assert.deepEqual(clipPromoErrors({ hold: 2 }), []); assert.match(clipPromoErrors({ name: "x" }).join(), /promo\.name is not a key/); assert.match(validatePromo({ render: {}, timeline: [{ type: "post", id: "p", promo: false }] }).join(), /promo is a clip's/); }); test("a clip's promo: the cut's with its own timing over it; none for `promo: false` or a cut that sets none; the lead held inside the clip", () => { assert.equal(promoOf({ type: "clip" }, {}), null); assert.equal(promoOf({ type: "clip", promo: false }, { promo: PROMO }), null); const p = promoOf({ type: "clip", promo: { hold: 2 } }, { promo: { ...PROMO, lead: 3 } }, 30); assert.deepEqual([p.lead, p.fade, p.hold, p.captions, p.note], [3, PROMO_TIMING.fade.default, 2, true, null]); const short = promoOf({ type: "clip" }, { promo: PROMO }, 4); assert.equal(short.lead, 3); assert.match(short.note, /lead is 4\.5 s, longer than the clip less a second: 3 s/); assert.equal(promoOf({ type: "clip" }, { promo: { ...PROMO, captions: false } }).captions, false); }); test("the colours: the cut's palette, the promo's over it, the url's host in its platform's colour", () => { const pal = promoPalette({ palette: { bg: "#12100c", fg: "#f6f1e6", accent: "#c8752a", amber: "#ffc860" } }, PROMO); assert.deepEqual([pal.ground, pal.ink, pal.accent, pal.link, pal.plate], ["#12100c", "#f6f1e6", "#ffc860", "#53fc18", "#ffffff"], "the code's plate white whatever the palette"); // A streamer's own colours, for the card alone. const own = promoPalette({ palette: { bg: "#12100c", fg: "#f6f1e6", accent: "#c8752a" } }, { ...PROMO, url: "https://example.org/me", palette: { ground: "#001122", accent: "#ff00aa" } }); assert.deepEqual([own.ground, own.accent, own.link], ["#001122", "#ff00aa", "#ff00aa"]); assert.equal(linkColourOf("https://www.twitch.tv/x"), "#a970ff"); assert.equal(linkColourOf("nope"), null); assert.deepEqual(urlParts("https://www.kick.com/synth/"), { host: "kick.com/", rest: "synth" }); assert.deepEqual(nameLines("Bread Baking Channel"), ["Bread Baking", "Channel"]); assert.deepEqual(nameLines("Short"), ["Short"]); }); test("the card's page: only portrait, name, url and code -- a kicker only when given; laid out inside the safe area, the captions' band kept clear", () => { const fonts = { display: "file:///d.ttf", text: "file:///t.ttf" }; const palette = promoPalette({}, PROMO); const html = promoCardHtml({ promo: PROMO, width: 1080, height: 1920, palette, portraitUrl: "file:///p.png", qrUrl: "file:///q.png", fonts }); assert.match(html, /Example Channel<\/span>Live<\/span>/); assert.match(html, /kick\.com\/<\/b>synth/); assert.match(html, /data-promo-qr/); assert.match(html, /data-promo-face/); assert.ok(!/data-promo-kicker/.test(html), "no kicker unless the promo gives one"); assert.ok(!/Live on|Clipped from/.test(html.replace(/Live<\/span>/, "")), "no platform line, no stock kicker"); assert.match(promoCardHtml({ promo: { ...PROMO, kicker: "Clipped from" }, width: 1080, height: 1920, palette, fonts }), /data-promo-kicker="">Clipped from/); assert.ok(!/data-promo-qr/.test(promoCardHtml({ promo: PROMO, width: 1080, height: 1920, palette, qrUrl: null, fonts }))); // A still: no animation in the page. assert.ok(!/@keyframes|animation:|transition:/.test(html)); for (const [W, H] of [[1080, 1920], [1920, 1080]]) { const b = promoBand({ width: W, height: H }); assert.ok(b.box.y1 < b.band.y0, `${W}x${H}: the card's content above the captions' band`); if (H > W) { assert.ok(b.box.y0 >= H * 0.08 && b.band.y1 <= H * 0.8 && b.box.x1 <= W * 0.88, "9:16: inside the platforms' safe area (top 8 %, bottom 20 %, right 12 %)"); } assert.equal(promoBand({ width: W, height: H, captions: false }).band, null); } }); test("the segment's graph: held past its end, the card faded in at end - lead, the sound faded out and silent for the hold", () => { const g = promoFilterParts({ vIn: "[vp]", aIn: "[al]", cardIdx: 3, seconds: 20, lead: 4.5, fade: 0.7, hold: 1.5, fps: 30 }); assert.deepEqual(g.parts, [ "[vp]tpad=stop_mode=clone:stop_duration=1.500[pmv]", "[3:v]fps=30,format=rgba,fade=t=in:st=0:d=0.700:alpha=1,setpts=PTS+15.500/TB[pmc]", "[pmv][pmc]overlay=0:0:eof_action=pass:enable='gte(t,15.500)':format=auto[pmo]", "[al]afade=t=out:st=19.850:d=0.150,apad=pad_dur=1.500[pma]", ]); assert.deepEqual([g.v, g.a, g.seconds, g.at], ["[pmo]", "[pma]", 21.5, 15.5]); // No zoom, no push: a still laid over. assert.ok(!g.parts.join(";").includes("zoompan")); }); test("the captions over the card: no group across its start, those after it in its band, the tag and the hook fading with it", () => { const words = [0.2, 0.5, 0.8, 1.1, 1.4, 1.7, 2.0, 2.3].map((t, i) => ({ text: `w${i}`, start: t, end: t + 0.2 })); const groups = captionGroups(words, { maxChars: 40, lines: 2, breaks: [1.3] }); assert.ok(groups.every((g) => g.words.every((w) => w.start < 1.3) || g.words.every((w) => w.start >= 1.3)), "none runs across the break"); assert.ok(groups.filter((g) => g.start < 1.3).every((g) => g.end <= 1.3), "none held past it"); const band = promoBand({ width: 1080, height: 1920 }).band; const geo = clipGeometry("framed", {}, 1080, 1920); const promo = { from: 1.3, fade: 0.5, captions: true, band }; const doc = verticalAss({ geo, render: {}, words, seconds: 3, tag: "Synth", hook: "A hook", promo }); const caps = doc.split("\n").filter((l) => l.includes(",cap,,")); assert.ok(caps.some((l) => l.startsWith("Dialogue: 1,0:00:00.20") && !l.includes("\\pos")), "before the card: where they always are"); assert.ok(caps.filter((l) => /,0:00:0[12]\.[0-9]{2},cap/.test(l) && new RegExp(`\\\\an2\\\\pos\\(\\d+,${band.y1}\\)`).test(l)).length >= 1, "after: in the band, centred in the captions' margins"); assert.match(doc, /Dialogue: 0,0:00:00\.00,0:00:01\.80,tag,,0,0,0,,\{\\fad\(0,500\)\}Synth/); assert.match(doc, /Dialogue: 0,0:00:00\.00,0:00:01\.80,hook,,0,0,0,,\{\\fad\(0,500\)\}A hook/); // captions: false -- none said under the card. const off = verticalAss({ geo, render: {}, words, seconds: 3, promo: { ...promo, captions: false, band: null } }); assert.ok(off.split("\n").filter((l) => l.includes(",cap,,")).every((l) => !/Dialogue: 1,0:00:0(1\.[3-9]|2)/.test(l))); // A desktop clip's band, along its foot. const dband = promoBand({ width: 1920, height: 1080 }).band; const ddoc = verticalAss({ geo: desktopGeometry({}, 1920, 1080), render: {}, words, seconds: 3, W: 1920, H: 1080, promo: { from: 1.3, fade: 0.5, captions: true, band: dband } }); assert.ok(ddoc.includes(`\\pos(960,${dband.y1})`)); // No promo: the document it always wrote. assert.equal(verticalAss({ geo, render: {}, words, seconds: 3, tag: "Synth", hook: "A hook" }), verticalAss({ geo, render: {}, words, seconds: 3, tag: "Synth", hook: "A hook", promo: null })); }); test("umtool promo's arguments", () => { assert.deepEqual(parsePortraitFrom("w01@10650.2"), { clip: "w01", at: 10650.2 }); assert.throws(() => parsePortraitFrom("w01"), /@/); assert.deepEqual(parseBox("0.5,0,0.3,0.5"), [0.5, 0, 0.3, 0.5]); assert.throws(() => parseBox("0.9,0,0.3,1"), /inside it/); });