원곡 찾기 진행 상황 자세히: 상태 배지(찾는 중·검색 실패 대기·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

@@ -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; } }