From 04da87562b54c841a6e78d31172ca2b9d255e54c Mon Sep 17 00:00:00 2001 From: EJClaw Date: Wed, 4 Nov 2026 16:19:06 +0900 Subject: [PATCH] =?UTF-8?q?=EC=A0=95=EB=8B=B5=20=EC=9E=90=EB=8F=99=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1:=20=ED=94=8C=EB=A0=88=EC=9D=B4=EB=A6=AC?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EA=B0=80=EC=A0=B8=EC=98=A4=EA=B8=B0?= =?UTF-8?q?=EA=B0=80=20=EC=A0=9C=EB=AA=A9=EC=9D=84=20=EB=A8=BC=EC=A0=80=20?= =?UTF-8?q?=EC=A0=95=EB=A6=AC=ED=95=9C=20=EB=92=A4=20=EC=A0=95=EB=8B=B5?= =?UTF-8?q?=EC=9D=84=20=EB=A7=8C=EB=93=A4=EC=96=B4=20=EA=B4=84=ED=98=B8=20?= =?UTF-8?q?=EC=95=88=20=EB=8B=A4=EB=A5=B8=20=EC=9D=B4=EB=A6=84(LOVE=20SCEN?= =?UTF-8?q?ARIO)=C2=B7=EC=9D=BC=EB=B3=B8=EC=96=B4=20=EC=9B=90=EC=A0=9C?= =?UTF-8?q?=C2=B7=EA=B7=B8=20=EB=B0=9C=EC=9D=8C=EC=9D=84=20=EC=9E=83?= =?UTF-8?q?=EB=8D=98=20=EA=B2=83=20=E2=80=94=20=EC=B0=BE=EC=9D=80=20?= =?UTF-8?q?=EA=B7=B8=EB=8C=80=EB=A1=9C=EC=9D=98=20=EC=A0=9C=EB=AA=A9?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EC=A0=95=EB=8B=B5=EC=9D=84=20=EB=A7=8C?= =?UTF-8?q?=EB=93=A4=EA=B3=A0=20=ED=99=94=EB=A9=B4=EC=97=90=EB=8A=94=20?= =?UTF-8?q?=EC=A0=95=EB=A6=AC=EB=90=9C=20=EC=A0=9C=EB=AA=A9.=20=EA=B4=84?= =?UTF-8?q?=ED=98=B8=20=EC=95=88=20=ED=95=9C=EA=B8=80=EB=A1=9C=20=EC=9D=B4?= =?UTF-8?q?=EB=AF=B8=20=EB=B0=94=EB=80=90=20=EC=9D=BC=EB=B3=B8=EC=96=B4=20?= =?UTF-8?q?=EC=A0=9C=EB=AA=A9(=E5=A4=9C=E3=81=AB=E9=A7=86=E3=81=91?= =?UTF-8?q?=E3=82=8B=20(=EB=B0=A4=EC=97=90=20=EB=8B=AC=EB=A6=AC=EB=8B=A4))?= =?UTF-8?q?=EC=9D=80=20=EC=9C=84=ED=82=A4=EB=B0=B1=EA=B3=BC=20=EC=9A=B0?= =?UTF-8?q?=EC=84=A0=20=EC=B2=98=EB=A6=AC=EB=A5=BC=20=EA=B1=B4=EB=84=88?= =?UTF-8?q?=EB=9B=B0=EB=8D=98=20=EA=B2=83=20=E2=80=94=20=EC=9B=90=EC=A0=9C?= =?UTF-8?q?=EB=A1=9C=20=EC=9C=84=ED=82=A4=EB=B0=B1=EA=B3=BC=20=E2=86=92=20?= =?UTF-8?q?=EA=B4=84=ED=98=B8=20=EC=95=88=20=ED=95=9C=EA=B8=80=20=E2=86=92?= =?UTF-8?q?=20=EC=9D=BD=EB=8A=94=20=EC=86=8C=EB=A6=AC=20=EC=88=9C=EC=84=9C?= =?UTF-8?q?=EB=A5=BC=20=EC=A0=95=ED=95=98=EA=B3=A0,=20=EB=B0=80=EB=A6=B0?= =?UTF-8?q?=20=EA=B4=84=ED=98=B8=20=EC=95=88=20=ED=95=9C=EA=B8=80=20?= =?UTF-8?q?=EC=9D=B4=EB=A6=84=EC=9D=80=20=EC=A0=95=EB=8B=B5=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EB=82=A8=EA=B9=80.=20=ED=9A=8C=EA=B7=80=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=202=EA=B0=9C(=EA=B3=A0=EC=B9=98?= =?UTF-8?q?=EA=B8=B0=20=EC=A0=84=20=EC=BD=94=EB=93=9C=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EC=8B=A4=ED=8C=A8=20=ED=99=95=EC=9D=B8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- apps/server/src/answers/answers.test.ts | 48 +++++++++++++++++++++++++ apps/server/src/answers/index.ts | 10 +++++- apps/server/src/quizzes/playlist.ts | 5 ++- 3 files changed, 61 insertions(+), 2 deletions(-) diff --git a/apps/server/src/answers/answers.test.ts b/apps/server/src/answers/answers.test.ts index 237b202..a296d9e 100644 --- a/apps/server/src/answers/answers.test.ts +++ b/apps/server/src/answers/answers.test.ts @@ -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 = { @@ -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(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(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(['夜に駆ける', '요루니 카케루', '요루니 가케루'])); +}); diff --git a/apps/server/src/answers/index.ts b/apps/server/src/answers/index.ts index bd598f6..779a697 100644 --- a/apps/server/src/answers/index.ts +++ b/apps/server/src/answers/index.ts @@ -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); diff --git a/apps/server/src/quizzes/playlist.ts b/apps/server/src/quizzes/playlist.ts index 552268c..3674f99 100644 --- a/apps/server/src/quizzes/playlist.ts +++ b/apps/server/src/quizzes/playlist.ts @@ -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) => {