From 0789a11a39796f0016802ac407c88e7632e0a94e Mon Sep 17 00:00:00 2001 From: poli0981 <127664709+poli0981@users.noreply.github.com> Date: Fri, 6 Nov 2026 22:22:33 +0700 Subject: [PATCH] feat(tags): the boss name as a tag in boss videos Boss Fight and Boss No Hit videos get the boss's name as a tag of its own, right after the game's name, so fitting the list to 500 characters never drops it. bossNameTag cleans the Boss Name field the way a search term reads: - NFC first; everything but letters (any script), marks, digits, whitespace and in-word ' ' - becomes a space: , : ; ! ? quotes, brackets, &, the CJK brackets and dots, (TM), emoji. - A dot stays between digits ("Phase 2.0"), goes between initials ("S.T.A.L.K.E.R." -> "STALKER") and is a space anywhere else ("Mr.X" -> "Mr X"). Done per word in code: a lookbehind would be a syntax error in the macOS 11-13 webview and stop the chunk loading. - Over 30 characters, the name before its title ("Loretta, Knight of the Haligtree" -> "Loretta"), else the leading words that fit; the word fit is now a helper shared with tagFriendlyGameName (same result there). Only the video types whose extraFields include bossName add it, so a boss name left in the draft after switching to Full Gameplay is not tagged. Docs: FEATURES, ARCHITECTURE 2.3, TECH-SPEC. Co-Authored-By: Claude Opus 5.5 --- docs/ARCHITECTURE.md | 17 ++-- docs/FEATURES.md | 12 +++ docs/TECH-SPEC.md | 2 +- src/engine/tag-generator.ts | 123 +++++++++++++++++++++++++--- tests/engine/tag-generator.test.ts | 126 +++++++++++++++++++++++++++++ 5 files changed, 262 insertions(+), 18 deletions(-) diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 364af96..71472b6 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -219,14 +219,15 @@ generateTags(input, { includeMultilingualTags, includeTrendingTags, year }) priority pool source 1 game name bare tag (≤ 30 chars) + a shorter form for composites - 2 core CORE_TAGS_BY_LANG[language] - 3 genre GENRE_TAG_REGISTRY[genre], for every selected genre - 4 video type VIDEO_TYPE_TAGS[videoType] - 5 platform PLATFORMS[].tagName ("Steam", "itch.io", …) - 6 quality resolution / fps - 7 multilingual MULTILINGUAL_TAGS[language] (setting) - 8 trending year-based, first genre only (setting) - 9 publisher/developer pubDevName, as a bare tag + 2 boss name bossNameTag(bossName) — Boss Fight / Boss No Hit only + 3 core CORE_TAGS_BY_LANG[language] + 4 genre GENRE_TAG_REGISTRY[genre], for every selected genre + 5 video type VIDEO_TYPE_TAGS[videoType] + 6 platform PLATFORMS[].tagName ("Steam", "itch.io", …) + 7 quality resolution / fps + 8 multilingual MULTILINGUAL_TAGS[language] (setting) + 9 trending year-based, first genre only (setting) + 10 publisher/developer pubDevName, as a bare tag │ ▼ de-duplicate (case-insensitive) · drop tags over 30 characters diff --git a/docs/FEATURES.md b/docs/FEATURES.md index 4407d7d..9146135 100644 --- a/docs/FEATURES.md +++ b/docs/FEATURES.md @@ -254,6 +254,7 @@ per platform). | Pool | Triggered By | Sample Output | | ------------ | --------------------------------- | ------------------------------------------------------------------------ | | Game name | Always | `[game]` (shortened to fit 30 characters) | +| Boss name | Boss Fight / Boss No Hit (v1.4.0) | `[boss]` — the Boss Name field, without punctuation | | Core | Always, in the output language | `[game] gameplay`, `[game] no commentary`, `gameplay no commentary` | | Genre | Each selected genre | `horror game no commentary`, `RPG gameplay no commentary` | | VideoType | Video type | `[game] boss fight`, `[game] speedrun`, `[game] all endings` | @@ -276,6 +277,17 @@ per platform). Game names are cleaned of characters YouTube splits tags on (`,` `;` `|`) and of ™ / ® / ©. +**Boss name tag (v1.4.0)** — Boss Fight and Boss No Hit videos get the boss's +name as a tag of its own, right after the game's name, so fitting the list to +500 characters never drops it. Marks that add nothing to a search go: `,` `:` +`;` `!` `?` quotes, brackets, `&`, `「」` `・` `、`, ™, emoji. A dot is kept +between digits ("Phase 2.0"), dropped between initials ("S.T.A.L.K.E.R." → +`STALKER`) and a space anywhere else ("Mr. X" / "Mr.X" → `Mr X`); apostrophes +and hyphens stay inside a word ("Mergo's Wet Nurse", "T-103"). "Gael, Slave +Knight" → `Gael Slave Knight`. Over 30 characters, the name before its title is +used ("Loretta, Knight of the Haligtree" → `Loretta`), otherwise the leading +words that fit. + ## ⚡ Faster Data Entry (v1.0.0) - **Quick start** — at the top of the editor, pick a **channel profile** and diff --git a/docs/TECH-SPEC.md b/docs/TECH-SPEC.md index 85b3122..fcf6c14 100644 --- a/docs/TECH-SPEC.md +++ b/docs/TECH-SPEC.md @@ -414,7 +414,7 @@ export interface TitleFormatConfig { **Tag length, counted the way YouTube counts it** (`tag-generator.ts`): - `youtubeTagsLength(tags)` = the sum of each tag's length, plus 2 for the quotes YouTube puts around any tag containing whitespace, plus one comma between tags. The old measure (length of the `", "`-joined string) ignored the quotes; 15 of 51 real tag sets were over 500 by YouTube's count while showing as under. -- `generateTags` collects, in priority order: the game name (bare, and a shortened form for composites), core tags for the output language, genre tags for every selected genre, video-type tags, platform tags, quality tags, the output language's multilingual tags (setting), trending tags for the first genre (setting), and the publisher/developer name. It then de-duplicates case-insensitively, drops tags over 30 characters, and `trimToCharLimit(tags, 500)` keeps tags in priority order while they fit — a tag that doesn't fit is skipped and the shorter ones after it are still tried. +- `generateTags` collects, in priority order: the game name (bare, and a shortened form for composites), the boss name for the video types whose `extraFields` include `bossName` (v1.4.0 — `bossNameTag`: NFC, every mark but in-word `'` `’` `-` and digit-to-digit `.` removed, dots between initials dropped, the name before its title or the leading words when over 30 characters), core tags for the output language, genre tags for every selected genre, video-type tags, platform tags, quality tags, the output language's multilingual tags (setting), trending tags for the first genre (setting), and the publisher/developer name. It then de-duplicates case-insensitively, drops tags over 30 characters, and `trimToCharLimit(tags, 500)` keeps tags in priority order while they fit — a tag that doesn't fit is skipped and the shorter ones after it are still tried. - Platform tags use `PlatformConfig.tagName` ("Steam", "Epic Games", "itch.io"), not the id; the publisher's own site has no tag name and adds no platform tags. **Empty channel name** (`channel-phrase.ts`, used by the description, pinned comment and playlist builders): templates render with `CHANNEL_SLOT` (`@@CHANNEL@@`) in place of an empty channel name. `withoutEmptyChannel(text, language)` then removes the words that go with the channel name in that language ("trên kênh", "による", "en", "no", "di", …) and the English "on" (for English, and for locales that still carry English sentences for newer video types), replaces any slot left over with a neutral fallback ("this channel", "kênh", …) and tidies the spacing before punctuation. "…of Hades on ." no longer happens in any of the eight languages. diff --git a/src/engine/tag-generator.ts b/src/engine/tag-generator.ts index 3a67b1e..ddeff9b 100644 --- a/src/engine/tag-generator.ts +++ b/src/engine/tag-generator.ts @@ -1,6 +1,7 @@ import type { GeneratorInput, SupportedLanguage } from "./types"; import { YT_LIMITS } from "./types"; import { PLATFORMS } from "@config/platforms"; +import { VIDEO_TYPES } from "@config/video-types"; /** * Length of a tag list as YouTube counts it against the 500-character @@ -73,16 +74,111 @@ export function tagFriendlyGameName(name: string, budget: number): string { n = head; } - const words = n.split(/\s+/); - const acc: string[] = []; - let len = 0; - for (const w of words) { - const sep = acc.length === 0 ? 0 : 1; - if (len + sep + w.length > budget) break; - acc.push(w); - len += sep + w.length; + return leadingWordsWithin(n.split(/\s+/), budget); +} + +/** + * The leading whole words that fit `budget` characters, joined by single + * spaces; when even the first word is longer, its first `budget` + * characters. + */ +function leadingWordsWithin(words: readonly string[], budget: number): string { + const kept: string[] = []; + let length = 0; + for (const word of words) { + const separator = kept.length === 0 ? 0 : 1; + if (length + separator + word.length > budget) break; + kept.push(word); + length += separator + word.length; } - return acc.join(" ") || n.slice(0, budget); + return kept.join(" ") || (words[0] ?? "").slice(0, budget); +} + +/** + * What a boss name's tag keeps: letters in any script (with their + * combining marks), digits, whitespace, and `.` `'` `’` `-` for the word + * rules below. Everything else — `,` `;` `:` `!` `?` quotes, brackets, + * `&` `/` `#`, `「」` `・` `、` `。`, ™, emoji — becomes a space. A single + * character class: linear. + */ +const BOSS_NAME_NOISE = /[^\p{L}\p{M}\p{N}\s.'’-]/gu; + +/** + * Where a long boss name's title starts: "Loretta, Knight of the + * Haligtree", "Margit – the Fell Omen", "Sister Friede (Phase 2)". + */ +const BOSS_NAME_BREAK = /[,,、::;;(([【「『|—–]| - /; + +const DIGIT = /^\p{Nd}$/u; +const INITIAL = /^\p{L}\p{M}*$/u; + +/** Apostrophes and hyphens belong inside a word ("Mergo's", "T-103"), not at its edges. */ +const WORD_EDGE_MARKS = new Set(["'", "’", "-"]); + +function trimWordEdges(word: string): string { + let start = 0; + let end = word.length; + while (start < end && WORD_EDGE_MARKS.has(word.charAt(start))) start++; + while (end > start && WORD_EDGE_MARKS.has(word.charAt(end - 1))) end--; + return word.slice(start, end); +} + +/** + * The dots in one word: kept between two digits ("2.0"), dropped between + * initials ("S.T.A.L.K.E.R." → "STALKER", "K.K." → "KK"), a space + * everywhere else ("Mr.X" → "Mr X", "Dr.ワイリー" → "Dr ワイリー"). + * Done in code, not with a lookbehind: older WebKit (the macOS 11–13 + * desktop webview) rejects one, and the whole chunk would fail to load. + */ +function resolveDots(word: string): string { + const parts = word.split("."); + let out = parts[0] ?? ""; + for (let i = 1; i < parts.length; i++) { + const before = parts[i - 1] ?? ""; + const after = parts[i] ?? ""; + if (DIGIT.test(before.slice(-1)) && DIGIT.test(after.charAt(0))) out += "."; + else if (!(INITIAL.test(before) && (after === "" || INITIAL.test(after)))) out += " "; + out += after; + } + return out; +} + +function bossNameWords(text: string): string[] { + return text + .replace(BOSS_NAME_NOISE, " ") + .split(/\s+/) + .flatMap((word) => resolveDots(word).split(" ")) + .map(trimWordEdges) + .filter(Boolean); +} + +/** + * The boss's name as one tag, without the marks that add nothing to a + * search: "Gael, Slave Knight" → "Gael Slave Knight", "Mr. X" → "Mr X", + * "「マレニア」" → "マレニア". Over 30 characters (the per-tag limit), the + * name before its title is tried ("Loretta, Knight of the Haligtree" → + * "Loretta"), then the leading words that fit. Empty when nothing is left. + * + * Pure — exported for testing. + */ +export function bossNameTag(name: string): string { + const text = name.normalize("NFC"); + const words = bossNameWords(text); + const full = words.join(" "); + if (full.length <= YT_LIMITS.SINGLE_TAG_MAX) return full; + + const breakAt = text.search(BOSS_NAME_BREAK); + const headWords = breakAt > 0 ? bossNameWords(text.slice(0, breakAt)) : []; + const head = headWords.join(" "); + if (head && head.length <= YT_LIMITS.SINGLE_TAG_MAX) return head; + return leadingWordsWithin(headWords.length > 0 ? headWords : words, YT_LIMITS.SINGLE_TAG_MAX); +} + +/** Video types that ask for a boss name (Boss Fight, Boss No Hit). */ +function takesBossName(videoType: string): boolean { + const extraFields: readonly string[] = + VIDEO_TYPES.find((type) => type.id === videoType)?.extraFields ?? []; + return extraFields.includes("bossName"); } /** @@ -541,6 +637,15 @@ export function generateTags(input: GeneratorInput, options?: TagOptions): strin if (bareNameTag) allTags.push(bareNameTag); if (composeName && composeName !== bareNameTag) allTags.push(composeName); + // Boss videos (v1.4.0): the boss's name as a tag of its own, right after + // the game's, so fitting the list to 500 characters never drops it. Only + // for the video types that ask for a boss name — one left in the draft + // after switching to another type isn't this video's. + if (takesBossName(input.videoType)) { + const bossTag = bossNameTag(input.bossName ?? ""); + if (bossTag) allTags.push(bossTag); + } + // Core tags — language-specific (highest priority) const coreFn = CORE_TAGS_BY_LANG[input.language] ?? CORE_TAGS_BY_LANG.en; allTags.push(...coreFn(composeName)); diff --git a/tests/engine/tag-generator.test.ts b/tests/engine/tag-generator.test.ts index eb5bb67..d1f565f 100644 --- a/tests/engine/tag-generator.test.ts +++ b/tests/engine/tag-generator.test.ts @@ -1,5 +1,6 @@ import { describe, it, expect } from "vitest"; import { + bossNameTag, generateTags, formatTagString, tagFriendlyGameName, @@ -307,6 +308,131 @@ describe("tagFriendlyGameName — punctuation sanitization (v0.20.0)", () => { }); }); +describe("tagFriendlyGameName — word fit", () => { + it("cuts a first word longer than the budget to fit", () => { + expect(tagFriendlyGameName("Supercalifragilisticexpialidocious Adventure", 30)).toBe( + "Supercalifragilisticexpialidoc", + ); + }); +}); + +describe("bossNameTag (v1.4.0)", () => { + it.each([ + ["Gael, Slave Knight", "Gael Slave Knight"], + ["Mr. X", "Mr X"], + ["Mr.X", "Mr X"], + ["S.T.A.L.K.E.R.", "STALKER"], + ["K.K. Slider", "KK Slider"], + ["A.Bomb", "A Bomb"], + ["Dr.ワイリー", "Dr ワイリー"], + ["No.1 Boss", "No 1 Boss"], + ["Phase 2.0", "Phase 2.0"], + ["Mergo's Wet Nurse", "Mergo's Wet Nurse"], + ["Mergo’s Wet Nurse", "Mergo’s Wet Nurse"], + ["T-103", "T-103"], + ["'Nameless King'", "Nameless King"], + ["- Phase 2 -", "Phase 2"], + ["「マレニア」", "マレニア"], + ["ゲール・スレイブナイト", "ゲール スレイブナイト"], + ["无名之王,奥斯卡", "无名之王 奥斯卡"], + ["Gwyn™, Lord of Cinder", "Gwyn Lord of Cinder"], + ["Ornstein & Smough", "Ornstein Smough"], + ["Trùm cuối: Rồng Lửa", "Trùm cuối Rồng Lửa"], + ['"Nemesis" (Final Form)', "Nemesis Final Form"], + ["???", ""], + ["👹🔥", ""], + [" ", ""], + ["", ""], + ])("%s → %s", (name, tag) => { + expect(bossNameTag(name)).toBe(tag); + }); + + it("composes decomposed letters, as macOS can paste them", () => { + const decomposed = "Trùm cuối".normalize("NFD"); + expect(bossNameTag(decomposed)).toBe("Trùm cuối".normalize("NFC")); + }); + + it("keeps a long name to 30 characters, preferring the part before its title", () => { + expect(bossNameTag("Loretta, Knight of the Haligtree")).toBe("Loretta"); + // Exactly 30 once the colon goes: kept whole. + expect(bossNameTag("Rennala: Queen of the Full Moon")).toBe("Rennala Queen of the Full Moon"); + expect(bossNameTag("Radagon of the Golden Order: Elden Beast")).toBe( + "Radagon of the Golden Order", + ); + expect(bossNameTag("Lady Maria of the Astral Clocktower")).toBe("Lady Maria of the Astral"); + expect(bossNameTag("A".repeat(31))).toBe("A".repeat(30)); + }); + + it("never leaves a tag delimiter, quote or angle bracket", () => { + const tag = bossNameTag('A, B; C | D "E" G'); + expect(tag).toBe("A B C D E F G"); + expect(tag).not.toMatch(/[,;|"<>]/); + }); + + it("gives the same tag when run on its own output", () => { + for (const name of [ + "Gael, Slave Knight", + "S.T.A.L.K.E.R.", + "- 'x' -", + "Loretta, Knight of the Haligtree", + ]) { + const once = bossNameTag(name); + expect(bossNameTag(once)).toBe(once); + } + }); + + it("stays fast on long runs of spaces and dots", () => { + expect(bossNameTag(`${" ".repeat(10_000)}x`)).toBe("x"); + expect(bossNameTag(".".repeat(10_000))).toBe(""); + expect(bossNameTag(`${"-".repeat(10_000)}x`)).toBe("x"); + }); +}); + +describe("generateTags — boss name (v1.4.0)", () => { + it("puts the boss's name right after the game's name in boss videos", () => { + for (const videoType of ["boss", "boss_nohit"] as const) { + const tags = generateTags(makeInput({ videoType, bossName: "Gael, Slave Knight" })); + expect(tags.slice(0, 2)).toEqual(["Elden Ring", "Gael Slave Knight"]); + } + }); + + it("adds no boss tag to other video types", () => { + const tags = generateTags(makeInput({ videoType: "full", bossName: "Gael, Slave Knight" })); + expect(tags).not.toContain("Gael Slave Knight"); + expect(tags).toEqual(generateTags(makeInput({ videoType: "full" }))); + }); + + it("adds nothing for an empty or symbols-only name", () => { + const base = generateTags(makeInput({ videoType: "boss" })); + expect(generateTags(makeInput({ videoType: "boss", bossName: "" }))).toEqual(base); + expect(generateTags(makeInput({ videoType: "boss", bossName: "?! …" }))).toEqual(base); + }); + + it("gives one tag when the boss shares the game's name", () => { + const tags = generateTags( + makeInput({ videoType: "boss", gameName: "Cuphead", bossName: "CUPHEAD." }), + ); + expect(tags.filter((t) => t.toLowerCase() === "cuphead")).toHaveLength(1); + }); + + it("keeps the boss tag when the 500-character budget is full", () => { + const tags = generateTags( + makeInput({ + gameName: "The Legend of Heroes Trails through Daybreak", + genres: ["jrpg", "action_rpg", "openworld"], + videoType: "boss_nohit", + bossName: "Loretta, Knight of the Haligtree", + resolution: "4K", + fps: "120", + pubDevName: "Nihon Falcom", + }), + { year: 2026 }, + ); + expect(tags).toContain("Loretta"); + expect(youtubeTagsLength(tags)).toBeLessThanOrEqual(500); + }); +}); + describe("tag length as YouTube counts it (v1.0.0)", () => { it("counts quotes around multi-word tags and one comma between tags", () => { expect(youtubeTagsLength([])).toBe(0);