원곡 찾기 진행 상황 자세히: 상태 배지(찾는 중·검색 실패 대기·N분째 진행 없음·프로세스 없음), 숫자 카드(처리·남은 곡·최근 10분 속도·지난/남은 시간·끝 예상·마지막 처리), 검색 방법, 결과 비율 막대, 방금 처리한 곡 8개, 작업 기록(쉬운 말), 지난 작업, 전체 확정 비율·다음 자동 실행. 끝 예상은 최근 10분 속도로, 마감(--deadline)은 시작 로그에서 읽음

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-19 22:09:45 +09:00
parent 8d4e32d737
commit 0c0b822adc
7 changed files with 341 additions and 45 deletions

View File

@@ -45,6 +45,8 @@ export async function matchYoutube(db: Database, ytm: Pick<YtMusic, 'searchSongs
const stats = { matched: 0, candidate: 0, none: 0 };
let tried = 0;
const src = opts.source ?? 'ytmusic';
// 관리자 → 원곡 찾기 reads the deadline back from this line
job.log(`start ${rows.length} songs via ${src}${opts.deadline !== undefined ? ` deadline ${new Date(opts.deadline).toISOString()}` : ''}`);
/**
* Writes the result only if the song is still open for automatic matching: an admin may have saved a video
* while we were waiting on the search. Returns whether the row was changed.

View File

@@ -32,22 +32,95 @@ export function reviewCounts(db: Database): Record<ReviewTab, number> {
return Object.fromEntries(REVIEW_TABS.map((t) => [t, r[t] ?? 0])) as Record<ReviewTab, number>;
}
/** The latest match-youtube run, with what it has decided so far. */
export function reviewJob(db: Database) {
const job = db
.query<{ id: number; status: string; done: number; total: number; started_at: number; finished_at: number | null }, []>(
"SELECT id, status, done, total, started_at, finished_at FROM collect_jobs WHERE kind = 'match-youtube' ORDER BY id DESC LIMIT 1",
)
.get();
const pidAlive = (pid: number) => {
try {
process.kill(pid, 0);
return true;
} catch (e) {
return (e as NodeJS.ErrnoException).code === 'EPERM'; // there, owned by someone else
}
};
/** Speed and ETA are taken over the last 10 minutes, so a slow start or a 60s retry wait fades out. */
export const RATE_WINDOW = 10 * 60_000;
/**
* The latest match-youtube run, in detail: what it decided so far, how fast it goes, when it should end,
* whether its process is still there, the last songs it looked at, its log, and the runs before it.
*/
export function reviewJob(db: Database, now = Date.now(), alive: (pid: number) => boolean = pidAlive) {
type JobRow = { id: number; status: string; done: number; total: number; started_at: number; finished_at: number | null };
const history = db
.query<JobRow, []>("SELECT id, status, done, total, started_at, finished_at FROM collect_jobs WHERE kind = 'match-youtube' ORDER BY id DESC LIMIT 6")
.all();
const job = history[0];
if (!job) return null;
const end = job.finished_at ?? Date.now() + 1;
const { pid, log } = db.query<{ pid: number | null; log: string }, [number]>('SELECT pid, log FROM collect_jobs WHERE id = ?').get(job.id)!;
const running = job.status === 'running';
const end = job.finished_at ?? now + 1;
const tried = `t.kind LIKE 'yt_tried_%' AND t.value >= ? AND t.value <= ?`;
const r = db
.query<{ matched: number | null; candidate: number | null; none: number | null }, [number, number]>(
`SELECT SUM(s.youtube_status = 'matched') matched, SUM(s.youtube_status = 'candidate') candidate, SUM(s.youtube_status = 'none') none
FROM songs s WHERE s.deleted_at IS NULL AND EXISTS (SELECT 1 FROM signals t WHERE t.song_id = s.id AND t.kind LIKE 'yt_tried_%' AND t.value >= ? AND t.value <= ?)`,
FROM songs s WHERE s.deleted_at IS NULL AND EXISTS (SELECT 1 FROM signals t WHERE t.song_id = s.id AND ${tried})`,
)
.get(job.started_at, end)!;
return { ...job, result: { matched: r.matched ?? 0, candidate: r.candidate ?? 0, none: r.none ?? 0 } };
const recent = db
.query<
{ id: number; title: string; artist: string; youtube_status: string; youtube_source: string | null; youtube_title: string | null; youtube_channel: string | null; kind: string; at: number },
[number, number]
>(
`SELECT s.id, s.title, s.artist, s.youtube_status, s.youtube_source, s.youtube_title, s.youtube_channel, t.kind, t.value at
FROM signals t JOIN songs s ON s.id = t.song_id WHERE ${tried} ORDER BY t.value DESC LIMIT 8`,
)
.all(job.started_at, end);
// speed: songs per minute over the last 10 minutes of the run (the whole run while it is younger than that)
const runEnd = running ? now : end;
const from = Math.max(job.started_at, runEnd - RATE_WINDOW);
const inWindow = db.query<{ n: number }, [number, number]>(`SELECT COUNT(*) n FROM signals t WHERE ${tried}`).get(from, end)!.n;
const perMin = runEnd > from ? (inWindow / (runEnd - from)) * 60_000 : 0;
const left = Math.max(0, job.total - job.done);
const lines = parseLog(log, job.started_at);
const deadline = lines.reduce<number | null>((d, l) => (l.deadline ? l.deadline : d), null);
const { kind } = recent[0] ?? { kind: '' };
return {
...job,
result: { matched: r.matched ?? 0, candidate: r.candidate ?? 0, none: r.none ?? 0 },
/** Search used: ytmusic (with the cookie) or the youtube fallback. */
source: kind ? kind.slice('yt_tried_'.length) : null,
lastAt: recent[0]?.at ?? null,
perMin: Math.round(perMin * 10) / 10,
eta: running && perMin > 0 && left > 0 ? Math.round(now + (left / perMin) * 60_000) : null,
/** Running but its process is gone (container restarted, killed): the row is stale. */
alive: running && pid ? alive(pid) : null,
deadline,
recent: recent.map(({ kind: _, ...x }) => x),
log: lines.slice(-12).map(({ at, text }) => ({ at, text })),
history: history.slice(1),
};
}
/**
* Job log lines are "HH:MM:SS text" in UTC; turn the time back into epoch ms (the run may cross midnight).
* The matcher's start line carries its deadline ("deadline 2026-10-20T07:55:00.000Z").
*/
export function parseLog(log: string, startedAt: number) {
const out: { at: number; text: string; deadline?: number }[] = [];
let day = Math.floor(startedAt / 86400_000) * 86400_000;
let prev = startedAt - 60_000;
for (const line of log.split('\n')) {
const m = /^(\d\d):(\d\d):(\d\d) (.*)$/.exec(line);
if (!m) continue;
let at = day + ((+m[1]! * 60 + +m[2]!) * 60 + +m[3]!) * 1000;
if (at < prev - 3600_000) {
day += 86400_000;
at += 86400_000;
}
prev = at;
const d = / deadline (\S+)/.exec(m[4]!);
out.push({ at, text: m[4]!, ...(d && Number.isFinite(Date.parse(d[1]!)) ? { deadline: Date.parse(d[1]!) } : {}) });
}
return out;
}
export interface ReviewRow {

View File

@@ -3,6 +3,7 @@ import { afterEach, expect, test } from 'bun:test';
import { Catalog } from './collector/catalog';
import { matchYoutube } from './collector/match-youtube';
import { quizSong } from './songs/quiz';
import { parseLog, reviewJob } from './songs/youtube-review';
import { api, boot, discordLogin, TEST_SUPERADMINS } from './test-utils';
let s: ReturnType<typeof boot>;
@@ -77,3 +78,36 @@ test('원곡 찾기 tabs and actions; admin choices stick across matcher runs',
expect(audit).toEqual(expect.arrayContaining(['song.youtube.unconfirm', 'song.youtube.none', 'song.update']));
expect((await call('/youtube?tab=nope')).body.tab).toBe('candidate');
});
test('원곡 찾기 진행 상황: speed over the last 10 minutes, ETA, stale process, last songs, log across midnight, earlier runs', () => {
s = boot();
const c = new Catalog(s.db);
const ids = Array.from({ length: 30 }, (_, i) => c.upsert({ title: `곡${i}`, artists: [{ name: '가수' }], source: 't', ref: String(i) })[0]!);
const day = Date.UTC(2026, 9, 19);
const start = day + 23 * 3600_000 + 50 * 60_000; // 23:50 UTC
s.db.query("INSERT INTO collect_jobs (kind, status, done, total, started_at, finished_at) VALUES ('match-youtube', 'done', 5, 5, ?, ?)").run(start - 86400_000, start - 86000_000);
const log = ['23:50:00 start 100 songs via ytmusic deadline 2026-10-20T07:55:00.000Z', '23:59:59 youtube 50/100 matched 40 candidate 5 none 5', '00:01:00 search failed (429), waiting 60s', ''].join('\n');
const job = Number(s.db.query("INSERT INTO collect_jobs (kind, status, done, total, started_at, pid, log) VALUES ('match-youtube', 'running', 30, 100, ?, 4242, ?)").run(start, log).lastInsertRowid);
// 20 songs in the first 10 minutes, 10 in the last 10: the ETA follows the recent pace (1 song a minute)
const now = start + 20 * 60_000;
ids.forEach((id, i) => {
const at = i < 20 ? start + i * 30_000 : now - 10 * 60_000 + (i - 19) * 60_000 - 1;
s.db.query("INSERT INTO signals (song_id, kind, value, fetched_at) VALUES (?, 'yt_tried_ytmusic', ?, ?)").run(id, at, at);
});
s.db.query("UPDATE songs SET youtube_status = 'matched', youtube_id = 'v', youtube_title = '영상' WHERE id = ?").run(ids[29]!);
const alive: number[] = [];
const r = reviewJob(s.db, now, (pid) => (alive.push(pid), false))!;
expect(r).toMatchObject({ id: job, status: 'running', source: 'ytmusic', alive: false, lastAt: now - 1, deadline: Date.parse('2026-10-20T07:55:00.000Z') });
expect(alive).toEqual([4242]);
expect(r.perMin).toBe(1);
expect(r.eta).toBe(now + 70 * 60_000);
expect(r.result).toEqual({ matched: 1, candidate: 0, none: 29 });
expect(r.recent.map((x) => x.id)).toEqual(ids.slice(22).reverse());
expect(r.recent[0]).toMatchObject({ youtube_status: 'matched', youtube_title: '영상' });
expect(r.log.map((l) => l.at)).toEqual([start, day + 86400_000 - 1000, day + 86400_000 + 60_000]);
expect(r.history).toHaveLength(1);
// a finished run: no ETA, no process check
s.db.query("UPDATE collect_jobs SET status = 'done', finished_at = ? WHERE id = ?").run(now, job);
expect(reviewJob(s.db, now + 3600_000, () => true)).toMatchObject({ eta: null, alive: null, perMin: 1 });
expect(parseLog('garbage\n10:00:00 hi', Date.UTC(2026, 0, 1, 9))).toEqual([{ at: Date.UTC(2026, 0, 1, 10), text: 'hi' }]);
});

View File

@@ -35,14 +35,25 @@ interface Row {
touched: number;
candidates: Cand[];
}
interface Job {
interface JobBase {
id: number;
status: string;
done: number;
total: number;
started_at: number;
finished_at: number | null;
}
interface Job extends JobBase {
result: { matched: number; candidate: number; none: number };
source: string | null;
lastAt: number | null;
perMin: number;
eta: number | null;
alive: boolean | null;
deadline: number | null;
recent: { id: number; title: string; artist: string; youtube_status: string; youtube_source: string | null; youtube_title: string | null; youtube_channel: string | null; at: number }[];
log: { at: number; text: string }[];
history: JobBase[];
}
interface Data {
tab: Tab;
@@ -79,6 +90,189 @@ function ago(ms: number, now: number): string {
if (s < 86400) return `${Math.floor(s / 3600)}시간 전`;
return new Date(ms).toLocaleDateString('ko-KR', { month: 'short', day: 'numeric' });
}
/** 1시간 43분 · 12분 · 40초 */
function span(ms: number): string {
const m = Math.round(ms / 60_000);
if (ms < 60_000) return `${Math.max(0, Math.round(ms / 1000))}초`;
return m >= 60 ? `${Math.floor(m / 60)}시간${m % 60 ? ` ${m % 60}분` : ''}` : `${m}분`;
}
/** 23:46, or 내일 00:12 / 10. 21. 08:10 when it is not today. */
function when(ms: number, now: number): string {
const day = (t: number) => new Date(t).toDateString();
if (day(ms) === day(now)) return clock(ms);
if (day(ms) === day(now + 86400_000)) return `내일 ${clock(ms)}`;
return new Date(ms).toLocaleString('ko-KR', { month: 'numeric', day: 'numeric', hour: '2-digit', minute: '2-digit' });
}
/** The daily cron: 08:10 local. */
function nextCron(now: number): number {
const d = new Date(now);
d.setHours(8, 10, 0, 0);
if (d.getTime() <= now) d.setDate(d.getDate() + 1);
return d.getTime();
}
const SEARCH: Record<string, string> = { ytmusic: '유튜브 뮤직 (쿠키 사용)', youtube: '유튜브 검색 (쿠키 없이, 정확도 낮음)' };
/** The matcher's log in plain words. */
function logText(t: string): string {
let m: RegExpExecArray | null;
const n = (x: string) => Number(x).toLocaleString();
if ((m = /^start (\d+) songs via (\w+)(?: deadline (\S+))?/.exec(t))) return `시작: ${n(m[1]!)}곡 · ${SEARCH[m[2]!] ?? m[2]}${m[3] ? ` · ${clock(Date.parse(m[3]))}에 마감` : ''}`;
if ((m = /^youtube (done )?(\d+)\/(\d+):? matched (\d+) candidate (\d+) none (\d+)/.exec(t)))
return `${m[1] ? '끝: ' : ''}${n(m[2]!)} / ${n(m[3]!)}곡 · 확정 ${n(m[4]!)} · 후보 ${n(m[5]!)} · 못 찾음 ${n(m[6]!)}`;
if ((m = /^search failed \((.*)\), waiting 60s/.exec(t))) return `⚠ 검색 실패 (${m[1]}) → 60초 쉬고 다시 해요`;
if ((m = /^deadline reached after (\d+)\/(\d+)/.exec(t))) return `마감 시각이 돼서 ${n(m[1]!)} / ${n(m[2]!)}곡에서 멈췄어요`;
if ((m = /^stopped: (.*)/.exec(t))) return `⚠ 멈춤: ${m[1]}`;
return t;
}
/** No song finished for this long while running: the run is probably stuck (normal pace is a few seconds a song). */
const STALL_MS = 3 * 60_000;
/** 진행 상황: is it running, how far, how fast, when it ends, what it decided, and what it just did. */
function JobStatus({ job, counts, now, onPick }: { job: Job | null | undefined; counts: Record<Tab, number> | undefined; now: number; onPick: (id: number) => void }) {
const all = counts ? Object.values(counts).reduce((a, b) => a + b, 0) : 0;
const footer = (
<p className="muted small">
{counts && all > 0 && (
<>
전체 {all.toLocaleString()}곡 중 게임에 나오는 곡(확정) <b>{counts.matched.toLocaleString()}</b>곡 ({Math.floor((counts.matched / all) * 100)}%) · 아직 안 찾은 곡{' '}
{counts.pending.toLocaleString()}곡 ·{' '}
</>
)}
다음 자동 실행 {when(nextCron(now), now)} (매일 08:10, 3,000곡까지). 확정한 영상은 저장하는 즉시 새 게임과 다음 문제부터 나와요(지금 재생 중인 곡은 그대로).
</p>
);
if (!job)
return (
<section className="card stack" style={{ gap: 8 }} aria-label="진행 상황">
<p className="muted small">아직 돌린 원곡 찾기 작업이 없어요.</p>
{footer}
</section>
);
const running = job.status === 'running';
const left = Math.max(0, job.total - job.done);
const pct = job.total ? Math.floor((job.done / job.total) * 100) : 0;
const since = job.lastAt ?? job.started_at;
const gone = running && job.alive === false;
const stalled = running && !gone && now - since > STALL_MS;
const lastLog = job.log[job.log.length - 1];
// a search failed and no song has finished since: the matcher waits 60s and tries again
const waiting = running && !!lastLog && /^search failed/.test(lastLog.text) && (job.lastAt ?? 0) < lastLog.at;
const elapsed = (job.finished_at ?? now) - job.started_at;
const r = job.result;
const decided = r.matched + r.candidate + r.none;
const share = (n: number) => (decided ? `${Math.round((n / decided) * 100)}%` : '-');
const cutByDeadline = running && job.deadline && job.eta && job.eta > job.deadline;
let badge: [string, string];
if (gone) badge = ['⚠ 멈춘 것 같아요', 'warn'];
else if (stalled) badge = [`⚠ ${span(now - since)}째 진행 없음`, 'warn'];
else if (waiting) badge = ['⏳ 검색 실패, 잠깐 쉬는 중', 'warn'];
else if (running) badge = ['● 찾는 중', 'live'];
else badge = [JOB_STATUS[job.status] ?? job.status, job.status === 'done' ? 'ok' : 'warn'];
const stats: [string, string, string?][] = [
['처리', `${job.done.toLocaleString()} / ${job.total.toLocaleString()}`, `${pct}%`],
['남은 곡', `${left.toLocaleString()}곡`],
['속도', job.perMin ? `${job.perMin.toLocaleString()}곡/분` : '-', job.perMin ? `1곡에 ${(60 / job.perMin).toFixed(1)}초 · 최근 10분` : undefined],
[running ? '지난 시간' : '걸린 시간', span(elapsed), `시작 ${when(job.started_at, now)}`],
...(running
? ([
['남은 시간', job.eta ? `약 ${span(job.eta - now)}` : '-'],
['끝 예상', job.eta ? when(job.eta, now) : '-', cutByDeadline ? `${clock(job.deadline!)} 마감에 멈춰요` : undefined],
] as [string, string, string?][])
: ([['끝난 시각', job.finished_at ? when(job.finished_at, now) : '-']] as [string, string, string?][])),
['마지막 처리', job.lastAt ? ago(job.lastAt, now) : '-', job.lastAt ? clock(job.lastAt) : undefined],
];
return (
<section className="card stack" style={{ gap: 10 }} aria-label="진행 상황">
<div className="row">
<span className={`badge ${badge[1]}`}>{badge[0]}</span>
<b className="grow">
작업 #{job.id} <span className="mono">{pct}%</span>
</b>
{job.source && <span className="muted small">검색: {SEARCH[job.source] ?? job.source}</span>}
</div>
{gone && <p className="small">작업 기록은 &apos;찾는 중&apos;인데 작업 프로세스가 없어요(서버 재시작 등). 수집 화면에서 다시 실행하면 이어서 찾아요.</p>}
{stalled && <p className="small">보통 1곡에 몇 초면 끝나는데 {span(now - since)} 동안 처리한 곡이 없어요. 아래 작업 기록을 확인하고, 계속 그러면 수집 화면에서 멈췄다 다시 실행해 주세요.</p>}
{!running && job.status !== 'done' && lastLog && <p className="small">{logText(lastLog.text)}</p>}
<progress className="yt-progress" max={job.total || 1} value={job.done} aria-label="원곡 찾기 진행률" />
<div className="yt-stats">
{stats.map(([k, v, sub]) => (
<div key={k} className="yt-stat">
<span className="muted small">{k}</span>
<b className="mono">{v}</b>
{sub && <span className="muted small">{sub}</span>}
</div>
))}
</div>
{cutByDeadline && (
<p className="small">
{clock(job.deadline!)}가 되면 정기 작업과 겹치지 않게 멈춰요. 그때까지 약 {Math.round(((job.deadline! - now) / 60_000) * job.perMin).toLocaleString()}곡 더 찾고, 남은 곡은 다음 작업이 이어서 찾아요.
</p>
)}
<div className="stack" style={{ gap: 4 }}>
<span className="small">
이번 작업 결과 ({decided.toLocaleString()}곡): 확정 <b>{r.matched.toLocaleString()}</b> ({share(r.matched)}) · 후보 <b>{r.candidate.toLocaleString()}</b> ({share(r.candidate)}) · 못 찾음{' '}
<b>{r.none.toLocaleString()}</b> ({share(r.none)})
</span>
{decided > 0 && (
<div className="yt-split" aria-hidden="true">
<span className="m" style={{ flexGrow: r.matched }} />
<span className="c" style={{ flexGrow: r.candidate }} />
<span className="n" style={{ flexGrow: r.none }} />
</div>
)}
</div>
{job.recent.length > 0 && (
<div className="stack" style={{ gap: 4 }}>
<span className="field">방금 처리한 곡</span>
<ul className="yt-recent">
{job.recent.map((x) => {
const [label, cls] = x.youtube_status === 'none' && x.youtube_source === 'admin' ? ['원곡 없음', ''] : x.youtube_status === 'none' ? ['못 찾음', ''] : (STATUS[x.youtube_status] ?? [x.youtube_status, '']);
return (
<li key={x.id}>
<span className="muted small mono">{ago(x.at, now)}</span>
<span className={`badge ${cls}`}>{label}</span>
<button type="button" className="linklike" onClick={() => onPick(x.id)}>
{x.title}
</button>
<span className="muted small">
{x.artist}
{x.youtube_title ? ` → ${x.youtube_title}${x.youtube_channel ? ` · ${x.youtube_channel}` : ''}` : ''}
</span>
</li>
);
})}
</ul>
</div>
)}
{job.log.length > 0 && (
<details>
<summary className="small">작업 기록 (최근 {job.log.length}줄)</summary>
<ul className="yt-log small">
{job.log.map((l, i) => (
<li key={i}>
<span className="mono muted">{clock(l.at)}</span> {logText(l.text)}
</li>
))}
</ul>
</details>
)}
{job.history.length > 0 && (
<details>
<summary className="small">지난 작업 {job.history.length}개</summary>
<ul className="yt-log small">
{job.history.map((h) => (
<li key={h.id}>
<span className="mono muted">#{h.id}</span> {when(h.started_at, now)} 시작 · {JOB_STATUS[h.status] ?? h.status} · {h.done.toLocaleString()} / {h.total.toLocaleString()}곡
{h.finished_at ? ` · ${span(h.finished_at - h.started_at)} 걸림` : ''}
</li>
))}
</ul>
</details>
)}
{footer}
</section>
);
}
/** Which tab a song belongs to now (same rules as the server). */
function tabOf(d: Detail): Tab {
const s = d.song;
@@ -157,11 +351,8 @@ export function YoutubePage() {
}
};
const job = data?.job;
const running = job?.status === 'running';
const pages = data ? Math.max(1, Math.ceil(data.total / data.pageSize)) : 1;
const now = Date.now();
const eta = running && job.done > 0 && job.total > job.done ? now + ((now - job.started_at) / job.done) * (job.total - job.done) : null;
return (
<div className={`songs-layout ${selected ? 'with-panel' : ''}`}>
@@ -172,33 +363,7 @@ export function YoutubePage() {
수집 화면에서 실행·멈추기
</Link>
</div>
<section className="card stack" style={{ gap: 8 }} aria-label="진행 상황">
{job ? (
<>
<div className="row">
<b className="grow">
{running ? '🔎 지금 찾는 중' : `마지막 작업: ${JOB_STATUS[job.status] ?? job.status}`}{' '}
<span className="mono">
{job.done.toLocaleString()} / {job.total.toLocaleString()}
{job.total ? ` (${Math.floor((job.done / job.total) * 100)}%)` : ''}
</span>
</b>
<span className="muted small">
시작 {clock(job.started_at)}
{running && eta && ` · 끝 예상 ${clock(eta)}`}
{!running && job.finished_at && ` · 끝 ${new Date(job.finished_at).toLocaleString('ko-KR', { dateStyle: 'short', timeStyle: 'short' })}`}
</span>
</div>
<progress className="yt-progress" max={job.total || 1} value={job.done} aria-label="원곡 찾기 진행률" />
<p className="small">
이번 작업 결과: 확정 <b>{job.result.matched.toLocaleString()}</b> · 후보 <b>{job.result.candidate.toLocaleString()}</b> · 못 찾음 <b>{job.result.none.toLocaleString()}</b>
</p>
</>
) : (
<p className="muted small">아직 돌린 원곡 찾기 작업이 없어요.</p>
)}
<p className="muted small">매일 08:10에 3,000곡씩 자동으로 찾아요. 확정한 영상은 저장하는 즉시 새 게임과 다음 문제부터 나와요(지금 재생 중인 곡은 그대로).</p>
</section>
<JobStatus job={data?.job} counts={data?.counts} now={now} onPick={(id) => (setSelected(id), setEditing(false))} />
<div className="row" role="group" aria-label="원곡 찾기 결과 종류">
{TABS.map(([t, label]) => (
<button key={t} type="button" className="chip" aria-pressed={tab === t} onClick={() => choose(t)}>

View File

@@ -318,6 +318,17 @@ input.input.sm { width: 76px; }
.cand { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border: 1.5px solid var(--line); border-radius: 9px; background: var(--surface); color: var(--text); font: inherit; font-size: 0.85rem; font-weight: 650; cursor: pointer; }
.cand.on { border-color: var(--ink); background: var(--primary-soft); }
.yt-progress { width: 100%; height: 10px; accent-color: var(--primary); }
.yt-stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
.yt-stat { display: flex; flex-direction: column; gap: 2px; background: var(--surface-2); border-radius: var(--radius-sm); padding: 8px 10px; min-width: 0; }
.yt-stat b { font-size: 1.05rem; }
.yt-split { display: flex; gap: 2px; height: 8px; border-radius: 4px; overflow: hidden; }
.yt-split > span { flex-basis: 0; min-width: 0; }
.yt-split .m { background: var(--correct); }
.yt-split .c { background: var(--mustard); }
.yt-split .n { background: var(--text-sub); }
.yt-recent, .yt-log { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.yt-recent li { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }
.yt-log { max-height: 220px; overflow: auto; margin-top: 6px; }
.lyrics { white-space: pre-wrap; font: inherit; font-size: 0.85rem; background: var(--surface-2); padding: 10px; border-radius: 8px; max-height: 260px; overflow: auto; }
@media (max-width: 1100px) { .songs-layout.with-panel { grid-template-columns: 1fr; } .song-panel { position: static; max-height: none; } }

View File

@@ -64,7 +64,8 @@ joke-app 관리자와 같은 레이아웃(왼쪽 사이드 메뉴 + 오른쪽
- **중복 정리**: 제목·가수 정규화가 같은 곡 묶어서 보여주고 병합
### 원곡 찾기 화면 (2026-10-19)
- **진행 상황**: 지금(또는 마지막) 원곡 찾기 작업의 진행률·끝 예상 시각, 이번 작업 결과(확정·후보·못 찾음)
- **진행 상황**: 지금(또는 마지막) 원곡 찾기 작업의 상태 배지(찾는 중 · 검색 실패로 잠깐 쉬는 중 · N분째 진행 없음(3분 넘게 처리한 곡이 없을 때) · 멈춘 것 같아요(작업 기록은 running인데 프로세스가 없을 때) · 끝남/멈춤/실패와 이유), 진행률, 숫자 카드(처리 N/M·남은 곡·속도(최근 10분 곡/분, 1곡에 몇 초)·지난 시간·남은 시간·끝 예상·마지막 처리), 검색 방법(유튜브 뮤직/쿠키 없는 유튜브 검색), 이번 작업 결과(확정·후보·못 찾음 수와 비율 막대), 방금 처리한 곡 8개(누르면 오른쪽 패널), 작업 기록(최근 12줄, 쉬운 말로), 지난 작업 5개, 전체 곡 중 확정 비율·아직 안 찾은 곡·다음 자동 실행 시각
- 끝 예상은 최근 10분 속도로 계산한다(초반 느림·60초 재시도 대기가 오래 남지 않게). `--deadline`으로 돌린 작업은 시작 로그(`start N songs via … deadline <ISO>`)에서 마감을 읽어, 끝 예상이 마감보다 늦으면 "마감에 멈춰요"와 그때까지 찾을 곡 수를 보여 준다.
- **탭**: 확정 · 후보 · 못 찾음(찾아봤지만 없음, 7일 뒤 자동 재시도) · 원곡 없음(관리자 표시, 자동 찾기 제외) · 재생 불가 · 아직 안 찾음(자동 찾기 순서대로). 방금 처리된 곡이 맨 위
- **자동 새로고침**: 5초마다, 화면을 보고 있을 때만. 마우스가 목록 위에 있으면 줄이 밀리지 않게 잠깐 멈춤
- **바로 고치기**: 후보 줄의 [확정], 오른쪽 패널에서 미리듣기 · 다른 후보로 확정 · 주소 붙여넣기 · 확정 취소(→ 관리자 후보, 게임에서 빠지고 자동 찾기가 다시 확정하지 않음) · 원곡 없음으로 표시 · 다시 찾기. 처리한 곡이 탭에서 빠지면 다음 곡으로 넘어감

View File

@@ -272,12 +272,22 @@ try {
const [auto] = c.upsert({ title: '자동확정곡', artists: [{ name: '자동가수' }], source: 'e2e', ref: 'a' });
db.query("UPDATE songs SET youtube_status = 'matched', youtube_source = 'ytmusic', youtube_id = 'autovideo01', youtube_title = '자동확정곡', youtube_channel = '자동가수 - Topic', embeddable = 1, youtube_checked_at = ? WHERE id = ?").run(now, auto!);
tried(auto!, now);
db.query("INSERT INTO collect_jobs (kind, status, done, total, started_at, pid) VALUES ('match-youtube', 'running', 3, 10, ?, 1)").run(now - 60_000);
const hms = (t: number) => new Date(t).toISOString().slice(11, 19);
const log = `${hms(now - 60_000)} start 10 songs via ytmusic\n${hms(now - 30_000)} search failed (timeout), waiting 60s\n`;
db.query("INSERT INTO collect_jobs (kind, status, done, total, started_at, pid, log) VALUES ('match-youtube', 'running', 3, 10, ?, ?, ?)").run(now - 60_000, process.pid, log);
await p.getByRole('link', { name: '🔎 원곡 찾기' }).click();
await p.getByRole('heading', { name: '원곡 찾기' }).waitFor();
await p.getByText('🔎 지금 찾는 중').waitFor();
await p.getByText('3 / 10 (30%)').waitFor();
const status = p.getByRole('region', { name: '진행 상황' });
await status.getByText('● 찾는 중').waitFor();
await status.getByText('3 / 10', { exact: true }).waitFor();
await status.getByText('7곡', { exact: true }).waitFor();
await status.getByText('검색: 유튜브 뮤직 (쿠키 사용)').waitFor();
await status.locator('.yt-stat', { hasText: '끝 예상' }).waitFor();
await status.locator('.yt-recent li', { hasText: '자동확정곡' }).getByText('확정', { exact: true }).waitFor();
await status.getByText('작업 기록 (최근 2줄)').click();
await status.getByText('⚠ 검색 실패 (timeout) → 60초 쉬고 다시 해요').waitFor();
await status.screenshot({ path: join(SHOTS, 'youtube-progress.png') });
// 후보 tab is first: one click confirms, and it moves to 확정
await row(p, '후보곡').getByRole('button', { name: '확정', exact: true }).click();
await toastSeen(p, "'후보곡' 확정했어요");