엑셀 양식 2단계: 일반 퀴즈 파일을 제목·가수·정답·가수 정답으로 나눔(정답은 ;로 여러 개, 제목·가수는 늘 정답, 내보내기는 제목·가수를 정답 칸 맨 앞에), 길이·비고 열. 예전 양식(정답=제목·설명·다른 정답)은 '제목' 열이 없으면 그대로 읽음. 파일 제목도 괄호·feat.·버전 표시를 지우고 괄호 안 다른 이름은 정답으로. 정답·가수 정답 칸이 빈 곡은 서버가 채움(POST /api/admin/quizzes/answers — 제목 정리 별칭 + 같은 DB 곡 별칭, answers/index.ts). 재생목록으로 엑셀 만들기: 일반 퀴즈용(정답·가수 정답·힌트)과 이지선다용(빈 조회수 열 → 파일로 만들기가 이지선다로 고름) 두 양식, 플레이리스트 가져오기 결과에 정리된 제목과 정답. 단위·API 테스트, e2e quiz(두 양식 받기)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-11-04 16:00:33 +09:00
parent 2e333dd3f7
commit 74eaeb85da
11 changed files with 331 additions and 117 deletions

View File

@@ -41,7 +41,11 @@ test('CSV: quotes, commas and line breaks inside, tab files, BOM, and Korean Exc
test('columns are found by their headers (the sent BGM sheet, our export, English)', () => {
expect(guessColumns(['번호', '유튜브 영상 링크', '게임 제목(한글)', '노래 제목', '힌트(게임장르)', '재생목록 순번'])).toEqual([null, 'link', 'answer', 'desc', 'hint', 'order']);
expect(guessColumns(quizToRows([]).rows[0] as string[])).toEqual(['order', 'link', 'answer', 'desc', 'hint', 'answers', 'descAnswers', 'start', 'highlight']);
expect(guessColumns(quizToRows([]).rows[0] as string[])).toEqual(['order', 'link', 'answer', 'desc', 'answers', 'descAnswers', 'hint', 'start', 'highlight', 'duration', null]);
// old 일반 퀴즈 files: 정답 is the title, 설명 / 다른 정답 / 설명 다른 정답
expect(guessColumns(['순번', '유튜브 영상 링크', '정답', '설명', '힌트', '다른 정답(;로 구분)', '설명 다른 정답(;로 구분)'])).toEqual(['order', 'link', 'answer', 'desc', 'hint', 'answers', 'descAnswers']);
// new ones (docs/13): 제목 next to 정답 → 정답 lists more answers
expect(guessColumns(['링크', '제목', '가수', '정답', '가수 정답', '비고'])).toEqual(['link', 'answer', 'desc', 'answers', 'descAnswers', null]);
expect(guessColumns(['URL', 'Title', 'Artist', 'Hint 1', 'Hint 2'])).toEqual(['link', 'answer', 'desc', 'hint', 'hint']);
// the header row may sit under a title line
expect(headerRow([['게임 BGM 모음'], ['링크', '정답'], ['x', 'y']])).toBe(1);
@@ -61,14 +65,36 @@ test('rows → quiz songs: as written, 순번 order, bad links / no answer / rep
const p = parseQuizRows(rows, guessColumns(rows[0]!), 0);
expect(p.items.map((i) => [i.videoId, i.title, i.artist, i.hints])).toEqual([
['x0-xFqvJ-U8', '갓 오브 워 2', 'The End Begins', ['확인필요']],
['iIIjS6yDMQo', '감옥탈출(구토할배)', '트레일러', ['방탈출(플래시)']],
['iIIjS6yDMQo', '감옥탈출', '트레일러', ['방탈출(플래시)']],
['Es6JbQQE79g', '번호 없음', '', []],
]);
expect(p.items.every((i) => i.fromFile && i.songId === null && i.auto)).toBe(true);
expect(p.rows.filter((r) => r.problem).map((r) => [r.line, r.problem])).toEqual([
[5, '유튜브 링크가 아니에요'],
[6, '2번째 줄과 같은 영상이에요'],
[7, '정답이 비어 있어요'],
[7, '제목이 비어 있어요'],
]);
// the bracket went from the title and stays an answer
expect(p.items[1]!.titleAnswers).toEqual(['구토할배', '감옥탈출 구토할배']);
});
test('일반 퀴즈 파일 (docs/13): 제목 cleaned, 정답 / 가수 정답 as written, empty ones marked for the server to fill', () => {
const rows = [
['링크', '제목', '가수', '정답', '가수 정답'],
['iIIjS6yDMQo', 'Pretender (feat. 누구)', 'Official髭男dism', 'Pretender; 프리텐더', '오피셜히게단디즘'],
['x0-xFqvJ-U8', '사랑을 했다(LOVE SCENARIO)', '아이콘', '', ''],
['Es6JbQQE79g', 'Finesse (Remix)', '', '', ''],
];
const p = parseQuizRows(rows, guessColumns(rows[0]!), 0);
expect(p.items.map((i) => [i.title, i.artist, i.titleAnswers, i.artistAnswers])).toEqual([
['Pretender', 'Official髭男dism', ['프리텐더'], ['오피셜히게단디즘']],
['사랑을 했다', '아이콘', ['LOVE SCENARIO', '사랑을 했다 LOVE SCENARIO'], []],
['Finesse', '', [], []],
]);
expect(p.rows.map((r) => r.fill)).toEqual([
{ title: false, artist: false },
{ title: true, artist: true },
{ title: true, artist: false },
]);
});
@@ -80,10 +106,8 @@ test('our export reads back to the same songs (answers, own positions, several h
const { rows } = quizToRows(items);
const text = rows.map((r) => r.map((c) => (c === null ? '' : String(c))));
const back = parseQuizRows(text, guessColumns(text[0]!), 0).items;
expect(back).toEqual([
{ ...items[0]!, durationSec: null },
{ ...items[1]!, songId: null, fromFile: true, durationSec: null },
]);
expect(rows[1]!.slice(2, 6)).toEqual(['감옥탈출', '트레일러', '감옥탈출; 구토할배', '트레일러; trailer']);
expect(back).toEqual([items[0]!, { ...items[1]!, songId: null, fromFile: true }]);
const t = quizTemplateRows().rows.map((r) => r.map((c) => (c === null ? '' : String(c))));
expect(parseQuizRows(t, guessColumns(t[0]!), 0).items).toHaveLength(1);
});
@@ -132,14 +156,14 @@ test('이지선다 파일: 제목·가수, 조회수 optional (empty = fetched b
const fetched = { state: 'done' as const, topicId: 'aaaaaaaaaaa', topicViews: 10, mvId: 'bbbbbbbbbbb', mvViews: 20, error: null, at: 1 };
const withAuto = p.items.map((it, i) => (i === 1 ? { ...it, views: 30, viewsAuto: fetched } : it));
const { rows: out } = quizToRows(withAuto, 'duel');
expect(out[0]).toEqual(['순번', '유튜브 영상 링크', '제목', '가수', '조회수', '시작(초)', '하이라이트(초)']);
expect(out[0]).toEqual(['순번', '유튜브 영상 링크', '제목', '가수', '조회수', '시작(초)', '하이라이트(초)', '길이(초)', '비고']);
const text = out.map((r) => r.map((c) => (c === null ? '' : String(c))));
expect(parseQuizRows(text, guessColumns(text[0]!), 0, 'duel').items.map((i) => i.views)).toEqual([3456789, null, null]);
// nothing written by hand: no 조회수 column at all
expect(quizToRows([{ ...p.items[2]! }], 'duel').rows[0]).not.toContain('조회수');
// 빈 양식: no 조회수 column, the example row reads back with its views left to the server
const t = quizTemplateRows('duel').rows.map((r) => r.map((c) => (c === null ? '' : String(c))));
expect(t[0]).toEqual(['순번', '유튜브 영상 링크', '제목', '가수', '시작(초)', '하이라이트(초)']);
expect(t[0]).toEqual(['순번', '유튜브 영상 링크', '제목', '가수', '시작(초)', '하이라이트(초)', '길이(초)', '비고']);
expect(parseQuizRows(t, guessColumns(t[0]!), 0, 'duel').items.map((i) => [i.title, i.views])).toEqual([['라일락', null]]);
});
@@ -154,43 +178,58 @@ test('재생목록으로 엑셀 만들기: kept songs with 비고, unplayable /
note: '',
...p,
});
const sheets = playlistSheets([
row({ n: 1, videoId: 'goodday0001', status: 'db', note: '서버 DB 곡 (플레이리스트 영상 사용)', title: '좋은 날', artist: '아이유', durationSec: 230 }),
const list = [
row({ n: 1, videoId: 'goodday0001', status: 'db', note: '서버 DB 곡 (플레이리스트 영상 사용)', title: '좋은 날', artist: '아이유', durationSec: 230, titleAnswers: ['Good Day'], artistAnswers: ['IU'] }),
row({ n: 2, videoId: 'lovedive001', note: '제목·가수 확인 필요 (영상 제목 형식이 달라 채널 이름을 가수로 씀)' }),
row({ n: 3, videoId: 'blocked0001', status: 'blocked', note: '다른 사이트 재생이 막힌 영상' }),
row({ n: 4, videoId: 'goodday0001', status: 'db' }),
row({ n: 5, status: 'missing', note: '유튜브에서 못 찾았어요' }),
row({ n: 6, videoId: 'hypeboy0001', status: 'check', note: '확인 필요: NewJeans - Hype Boy' }),
row({ n: 7, videoId: 'ditto000001', status: 'found', durationSec: null }),
]);
];
const sheets = playlistSheets(list);
expect(sheets.map((x) => x.name)).toEqual(['퀴즈', '빠진 곡']);
expect(sheets[0]!.rows).toEqual([
['순번', '유튜브 영상 링크', '제목', '가수', '시작(초)', '하이라이트(초)', '길이(초)', '비고'],
[1, 'https://youtu.be/goodday0001', '좋은 날', '아이유', null, null, 230, 'DB 곡'],
[2, 'https://youtu.be/lovedive001', '곡 2', '가수 2', null, null, 200, '제목·가수 확인 필요 (영상 제목 형식이 달라 채널 이름을 가수로 씀)'],
[3, 'https://youtu.be/hypeboy0001', '곡 6', '가수 6', null, null, 200, '확인 필요: NewJeans - Hype Boy'],
[4, 'https://youtu.be/ditto000001', '곡 7', '가수 7', null, null, null, '유튜브 뮤직에서 찾음'],
['순번', '유튜브 영상 링크', '제목', '가수', '정답(;로 구분)', '가수 정답(;로 구분)', '힌트', '시작(초)', '하이라이트(초)', '길이(초)', '비고'],
[1, 'https://youtu.be/goodday0001', '좋은 날', '아이유', '좋은 날; Good Day', '아이유; IU', null, null, null, 230, 'DB 곡'],
[2, 'https://youtu.be/lovedive001', '곡 2', '가수 2', '곡 2', '가수 2', null, null, null, 200, '제목·가수 확인 필요 (영상 제목 형식이 달라 채널 이름을 가수로 씀)'],
[3, 'https://youtu.be/hypeboy0001', '곡 6', '가수 6', '곡 6', '가수 6', null, null, null, 200, '확인 필요: NewJeans - Hype Boy'],
[4, 'https://youtu.be/ditto000001', '곡 7', '가수 7', '곡 7', '가수 7', null, null, null, null, '유튜브 뮤직에서 찾음'],
]);
expect(sheets[1]!.rows.slice(1)).toEqual([
[3, 'https://youtu.be/blocked0001', '원래 3', '채널', '다른 사이트 재생이 막힌 영상'],
[4, 'https://youtu.be/goodday0001', '원래 4', '채널', '재생목록 1번 곡과 같은 영상'],
[5, '', '원래 5', '채널', '유튜브에서 못 찾았어요'],
]);
// the file as downloaded: 파일로 만들기 finds the columns by name, and the 빠진 곡 sheet gives no songs
const duel = playlistSheets(list, 'duel');
expect(duel[0]!.name).toBe('이지선다');
expect(duel[0]!.rows.slice(0, 2)).toEqual([
['순번', '유튜브 영상 링크', '제목', '가수', '조회수', '시작(초)', '하이라이트(초)', '길이(초)', '비고'],
[1, 'https://youtu.be/goodday0001', '좋은 날', '아이유', null, null, null, 230, 'DB 곡'],
]);
// the files as downloaded: 파일로 만들기 finds the columns by name, and the 빠진 곡 sheet gives no songs
const book = await readSheetFile('재생목록.xlsx', writeXlsxSheets(sheets));
expect(book.map((x) => x.name)).toEqual(['퀴즈', '빠진 곡']);
const cols = guessColumns(book[0]!.rows[0]!);
expect(cols).toEqual(['order', 'link', 'answer', 'desc', 'start', 'highlight', 'duration', null]);
expect(cols).toEqual(['order', 'link', 'answer', 'desc', 'answers', 'descAnswers', 'hint', 'start', 'highlight', 'duration', null]);
expect(parseQuizRows(book[1]!.rows, guessColumns(book[1]!.rows[headerRow(book[1]!.rows)]!), headerRow(book[1]!.rows)).items).toEqual([]);
for (const kind of ['normal', 'duel'] as const) {
const items = parseQuizRows(book[0]!.rows, cols, 0, kind).items;
expect(items.map((i) => [i.videoId, i.title, i.artist, i.durationSec, i.auto])).toEqual([
['goodday0001', '좋은 날', '아이유', 230, true],
['lovedive001', '곡 2', '가수 2', 200, true],
['hypeboy0001', '곡 6', '가수 6', 200, true],
['ditto000001', '곡 7', '가수 7', null, true],
]);
}
const normal = parseQuizRows(book[0]!.rows, cols, 0).items;
expect(normal.map((i) => [i.videoId, i.title, i.artist, i.titleAnswers, i.artistAnswers, i.durationSec, i.auto])).toEqual([
['goodday0001', '좋은 날', '아이유', ['Good Day'], ['IU'], 230, true],
['lovedive001', '곡 2', '가수 2', [], [], 200, true],
['hypeboy0001', '곡 6', '가수 6', [], [], 200, true],
['ditto000001', '곡 7', '가수 7', [], [], null, true],
]);
// the 이지선다 file has the (empty) 조회수 column: 파일로 만들기 picks 이지선다 and leaves the views to the server
const duelBook = await readSheetFile('재생목록.xlsx', writeXlsxSheets(duel));
const duelCols = guessColumns(duelBook[0]!.rows[0]!);
expect(duelCols).toContain('views');
expect(parseQuizRows(duelBook[0]!.rows, duelCols, 0, 'duel').items.map((i) => [i.title, i.artist, i.views, i.durationSec])).toEqual([
['좋은 날', '아이유', null, 230],
['곡 2', '가수 2', null, 200],
['곡 6', '가수 6', null, 200],
['곡 7', '가수 7', null, null],
]);
});
test('시작·하이라이트가 빈 곡: 자동 (start 0 + highlight worked out) or 처음부터 (0 / 0); written values are kept either way', () => {

View File

@@ -1,19 +1,22 @@
/**
* 퀴즈 파일 (관리자 → 퀴즈 → 파일로 만들기 / 내보내기): which column is what, rows → quiz songs, quiz songs → rows.
* Values are used as written (no DB lookup): 정답 = the answer, 설명 = shown with it on the reveal, 힌트 columns in order
* before the 초성 hint.
* 일반 퀴즈 (docs/13): 제목·가수 = the names shown when the answer is revealed (both always count as answers),
* 정답·가수 정답 = more accepted answers (;로 여러 개). Old files (정답 = the title, 설명, 다른 정답) still read the same.
* Titles lose brackets, feat. and version marks (cleanTitle); another name that was in brackets becomes an answer.
*/
import type { QuizItem, QuizKind } from './custom-quiz';
import { cleanTitle } from './title-clean';
/** answer = 제목 (the title), desc = 가수, answers = 정답 (more title answers), descAnswers = 가수 정답. */
export type QuizColumn = 'link' | 'answer' | 'desc' | 'hint' | 'answers' | 'descAnswers' | 'order' | 'start' | 'highlight' | 'duration' | 'views';
export const QUIZ_COLUMN_LABEL: Record<QuizColumn, string> = {
link: '유튜브 영상 링크',
answer: '정답',
desc: '설명',
answer: '제목',
desc: '가수',
hint: '힌트',
answers: '다른 정답',
descAnswers: '설명 다른 정답',
answers: '정답',
descAnswers: '가수 정답',
order: '순번',
start: '시작(초)',
highlight: '하이라이트(초)',
@@ -21,15 +24,18 @@ export const QUIZ_COLUMN_LABEL: Record<QuizColumn, string> = {
views: '조회수',
};
/** 이지선다 퀴즈 files call the same columns 제목 / 가수 (shown on the cards). */
export const DUEL_COLUMN_LABEL: Partial<Record<QuizColumn, string>> = { answer: '제목', desc: '가수' };
/** 이지선다 퀴즈 files: the same names (제목 / 가수 shown on the cards). */
export const DUEL_COLUMN_LABEL: Partial<Record<QuizColumn, string>> = {};
/** The columns each kind of quiz file uses, in the order the column pickers list them. */
export const QUIZ_FILE_COLUMNS: Record<QuizKind, QuizColumn[]> = {
normal: ['link', 'answer', 'desc', 'hint', 'answers', 'descAnswers', 'order', 'start', 'highlight', 'duration'],
normal: ['link', 'answer', 'desc', 'answers', 'descAnswers', 'hint', 'order', 'start', 'highlight', 'duration'],
duel: ['link', 'answer', 'desc', 'views', 'order', 'start', 'highlight', 'duration'],
};
/** 일반 퀴즈 file headers (빈 양식, 내보내기, 재생목록으로 엑셀 만들기). */
const NORMAL_HEAD = { answers: '정답(;로 구분)', descAnswers: '가수 정답(;로 구분)' };
/**
* 조회수 as people write it: 1234567 · 1,234,567 · 1234567회 · 123만 · 1.2억 · 1억 2,345만 · 3.4M · 12K (Excel's 1.2E+9 too).
* '' → null; anything else → undefined (invalid).
@@ -64,16 +70,20 @@ export function parseVideoId(s: string): string | null {
const norm = (h: string) => h.toLowerCase().replace(/\s+/g, '');
/** A 제목 column next to a 정답 column: the new 일반 퀴즈 file, where 정답 lists more answers (not the title). */
const TITLE_HEAD = /^(제목|title)(\(|$)|^(곡|노래)?제목\(|^songtitle$/;
/** Guess each column from its header. Several 힌트 columns are allowed (shown in column order); others once. */
export function guessColumns(header: string[]): (QuizColumn | null)[] {
const out: (QuizColumn | null)[] = header.map(() => null);
const taken = new Set<QuizColumn>();
const titled = header.some((h) => TITLE_HEAD.test(norm(h))) && header.some((h) => /^정답/.test(norm(h)));
const rules: [QuizColumn, RegExp][] = [
['views', /조회수|조회|재생수|views?|viewcount/],
['order', /순번|순서|^order$|^no\.?$/],
['link', /링크|주소|url|영상|유튜브|youtube|video|link/],
['descAnswers', /(설명|가수|노래|artist).*(다른|추가|복수)정답|(다른|추가|복수)정답.*(설명|가수|노래|artist)/],
['answers', /(다른|추가|복수)정답|별칭|alias|answers/],
['descAnswers', /(설명|가수|노래|artist).*(다른|추가|복수)정답|(다른|추가|복수)정답.*(설명|가수|노래|artist)|^(설명|가수|artist)정답|^artistanswers?/],
['answers', titled ? /(다른|추가|복수)정답|^정답|별칭|alias|answers/ : /(다른|추가|복수)정답|별칭|alias|answers/],
['hint', /힌트|hint/],
['highlight', /하이라이트|highlight/],
['duration', /길이|duration|^length/],
@@ -121,6 +131,8 @@ export interface FileRow {
/** Row number in the sheet (1-based, as Excel shows it). */
line: number;
item: QuizItem | null;
/** 일반 퀴즈: the 정답 / 가수 정답 cell was empty (or there is no such column): the server fills it in (docs/13). */
fill: { title: boolean; artist: boolean };
/** Why the row is left out: bad link, no answer, same video as an earlier row. */
problem: string | null;
/** Raw link text, for the preview of bad rows. */
@@ -173,16 +185,14 @@ export function parseQuizRows(rows: string[][], columns: (QuizColumn | null)[],
: !videoId
? '유튜브 링크가 아니에요'
: !title
? duel
? '제목이 비어 있어요'
: '정답이 비어 있어요'
? '제목이 비어 있어요'
: views === undefined
? `조회수를 읽을 수 없어요 (${cell(r, at('views')).slice(0, 30)})`
: seen.has(videoId)
? `${seen.get(videoId)}번째 줄과 같은 영상이에요`
: null;
if (problem) {
out.push({ line, item: null, problem, link });
out.push({ line, item: null, problem, link, fill: { title: false, artist: false } });
continue;
}
seen.set(videoId!, line);
@@ -191,17 +201,22 @@ export function parseQuizRows(rows: string[][], columns: (QuizColumn | null)[],
const own = (start !== null && start !== undefined) || (highlight !== null && highlight !== undefined);
const fromStart = !own && blank === 'start';
const length = parseSec(cell(r, at('duration')));
const clean = cleanTitle(title);
const artist = cell(r, at('desc')).slice(0, 200);
const written = splitAnswers(cell(r, at('answers')));
const writtenArtist = splitAnswers(cell(r, at('descAnswers')));
out.push({
line,
link,
problem: null,
fill: { title: !duel && !written.length, artist: !duel && !writtenArtist.length && !!artist },
item: {
songId: null,
videoId: videoId!,
title,
artist: cell(r, at('desc')).slice(0, 200),
titleAnswers: duel ? [] : splitAnswers(cell(r, at('answers'))).filter((a) => a !== title),
artistAnswers: duel ? [] : splitAnswers(cell(r, at('descAnswers'))),
title: clean.title.slice(0, 200),
artist,
titleAnswers: duel ? [] : [...new Set([...clean.aliases, ...written])].filter((a) => a !== clean.title).slice(0, 30),
artistAnswers: duel ? [] : writtenArtist.filter((a) => a !== artist),
hints: duel ? [] : hintCols.map((i) => cell(r, i).slice(0, 200)).filter(Boolean).slice(0, 5),
fromFile: true,
durationSec: length ? Math.min(36000, Math.round(length)) : null,
@@ -218,58 +233,38 @@ export function parseQuizRows(rows: string[][], columns: (QuizColumn | null)[],
/** Quiz songs → sheet rows with the headers this file format reads back (내보내기, 빈 양식). */
export function quizToRows(items: QuizItem[], kind: QuizKind = 'normal'): { rows: (string | number | null)[][]; widths: number[] } {
const pos = (it: QuizItem) => [it.auto ? null : (it.startSec ?? 0), it.auto ? null : it.highlightSec, it.durationSec];
if (kind === 'duel') {
// 조회수 only for numbers written by hand: fetched ones (and empty ones) are fetched again when the file comes back
const own = (it: QuizItem) => (it.viewsAuto ? null : it.views);
const withViews = items.some((it) => own(it) !== null);
const header = ['순번', QUIZ_COLUMN_LABEL.link, '제목', '가수', ...(withViews ? ['조회수'] : []), '시작(초)', '하이라이트(초)'];
const rows = items.map((it, i) => [i + 1, `https://youtu.be/${it.videoId}`, it.title, it.artist, ...(withViews ? [own(it)] : []), it.auto ? null : (it.startSec ?? 0), it.auto ? null : it.highlightSec]);
return { rows: [header, ...rows], widths: [6, 32, 30, 24, ...(withViews ? [16] : []), 10, 14] };
const header = ['순번', QUIZ_COLUMN_LABEL.link, '제목', '가수', ...(withViews ? ['조회수'] : []), '시작(초)', '하이라이트(초)', '길이(초)', '비고'];
const rows = items.map((it, i) => [i + 1, `https://youtu.be/${it.videoId}`, it.title, it.artist, ...(withViews ? [own(it)] : []), ...pos(it), null]);
return { rows: [header, ...rows], widths: [6, 32, 30, 24, ...(withViews ? [16] : []), 10, 14, 10, 30] };
}
const hintN = Math.max(1, ...items.map((i) => i.hints.length));
const hintHeads = hintN === 1 ? ['힌트'] : Array.from({ length: hintN }, (_, i) => `힌트${i + 1}`);
const header = ['순번', QUIZ_COLUMN_LABEL.link, '정답', '설명', ...hintHeads, '다른 정답(;로 구분)', '설명 다른 정답(;로 구분)', '시작(초)', '하이라이트(초)'];
const header = ['순번', QUIZ_COLUMN_LABEL.link, '제목', '가수', NORMAL_HEAD.answers, NORMAL_HEAD.descAnswers, ...hintHeads, '시작(초)', '하이라이트(초)', '길이(초)', '비고'];
const rows = items.map((it, i) => [
i + 1,
`https://youtu.be/${it.videoId}`,
it.title,
it.artist,
// the title and the artist always count: listed first so the cell shows every accepted answer
[it.title, ...it.titleAnswers].join('; '),
[it.artist, ...it.artistAnswers].filter(Boolean).join('; '),
...Array.from({ length: hintN }, (_, k) => it.hints[k] ?? ''),
it.titleAnswers.join('; '),
it.artistAnswers.join('; '),
it.auto ? null : (it.startSec ?? 0),
it.auto ? null : it.highlightSec,
...pos(it),
null,
]);
return { rows: [header, ...rows], widths: [6, 32, 30, 30, ...hintHeads.map(() => 20), 24, 24, 10, 14] };
return { rows: [header, ...rows], widths: [6, 32, 30, 24, 36, 30, ...hintHeads.map(() => 20), 10, 14, 10, 30] };
}
/** 빈 양식: the headers and one example row. */
export function quizTemplateRows(kind: QuizKind = 'normal'): { rows: (string | number | null)[][]; widths: number[] } {
if (kind === 'duel')
return quizToRows(
[
{ songId: null, videoId: 'v7bnOxV4jAc', title: '라일락', artist: '아이유', titleAnswers: [], artistAnswers: [], hints: [], fromFile: true, durationSec: null, auto: true, startSec: null, highlightSec: null, views: null, viewsAuto: null },
],
'duel',
);
return quizToRows([
{
songId: null,
videoId: 'iIIjS6yDMQo',
title: '감옥탈출',
artist: '트레일러',
titleAnswers: ['구토할배 감옥탈출'],
artistAnswers: [],
hints: ['방탈출(플래시)'],
fromFile: true,
durationSec: null,
auto: true,
startSec: null,
highlightSec: null,
views: null,
viewsAuto: null,
},
]);
const base = { songId: null, videoId: 'v7bnOxV4jAc', title: '라일락', artist: '아이유', fromFile: true, durationSec: null, auto: true, startSec: null, highlightSec: null, views: null, viewsAuto: null };
if (kind === 'duel') return quizToRows([{ ...base, titleAnswers: [], artistAnswers: [], hints: [] }], 'duel');
return quizToRows([{ ...base, titleAnswers: ['LILAC'], artistAnswers: ['IU'], hints: ['2021년 봄'] }]);
}
/** One song of 플레이리스트 가져오기 (server quizzes/playlist.ts ImportRow), as 재생목록으로 엑셀 만들기 needs it. */
@@ -278,6 +273,9 @@ export interface PlaylistSheetRow {
source: { title: string; artist: string };
title: string;
artist: string;
/** Accepted answers worked out by the server (docs/13): other names, 한글 발음, 일본어 원어·읽는 소리. */
titleAnswers?: string[];
artistAnswers?: string[];
durationSec: number | null;
videoId: string | null;
status: 'db' | 'video' | 'found' | 'check' | 'missing' | 'blocked';
@@ -285,11 +283,13 @@ export interface PlaylistSheetRow {
}
/**
* 재생목록으로 엑셀 만들기: the checked playlist as a quiz file 파일로 만들기 reads as is (일반 or 이지선다). Songs that
* would not play (재생 불가, 못 찾음, the same video again) go to a second sheet 빠진 곡 with the reason; that sheet has no
* 제목 column, so 파일로 만들기 never reads songs from it. 비고 says where each title/artist came from.
* 재생목록으로 엑셀 만들기: the checked playlist as a quiz file 파일로 만들기 reads as is, in the 일반 퀴즈 form
* (제목 · 가수 · 정답 · 가수 정답 · 힌트) or the 이지선다 form (제목 · 가수 · an empty 조회수 column, which also makes
* 파일로 만들기 pick 이지선다; the server fetches the views). Songs that would not play (재생 불가, 못 찾음, the same video
* again) go to a second sheet 빠진 곡 with the reason; that sheet has no 제목 column, so 파일로 만들기 never reads songs from
* it. 비고 says where each title/artist came from.
*/
export function playlistSheets(list: PlaylistSheetRow[]): { name: string; rows: (string | number | null)[][]; widths: number[] }[] {
export function playlistSheets(list: PlaylistSheetRow[], kind: QuizKind = 'normal'): { name: string; rows: (string | number | null)[][]; widths: number[] }[] {
const kept: (string | number | null)[][] = [];
const left: (string | number | null)[][] = [];
const firstOf = new Map<string, number>();
@@ -315,11 +315,22 @@ export function playlistSheets(list: PlaylistSheetRow[]): { name: string; rows:
: r.status === 'found'
? '유튜브 뮤직에서 찾음'
: r.note;
kept.push([kept.length + 1, `https://youtu.be/${r.videoId}`, r.title, r.artist, null, null, r.durationSec, note || null]);
const head = [kept.length + 1, `https://youtu.be/${r.videoId}`, r.title, r.artist];
const tail = [null, null, r.durationSec, note || null];
if (kind === 'duel') kept.push([...head, null, ...tail]);
else
kept.push([
...head,
[r.title, ...(r.titleAnswers ?? []).filter((a) => a !== r.title)].join('; '),
[r.artist, ...(r.artistAnswers ?? []).filter((a) => a !== r.artist)].filter(Boolean).join('; '),
null,
...tail,
]);
}
const head = ['순번', QUIZ_COLUMN_LABEL.link, '제목', '가수', QUIZ_COLUMN_LABEL.start, QUIZ_COLUMN_LABEL.highlight, QUIZ_COLUMN_LABEL.duration, '비고'];
return [
{ name: '퀴즈', rows: [head, ...kept], widths: [6, 32, 30, 24, 10, 14, 10, 40] },
{ name: '빠진 곡', rows: [['재생목록 순번', '링크', '곡 제목(재생목록)', '채널·가수(재생목록)', '빠진 이유'], ...left], widths: [12, 32, 36, 24, 40] },
];
const pos = [QUIZ_COLUMN_LABEL.start, QUIZ_COLUMN_LABEL.highlight, QUIZ_COLUMN_LABEL.duration, '비고'];
const quiz =
kind === 'duel'
? { name: '이지선다', rows: [['순번', QUIZ_COLUMN_LABEL.link, '제목', '가수', QUIZ_COLUMN_LABEL.views, ...pos], ...kept], widths: [6, 32, 30, 24, 12, 10, 14, 10, 40] }
: { name: '퀴즈', rows: [['순번', QUIZ_COLUMN_LABEL.link, '제목', '가수', NORMAL_HEAD.answers, NORMAL_HEAD.descAnswers, '힌트', ...pos], ...kept], widths: [6, 32, 30, 24, 36, 30, 16, 10, 14, 10, 40] };
return [quiz, { name: '빠진 곡', rows: [['재생목록 순번', '링크', '곡 제목(재생목록)', '채널·가수(재생목록)', '빠진 이유'], ...left], widths: [12, 32, 36, 24, 40] }];
}