Split any YouTube song into stems
TypeScript
fix(export): cap long titles so export names keep their suffix
David Navia5738244282c2
diff --git a/src/shared/export-rules.ts b/src/shared/export-rules.tsindex 145dc1b..e74eb8c 100644--- a/src/shared/export-rules.ts+++ b/src/shared/export-rules.ts@@ -30,6 +30,14 @@ function shiftSuffix(semitones: number): string {return ` (${semitones > 0 ? '+' : '-'}${Math.abs(semitones)})`}+// main cuts sanitized names at 120 chars; capping the title first keeps the+// " - drums+bass (+2)" part, which is what tells two exports of a song apart+const TITLE_LIMIT = 80++function shortTitle(title: string): string {+ return title.length > TITLE_LIMIT ? title.slice(0, TITLE_LIMIT).trimEnd() : title+}+export function mixedBaseName(title: string,selected: string[],@@ -42,9 +50,9 @@ export function mixedBaseName(chosen.length === allStems.length - 1 &&!chosen.includes('vocals')const part = isInstrumental ? 'instrumental' : chosen.join('+')- return `${title} - ${part}${shiftSuffix(semitones)}`+ return `${shortTitle(title)} - ${part}${shiftSuffix(semitones)}`}export function separateFolderName(title: string, semitones: number): string {- return `${title}${shiftSuffix(semitones)}`+ return `${shortTitle(title)}${shiftSuffix(semitones)}`}diff --git a/tests/export-rules.test.mjs b/tests/export-rules.test.mjsindex 40bbb63..cc1a7d5 100644--- a/tests/export-rules.test.mjs+++ b/tests/export-rules.test.mjs@@ -50,3 +50,14 @@ test('separateFolderName appends the shift only when non-zero', () => {assert.equal(separateFolderName('Song', 2), 'Song (+2)')assert.equal(separateFolderName('Song', -3), 'Song (-3)')})++test('long titles are cut so the stem and shift suffix survive a 120-char name limit', () => {+ const title = 'x'.repeat(200)+ const mixed = mixedBaseName(title, ['drums', 'bass'], ALL, 2)+ assert.ok(mixed.length <= 120, `length ${mixed.length}`)+ assert.ok(mixed.endsWith(' - drums+bass (+2)'))+ assert.equal(mixed, `${'x'.repeat(80)} - drums+bass (+2)`)+ assert.equal(separateFolderName(title, -1), `${'x'.repeat(80)} (-1)`)+ // short titles are untouched+ assert.equal(separateFolderName('Song', 0), 'Song')+})