정답 자동 생성: 플레이리스트 가져오기가 제목을 먼저 정리한 뒤 정답을 만들어 괄호 안 다른 이름(LOVE SCENARIO)·일본어 원제·그 발음을 잃던 것 — 찾은 그대로의 제목으로 정답을 만들고 화면에는 정리된 제목. 괄호 안 한글로 이미 바뀐 일본어 제목(夜に駆ける (밤에 달리다))은 위키백과 우선 처리를 건너뛰던 것 — 원제로 위키백과 → 괄호 안 한글 → 읽는 소리 순서를 정하고, 밀린 괄호 안 한글 이름은 정답으로 남김. 회귀 테스트 2개(고치기 전 코드에서 실패 확인)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,9 @@ import { kanaToHangul, romajiToHangul } from './ja-ko';
|
||||
import { readJapanese } from './ja-reading';
|
||||
import { wikiLookup } from './wiki';
|
||||
import { songAnswersBatch } from '.';
|
||||
import { openDb } from '../db';
|
||||
import { tempDbPath } from '../test-utils';
|
||||
import { startImport } from '../quizzes/playlist';
|
||||
|
||||
test('영어 → 한글: 외래어 표기 규칙과 흔히 쓰는 표기', () => {
|
||||
const cases: Record<string, string> = {
|
||||
@@ -106,3 +109,48 @@ test('곡 정답: cleaned title, other names, 한글 발음; J-POP shown by its
|
||||
const [asIs] = await songAnswersBatch(null, [{ title: '夜に駆ける', artist: 'YOASOBI' }]);
|
||||
expect(asIs).toMatchObject({ title: '夜に駆ける', titleAnswers: ['요루니 카케루', '요루니 가케루'] });
|
||||
});
|
||||
|
||||
test('a Japanese title already shown by its bracket\'s Korean name still asks Wikipedia first (the original decides)', async () => {
|
||||
const wiki = async (names: string[]) => new Map<string, string>(names.includes('夜に駆ける') ? [['夜に駆ける', '밤을 달리다']] : []);
|
||||
const [a] = await songAnswersBatch(null, [{ title: '夜に駆ける (밤에 달리다)', artist: 'YOASOBI' }], { korean: true, wiki });
|
||||
expect(a!.title).toBe('밤을 달리다');
|
||||
expect(a!.titleAnswers).toEqual(expect.arrayContaining(['夜に駆ける', '밤에 달리다', '요루니 카케루', '요루니 가케루']));
|
||||
expect(a!.note).toBeNull();
|
||||
// no Wikipedia article: the bracket's Korean name is shown
|
||||
const [b] = await songAnswersBatch(null, [{ title: '夜に駆ける (밤에 달리다)', artist: 'YOASOBI' }], { korean: true, wiki: async () => new Map() });
|
||||
expect(b).toMatchObject({ title: '밤에 달리다', note: null });
|
||||
expect(b!.titleAnswers).toEqual(expect.arrayContaining(['夜に駆ける', '요루니 카케루']));
|
||||
});
|
||||
|
||||
test('플레이리스트 가져오기: the answers come from the title as found (brackets, Japanese original), the row shows it cleaned', async () => {
|
||||
const db = openDb(tempDbPath());
|
||||
const playlist = {
|
||||
loadType: 'playlist',
|
||||
data: {
|
||||
info: { name: 'p' },
|
||||
tracks: [
|
||||
{ info: { identifier: 'lovescen001', title: '사랑을 했다(LOVE SCENARIO)', author: 'iKON - Topic', length: 210000, sourceName: 'youtube' } },
|
||||
{ info: { identifier: 'yoruni00001', title: '夜に駆ける', author: 'YOASOBI - Topic', length: 260000, sourceName: 'youtube' } },
|
||||
],
|
||||
},
|
||||
};
|
||||
const job = await startImport(
|
||||
{
|
||||
db,
|
||||
lavalink: { url: 'http://ll.test', password: 'x' },
|
||||
search: async () => [],
|
||||
embed: async () => ({ state: 'ok', author: 'x', title: 'x' }),
|
||||
delayMs: 0,
|
||||
fetchImpl: (async () => Response.json(playlist)) as unknown as typeof fetch,
|
||||
wiki: async (names) => new Map<string, string>(names.includes('夜に駆ける') ? [['夜に駆ける', '밤을 달리다']] : []),
|
||||
},
|
||||
'me',
|
||||
'https://youtube.com/playlist?list=x',
|
||||
);
|
||||
if (typeof job === 'string') throw new Error(job);
|
||||
for (let i = 0; i < 200 && job.status === 'running'; i++) await Bun.sleep(20);
|
||||
expect(job.status).toBe('done');
|
||||
expect(job.rows[0]).toMatchObject({ title: '사랑을 했다', titleAnswers: ['LOVE SCENARIO', '사랑을 했다 LOVE SCENARIO', '러브 시나리오'] });
|
||||
expect(job.rows[1]!.title).toBe('밤을 달리다');
|
||||
expect(job.rows[1]!.titleAnswers).toEqual(expect.arrayContaining(['夜に駆ける', '요루니 카케루', '요루니 가케루']));
|
||||
});
|
||||
|
||||
@@ -108,9 +108,17 @@ export async function songAnswersBatch(db: Database | null, songs: { title: stri
|
||||
}
|
||||
if (!wikiNames.has(name) && !bracket) notes.push('한글 이름 자동 변환');
|
||||
push.push(name);
|
||||
// the bracket's Korean name stays an answer when Wikipedia's wins
|
||||
if (bracket && bracket !== ko) push.push(bracket);
|
||||
return ko;
|
||||
};
|
||||
if (opts.korean && hasJapanese(title)) title = korean(title, c.aliases.find((a) => HANGUL.test(a) && !hasJapanese(a)), extraTitle);
|
||||
// the Japanese title: shown as is, or already swapped for its bracket's Korean name by cleanTitle
|
||||
// ("夜に駆ける (밤에 달리다)") — Wikipedia still goes first, so the order is decided on the original
|
||||
const jaTitle = hasJapanese(c.title) ? c.title : c.aliases.find((a) => hasJapanese(a));
|
||||
if (opts.korean && jaTitle) {
|
||||
const bracket = hasJapanese(c.title) ? c.aliases.find((a) => HANGUL.test(a) && !hasJapanese(a)) : c.title;
|
||||
title = korean(jaTitle, bracket, extraTitle);
|
||||
}
|
||||
if (opts.korean && hasJapanese(artist)) artist = korean(artist, undefined, extraArtist);
|
||||
const titleAnswers = uniq([...c.aliases, ...extraTitle, ...fromDb.title, ...[c.title, ...c.aliases, ...extraTitle, ...fromDb.title].flatMap(say)], [title]);
|
||||
const names = artistNames(s.artist);
|
||||
|
||||
@@ -138,6 +138,7 @@ async function runImport(d: ImportDeps, job: ImportJob, tracks: LavalinkTrack[])
|
||||
'SELECT id, title, artist, youtube_id, youtube_status, duration_sec FROM songs WHERE match_key = ? AND deleted_at IS NULL ORDER BY youtube_status = \'matched\' DESC LIMIT 1',
|
||||
);
|
||||
const aliases = aliasesOf(d.db);
|
||||
const rawTitles: string[] = [];
|
||||
for (const [i, t] of tracks.entries()) {
|
||||
const dur = t.length ? Math.round(t.length / 1000) : null;
|
||||
const yt = t.sourceName === 'youtube';
|
||||
@@ -177,6 +178,8 @@ async function runImport(d: ImportDeps, job: ImportJob, tracks: LavalinkTrack[])
|
||||
if (i < tracks.length - 1) await Bun.sleep(d.delayMs ?? 700);
|
||||
}
|
||||
// shown title without brackets / feat. / version marks (the answers come at the end, docs/13)
|
||||
// the title as found goes to the answers below (its brackets hold other names), the row shows it cleaned meanwhile
|
||||
rawTitles.push(row.title);
|
||||
row.title = cleanTitle(row.title).title;
|
||||
job.rows.push(row);
|
||||
job.done = i + 1;
|
||||
@@ -184,7 +187,7 @@ async function runImport(d: ImportDeps, job: ImportJob, tracks: LavalinkTrack[])
|
||||
// answers for every song at once: 한글 발음, 일본어 읽기 (one process), J-POP 한글 이름 (위키백과)
|
||||
const answers = await songAnswersBatch(
|
||||
d.db,
|
||||
job.rows.map((r) => ({ title: r.title, artist: r.artist, songId: r.songId })),
|
||||
job.rows.map((r, i) => ({ title: rawTitles[i]!, artist: r.artist, songId: r.songId })),
|
||||
{ korean: true, wiki: d.wiki, read: d.read },
|
||||
);
|
||||
job.rows.forEach((r, i) => {
|
||||
|
||||
Reference in New Issue
Block a user