|
|
|
|
@@ -0,0 +1,454 @@
|
|
|
|
|
/**
|
|
|
|
|
* 관리자 → 원곡 찾기: what the YouTube matcher decided, newest first, refreshed every 5 seconds while the page is in view.
|
|
|
|
|
* Each song can be fixed on the spot: 확정 · 다른 후보 · 주소 붙여넣기 · 확정 취소 · 원곡 없음 · 다시 찾기.
|
|
|
|
|
* Saving goes through the same paths as the song editor, so new games use the video right away.
|
|
|
|
|
*/
|
|
|
|
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
|
|
|
import { Link } from 'react-router';
|
|
|
|
|
import { apiCall } from '../../net/api';
|
|
|
|
|
import { toast } from '../../store/toast';
|
|
|
|
|
import { ConfirmSheet } from '../../components/ui';
|
|
|
|
|
import { SongEditor, YtPreview, type Genre } from './SongsPage';
|
|
|
|
|
|
|
|
|
|
type Tab = 'matched' | 'candidate' | 'missing' | 'noorig' | 'dead' | 'pending';
|
|
|
|
|
interface Cand {
|
|
|
|
|
video_id: string;
|
|
|
|
|
title: string | null;
|
|
|
|
|
channel: string | null;
|
|
|
|
|
duration_sec: number | null;
|
|
|
|
|
score: number;
|
|
|
|
|
source: string;
|
|
|
|
|
}
|
|
|
|
|
interface Row {
|
|
|
|
|
id: number;
|
|
|
|
|
title: string;
|
|
|
|
|
artist: string;
|
|
|
|
|
year: number | null;
|
|
|
|
|
level: number | null;
|
|
|
|
|
youtube_id: string | null;
|
|
|
|
|
youtube_status: string;
|
|
|
|
|
youtube_source: string | null;
|
|
|
|
|
youtube_channel: string | null;
|
|
|
|
|
youtube_title: string | null;
|
|
|
|
|
score: number | null;
|
|
|
|
|
note: string | null;
|
|
|
|
|
touched: number;
|
|
|
|
|
candidates: Cand[];
|
|
|
|
|
}
|
|
|
|
|
interface Job {
|
|
|
|
|
id: number;
|
|
|
|
|
status: string;
|
|
|
|
|
done: number;
|
|
|
|
|
total: number;
|
|
|
|
|
started_at: number;
|
|
|
|
|
finished_at: number | null;
|
|
|
|
|
result: { matched: number; candidate: number; none: number };
|
|
|
|
|
}
|
|
|
|
|
interface Data {
|
|
|
|
|
tab: Tab;
|
|
|
|
|
counts: Record<Tab, number>;
|
|
|
|
|
job: Job | null;
|
|
|
|
|
total: number;
|
|
|
|
|
pageSize: number;
|
|
|
|
|
rows: Row[];
|
|
|
|
|
}
|
|
|
|
|
interface Detail {
|
|
|
|
|
song: { id: number; title: string; artist: string; year: number | null; youtube_id: string | null; youtube_status: string; youtube_source: string | null; youtube_channel: string | null; youtube_title: string | null };
|
|
|
|
|
candidates: Cand[];
|
|
|
|
|
signals: { kind: string; value: number }[];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const TABS: [Tab, string, string][] = [
|
|
|
|
|
['matched', '확정', '게임에 나오는 영상이에요. 틀린 영상이면 확정 취소하거나 다른 영상으로 바꿔 주세요.'],
|
|
|
|
|
['candidate', '후보', '자동으로 확신하지 못한 곡이에요. 게임에는 아직 안 나와요. 맞으면 확정을 눌러 주세요.'],
|
|
|
|
|
['missing', '못 찾음', '찾아봤지만 쓸 만한 영상이 없었어요. 7일 뒤 자동으로 다시 찾아요. 주소를 직접 넣거나 원곡 없음으로 표시할 수 있어요.'],
|
|
|
|
|
['noorig', '원곡 없음', '관리자가 원곡 없음으로 표시한 곡이에요. 자동 찾기가 건너뛰어요. 다시 찾기를 누르면 다음 작업에서 다시 찾아요.'],
|
|
|
|
|
['dead', '재생 불가', '게임 중에 재생이 안 된 영상이에요(삭제·퍼가기 금지). 다른 영상으로 바꿔 주세요.'],
|
|
|
|
|
['pending', '아직 안 찾음', '아직 한 번도 찾아보지 않은 곡이에요. 자동 찾기가 이 순서(인기 많은 곡부터)로 찾아요.'],
|
|
|
|
|
];
|
|
|
|
|
const SOURCE: Record<string, string> = { ytmusic: '유튜브 뮤직', youtube: '유튜브 검색', norabose: '노라보세', admin: '관리자' };
|
|
|
|
|
const STATUS: Record<string, [string, string]> = { matched: ['확정', 'ok'], candidate: ['후보', 'warn'], none: ['없음', ''], dead: ['재생 불가', 'warn'] };
|
|
|
|
|
const JOB_STATUS: Record<string, string> = { running: '찾는 중', done: '끝남', failed: '실패', stopped: '멈춤' };
|
|
|
|
|
const mmss = (s: number | null) => (s == null ? '-' : `${Math.floor(s / 60)}:${String(Math.round(s % 60)).padStart(2, '0')}`);
|
|
|
|
|
const clock = (ms: number) => new Date(ms).toLocaleTimeString('ko-KR', { hour: '2-digit', minute: '2-digit' });
|
|
|
|
|
function ago(ms: number, now: number): string {
|
|
|
|
|
if (!ms) return '-';
|
|
|
|
|
const s = Math.max(0, Math.round((now - ms) / 1000));
|
|
|
|
|
if (s < 60) return `${s}초 전`;
|
|
|
|
|
if (s < 3600) return `${Math.floor(s / 60)}분 전`;
|
|
|
|
|
if (s < 86400) return `${Math.floor(s / 3600)}시간 전`;
|
|
|
|
|
return new Date(ms).toLocaleDateString('ko-KR', { month: 'short', day: 'numeric' });
|
|
|
|
|
}
|
|
|
|
|
/** Which tab a song belongs to now (same rules as the server). */
|
|
|
|
|
function tabOf(d: Detail): Tab {
|
|
|
|
|
const s = d.song;
|
|
|
|
|
if (s.youtube_status === 'matched' || s.youtube_status === 'candidate' || s.youtube_status === 'dead') return s.youtube_status;
|
|
|
|
|
if (s.youtube_source === 'admin') return 'noorig';
|
|
|
|
|
return d.signals.some((x) => x.kind.startsWith('yt_tried_')) ? 'missing' : 'pending';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function YoutubePage() {
|
|
|
|
|
const [tab, setTab] = useState<Tab>('candidate');
|
|
|
|
|
const [q, setQ] = useState('');
|
|
|
|
|
const [query, setQuery] = useState('');
|
|
|
|
|
const [page, setPage] = useState(0);
|
|
|
|
|
const [data, setData] = useState<Data | null>(null);
|
|
|
|
|
const [selected, setSelected] = useState<number | null>(null);
|
|
|
|
|
const [editing, setEditing] = useState(false);
|
|
|
|
|
const [auto, setAuto] = useState(true);
|
|
|
|
|
const [hover, setHover] = useState(false);
|
|
|
|
|
const [lastAt, setLastAt] = useState(0);
|
|
|
|
|
const [genres, setGenres] = useState<Genre[]>([]);
|
|
|
|
|
const seq = useRef(0);
|
|
|
|
|
// Read when an action finishes (the list may have refreshed meanwhile).
|
|
|
|
|
const latest = useRef({ data, selected, tab });
|
|
|
|
|
latest.current = { data, selected, tab };
|
|
|
|
|
|
|
|
|
|
const reload = useCallback(() => {
|
|
|
|
|
const my = ++seq.current;
|
|
|
|
|
const p = new URLSearchParams({ tab, page: String(page) });
|
|
|
|
|
if (query) p.set('q', query);
|
|
|
|
|
apiCall<Data>('GET', `/api/admin/youtube?${p}`).then(
|
|
|
|
|
(d) => {
|
|
|
|
|
if (my !== seq.current) return; // a newer request (other tab/page) is on its way
|
|
|
|
|
setData(d);
|
|
|
|
|
setLastAt(Date.now());
|
|
|
|
|
},
|
|
|
|
|
(e: Error) => my === seq.current && toast(e.message, 'error'),
|
|
|
|
|
);
|
|
|
|
|
}, [tab, page, query]);
|
|
|
|
|
useEffect(reload, [reload]);
|
|
|
|
|
useEffect(() => void apiCall<{ genres: Genre[] }>('GET', '/api/admin/genres').then((r) => setGenres(r.genres), () => {}), []);
|
|
|
|
|
|
|
|
|
|
// 5초마다, only while this page is on screen and the list is not under the pointer (rows would move under a click).
|
|
|
|
|
const paused = !auto || hover;
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (paused) return;
|
|
|
|
|
const tick = () => document.visibilityState === 'visible' && reload();
|
|
|
|
|
const t = setInterval(tick, 5000);
|
|
|
|
|
document.addEventListener('visibilitychange', tick);
|
|
|
|
|
return () => {
|
|
|
|
|
clearInterval(t);
|
|
|
|
|
document.removeEventListener('visibilitychange', tick);
|
|
|
|
|
};
|
|
|
|
|
}, [paused, reload]);
|
|
|
|
|
|
|
|
|
|
const choose = (t: Tab) => {
|
|
|
|
|
setTab(t);
|
|
|
|
|
setPage(0);
|
|
|
|
|
};
|
|
|
|
|
/** After an action: refresh, and when the song left this tab, move on to the next one in the list. */
|
|
|
|
|
const afterAction = (id: number, now: Tab | null) => {
|
|
|
|
|
const { data, selected, tab } = latest.current;
|
|
|
|
|
if (now !== null && now !== tab && selected === id && data) {
|
|
|
|
|
const i = data.rows.findIndex((r) => r.id === id);
|
|
|
|
|
const next = data.rows[i + 1] ?? data.rows[i - 1];
|
|
|
|
|
setSelected(next && next.id !== id ? next.id : null);
|
|
|
|
|
}
|
|
|
|
|
reload();
|
|
|
|
|
};
|
|
|
|
|
const quickConfirm = async (r: Row) => {
|
|
|
|
|
try {
|
|
|
|
|
await apiCall('PATCH', `/api/admin/songs/${r.id}`, { youtube: `https://youtu.be/${r.youtube_id}` });
|
|
|
|
|
toast(`'${r.title}' 확정했어요.`);
|
|
|
|
|
afterAction(r.id, 'matched');
|
|
|
|
|
} catch (e) {
|
|
|
|
|
toast((e as Error).message, 'error');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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' : ''}`}>
|
|
|
|
|
<div className="stack" style={{ minWidth: 0 }}>
|
|
|
|
|
<div className="row">
|
|
|
|
|
<h1 className="grow">원곡 찾기</h1>
|
|
|
|
|
<Link className="btn btn-sm" to="/admin/collect">
|
|
|
|
|
수집 화면에서 실행·멈추기
|
|
|
|
|
</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>
|
|
|
|
|
<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)}>
|
|
|
|
|
{label} <span className="mono">{data ? data.counts[t].toLocaleString() : ''}</span>
|
|
|
|
|
</button>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
<p className="muted small">{TABS.find((x) => x[0] === tab)![2]}</p>
|
|
|
|
|
<form
|
|
|
|
|
className="row"
|
|
|
|
|
onSubmit={(e) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
setPage(0);
|
|
|
|
|
setQuery(q.trim());
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<input className="input grow" style={{ minWidth: 160 }} placeholder="제목·가수 검색" value={q} onChange={(e) => setQ(e.target.value)} aria-label="제목·가수 검색" />
|
|
|
|
|
<button className="btn btn-sm">검색</button>
|
|
|
|
|
<label className="check small">
|
|
|
|
|
<input type="checkbox" checked={auto} onChange={(e) => setAuto(e.target.checked)} />
|
|
|
|
|
5초마다 새로고침
|
|
|
|
|
</label>
|
|
|
|
|
<span className="muted small" aria-live="polite">
|
|
|
|
|
{auto && hover ? '목록 위에서는 잠깐 멈춰요' : lastAt ? `${clock(lastAt)} 기준` : ''}
|
|
|
|
|
</span>
|
|
|
|
|
</form>
|
|
|
|
|
<div className="table-wrap" onMouseEnter={() => setHover(true)} onMouseLeave={() => setHover(false)}>
|
|
|
|
|
<table className="data-table">
|
|
|
|
|
<thead>
|
|
|
|
|
<tr>
|
|
|
|
|
<th>노래</th>
|
|
|
|
|
<th>붙은 영상</th>
|
|
|
|
|
<th>점수</th>
|
|
|
|
|
<th>출처</th>
|
|
|
|
|
<th>{tab === 'pending' ? '난이도' : '처리'}</th>
|
|
|
|
|
{tab === 'candidate' && <th />}
|
|
|
|
|
</tr>
|
|
|
|
|
</thead>
|
|
|
|
|
<tbody>
|
|
|
|
|
{data?.rows.map((r) => (
|
|
|
|
|
<tr key={r.id} className={selected === r.id ? 'sel' : ''} onClick={() => (setSelected(r.id), setEditing(false))} style={{ cursor: 'pointer' }}>
|
|
|
|
|
<td>
|
|
|
|
|
<button type="button" className="linklike" onClick={(e) => (e.stopPropagation(), setSelected(r.id), setEditing(false))}>
|
|
|
|
|
{r.title}
|
|
|
|
|
</button>
|
|
|
|
|
<div className="muted small">
|
|
|
|
|
{r.artist}
|
|
|
|
|
{r.year ? ` · ${r.year}` : ''}
|
|
|
|
|
</div>
|
|
|
|
|
</td>
|
|
|
|
|
<td className="small">
|
|
|
|
|
{r.youtube_id ? (
|
|
|
|
|
<>
|
|
|
|
|
{r.youtube_title ?? r.youtube_id}
|
|
|
|
|
<div className="muted">{r.youtube_channel ?? ''}</div>
|
|
|
|
|
</>
|
|
|
|
|
) : r.candidates.length ? (
|
|
|
|
|
<span className="muted">후보 {r.candidates.length}개 (붙은 영상 없음)</span>
|
|
|
|
|
) : (
|
|
|
|
|
<span className="muted">-</span>
|
|
|
|
|
)}
|
|
|
|
|
{tab === 'dead' && r.note && <div className="muted">{r.note}</div>}
|
|
|
|
|
</td>
|
|
|
|
|
<td className="mono">{r.score != null ? Math.round(r.score) : '-'}</td>
|
|
|
|
|
<td className="small">{r.youtube_source ? (SOURCE[r.youtube_source] ?? r.youtube_source) : '-'}</td>
|
|
|
|
|
<td className="small mono">{tab === 'pending' ? (r.level ? `★${r.level}` : '-') : ago(r.touched, now)}</td>
|
|
|
|
|
{tab === 'candidate' && (
|
|
|
|
|
<td>
|
|
|
|
|
{r.youtube_id && (
|
|
|
|
|
<button type="button" className="btn btn-sm btn-primary" onClick={(e) => (e.stopPropagation(), void quickConfirm(r))}>
|
|
|
|
|
확정
|
|
|
|
|
</button>
|
|
|
|
|
)}
|
|
|
|
|
</td>
|
|
|
|
|
)}
|
|
|
|
|
</tr>
|
|
|
|
|
))}
|
|
|
|
|
{data && !data.rows.length && (
|
|
|
|
|
<tr>
|
|
|
|
|
<td colSpan={6} className="muted">
|
|
|
|
|
{query ? '검색한 곡이 없어요.' : '이 종류의 곡이 없어요.'}
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
)}
|
|
|
|
|
</tbody>
|
|
|
|
|
</table>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="row">
|
|
|
|
|
<button type="button" className="btn btn-sm" disabled={page === 0} onClick={() => setPage(page - 1)}>
|
|
|
|
|
이전
|
|
|
|
|
</button>
|
|
|
|
|
<span className="muted small mono">
|
|
|
|
|
{page + 1} / {pages} · {data?.total.toLocaleString() ?? 0}곡
|
|
|
|
|
</span>
|
|
|
|
|
<button type="button" className="btn btn-sm" disabled={page + 1 >= pages} onClick={() => setPage(page + 1)}>
|
|
|
|
|
다음
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
{selected &&
|
|
|
|
|
(editing ? (
|
|
|
|
|
<SongEditor key={`e${selected}`} id={selected} genres={genres} onClose={() => setEditing(false)} onSaved={reload} />
|
|
|
|
|
) : (
|
|
|
|
|
<ReviewPanel key={selected} id={selected} onClose={() => setSelected(null)} onEdit={() => setEditing(true)} onChanged={afterAction} />
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** One song: listen, then 확정 / 다른 영상 / 확정 취소 / 원곡 없음 / 다시 찾기. */
|
|
|
|
|
function ReviewPanel({ id, onClose, onEdit, onChanged }: { id: number; onClose: () => void; onEdit: () => void; onChanged: (id: number, now: Tab | null) => void }) {
|
|
|
|
|
const [d, setD] = useState<Detail | null>(null);
|
|
|
|
|
const [listen, setListen] = useState<string | null>(null);
|
|
|
|
|
const [url, setUrl] = useState('');
|
|
|
|
|
const [busy, setBusy] = useState(false);
|
|
|
|
|
const [confirmRematch, setConfirmRematch] = useState(false);
|
|
|
|
|
const previewRef = useRef<{ time(): number | undefined } | null>(null);
|
|
|
|
|
const load = useCallback(
|
|
|
|
|
() =>
|
|
|
|
|
apiCall<Detail>('GET', `/api/admin/songs/${id}`).then(
|
|
|
|
|
(x) => (setD(x), x),
|
|
|
|
|
(e: Error) => (toast(e.message, 'error'), null),
|
|
|
|
|
),
|
|
|
|
|
[id],
|
|
|
|
|
);
|
|
|
|
|
useEffect(() => void load().then((x) => x && setListen(x.song.youtube_id ?? x.candidates[0]?.video_id ?? null)), [load]);
|
|
|
|
|
if (!d) return <aside className="song-panel muted">불러오는 중…</aside>;
|
|
|
|
|
const s = d.song;
|
|
|
|
|
const act = async (what: () => Promise<unknown>, done: string): Promise<boolean> => {
|
|
|
|
|
setBusy(true);
|
|
|
|
|
try {
|
|
|
|
|
await what();
|
|
|
|
|
toast(done);
|
|
|
|
|
const x = await load();
|
|
|
|
|
if (x) setListen(x.song.youtube_id ?? listen);
|
|
|
|
|
onChanged(id, x ? tabOf(x) : null);
|
|
|
|
|
return true;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
toast((e as Error).message, 'error');
|
|
|
|
|
return false;
|
|
|
|
|
} finally {
|
|
|
|
|
setBusy(false);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
const setVideo = (video: string) => act(() => apiCall('PATCH', `/api/admin/songs/${id}`, { youtube: video }), '이 영상으로 확정했어요.');
|
|
|
|
|
const rematch = () => act(() => apiCall('POST', '/api/admin/songs/bulk', { ids: [id], action: 'rematch' }), '다음 원곡 찾기 때 다시 찾아요.');
|
|
|
|
|
const [label, cls] = STATUS[s.youtube_status] ?? [s.youtube_status, ''];
|
|
|
|
|
return (
|
|
|
|
|
<aside className="song-panel stack" aria-label="원곡 확인">
|
|
|
|
|
<div className="row">
|
|
|
|
|
<h2 className="grow">{s.title}</h2>
|
|
|
|
|
<button type="button" className="btn btn-sm btn-ghost" onClick={onClose} aria-label="닫기">
|
|
|
|
|
✕
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
<p className="muted small">
|
|
|
|
|
{s.artist}
|
|
|
|
|
{s.year ? ` · ${s.year}` : ''} · #{s.id} ·{' '}
|
|
|
|
|
<button type="button" className="linklike small" onClick={onEdit}>
|
|
|
|
|
제목·가수 등 전체 편집
|
|
|
|
|
</button>
|
|
|
|
|
</p>
|
|
|
|
|
<p className="small">
|
|
|
|
|
<span className={`badge ${cls}`}>{tabOf(d) === 'noorig' ? '원곡 없음' : label}</span>{' '}
|
|
|
|
|
{s.youtube_id ? (
|
|
|
|
|
<span>
|
|
|
|
|
{s.youtube_title ?? s.youtube_id} <span className="muted">· {s.youtube_channel ?? ''} · {SOURCE[s.youtube_source ?? ''] ?? s.youtube_source ?? ''}</span>
|
|
|
|
|
</span>
|
|
|
|
|
) : (
|
|
|
|
|
<span className="muted">붙은 영상 없음</span>
|
|
|
|
|
)}
|
|
|
|
|
</p>
|
|
|
|
|
{listen && (
|
|
|
|
|
<>
|
|
|
|
|
<YtPreview key={listen} videoId={listen} start={0} apiRef={previewRef} />
|
|
|
|
|
{listen !== s.youtube_id && <p className="muted small">후보 영상을 듣는 중이에요.</p>}
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
<div className="row">
|
|
|
|
|
{s.youtube_status === 'candidate' && s.youtube_id && (
|
|
|
|
|
<button type="button" className="btn btn-sm btn-primary" disabled={busy} onClick={() => void setVideo(`https://youtu.be/${s.youtube_id}`)}>
|
|
|
|
|
✓ 지금 영상으로 확정
|
|
|
|
|
</button>
|
|
|
|
|
)}
|
|
|
|
|
{s.youtube_status === 'matched' && (
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
className="btn btn-sm"
|
|
|
|
|
disabled={busy}
|
|
|
|
|
onClick={() => void act(() => apiCall('POST', `/api/admin/youtube/${id}/unconfirm`), '확정을 취소했어요. 후보로 돌아가서 게임에는 안 나와요.')}
|
|
|
|
|
>
|
|
|
|
|
확정 취소
|
|
|
|
|
</button>
|
|
|
|
|
)}
|
|
|
|
|
{tabOf(d) !== 'noorig' && (
|
|
|
|
|
<button type="button" className="btn btn-sm" disabled={busy} onClick={() => void act(() => apiCall('POST', `/api/admin/youtube/${id}/no-original`), '원곡 없음으로 표시했어요. 자동 찾기가 건너뛰어요.')}>
|
|
|
|
|
원곡 없음으로 표시
|
|
|
|
|
</button>
|
|
|
|
|
)}
|
|
|
|
|
<button type="button" className="btn btn-sm" disabled={busy} onClick={() => (s.youtube_status === 'matched' ? setConfirmRematch(true) : void rematch())}>
|
|
|
|
|
다시 찾기
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
{d.candidates.length > 0 && (
|
|
|
|
|
<div className="stack" style={{ gap: 6 }}>
|
|
|
|
|
<span className="field">후보 영상 (점수 높은 순)</span>
|
|
|
|
|
{d.candidates.slice(0, 6).map((c) => (
|
|
|
|
|
<div key={c.video_id} className={`cand ${listen === c.video_id ? 'on' : ''}`}>
|
|
|
|
|
<span className="mono small">{Math.round(c.score)}</span>
|
|
|
|
|
<span className="grow">
|
|
|
|
|
{c.title ?? c.video_id}
|
|
|
|
|
<span className="muted small"> · {c.channel ?? (c.source === 'norabose' ? '노라보세 영상' : '')} · {mmss(c.duration_sec)}</span>
|
|
|
|
|
</span>
|
|
|
|
|
<button type="button" className="btn btn-sm btn-ghost" aria-label={`${c.title ?? c.video_id} 듣기`} onClick={() => setListen(c.video_id)}>
|
|
|
|
|
▶
|
|
|
|
|
</button>
|
|
|
|
|
{!(s.youtube_status === 'matched' && s.youtube_id === c.video_id) && (
|
|
|
|
|
<button type="button" className="btn btn-sm" disabled={busy} onClick={() => void setVideo(`https://youtu.be/${c.video_id}`)}>
|
|
|
|
|
확정
|
|
|
|
|
</button>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
<form
|
|
|
|
|
className="stack"
|
|
|
|
|
style={{ gap: 6 }}
|
|
|
|
|
onSubmit={(e) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
if (url.trim()) void setVideo(url.trim()).then((ok) => ok && setUrl(''));
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<label className="field">
|
|
|
|
|
유튜브 주소 붙여넣기
|
|
|
|
|
<input className="input" placeholder="https://youtu.be/…" value={url} onChange={(e) => setUrl(e.target.value)} />
|
|
|
|
|
</label>
|
|
|
|
|
<button className="btn btn-sm" disabled={busy || !url.trim()}>
|
|
|
|
|
이 주소로 확정
|
|
|
|
|
</button>
|
|
|
|
|
</form>
|
|
|
|
|
{confirmRematch && (
|
|
|
|
|
<ConfirmSheet
|
|
|
|
|
title="다시 찾을까요?"
|
|
|
|
|
body="지금 확정된 영상을 지우고 다음 원곡 찾기 때 다시 찾아요. 그 전까지 이 곡은 게임에 안 나와요."
|
|
|
|
|
confirm="다시 찾기"
|
|
|
|
|
onConfirm={() => void rematch()}
|
|
|
|
|
onClose={() => setConfirmRematch(false)}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</aside>
|
|
|
|
|
);
|
|
|
|
|
}
|