원곡찾기: 노래 제목에 보류 표시가 하나라도 있으면(Live Wire의 live, 거북선 Remix의 remix) inst.·커버·MV 검사가 통째로 꺼지던 것 — 표시를 하나씩 세어 노래 제목에 있는 표시만 그 개수만큼 예외('Remix Version'=remix 하나). 검색 줄 제목·실제 영상 제목 모두, 매칭·reconfirm 회귀 테스트

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-29 11:13:26 +09:00
parent 9ab3c9258e
commit 8fc62458f3
4 changed files with 68 additions and 13 deletions

View File

@@ -81,6 +81,36 @@ test('scoring: accents, 및, "Radio Edit Version" and the length limit', () => {
expect(notConfidentReasons(other)).toEqual(['가수 다름: Ashiyane']);
});
test('a song whose own title has a mark ("Live Wire", "거북선 Remix") still keeps out an added inst./cover/MV', async () => {
const yt = (title: string, artists: string, durationSec: number): YtmSong => ({ videoId: 'x', title, artists, album: null, durationSec });
const wire = { title: 'Live Wire', artist: '서태지', durationSec: 242 };
const turtle = { title: '거북선 Remix', artist: '팔로알토', durationSec: 279 };
expect(isConfident(scoreResult(wire, yt('Live Wire', '서태지', 242), 0))).toBe(true);
for (const t of ['Live Wire (Inst.)', 'Live Wire (Cover)', 'Live Wire (Official MV)', 'Live Wire (Live)']) expect([t, isConfident(scoreResult(wire, yt(t, '서태지', 242), 0))]).toEqual([t, false]);
expect(isConfident(scoreResult(turtle, yt('거북선 Remix Version', '팔로알토', 281), 0))).toBe(true);
expect(isConfident(scoreResult(turtle, yt('거북선 Remix (Inst.)', '팔로알토', 279), 0))).toBe(false);
// the same through matching and reconfirm-youtube, when only the actual video's title shows it
const db = freshDb();
const c = new Catalog(db);
const add = (title: string, artist: string, dur: number, ref: string) => c.upsert({ title, artists: [{ name: artist }], durationSec: dur, source: 't', ref })[0]!;
const ids = { wire: add('Live Wire', '서태지', 242, '1'), wireInst: add('Live Wire 2', '서태지', 242, '2'), turtle: add('거북선 Remix', '팔로알토', 279, '3'), turtleInst: add('거북선 Remix 2', '팔로알토', 279, '4') };
const results: Record<string, YtmSong[]> = {
'서태지 Live Wire': [{ videoId: 'wire0000001', title: 'Live Wire', artists: '서태지', album: null, durationSec: 242 }],
'서태지 Live Wire 2': [{ videoId: 'wireinst001', title: 'Live Wire 2', artists: '서태지', album: null, durationSec: 242 }],
'팔로알토 거북선 Remix': [{ videoId: 'turtle00001', title: '거북선 Remix Version', artists: '팔로알토', album: null, durationSec: 281 }],
'팔로알토 거북선 Remix 2': [{ videoId: 'turtleinst1', title: '거북선 Remix 2', artists: '팔로알토', album: null, durationSec: 279 }],
};
const titles: Record<string, string> = { wire0000001: 'Live Wire', wireinst001: 'Live Wire 2 (Inst.)', turtle00001: '거북선 Remix Version', turtleinst1: '거북선 Remix 2 (Inst.)' };
const embed = async (id: string) => ({ state: 'ok' as const, author: 'x', title: titles[id]! });
await matchYoutube(db, { searchSongs: async (q) => results[q] ?? [] }, { delayMs: 0 }, embed);
const st = (id: number) => db.query<{ youtube_status: string }, [number]>('SELECT youtube_status FROM songs WHERE id = ?').get(id)!.youtube_status;
expect([st(ids.wire), st(ids.wireInst), st(ids.turtle), st(ids.turtleInst)]).toEqual(['matched', 'candidate', 'matched', 'candidate']);
db.query("UPDATE songs SET youtube_status = 'candidate', youtube_source = 'norabose' WHERE id IN (?, ?)").run(ids.wire, ids.turtle);
await reconfirmCandidates(db, { delayMs: 0 }, embed);
expect([st(ids.wire), st(ids.wireInst), st(ids.turtle), st(ids.turtleInst)]).toEqual(['matched', 'candidate', 'matched', 'candidate']);
});
test('Hangul and Latin artist names that sound the same', () => {
const same = [
['디제이디오씨', 'DJ DOC'], ['에스이에스', 'S.E.S.'], ['플라이투더스카이', 'Fly to the Sky'], ['조규찬', 'Cho Kyu Chan'], ['강타', 'KANGTA'],

View File

@@ -6,7 +6,7 @@
import type { Database } from 'bun:sqlite';
import { Job, sleep } from './catalog';
import { checkEmbed } from './oembed';
import { confirmedDespiteLength, isConfident, isJunkTitle, isVideoTitle, namesOtherCut, scoreResult, type Scored } from './score';
import { addsJunk, addsVideo, confirmedDespiteLength, isConfident, namesOtherCut, scoreResult, type Scored } from './score';
import { learnArtistAliases } from './artist-aliases';
import { otherScriptNames } from './other-names';
import { CookieError, type YtMusic, type YtmSong } from './ytmusic';
@@ -47,7 +47,7 @@ function setAutoVideo(db: Database, id: number, status: 'matched' | 'candidate',
* 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 ((isVideoTitle(videoTitle) && !isVideoTitle(songTitle)) || (isJunkTitle(videoTitle) && !isJunkTitle(songTitle))) return true;
if (addsVideo(videoTitle, songTitle) || addsJunk(videoTitle, songTitle)) return true;
return confirmedDespiteLength(c) && namesOtherCut(videoTitle, songTitle);
}

View File

@@ -3,7 +3,9 @@ import { artistKeys, artistParts, keysOverlap, titleKeys, titleRunKeys } from '@
import { soundsLike } from './sound';
import type { YtmSong } from './ytmusic';
const JUNK = /\b(inst|instrumental|mr|karaoke|cover|remix|sped ?up|slowed|live|ver|version|acoustic|made famous by|in the style of|originally performed|tribute)\b|노래방|커버|라이브|반주/i;
const JUNK = /\b(?:inst|instrumental|mr|karaoke|cover|remix|sped ?up|slowed|live|ver|version|acoustic|made famous by|in the style of|originally performed|tribute)\b|노래방|커버|라이브|반주/gi;
/** "Remix Version", "Live Ver." name one take (remix, live), not two marks. */
const TAG_VERSION = /\b(inst|instrumental|mr|karaoke|cover|remix|live|acoustic)\s*(?:ver\.?|version)(?=\W|$)/gi;
/** "Radio Edit Version", "Original Version", "7\" Version" are the same recording, not a different take. */
const BENIGN = /\b(?:radio edit|original|album|single|mono|stereo|remaster(?:ed)?)\s*(?:ver\.?|version)?|\d{1,2}"\s*(?:ver\.?|version)|\bedit\b/gi;
/** Without the artist, a title only confirms with a length this close (when both lengths are known). */
@@ -17,7 +19,7 @@ const CUT = /\b(?:mix|edit|ver|version|edition|demo|medley|reprise|session|take|
const REMASTER = /\b(?:(?:19|20)\d{2}\s+)?remaster(?:ed)?(?:\s+(?:19|20)\d{2})?\b|\bradio edit\b|\b(?:original|album|single)\s+(?:ver\.?|version)\b/gi;
/** Titles an artist reuses album after album ("Intro"): the same title says nothing when the length is off. */
const GENERIC_TITLE = /^\s*(?:intro|outro|interlude|skit|prologue|epilogue|opening|ending|theme|bonus\s+track|hidden\s+track)\s*\d*\s*$/i;
const VIDEO = /\b(?:m\/?v|music\s+video|official\s+video|performance\s+video|lyrics?\s+video|visualizer|teaser|dance\s+practice|special\s+clip|full\s+ver)\b|뮤직\s*비디오|뮤비|직캠/i;
const VIDEO = /\b(?:m\/?v|music\s+video|official\s+video|performance\s+video|lyrics?\s+video|visualizer|teaser|dance\s+practice|special\s+clip|full\s+ver)\b|뮤직\s*비디오|뮤비|직캠/gi;
/** Song-side artist key → YouTube-side keys learnt from already confirmed songs ("태연" → "taeyeon"). */
export type ArtistAliases = Map<string, Set<string>>;
@@ -41,13 +43,36 @@ export interface Scored extends YtmSong {
lengthDiff: number | null;
}
export function isJunkTitle(title: string): boolean {
return JUNK.test(title.replace(BENIGN, ' '));
/** Each mark the regex finds in the title, counted ("instrumental" = "inst", "version" = "ver"). */
function marks(re: RegExp, title: string): Map<string, number> {
const out = new Map<string, number>();
for (const m of title.match(re) ?? []) {
const k = m.toLowerCase().replace(/\s+/g, ' ').replace(/^instrumental$/, 'inst').replace(/^version$/, 'ver').replace(/^m\/v$/, 'mv');
out.set(k, (out.get(k) ?? 0) + 1);
}
return out;
}
/** A music video, lyric video, live stage … or a cover/inst./remix (isJunkTitle): not the plain recording. */
export function isVideoTitle(title: string): boolean {
return VIDEO.test(title);
/**
* The result adds a mark the song's own title doesn't have: each mark is matched against the song's ("Live Wire" lets
* one "live" through, not "(Inst.)" or a second "Live").
*/
function addsMark(re: RegExp, resultTitle: string, songTitle: string): boolean {
const own = marks(re, songTitle);
for (const [k, n] of marks(re, resultTitle)) if (n > (own.get(k) ?? 0)) return true;
return false;
}
const junkText = (t: string) => t.replace(BENIGN, ' ').replace(TAG_VERSION, '$1');
/** The result is a cover, inst., MR, live, remix, another version … that the song's own title doesn't say. */
export function addsJunk(resultTitle: string, songTitle: string): boolean {
return addsMark(JUNK, junkText(resultTitle), junkText(songTitle));
}
/** The result is a music video, lyric video, stage clip … that the song's own title doesn't say. */
export function addsVideo(resultTitle: string, songTitle: string): boolean {
return addsMark(VIDEO, resultTitle, songTitle);
}
/** Some name of the song's artist sounds like some name of the result's, across Hangul and Latin. */
@@ -90,10 +115,10 @@ export function scoreResult(song: { title: string; artist: string; durationSec:
if (rank === 0) score += 5;
// Plain YouTube fallback: only official Topic art tracks are trusted; MVs, lyric videos and fan uploads are scored down.
if (r.topic === false) score -= 25;
// Junk words only count when the original title doesn't have them (a real "Remix" song stays fine).
const junk = isJunkTitle(r.title) && !isJunkTitle(song.title);
// Junk words only count beyond the ones in the original title (a real "Remix" song stays fine, its "(Inst.)" doesn't).
const junk = addsJunk(r.title, song.title);
if (junk) score -= 40;
const video = isVideoTitle(r.title) && !isVideoTitle(song.title);
const video = addsVideo(r.title, song.title);
const otherCut = namesOtherCut(r.title, song.title);
const oddLength = !!song.durationSec && song.durationSec >= 90 && !!r.durationSec && (r.durationSec < 90 || (r.durationSec > 420 && r.durationSec > 2 * song.durationSec));
return { ...r, score, titleOk, artistOk, artistSound, junk, video, otherCut, genericTitle: GENERIC_TITLE.test(song.title), oddLength, lengthDiff };