원곡찾기: MV·inst.·라이브·커버는 길이가 같아도 확정하지 않음 — 검색 줄 제목(점수 경로 포함)과 실제 영상 제목(oEmbed) 모두. 길이가 같은 결과의 실제 영상이 '광 (Official MV)'·'(Inst.)'이면 matched로 저장되던 것. 회귀 테스트(매칭·reconfirm)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-29 11:06:04 +09:00
parent 71251a08a8
commit 9ab3c9258e
4 changed files with 34 additions and 12 deletions

View File

@@ -52,8 +52,9 @@ test('scoring: title+artist confident whatever the length, MR/cover/MV/other mix
expect(isConfident(scoreResult(song, yt('광 (Sleep Mix)', 'SG워너비', 3600), 0))).toBe(false);
expect(isConfident(scoreResult(song, yt('광 (2021)', 'SG워너비', 300), 0))).toBe(false);
expect(isConfident(scoreResult(song, { ...yt('광', 'SG워너비', 300), topic: false }, 0))).toBe(false);
// an MV with the same length still counts as before (score path)
expect(isConfident(scoreResult(song, yt('광 (Official MV)', 'SG워너비', 238), 0))).toBe(true);
// an MV or inst. is never the original, even with the same length
expect(isConfident(scoreResult(song, yt('광 (Official MV)', 'SG워너비', 237), 0))).toBe(false);
expect(isConfident(scoreResult(song, { ...yt('광 (Official MV)', 'SG워너비', 237), topic: false }, 0))).toBe(false);
// a 38-second track or a 10-minute one under the same title is an intro, skit or megamix, not the song
expect(isConfident(scoreResult(song, yt('광', 'SG워너비', 38), 0))).toBe(false);
expect(isConfident(scoreResult(song, yt('광', 'SG워너비', 555), 0))).toBe(false);
@@ -180,6 +181,26 @@ test('artist names learnt from confirmed songs (2+ songs) confirm waiting candid
expect(st(farMv).youtube_status).toBe('candidate');
});
test('YouTube matching: the actual video being an MV or inst. keeps the song a 후보 even with the same length', async () => {
const db = freshDb();
const c = new Catalog(db);
const [mv] = c.upsert({ title: '광', artists: [{ name: 'SG워너비' }], durationSec: 237, source: 't', ref: '1' });
const [inst] = c.upsert({ title: '내사람', artists: [{ name: 'SG워너비' }], durationSec: 300, source: 't', ref: '2' });
const results: Record<string, YtmSong[]> = {
'SG워너비 광': [{ videoId: 'gwangmv0001', title: '광', artists: 'SG워너비', album: null, durationSec: 237 }],
'SG워너비 내사람': [{ videoId: 'mineinst001', title: '내사람', artists: 'SG워너비', album: null, durationSec: 300 }],
};
const titles: Record<string, string> = { gwangmv0001: '광 (Official MV)', mineinst001: '내사람 (Inst.)' };
const stats = await matchYoutube(db, { searchSongs: async (q) => results[q] ?? [] }, { delayMs: 0 }, async (id) => ({ state: 'ok', author: 'SG Wannabe', title: titles[id]! }));
expect(stats.matched).toBe(0);
const st = (id: number) => db.query<{ youtube_status: string }, [number]>('SELECT youtube_status FROM songs WHERE id = ?').get(id)!.youtube_status;
expect(st(mv!)).toBe('candidate');
expect(st(inst!)).toBe('candidate');
// reconfirm-youtube checks the same way
expect((await reconfirmCandidates(db, { delayMs: 0 }, async (id) => ({ state: 'ok', author: 'SG Wannabe', title: titles[id]! }))).matched).toBe(0);
expect([st(mv!), st(inst!)]).toEqual(['candidate', 'candidate']);
});
function freshDb() {
return openDb(tempDbPath());
}

View File

@@ -43,12 +43,12 @@ function setAutoVideo(db: Database, id: number, status: 'matched' | 'candidate',
}
/**
* A result confirmed despite a length difference (title + artist) whose actual video turns out to be a music video,
* inst., live, another mix … (the YouTube title, not the search row): left as 후보.
* The actual video (its YouTube title, not the search row) turns out to be a music video, inst., live … — whatever the
* length — or, for a result confirmed despite a length difference, another mix/edit/year: left as 후보.
*/
function isOtherCut(c: Scored, videoTitle: string, songTitle: string): boolean {
if (!confirmedDespiteLength(c)) return false;
return (isVideoTitle(videoTitle) && !isVideoTitle(songTitle)) || (isJunkTitle(videoTitle) && !isJunkTitle(songTitle)) || namesOtherCut(videoTitle, songTitle);
if ((isVideoTitle(videoTitle) && !isVideoTitle(songTitle)) || (isJunkTitle(videoTitle) && !isJunkTitle(songTitle))) return true;
return confirmedDespiteLength(c) && namesOtherCut(videoTitle, songTitle);
}
async function searchRetry(ytm: Pick<YtMusic, 'searchSongs'>, query: string, job: Job | null): Promise<YtmSong[]> {

View File

@@ -10,7 +10,7 @@ const BENIGN = /\b(?:radio edit|original|album|single|mono|stereo|remaster(?:ed)
export const MAX_LENGTH_DIFF = 15;
/** An artist that only sounds the same in the other script (디제이디오씨 ~ DJ DOC) confirms only this close. */
export const MAX_SOUND_LENGTH_DIFF = 8;
/** A music video or another cut of the song: never confirmed by title and artist alone when the length is off. */
/** A music video, lyric video, stage clip …: never confirmed (unless the song's own title says so). */
/** Words of a different cut or recording: a mix, an edit, a dated re-recording … (only used when the length is off too). */
const CUT = /\b(?:mix|edit|ver|version|edition|demo|medley|reprise|session|take|cut|re-?recorded|piano|orchestra|strings|sleep|lo-?fi|extended|short|full|intro|outro)\b|\b(?:19|20)\d{2}\b|버전|믹스/gi;
/** A remaster is the same recording: "(2021 Remastered)" is not a dated re-recording. */
@@ -100,16 +100,17 @@ export function scoreResult(song: { title: string; artist: string; durationSec:
}
/**
* Auto-confirm, any of:
* Never a cover/inst./live (junk) or a music video. Otherwise auto-confirm, any of:
* - title + artist, whatever the length (a different take or a wrong Melon length), unless the result is a cover/inst./live
* (junk), a music video or not an official Topic track — and when the length is off, unless it names another mix/edit/year
* not an official Topic track — and when the length is off, unless it names another mix/edit/year
* or the title is one artists reuse ("Intro"), or the result is under 90 seconds / over 7 minutes and twice the song's length;
* - title + artist written in the other script that sounds the same, within MAX_SOUND_LENGTH_DIFF seconds;
* - title + a close length (score 70+, e.g. without the artist), within MAX_LENGTH_DIFF seconds.
*/
export function isConfident(s: Scored): boolean {
if (!s.titleOk) return false;
const plain = !s.junk && !s.video && s.topic !== false;
// a music video, inst., live, cover … is never the original, whatever its length
if (!s.titleOk || s.junk || s.video) return false;
const plain = s.topic !== false;
const lengthOff = s.lengthDiff !== null && s.lengthDiff > MAX_LENGTH_DIFF;
if (s.artistOk && plain && !(lengthOff && (s.otherCut || s.genericTitle || s.oddLength))) return true;
if (s.artistSound && plain && s.lengthDiff !== null && s.lengthDiff <= MAX_SOUND_LENGTH_DIFF) return true;