mirror of
https://github.com/MrSleeps/jellyfin-scene-search.git
synced 2026-11-17 23:41:28 +00:00
619 lines
25 KiB
HTML
619 lines
25 KiB
HTML
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
<title>Scene Search</title>
|
|
<style>
|
|
:root { color-scheme: dark; font-family: Inter, system-ui, sans-serif; background:#0f1115; color:#f4f5f7; }
|
|
* { box-sizing:border-box; }
|
|
body { margin:0; background:#0f1115; }
|
|
main { max-width:1180px; margin:0 auto; padding:28px 18px 60px; }
|
|
h1,h2 { margin-top:0; }
|
|
.muted { color:#9ca3af; }
|
|
.grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(300px,1fr)); gap:16px; }
|
|
.card { background:#181b21; border:1px solid #2a2f39; border-radius:14px; padding:18px; margin-bottom:16px; }
|
|
input,button { font:inherit; }
|
|
input[type=text],input[type=password] { width:100%; padding:11px 12px; border-radius:9px; border:1px solid #3a414d; background:#101318; color:#fff; }
|
|
button { padding:10px 14px; border:0; border-radius:9px; cursor:pointer; background:#3b82f6; color:white; font-weight:650; }
|
|
button.secondary { background:#303642; }
|
|
button.danger { background:#7f1d1d; }
|
|
button:disabled { opacity:.5; cursor:not-allowed; }
|
|
.row { display:flex; gap:10px; align-items:center; flex-wrap:wrap; }
|
|
.between { justify-content:space-between; }
|
|
.library { display:flex; gap:10px; align-items:flex-start; padding:9px 0; border-bottom:1px solid #282d36; }
|
|
.library:last-child { border-bottom:0; }
|
|
.library small { display:block; color:#9ca3af; margin-top:3px; }
|
|
progress { width:100%; height:18px; accent-color:#3b82f6; }
|
|
.big { font-size:1.7rem; font-weight:750; }
|
|
.status { margin-top:9px; min-height:1.4em; }
|
|
.error { color:#fca5a5; }
|
|
.ok { color:#86efac; }
|
|
#results { display:grid; gap:12px; }
|
|
.result { display:grid; grid-template-columns:180px 1fr; gap:14px; background:#12151a; border:1px solid #282d36; border-radius:11px; overflow:hidden; }
|
|
.result img { width:180px; height:102px; object-fit:cover; background:#08090b; }
|
|
.result .body { padding:12px 12px 12px 0; }
|
|
.result h3 { margin:0 0 6px; }
|
|
code { background:#101318; padding:2px 5px; border-radius:5px; }
|
|
@media(max-width:640px){ .result{grid-template-columns:1fr}.result img{width:100%;height:auto}.result .body{padding:0 12px 12px} }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<main>
|
|
<div class="row between">
|
|
<div>
|
|
<h1>Scene Search</h1>
|
|
<div class="muted">Jellyfin semantic scene search and indexing dashboard</div>
|
|
</div>
|
|
<div id="health" class="muted">Checking service…</div>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<div class="grid">
|
|
<div>
|
|
<label for="apiKey">API key</label>
|
|
<input id="apiKey" type="password" autocomplete="off" placeholder="SCENE_API_KEY (leave blank if disabled)">
|
|
</div>
|
|
<div style="align-self:end">
|
|
<div class="row">
|
|
<button id="saveKey" type="button">Save key locally</button>
|
|
<button id="clearKey" type="button" class="secondary">Clear</button>
|
|
</div>
|
|
<div class="muted" style="margin-top:6px">Stored only in this browser's local storage.</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="grid">
|
|
<section class="card">
|
|
<div class="row between">
|
|
<h2>Libraries</h2>
|
|
<div class="row">
|
|
<button id="selectAll" type="button" class="secondary">Select all</button>
|
|
<button id="refreshLibraries" type="button" class="secondary">Refresh</button>
|
|
</div>
|
|
</div>
|
|
<div class="muted" style="margin-bottom:8px">Apply selection removes deselected libraries directly from SQLite and Meilisearch. It does not rebuild the whole search index.</div>
|
|
<div id="libraries" class="muted">Loading…</div>
|
|
<div class="row" style="margin-top:14px">
|
|
<button id="applyLibraries" type="button" class="secondary">Apply selection only</button>
|
|
<button id="indexNow" type="button">Index selected libraries</button>
|
|
<label><input id="forceIndex" type="checkbox"> Force rebuild</label>
|
|
</div>
|
|
</section>
|
|
|
|
<section class="card">
|
|
<h2>Index progress</h2>
|
|
<div class="row between">
|
|
<div id="overallText" class="big">0%</div>
|
|
<div id="overallItems" class="muted">0 / 0 items</div>
|
|
</div>
|
|
<progress id="overallProgress" max="100" value="0"></progress>
|
|
<div id="indexStatus" class="status muted">Idle</div>
|
|
<div id="indexDetail" class="muted"></div>
|
|
<div id="indexReportActions" class="row" style="margin-top:12px">
|
|
<button id="reportFailed" type="button" class="secondary">Failed</button>
|
|
<button id="reportRemoved" type="button" class="secondary">Removed</button>
|
|
<button id="reportIndexed" type="button" class="secondary">Indexed</button>
|
|
</div>
|
|
<div id="indexReportMeta" class="muted" style="margin-top:10px"></div>
|
|
<div id="indexReportList" style="margin-top:8px;max-height:320px;overflow:auto"></div>
|
|
<button id="indexReportMore" type="button" class="secondary" style="margin-top:8px;display:none">Show more</button>
|
|
</section>
|
|
|
|
<section class="card">
|
|
<h2>Captioning</h2>
|
|
<div class="row between">
|
|
<div id="captionText" class="big">0%</div>
|
|
<div id="captionFrames" class="muted">0 / 0 frames</div>
|
|
</div>
|
|
<progress id="captionProgress" max="100" value="0"></progress>
|
|
<div id="captionStatus" class="status muted">Idle</div>
|
|
<div id="captionDetail" class="muted"></div>
|
|
<div class="row" style="margin-top:14px">
|
|
<button id="captionNow" type="button">Start / resume captioning</button>
|
|
<button id="captionStop" type="button" class="danger" disabled>Stop</button>
|
|
<label><input id="forceCaption" type="checkbox"> Force recaption</label>
|
|
</div>
|
|
</section>
|
|
</div>
|
|
|
|
<section class="card">
|
|
<h2>Search</h2>
|
|
<div class="row">
|
|
<div style="flex:1; min-width:220px"><input id="searchQuery" type="text" placeholder="e.g. woman standing outside"></div>
|
|
<button id="searchButton" type="button">Search scenes</button>
|
|
</div>
|
|
<div id="searchStatus" class="status muted"></div>
|
|
<div id="results"></div>
|
|
</section>
|
|
</main>
|
|
<script>
|
|
(() => {
|
|
const $ = id => document.getElementById(id);
|
|
let statusTimer = null;
|
|
let captionTimer = null;
|
|
let lastIndexRunning = false;
|
|
let lastCaptionRunning = false;
|
|
let captionLastStatus = null;
|
|
let reportCategory = null;
|
|
let reportOffset = 0;
|
|
let reportTotal = 0;
|
|
let thumbnailUrls = [];
|
|
|
|
$('apiKey').value = localStorage.getItem('sceneSearchApiKey') || '';
|
|
|
|
function headers(json=false) {
|
|
const h = {};
|
|
const key = $('apiKey').value.trim();
|
|
if (key) h.Authorization = 'Bearer ' + key;
|
|
if (json) h['Content-Type'] = 'application/json';
|
|
return h;
|
|
}
|
|
|
|
async function api(path, options={}) {
|
|
const response = await fetch(path, {...options, headers:{...headers(!!options.body), ...(options.headers||{})}});
|
|
if (!response.ok) {
|
|
let detail = '';
|
|
try { detail = (await response.json()).detail || ''; } catch (_) {}
|
|
throw new Error(detail || ('HTTP ' + response.status));
|
|
}
|
|
return response.status === 204 ? null : response.json();
|
|
}
|
|
|
|
async function refreshHealth() {
|
|
try {
|
|
const data = await fetch('/api/health').then(r => r.json());
|
|
$('health').textContent = 'Service ' + data.status + ' · ' + (data.frame_count || 0) + ' frames';
|
|
$('health').className = data.status === 'ok' ? 'ok' : 'muted';
|
|
} catch (e) {
|
|
$('health').textContent = 'Service unavailable';
|
|
$('health').className = 'error';
|
|
}
|
|
}
|
|
|
|
async function loadLibraries() {
|
|
$('libraries').textContent = 'Loading…';
|
|
try {
|
|
const data = await api('/api/jellyfin/libraries');
|
|
const libs = data.libraries || [];
|
|
if (!libs.length) {
|
|
$('libraries').textContent = 'No Jellyfin libraries returned.';
|
|
return;
|
|
}
|
|
$('libraries').innerHTML = libs.map(l => `
|
|
<label class="library">
|
|
<input type="checkbox" class="libraryCheck" value="${escapeHtml(l.id)}" ${l.indexed_items > 0 ? 'checked' : ''}>
|
|
<span><strong>${escapeHtml(l.name)}</strong><small>${l.indexed_items} indexed items · ${l.indexed_frames} frames</small></span>
|
|
</label>`).join('');
|
|
} catch (e) {
|
|
$('libraries').innerHTML = '<span class="error">' + escapeHtml(e.message) + '</span>';
|
|
}
|
|
}
|
|
|
|
function selectedLibraries() {
|
|
return Array.from(document.querySelectorAll('.libraryCheck:checked')).map(x => x.value);
|
|
}
|
|
|
|
function renderStatus(s) {
|
|
const percent = Number(s.overall_percent || (s.stage === 'complete' ? 100 : 0));
|
|
$('overallProgress').value = percent;
|
|
$('overallText').textContent = percent.toFixed(1).replace('.0','') + '%';
|
|
$('overallItems').textContent = (s.overall_items_completed || 0) + ' / ' + (s.overall_items_total || 0) + ' items';
|
|
|
|
if (s.running) {
|
|
$('indexStatus').className = 'status';
|
|
$('indexStatus').textContent = s.stage === 'sync' || s.stage === 'syncing'
|
|
? 'Rebuilding search index: ' + (s.documents_processed || 0)
|
|
: 'Indexing ' + (s.library || '');
|
|
const bits = [];
|
|
if (s.library_number && s.library_total) bits.push('library ' + s.library_number + '/' + s.library_total);
|
|
if (s.item) bits.push(s.item);
|
|
if (s.item_number && s.item_total) bits.push('item ' + s.item_number + '/' + s.item_total);
|
|
if (s.frames_total) bits.push((s.frames_processed || 0) + '/' + s.frames_total + ' frames');
|
|
if (s.stage === 'sync' || s.stage === 'syncing') bits.length = 0;
|
|
$('indexDetail').textContent = bits.join(' · ');
|
|
$('indexNow').disabled = true;
|
|
} else if (s.stage === 'failed') {
|
|
$('indexStatus').className = 'status error';
|
|
$('indexStatus').textContent = 'Failed: ' + (s.error || 'unknown error');
|
|
$('indexDetail').textContent = '';
|
|
$('indexNow').disabled = false;
|
|
} else if (s.stage === 'complete') {
|
|
$('indexStatus').className = 'status ok';
|
|
$('indexStatus').textContent = 'Complete';
|
|
$('indexDetail').textContent =
|
|
(s.indexed || 0) + ' indexed · ' + (s.skipped || 0) + ' unchanged · ' +
|
|
(s.failed || 0) + ' failed · ' + (s.pruned || 0) + ' removed';
|
|
$('indexNow').disabled = false;
|
|
} else {
|
|
$('indexStatus').className = 'status muted';
|
|
$('indexStatus').textContent = 'Idle';
|
|
$('indexDetail').textContent = '';
|
|
$('indexNow').disabled = false;
|
|
}
|
|
}
|
|
|
|
async function refreshIndexReportSummary() {
|
|
try {
|
|
const report = await api('/api/jellyfin/index/report?limit=1');
|
|
const summary = report.summary || {};
|
|
$('reportFailed').textContent = 'Failed (' + (summary.failed || 0) + ')';
|
|
$('reportRemoved').textContent = 'Removed (' + (summary.pruned || 0) + ')';
|
|
$('reportIndexed').textContent = 'Indexed (' + (summary.indexed || 0) + ')';
|
|
if (!report.available) {
|
|
$('indexReportMeta').textContent = 'No saved index report yet.';
|
|
}
|
|
} catch (_) {}
|
|
}
|
|
|
|
async function loadIndexReport(category, append=false) {
|
|
const offset = append ? reportOffset : 0;
|
|
try {
|
|
const report = await api(
|
|
'/api/jellyfin/index/report?category=' + encodeURIComponent(category) +
|
|
'&offset=' + offset + '&limit=200'
|
|
);
|
|
reportCategory = category;
|
|
reportOffset = offset + (report.items || []).length;
|
|
reportTotal = Number(report.total || 0);
|
|
|
|
const container = $('indexReportList');
|
|
if (!append) container.innerHTML = '';
|
|
|
|
for (const item of (report.items || [])) {
|
|
const row = document.createElement('div');
|
|
row.style.cssText = 'padding:8px 0;border-bottom:1px solid #282d36';
|
|
row.innerHTML =
|
|
'<strong>' + escapeHtml(item.title || item.item_id || '(unnamed)') + '</strong>' +
|
|
'<div class="muted">' +
|
|
escapeHtml(item.library || item.library_id || '') +
|
|
(item.item_id ? ' · ' + escapeHtml(item.item_id) : '') +
|
|
'</div>' +
|
|
'<div>' + escapeHtml(item.reason || '') + '</div>';
|
|
container.appendChild(row);
|
|
}
|
|
|
|
$('indexReportMeta').textContent =
|
|
reportTotal + ' ' + category + ' item' + (reportTotal === 1 ? '' : 's') +
|
|
(report.finished_at ? ' · last run ' + report.finished_at : '');
|
|
$('indexReportMore').style.display = reportOffset < reportTotal ? '' : 'none';
|
|
} catch (e) {
|
|
$('indexReportMeta').textContent = e.message;
|
|
}
|
|
}
|
|
|
|
async function refreshStatus() {
|
|
try {
|
|
const s = await api('/api/jellyfin/index/status');
|
|
const running = !!s.running;
|
|
renderStatus(s);
|
|
if (lastIndexRunning && !running) {
|
|
loadLibraries();
|
|
refreshHealth();
|
|
refreshIndexReportSummary();
|
|
}
|
|
lastIndexRunning = running;
|
|
return s;
|
|
} catch (e) {
|
|
$('indexStatus').className = 'status error';
|
|
$('indexStatus').textContent = e.message;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
async function applyLibrarySelection() {
|
|
const ids = selectedLibraries();
|
|
if (!ids.length && !window.confirm(
|
|
'No libraries are selected. This will remove all Jellyfin-backed Scene Search data from SQLite and Meilisearch. Continue?'
|
|
)) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
$('indexStatus').className = 'status';
|
|
$('indexStatus').textContent = 'Applying library selection...';
|
|
const result = await api('/api/jellyfin/libraries/selection', {
|
|
method:'POST',
|
|
body:JSON.stringify({library_ids:ids, force:false})
|
|
});
|
|
const removedLibraries = Number(result.removed_libraries || 0);
|
|
const removedMedia = Number(result.removed_media || 0);
|
|
$('indexStatus').className = 'status ok';
|
|
$('indexStatus').textContent = removedLibraries
|
|
? 'Selection applied: removed ' + removedLibraries + ' librar' +
|
|
(removedLibraries === 1 ? 'y' : 'ies') + ' and ' + removedMedia + ' media items'
|
|
: 'Selection applied: nothing to remove';
|
|
$('indexDetail').textContent = 'No full Meilisearch rebuild was run.';
|
|
await loadLibraries();
|
|
refreshHealth();
|
|
refreshIndexReportSummary();
|
|
} catch (e) {
|
|
$('indexStatus').className = 'status error';
|
|
$('indexStatus').textContent = e.message;
|
|
}
|
|
}
|
|
|
|
async function startIndex() {
|
|
const ids = selectedLibraries();
|
|
if (!ids.length && !window.confirm(
|
|
'No libraries are selected. This will remove all Jellyfin-backed Scene Search data from SQLite and Meilisearch. Continue?'
|
|
)) {
|
|
return;
|
|
}
|
|
try {
|
|
const s = await api('/api/jellyfin/index', {
|
|
method:'POST',
|
|
body:JSON.stringify({library_ids:ids, force:$('forceIndex').checked})
|
|
});
|
|
renderStatus(s);
|
|
lastIndexRunning = !!s.running;
|
|
if (!statusTimer) statusTimer = setInterval(refreshStatus, 2000);
|
|
} catch (e) {
|
|
$('indexStatus').className = 'status error';
|
|
$('indexStatus').textContent = e.message;
|
|
}
|
|
}
|
|
|
|
function renderCaptionStatus(s) {
|
|
captionLastStatus = s;
|
|
const percent = Number(s.percent || (s.stage === 'complete' ? 100 : 0));
|
|
$('captionProgress').value = percent;
|
|
$('captionText').textContent = percent.toFixed(1).replace('.0','') + '%';
|
|
$('captionFrames').textContent = (s.frames_completed || 0) + ' / ' + (s.frames_total || 0) + ' frames';
|
|
|
|
if (s.running) {
|
|
const starting = s.stage === 'starting';
|
|
const syncing = s.stage === 'syncing' || s.stage === 'sync';
|
|
const stopping = !!s.stop_requested;
|
|
$('captionNow').disabled = starting || syncing || stopping;
|
|
$('captionNow').textContent = starting
|
|
? 'Starting...'
|
|
: (syncing
|
|
? 'Finishing...'
|
|
: (stopping
|
|
? 'Stopping...'
|
|
: ((s.paused || s.pause_requested) ? 'Resume' : 'Pause')));
|
|
$('captionStop').disabled = syncing || stopping;
|
|
$('forceCaption').disabled = true;
|
|
$('captionStatus').className = 'status';
|
|
if (stopping) {
|
|
$('captionStatus').textContent = starting
|
|
? 'Stop requested; finishing preparation'
|
|
: 'Stop requested; finishing the current frame';
|
|
$('captionDetail').textContent = s.title || '';
|
|
} else if (starting) {
|
|
$('captionStatus').textContent = 'Starting captioning';
|
|
$('captionDetail').textContent =
|
|
s.preparing || 'Preparing caption job...';
|
|
} else if (s.paused) {
|
|
$('captionStatus').textContent = 'Captioning paused';
|
|
$('captionDetail').textContent =
|
|
(s.title ? s.title + (s.timestamp_ms != null ? ' at ' + formatTs(s.timestamp_ms) : '') : '') +
|
|
(s.frames_completed != null ? ' · ' + s.frames_completed + '/' + (s.frames_total || 0) + ' frames saved' : '');
|
|
} else if (s.pause_requested) {
|
|
$('captionStatus').textContent = 'Pause requested; finishing the current frame';
|
|
$('captionDetail').textContent = s.title || '';
|
|
} else if (s.stage === 'routing') {
|
|
$('captionStatus').textContent = 'Routing frames to caption models';
|
|
$('captionDetail').textContent = (s.frames_selected || s.frames_total || 0) + ' frames selected';
|
|
} else if (s.stage === 'syncing' || s.stage === 'sync') {
|
|
$('captionStatus').textContent = 'Rebuilding search index: ' + (s.documents_processed || 0);
|
|
$('captionDetail').textContent =
|
|
(s.frames_completed || 0) + ' captions saved, ' + (s.failed || 0) + ' failed';
|
|
} else {
|
|
$('captionStatus').textContent = 'Captioning: ' +
|
|
(s.title || 'current frame') +
|
|
(s.timestamp_ms != null ? ' at ' + formatTs(s.timestamp_ms) : '');
|
|
$('captionDetail').textContent =
|
|
(s.model || '') +
|
|
(s.route ? ', ' + s.route : '') +
|
|
', ' + (s.failed || 0) + ' failed';
|
|
}
|
|
} else if (s.stage === 'failed') {
|
|
$('captionNow').disabled = false;
|
|
$('captionNow').textContent = 'Start / resume captioning';
|
|
$('captionStop').disabled = true;
|
|
$('forceCaption').disabled = false;
|
|
$('captionStatus').className = 'status error';
|
|
$('captionStatus').textContent = 'Failed: ' + (s.error || 'unknown error');
|
|
$('captionDetail').textContent = '';
|
|
} else if (s.stage === 'complete') {
|
|
$('captionNow').disabled = false;
|
|
$('captionNow').textContent = 'Start / resume captioning';
|
|
$('captionStop').disabled = true;
|
|
$('forceCaption').disabled = false;
|
|
$('captionStatus').className = 'status ok';
|
|
$('captionStatus').textContent =
|
|
'Complete: ' + (s.frames_completed || 0) + ' saved, ' + (s.failed || 0) + ' failed';
|
|
$('captionDetail').textContent =
|
|
(s.retained || 0) + ' existing captions retained';
|
|
} else if (s.stage === 'stopped') {
|
|
$('captionNow').disabled = false;
|
|
$('captionNow').textContent = 'Start / resume captioning';
|
|
$('captionStop').disabled = true;
|
|
$('forceCaption').disabled = false;
|
|
$('captionStatus').className = 'status muted';
|
|
$('captionStatus').textContent = 'Stopped';
|
|
$('captionDetail').textContent =
|
|
(s.frames_completed || 0) +
|
|
' captions saved. Start / resume continues the remaining frames; search updates after a later completed run.';
|
|
} else {
|
|
$('captionNow').disabled = false;
|
|
$('captionNow').textContent = 'Start / resume captioning';
|
|
$('captionStop').disabled = true;
|
|
$('forceCaption').disabled = false;
|
|
$('captionStatus').className = 'status muted';
|
|
$('captionStatus').textContent = 'Idle';
|
|
$('captionDetail').textContent = '';
|
|
}
|
|
}
|
|
|
|
async function refreshCaptionStatus() {
|
|
try {
|
|
const s = await api('/api/caption/status');
|
|
const running = !!s.running;
|
|
renderCaptionStatus(s);
|
|
if (lastCaptionRunning && !running) {
|
|
refreshHealth();
|
|
}
|
|
lastCaptionRunning = running;
|
|
return s;
|
|
} catch (e) {
|
|
$('captionStatus').className = 'status error';
|
|
$('captionStatus').textContent = e.message;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
async function startCaption() {
|
|
const ids = selectedLibraries();
|
|
if (!ids.length) {
|
|
$('captionStatus').className = 'status error';
|
|
$('captionStatus').textContent = 'Select at least one library.';
|
|
return;
|
|
}
|
|
try {
|
|
$('captionNow').disabled = true;
|
|
$('captionNow').textContent = 'Starting...';
|
|
$('captionStop').disabled = true;
|
|
$('forceCaption').disabled = true;
|
|
$('captionStatus').className = 'status';
|
|
$('captionStatus').textContent = 'Starting captioning';
|
|
$('captionDetail').textContent = 'Sending start request...';
|
|
|
|
const s = await api('/api/caption', {
|
|
method:'POST',
|
|
body:JSON.stringify({library_ids:ids, force:$('forceCaption').checked})
|
|
});
|
|
renderCaptionStatus(s);
|
|
lastCaptionRunning = !!s.running;
|
|
if (!captionTimer) captionTimer = setInterval(refreshCaptionStatus, 2000);
|
|
} catch (e) {
|
|
$('captionStatus').className = 'status error';
|
|
$('captionStatus').textContent = e.message;
|
|
}
|
|
}
|
|
|
|
async function captionAction() {
|
|
if (!captionLastStatus || !captionLastStatus.running) {
|
|
await startCaption();
|
|
return;
|
|
}
|
|
|
|
if (captionLastStatus.stage === 'syncing' || captionLastStatus.stage === 'sync') {
|
|
return;
|
|
}
|
|
|
|
const resume = captionLastStatus.paused || captionLastStatus.pause_requested;
|
|
try {
|
|
const s = await api(resume ? '/api/caption/resume' : '/api/caption/pause', {
|
|
method:'POST'
|
|
});
|
|
renderCaptionStatus(s);
|
|
lastCaptionRunning = !!s.running;
|
|
} catch (e) {
|
|
$('captionStatus').className = 'status error';
|
|
$('captionStatus').textContent = e.message;
|
|
}
|
|
}
|
|
|
|
async function stopCaption() {
|
|
if (!captionLastStatus || !captionLastStatus.running) return;
|
|
if (captionLastStatus.stage === 'syncing' || captionLastStatus.stage === 'sync') return;
|
|
|
|
try {
|
|
const s = await api('/api/caption/stop', {method:'POST'});
|
|
renderCaptionStatus(s);
|
|
lastCaptionRunning = !!s.running;
|
|
} catch (e) {
|
|
$('captionStatus').className = 'status error';
|
|
$('captionStatus').textContent = e.message;
|
|
}
|
|
}
|
|
|
|
function formatTs(ms) {
|
|
const seconds = Math.floor((ms || 0) / 1000);
|
|
const h = Math.floor(seconds / 3600);
|
|
const m = Math.floor((seconds % 3600) / 60);
|
|
const s = seconds % 60;
|
|
return [h,m,s].map(x => String(x).padStart(2,'0')).join(':');
|
|
}
|
|
|
|
async function loadThumbnail(frameId, img) {
|
|
try {
|
|
const response = await fetch('/api/frames/' + encodeURIComponent(frameId) + '/thumbnail', {headers:headers()});
|
|
if (!response.ok) return;
|
|
const blob = await response.blob();
|
|
const url = URL.createObjectURL(blob);
|
|
thumbnailUrls.push(url);
|
|
img.src = url;
|
|
} catch (_) {}
|
|
}
|
|
|
|
async function search() {
|
|
const q = $('searchQuery').value.trim();
|
|
if (!q) return;
|
|
thumbnailUrls.forEach(URL.revokeObjectURL);
|
|
thumbnailUrls = [];
|
|
$('results').innerHTML = '';
|
|
$('searchStatus').textContent = 'Searching…';
|
|
try {
|
|
const data = await api('/api/search?q=' + encodeURIComponent(q) + '&scene_limit=20&item_limit=10');
|
|
const scenes = data.scenes || [];
|
|
$('searchStatus').textContent = scenes.length + ' scene match' + (scenes.length === 1 ? '' : 'es');
|
|
for (const scene of scenes) {
|
|
const el = document.createElement('article');
|
|
el.className = 'result';
|
|
el.innerHTML = '<img alt=""><div class="body"><h3>' + escapeHtml(scene.title || 'Untitled') +
|
|
' <span class="muted">@ ' + formatTs(scene.timestamp_ms) + '</span></h3><div>' +
|
|
escapeHtml(scene.caption || 'No caption yet') + '</div><div class="muted" style="margin-top:6px">score ' +
|
|
(scene.ranking_score == null ? '—' : Number(scene.ranking_score).toFixed(3)) + '</div></div>';
|
|
$('results').appendChild(el);
|
|
if (scene.frame_id) loadThumbnail(scene.frame_id, el.querySelector('img'));
|
|
}
|
|
} catch (e) {
|
|
$('searchStatus').className = 'status error';
|
|
$('searchStatus').textContent = e.message;
|
|
}
|
|
}
|
|
|
|
function escapeHtml(value) {
|
|
return String(value == null ? '' : value).replace(/[&<>"']/g, c => ({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]));
|
|
}
|
|
|
|
$('saveKey').onclick = () => {
|
|
localStorage.setItem('sceneSearchApiKey', $('apiKey').value.trim());
|
|
window.location.reload();
|
|
};
|
|
$('clearKey').onclick = () => {
|
|
localStorage.removeItem('sceneSearchApiKey');
|
|
window.location.reload();
|
|
};
|
|
$('refreshLibraries').onclick = loadLibraries;
|
|
$('selectAll').onclick = () => document.querySelectorAll('.libraryCheck').forEach(x => x.checked = true);
|
|
$('applyLibraries').onclick = applyLibrarySelection;
|
|
$('indexNow').onclick = startIndex;
|
|
$('captionNow').onclick = captionAction;
|
|
$('captionStop').onclick = stopCaption;
|
|
$('reportFailed').onclick = () => loadIndexReport('failed');
|
|
$('reportRemoved').onclick = () => loadIndexReport('removed');
|
|
$('reportIndexed').onclick = () => loadIndexReport('indexed');
|
|
$('indexReportMore').onclick = () => {
|
|
if (reportCategory) loadIndexReport(reportCategory, true);
|
|
};
|
|
$('searchButton').onclick = search;
|
|
$('searchQuery').addEventListener('keydown', e => { if (e.key === 'Enter') search(); });
|
|
|
|
refreshHealth();
|
|
loadLibraries();
|
|
refreshStatus();
|
|
refreshCaptionStatus();
|
|
refreshIndexReportSummary();
|
|
statusTimer = setInterval(refreshStatus, 2000);
|
|
captionTimer = setInterval(refreshCaptionStatus, 2000);
|
|
})();
|
|
</script>
|
|
</body>
|
|
</html>
|