3단계 노래 DB: 곡 스키마(장르·기준별 단계·가사·후보), 노라보세·스타맵 가져오기, 유튜브 원곡 찾기(쿠키 노래 검색 + 로그인 없는 Topic 대체), 관리자 노래·수집 화면
- 노라보세: 8,572곡(멜론 ID·연도·최고순위·장르·5단계 난이도·가사), 500 나는 묶음은 반씩 나눠 재요청, 원본 캐시로 재실행 안전 - 스타맵 803곡: 같은 곡은 합치고(363) 새 곡 440, 맵 제작자 연도(올해)는 버림 - 유튜브: 제목·가수·길이 점수로 확정/후보, 퍼가기 금지 영상 제외, 검색 방식별로 시도 기록 - 관리자: 노래 검색·장르·연도·난이도·유튜브 상태·출처 필터, 편집 패널(미리듣기·후보 선택·하이라이트·별칭·숨김), 수집 기록 - 테스트 32개, e2e에 노래 편집 단계 추가 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
export * from './nickname';
|
||||
export * from './protocol';
|
||||
export * from './types';
|
||||
export * from './match-key';
|
||||
|
||||
27
packages/shared/src/match-key.test.ts
Normal file
27
packages/shared/src/match-key.test.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { expect, test } from 'bun:test';
|
||||
import { artistKeys, keysOverlap, looseKey, songMatchKey, titleKeys } from './match-key';
|
||||
|
||||
test('loose keys ignore case, spaces and punctuation', () => {
|
||||
expect(looseKey('Bubble Pop!')).toBe('bubblepop');
|
||||
expect(looseKey('사건의 지평선')).toBe('사건의지평선');
|
||||
expect(looseKey('ABC')).toBe('abc');
|
||||
});
|
||||
|
||||
test('title variants cover brackets and feat tails', () => {
|
||||
const k = titleKeys('사랑을 했다 (LOVE SCENARIO)');
|
||||
expect(k).toContain('사랑을했다');
|
||||
expect(k).toContain('lovescenario');
|
||||
expect(titleKeys('Last Scene (feat. 원슈타인)')).toContain('lastscene');
|
||||
expect(keysOverlap(titleKeys('광 (狂)'), titleKeys('광'))).toBe(true);
|
||||
});
|
||||
|
||||
test('artist variants split groups and bracketed names', () => {
|
||||
expect(artistKeys('RESCENE (리센느)')).toEqual(expect.arrayContaining(['rescene', '리센느']));
|
||||
expect(artistKeys('허각, 정은지')).toEqual(expect.arrayContaining(['허각', '정은지']));
|
||||
});
|
||||
|
||||
test('song match key is stable across spellings', () => {
|
||||
expect(songMatchKey('Love wins all', '아이유')).toBe(songMatchKey('Love Wins All', '아이유'));
|
||||
expect(songMatchKey('Last Scene (feat. 원슈타인)', '아이유')).toBe('lastscene|아이유');
|
||||
expect(songMatchKey('0+0', '한로로')).toBe('00|한로로');
|
||||
});
|
||||
54
packages/shared/src/match-key.ts
Normal file
54
packages/shared/src/match-key.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* Loose comparison keys for de-duplicating songs across sources and matching YouTube results (docs/07 곡 맞추기).
|
||||
* NOT the quiz answer judge (that one honours the 띄어쓰기/숫자/특수문자 toggles, stage 5).
|
||||
*/
|
||||
const TAIL = /\s*[([{【]\s*(feat\.?|ft\.?|prod\.?|with|from|원곡|inst|remaster|remastered|bonus|ost|explicit|clean|sped up|live)\b[^)\]}】]*[)\]}】]/gi;
|
||||
|
||||
/** NFKC, lower case, letters and digits only (Hangul, Latin, Kana, Han kept). */
|
||||
export function looseKey(s: string): string {
|
||||
return s
|
||||
.normalize('NFKC')
|
||||
.toLowerCase()
|
||||
.replace(/[^\p{L}\p{N}]+/gu, '');
|
||||
}
|
||||
|
||||
/** Title variants: as is, without feat/prod tails, without any parenthesised part, and each parenthesised part alone. */
|
||||
export function titleKeys(title: string): string[] {
|
||||
const out = new Set<string>();
|
||||
const add = (s: string) => {
|
||||
const k = looseKey(s);
|
||||
if (k) out.add(k);
|
||||
};
|
||||
add(title);
|
||||
const noTail = title.replace(TAIL, ' ');
|
||||
add(noTail);
|
||||
add(noTail.replace(/\s*[([{【][^)\]}】]*[)\]}】]/g, ' '));
|
||||
for (const m of noTail.matchAll(/[([{【]([^)\]}】]+)[)\]}】]/g)) add(m[1]!);
|
||||
return [...out];
|
||||
}
|
||||
|
||||
/** Artist variants: split on , & / x and "(…)" so "RESCENE (리센느)" matches both names. */
|
||||
export function artistKeys(artist: string): string[] {
|
||||
const out = new Set<string>();
|
||||
const parts = artist.split(/\s*(?:,|&|\/|\bx\b|\band\b|·|feat\.?)\s*/i);
|
||||
for (const p of [artist, ...parts]) {
|
||||
const k = looseKey(p);
|
||||
if (k) out.add(k);
|
||||
const inner = /^(.*?)\s*\(([^)]+)\)\s*$/.exec(p);
|
||||
if (inner) for (const q of [inner[1]!, inner[2]!]) if (looseKey(q)) out.add(looseKey(q));
|
||||
}
|
||||
return [...out];
|
||||
}
|
||||
|
||||
/** One key per song for de-duplication: title without feat/brackets + first artist, both loose. */
|
||||
export function songMatchKey(title: string, artist: string): string {
|
||||
const bare = title.replace(TAIL, ' ').replace(/\s*[([{【][^)\]}】]*[)\]}】]/g, ' ');
|
||||
const t = looseKey(bare) || looseKey(title);
|
||||
const firstArtist = artist.split(/\s*(?:,|&|\/|·)\s*/)[0] ?? artist;
|
||||
const a = looseKey(firstArtist.replace(/\s*\([^)]*\)\s*$/, '')) || looseKey(firstArtist);
|
||||
return `${t}|${a}`;
|
||||
}
|
||||
|
||||
export function keysOverlap(a: string[], b: string[]): boolean {
|
||||
return a.some((x) => b.includes(x));
|
||||
}
|
||||
Reference in New Issue
Block a user