fix(download): dedup missed re-downloads when the title contains ' - ' (KH triple/quadruple)
findExistingTrack split the filename at the first ' - ' assuming 'Artist - Title',
so a title with internal dashes ('Kingdom Hearts 2 - Dearly Beloved - Main Theme')
or a garbage/absent artist prefix ('01-01 - …') was mis-parsed → the duplicate went
undetected and got re-downloaded (3-4x). Now match the query title against BOTH the
full stem AND the part after the first ' - ', so titles with dashes and prefix-only
filenames are recognized. Normal 'Artist - Title' files still match; no false
positives; remix-vs-base distinction preserved. Unit-tested on the exact KH case.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
75dceba97b
commit
b788fedec3
2 files changed
+61
-4
No files matched your search
@@ -0,0 +1,50 @@
|
||||
const { test, before, after } = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('fs');
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
const { findExistingTrack } = require('../lib/metadata');
|
||||
|
||||
let ROOT;
|
||||
const touch = (artist, album, file) => {
|
||||
const dir = path.join(ROOT, artist, album);
|
||||
fs.mkdirSync(dir, { recursive: true });
|
||||
fs.writeFileSync(path.join(dir, file), '');
|
||||
};
|
||||
|
||||
before(() => {
|
||||
ROOT = fs.mkdtempSync(path.join(os.tmpdir(), 'ns-dedup-'));
|
||||
// KH single: normal "01 - " prefix, title contains multiple " - "
|
||||
touch('Geek Music', 'Kingdom Hearts 2 - Dearly Beloved - Main Theme - Single',
|
||||
'01 - Kingdom Hearts 2 - Dearly Beloved - Main Theme.mp3');
|
||||
// KH album variant: garbage "01-01" artist prefix, no track number
|
||||
touch('Geek Music', 'Kingdom Hearts 2 - Dearly Beloved - Main Theme',
|
||||
'01-01 - Kingdom Hearts 2 - Dearly Beloved - Main Theme.mp3');
|
||||
// Normal "Artist - Title" file
|
||||
touch('Some Artist', 'Therapy - Single', '01 - Some Artist - Therapy.mp3');
|
||||
});
|
||||
after(() => { try { fs.rmSync(ROOT, { recursive: true, force: true }); } catch {} });
|
||||
|
||||
test('detects a re-download when the title itself contains " - " (KH bug)', () => {
|
||||
assert.ok(findExistingTrack(ROOT, 'Geek Music', 'Kingdom Hearts 2 - Dearly Beloved - Main Theme'));
|
||||
});
|
||||
|
||||
test('detects it even with a garbage "01-01 - " artist prefix', () => {
|
||||
// Both KH files should resolve; at least one must be found → dedup skips the re-download.
|
||||
const hit = findExistingTrack(ROOT, 'Geek Music', 'Kingdom Hearts 2 - Dearly Beloved - Main Theme');
|
||||
assert.ok(hit && hit.includes('Kingdom Hearts 2 - Dearly Beloved - Main Theme'));
|
||||
});
|
||||
|
||||
test('normal "Artist - Title" filename still matches on title alone', () => {
|
||||
assert.ok(findExistingTrack(ROOT, 'Some Artist', 'Therapy'));
|
||||
});
|
||||
|
||||
test('no false positive: a different title is not matched', () => {
|
||||
assert.equal(findExistingTrack(ROOT, 'Geek Music', 'Some Unrelated Song'), null);
|
||||
assert.equal(findExistingTrack(ROOT, 'Some Artist', 'Kingdom Hearts 2'), null);
|
||||
});
|
||||
|
||||
test('remix stays distinct from the base track (no regression from the version-marker fix)', () => {
|
||||
assert.equal(findExistingTrack(ROOT, 'Some Artist', 'Therapy (Remix)'), null);
|
||||
assert.ok(findExistingTrack(ROOT, 'Some Artist', 'Therapy')); // base still found
|
||||
});
|
||||
Reference in new issue
Block a user