Split any YouTube song into stems
TypeScript
fix(export): keep the full name suffix for every stem selection
David Naviadcfcd9af2188
diff --git a/src/shared/export-rules.ts b/src/shared/export-rules.tsindex e74eb8c..65ac988 100644--- a/src/shared/export-rules.ts+++ b/src/shared/export-rules.ts@@ -30,12 +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+// main cuts sanitized names at 120 chars (sanitizeName); the title gives way+// first so the " - drums+bass (+2)" part, which tells two exports apart, survives+const NAME_LIMIT = 120++function withSuffix(title: string, suffix: string): string {+ const room = Math.max(0, NAME_LIMIT - suffix.length)+ const head = title.length > room ? title.slice(0, room).trimEnd() : title+ return `${head}${suffix}`}export function mixedBaseName(@@ -50,9 +52,9 @@ export function mixedBaseName(chosen.length === allStems.length - 1 &&!chosen.includes('vocals')const part = isInstrumental ? 'instrumental' : chosen.join('+')- return `${shortTitle(title)} - ${part}${shiftSuffix(semitones)}`+ return withSuffix(title, ` - ${part}${shiftSuffix(semitones)}`)}export function separateFolderName(title: string, semitones: number): string {- return `${shortTitle(title)}${shiftSuffix(semitones)}`+ return withSuffix(title, shiftSuffix(semitones))}diff --git a/tests/export-rules.test.mjs b/tests/export-rules.test.mjsindex cc1a7d5..5370989 100644--- a/tests/export-rules.test.mjs+++ b/tests/export-rules.test.mjs@@ -56,8 +56,15 @@ test('long titles are cut so the stem and shift suffix survive a 120-char name lconst 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)`)+ assert.equal(mixed, `${'x'.repeat(102)} - drums+bass (+2)`)+ assert.equal(separateFolderName(title, -1), `${'x'.repeat(115)} (-1)`)// short titles are untouchedassert.equal(separateFolderName('Song', 0), 'Song')})++test('the suffix survives even with every stem of a 6-stem song checked and a shift', () => {+ const six = ['vocals', 'drums', 'bass', 'guitar', 'piano', 'other']+ const name = mixedBaseName('y'.repeat(200), six, six, -6)+ assert.ok(name.length <= 120, `length ${name.length}`)+ assert.ok(name.endsWith(' - vocals+drums+bass+guitar+piano+other (-6)'))+})