원곡찾기 자동 확정 2차: 제목+가수가 맞으면 곡 길이가 달라도 확정(길이가 15초 넘게 다르면 MV·inst.·라이브·커버, 노래 제목에 없는 믹스/에디트/연도 표시, Intro 같은 흔한 제목은 보류 — 실제 영상 제목도 확인, Topic 아닌 영상은 제외). "한글 English" 표기(북극성 Polaris, 헤이즈 Heize)를 나눠 비교(제목은 가수도 맞을 때만, Part 2·I·메들리는 안 나눔). 한글/영문 가수 이름 발음 비교(collector/sound.ts: 자음 뼈대 + 로마자 한국 이름은 모음 계열도, 성 뒤로·DJ DOC 알파벳 읽기; 발음으로만 맞으면 제목 같고 8초 이내만). 결과에 그 가수 곡이 없으면 저장된 결과에서 찾은 다른 문자 이름(DJ DOC)으로 다시 검색 — 매일 원곡 찾기에 포함, 쌓인 후보는 cli research-youtube(그 가수 곡만 확정). reconfirm-youtube가 못 찾음 곡도 다시 비교. 서버 테스트 150개
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { expect, test } from 'bun:test';
|
||||
import { artistKeys, keysOverlap, looseKey, songMatchKey, titleKeys } from './match-key';
|
||||
import { artistKeys, keysOverlap, looseKey, scriptRuns, songMatchKey, titleKeys, titleRunKeys } from './match-key';
|
||||
|
||||
test('loose keys ignore case, spaces and punctuation', () => {
|
||||
expect(looseKey('Bubble Pop!')).toBe('bubblepop');
|
||||
@@ -33,3 +33,16 @@ test('compare keys fold Latin accents and split 및 / with', () => {
|
||||
expect(keysOverlap(artistKeys('Human League'), artistKeys('The Human League'))).toBe(true);
|
||||
expect(titleKeys('が')).not.toContain('か'); // kana marks stay
|
||||
});
|
||||
|
||||
test('"한글 English" names split into both parts, numbered parts and medleys do not', () => {
|
||||
expect(scriptRuns('북극성 Polaris')).toEqual(['북극성', 'Polaris']);
|
||||
expect(scriptRuns('2년만에 After Two Years')).toEqual(['2년만에', 'After Two Years']);
|
||||
expect(scriptRuns('너에게 쓰는 편지 Part 2')).toEqual([]);
|
||||
expect(scriptRuns('사랑도 추억도 I')).toEqual([]);
|
||||
expect(scriptRuns('Overture/추억속의 재회/마도요')).toEqual([]);
|
||||
expect(scriptRuns('북극성')).toEqual([]);
|
||||
expect(artistKeys('헤이즈 Heize')).toEqual(expect.arrayContaining(['헤이즈', 'heize']));
|
||||
expect(artistKeys('더 클래식 The Classic')).toEqual(expect.arrayContaining(['더클래식', 'classic']));
|
||||
expect(titleRunKeys('약속 The Promise')).toContain('약속');
|
||||
expect(titleKeys('약속 The Promise')).not.toContain('약속'); // titleKeys stays strict
|
||||
});
|
||||
|
||||
@@ -35,17 +35,60 @@ export function titleKeys(title: string): string[] {
|
||||
return [...out];
|
||||
}
|
||||
|
||||
/** Artist variants: split on , & / x 및 with feat and "(…)" so "RESCENE (리센느)" matches both names. */
|
||||
export function artistKeys(artist: string): string[] {
|
||||
const out = new Set<string>();
|
||||
/**
|
||||
* Title variants of a "한글 English" title written without brackets ("북극성 Polaris" → 북극성, polaris), plus titleKeys.
|
||||
* Looser than titleKeys: only use it together with a matching artist.
|
||||
*/
|
||||
export function titleRunKeys(title: string): string[] {
|
||||
const bare = title.replace(TAIL, ' ').replace(/\s*[([{【][^)\]}】]*[)\]}】]/g, ' ');
|
||||
return [...new Set([...titleKeys(title), ...scriptRuns(bare).map(compareKey).filter(Boolean)])];
|
||||
}
|
||||
|
||||
const hasHangul = (s: string) => /\p{Script=Hangul}/u.test(s);
|
||||
const hasLatin = (s: string) => /[A-Za-z]/.test(s);
|
||||
/** A Latin part that says which song or part it is ("Part 2", "Vol.1", "II", "A"): splitting it off would join different songs. */
|
||||
const ORDINAL = /^(?:part|pt|vol|no|ver|chapter|ep|season)\b|^#|^[A-Z]$|^[IVX]+$|^[\d\s.]+$/i;
|
||||
|
||||
/**
|
||||
* Splits a name written in both scripts without brackets into its Hangul and Latin parts (other marks between them dropped):
|
||||
* "북극성 Polaris" → ["북극성", "Polaris"], "헤이즈 Heize" → ["헤이즈", "Heize"]. Empty unless both scripts are there,
|
||||
* and empty when a Latin part numbers the song ("편지 Part 2", "사랑도 추억도 I").
|
||||
*/
|
||||
export function scriptRuns(s: string): string[] {
|
||||
if (!hasHangul(s) || !hasLatin(s)) return [];
|
||||
const RUN = /[\p{Script=Hangul}\d][\p{Script=Hangul}\d\s'’′`‘"“”!?.,~&…-]*|[\p{Script=Latin}\d][\p{Script=Latin}\d\s'’′`‘"“”!?.,~&…-]*/gu;
|
||||
// several songs or names joined ("Overture/추억속의 재회/마도요", a medley) are not one name in two scripts
|
||||
if (/[/+]/.test(s)) return [];
|
||||
const runs = (s.match(RUN) ?? []).map((r) => r.trim());
|
||||
if (runs.some((r) => ORDINAL.test(r) || /\b(?:part|pt)\.?\s*\d/i.test(r))) return [];
|
||||
// one Latin letter alone ("K") is too short to be a name or a title
|
||||
return runs.filter((r) => /\p{Script=Hangul}/u.test(r) || r.replace(/[^A-Za-z\d]/g, '').length >= 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* The names inside an artist string: split on , & / x 및 with feat, "(…)" and "한글 English" so "RESCENE (리센느)" and
|
||||
* "헤이즈 Heize" give both names.
|
||||
*/
|
||||
export function artistParts(artist: string): string[] {
|
||||
const out: string[] = [];
|
||||
const parts = artist.split(/\s*(?:,|&|\/|×|\sx\s|\band\b|\s및\s|\bwith\b|\bvs\.?(?=\s)|·|\bfeat\.?|\bft\.)\s*/i);
|
||||
for (const p of [artist, ...parts]) {
|
||||
const k = compareKey(p);
|
||||
if (k) out.add(k);
|
||||
out.push(p);
|
||||
const inner = /^(.*?)\s*\(([^)]+)\)\s*$/.exec(p);
|
||||
const names = inner ? [inner[1]!, inner[2]!] : [p];
|
||||
if (inner) out.push(...names);
|
||||
for (const n of names) out.push(...scriptRuns(n));
|
||||
}
|
||||
return out.filter((p) => compareKey(p));
|
||||
}
|
||||
|
||||
/** Artist variants for comparing: each name of artistParts, also without a leading "The". */
|
||||
export function artistKeys(artist: string): string[] {
|
||||
const out = new Set<string>();
|
||||
for (const p of artistParts(artist)) {
|
||||
out.add(compareKey(p));
|
||||
const noThe = compareKey(p.replace(/^\s*the\s+/i, ''));
|
||||
if (noThe) out.add(noThe);
|
||||
const inner = /^(.*?)\s*\(([^)]+)\)\s*$/.exec(p);
|
||||
if (inner) for (const q of [inner[1]!, inner[2]!]) if (compareKey(q)) out.add(compareKey(q));
|
||||
}
|
||||
return [...out];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user