Files
jellyfin-scene-search/jellyfin-plugin/Jellyfin.Plugin.SceneSearch/Configuration/configPage.html
T
2026-10-07 17:51:43 +01:00

835 lines
46 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<title>Scene Search</title>
</head>
<body>
<div id="sceneSearchConfigPage" data-role="page" class="page type-interior pluginConfigurationPage" data-require="emby-input,emby-button,emby-checkbox">
<div data-role="content">
<div class="content-primary">
<h1>Scene Search</h1>
<p>Blend local semantic scene matches into normal Jellyfin search results alongside other search providers.</p>
<form class="sceneSearchConfigForm">
<label class="checkboxContainer">
<input is="emby-checkbox" type="checkbox" id="enabled" />
<span>Enable Scene Search provider</span>
</label>
<div class="inputContainer">
<input is="emby-input" type="text" id="apiUrl" required label="Scene Search API URL" />
<div class="fieldDescription">Usually http://127.0.0.1:8097 when Jellyfin and scene-search run on the same host.</div>
</div>
<div class="inputContainer">
<input is="emby-input" type="password" id="apiKey" label="API Key" />
<div class="fieldDescription">Must match SCENE_API_KEY in jellyfin-scene-search.</div>
</div>
<div class="inputContainer">
<input is="emby-input" type="text" id="searchPrefix" label="Optional Scene Prefix" />
<div class="fieldDescription">Normal searches include Scene Search alongside other providers. When this optional prefix is present, Scene Search strips it and strongly prefers its scene matches in Jellyfin's combined results; default: scene:.</div>
</div>
<div class="inputContainer">
<input is="emby-input" type="number" id="maxResults" min="1" max="50" step="1" label="Maximum Results" />
</div>
<div class="inputContainer">
<input is="emby-input" type="number" id="timeoutSeconds" min="5" max="300" step="1" label="API Timeout (seconds)" />
</div>
<h2>Jellyfin Search Diagnostics</h2>
<div class="fieldDescription" style="margin-bottom:1em;">
Tests the exact Jellyfin integration path: provider registration, the configured Scene Search API, and Jellyfin's own search manager. This uses the currently saved plugin settings.
</div>
<div class="inputContainer">
<input is="emby-input" type="text" id="searchDiagnosticQuery" label="Test Search Query" value="person standing outside" />
</div>
<button is="emby-button" type="button" id="testSearchDiagnostics" class="raised">
<span>Test Jellyfin search</span>
</button>
<div id="searchDiagnosticStatus" class="fieldDescription" style="margin-top:.75em;"></div>
<pre id="searchDiagnosticResult" style="white-space:pre-wrap;max-height:24em;overflow:auto;margin-bottom:1.5em;"></pre>
<h2>Indexed Libraries</h2>
<div class="fieldDescription" style="margin-bottom:1em;">
Choose which Jellyfin libraries Scene Search should keep indexed. Apply selection only removes deselected libraries directly from Scene Search SQLite and Meilisearch without rebuilding the full Meilisearch index. Selection is stored in this plugin, not in the Python .env file.
</div>
<div id="libraryList">Loading libraries…</div>
<div style="margin-top:1em; margin-bottom:1em;">
<button is="emby-button" type="button" id="applyLibraries" class="raised">
<span>Apply selection only</span>
</button>
<button is="emby-button" type="button" id="indexNow" class="raised">
<span>Index selected libraries</span>
</button>
<label class="checkboxContainer" style="margin-top:1em;">
<input is="emby-checkbox" type="checkbox" id="forceIndex" />
<span>Force rebuild already-indexed items</span>
</label>
</div>
<div style="margin-bottom:.5em;">
<div style="display:flex;justify-content:space-between;gap:1em;">
<strong id="overallProgressText">0%</strong>
<span id="overallProgressItems" class="fieldDescription">0 / 0 items</span>
</div>
<progress id="overallProgress" max="100" value="0" style="width:100%;height:1.1em;"></progress>
</div>
<div id="indexStatus" class="fieldDescription" style="margin-bottom:.75em;"></div>
<div style="margin-bottom:.5em;">
<button is="emby-button" type="button" id="reportFailed" class="raised"><span>Failed</span></button>
<button is="emby-button" type="button" id="reportRemoved" class="raised"><span>Removed</span></button>
<button is="emby-button" type="button" id="reportIndexed" class="raised"><span>Indexed</span></button>
</div>
<div id="indexReportMeta" class="fieldDescription" style="margin-bottom:.5em;"></div>
<div id="indexReportList" style="max-height:20em;overflow:auto;margin-bottom:.5em;"></div>
<button is="emby-button" type="button" id="indexReportMore" class="raised" style="display:none;margin-bottom:1.5em;">
<span>Show more</span>
</button>
<h2>Captioning</h2>
<div class="fieldDescription" style="margin-bottom:1em;">
Send indexed frames from the selected libraries to the configured AI caption models. Start / resume skips frames that already have a current caption.
</div>
<div style="margin-bottom:1em;">
<button is="emby-button" type="button" id="captionNow" class="raised">
<span>Start / resume captioning</span>
</button>
<button is="emby-button" type="button" id="captionStop" class="raised" disabled>
<span>Stop</span>
</button>
<label class="checkboxContainer" style="margin-top:1em;">
<input is="emby-checkbox" type="checkbox" id="forceCaption" />
<span>Force recaption existing frames</span>
</label>
</div>
<div style="margin-bottom:.5em;">
<div style="display:flex;justify-content:space-between;gap:1em;">
<strong id="captionProgressText">0%</strong>
<span id="captionProgressFrames" class="fieldDescription">0 / 0 frames</span>
</div>
<progress id="captionProgress" max="100" value="0" style="width:100%;height:1.1em;"></progress>
</div>
<div id="captionStatus" class="fieldDescription" style="margin-bottom:.5em;">Captioning idle.</div>
<div id="captionDetail" class="fieldDescription" style="margin-bottom:1.5em;"></div>
<button is="emby-button" type="submit" class="raised button-submit block">
<span>Save</span>
</button>
</form>
</div>
</div>
<script type="text/javascript">
(function () {
var pluginId = "2d8d1bb5-3f0c-4d5a-9d59-934463c06d35";
var page = document.querySelector('#sceneSearchConfigPage');
var currentConfig = null;
var statusTimer = null;
var captionTimer = null;
var lastIndexRunning = false;
var lastCaptionRunning = false;
var lastCaptionStatus = null;
var reportCategory = null;
var reportOffset = 0;
var reportTotal = 0;
function selectedLibraryIds() {
return Array.prototype.slice.call(
page.querySelectorAll('.sceneLibrary:checked')
).map(function (el) { return el.value; });
}
function runSearchDiagnostics() {
var query = page.querySelector('#searchDiagnosticQuery').value.trim();
var status = page.querySelector('#searchDiagnosticStatus');
var output = page.querySelector('#searchDiagnosticResult');
if (!query) {
status.textContent = 'Enter a test query first.';
output.textContent = '';
return;
}
status.textContent = 'Testing Jellyfin search path…';
output.textContent = '';
ApiClient.ajax({
type: 'GET',
url: ApiClient.getUrl(
'Plugins/SceneSearch/SearchDiagnostics',
{ query: query }
)
}).then(function (data) {
var providers = (data.registered_providers || []).map(function (provider) {
return provider.name + ' (' + provider.kind + ', priority ' + provider.priority + ')';
});
var lines = [
'Provider registered: ' + (data.provider_registered ? 'YES' : 'NO'),
'API configured: ' + (data.api_configured ? 'YES' : 'NO'),
'Backend query: ' + (data.backend_query || ''),
'Registered providers: ' + (providers.join(', ') || '(none)'),
'',
'Scene Search API results: ' + (data.api_result_count || 0),
'Jellyfin core results: ' + (data.core_result_count || 0),
'Resolved in Jellyfin DB: ' + (data.resolved_core_results || 0),
'API/core overlap: ' + (data.api_core_overlap || 0)
];
var apiResults = data.api_results || [];
if (apiResults.length) {
lines.push('', 'Top API results:');
apiResults.slice(0, 10).forEach(function (item) {
lines.push(
'- ' + (item.title || '(untitled)') +
' [' + (item.item_type || '?') + '] ' +
(item.item_id || '')
);
});
}
var coreResults = data.core_results || [];
if (coreResults.length) {
lines.push('', 'Top Jellyfin core results:');
coreResults.slice(0, 10).forEach(function (item) {
lines.push(
'- ' + (item.title || item.item_id || '(unknown)') +
' [' + (item.item_type || '?') + '] ' +
'score=' + Number(item.score || 0).toFixed(3) +
', resolved=' + (item.resolved ? 'yes' : 'no') +
', from API=' + (item.returned_by_api ? 'yes' : 'no')
);
});
}
output.textContent = lines.join('\n');
if (!data.provider_registered) {
status.textContent = 'Scene Search is NOT registered with Jellyfin search. Restart Jellyfin after installing/updating the plugin.';
} else if (!data.api_configured) {
status.textContent = 'The Scene Search provider is registered, but its API configuration is not valid.';
} else if (!data.api_result_count) {
status.textContent = 'Jellyfin can reach the integration, but the Scene Search API returned no grouped item results for this query.';
} else if (!data.core_result_count) {
status.textContent = 'The API returned items, but Jellyfin search returned none. Check item IDs/types and Jellyfin server logs.';
} else if (!data.resolved_core_results) {
status.textContent = 'Jellyfin received candidate IDs, but none resolve to current library items. Re-index the affected Jellyfin libraries.';
} else {
status.textContent = 'The Scene Search provider is registered and Jellyfin core is returning resolvable matches.';
}
}).catch(function (error) {
status.textContent = 'Search diagnostic failed. Check the Jellyfin server log.';
output.textContent = error && error.message ? error.message : '';
});
}
function renderLibraries(data) {
var container = page.querySelector('#libraryList');
var selected = new Set((currentConfig && currentConfig.SelectedLibraryIds) || []);
var libraries = (data && data.libraries) || [];
if (!libraries.length) {
container.textContent = 'No Jellyfin video libraries were returned by the Scene Search API.';
return;
}
container.innerHTML = libraries.map(function (library) {
var checked = selected.has(library.id) ? ' checked' : '';
var detail = library.indexed_items + ' indexed item' +
(library.indexed_items === 1 ? '' : 's') + ', ' +
library.indexed_frames + ' frames';
return '<label class="checkboxContainer">' +
'<input type="checkbox" class="sceneLibrary" value="' +
library.id.replace(/"/g, '&quot;') + '"' + checked + ' />' +
'<span>' + library.name.replace(/</g, '&lt;').replace(/>/g, '&gt;') + '</span>' +
'<div class="fieldDescription" style="margin-left:3em;">' + detail + '</div>' +
'</label>';
}).join('');
}
function renderStatus(status) {
var container = page.querySelector('#indexStatus');
var progress = page.querySelector('#overallProgress');
var progressText = page.querySelector('#overallProgressText');
var progressItems = page.querySelector('#overallProgressItems');
if (!status) {
container.textContent = 'Index status unavailable.';
progress.value = 0;
progressText.textContent = '0%';
progressItems.textContent = '0 / 0 items';
return;
}
var percent = Number(status.overall_percent || (status.stage === 'complete' ? 100 : 0));
progress.value = percent;
progressText.textContent = percent.toFixed(1).replace('.0', '') + '%';
progressItems.textContent =
(status.overall_items_completed || 0) + ' / ' +
(status.overall_items_total || 0) + ' items';
if (status.running) {
var parts = ['Indexing'];
if (status.library) {
parts.push(status.library);
}
if (status.item) {
parts.push(status.item);
}
if (status.item_number && status.item_total) {
parts.push(status.item_number + '/' + status.item_total);
}
if (status.frames_total) {
parts.push((status.frames_processed || 0) + '/' + status.frames_total + ' frames');
}
if (status.stage === 'sync' || status.stage === 'syncing') {
parts = [
'Rebuilding search index: ' + (status.documents_processed || 0)
];
}
container.textContent = parts.join(', ');
} else if (status.stage === 'failed') {
container.textContent = 'Index failed: ' + (status.error || 'unknown error');
} else if (status.stage === 'complete') {
container.textContent =
'Index complete: ' + (status.indexed || 0) + ' indexed, ' +
(status.skipped || 0) + ' unchanged, ' +
(status.failed || 0) + ' failed, ' +
(status.pruned || 0) + ' removed.';
} else {
container.textContent = 'Index idle.';
}
}
function refreshIndexReportSummary() {
return ApiClient.getJSON(
ApiClient.getUrl('Plugins/SceneSearch/IndexReport') + '?limit=1'
).then(function (report) {
var summary = (report && report.summary) || {};
page.querySelector('#reportFailed span').textContent =
'Failed (' + (summary.failed || 0) + ')';
page.querySelector('#reportRemoved span').textContent =
'Removed (' + (summary.pruned || 0) + ')';
page.querySelector('#reportIndexed span').textContent =
'Indexed (' + (summary.indexed || 0) + ')';
if (!report || !report.available) {
page.querySelector('#indexReportMeta').textContent =
'No saved index report yet.';
}
}).catch(function () {
// Status remains usable even if no report is available.
});
}
function loadIndexReport(category, append) {
append = !!append;
var offset = append ? reportOffset : 0;
var url = ApiClient.getUrl('Plugins/SceneSearch/IndexReport') +
'?category=' + encodeURIComponent(category) +
'&offset=' + offset + '&limit=200';
return ApiClient.getJSON(url).then(function (report) {
reportCategory = category;
var items = (report && report.items) || [];
reportOffset = offset + items.length;
reportTotal = Number((report && report.total) || 0);
var container = page.querySelector('#indexReportList');
if (!append) {
container.innerHTML = '';
}
items.forEach(function (item) {
var row = document.createElement('div');
row.style.cssText =
'padding:.65em 0;border-bottom:1px solid rgba(255,255,255,.12)';
var title = document.createElement('strong');
title.textContent = item.title || item.item_id || '(unnamed)';
row.appendChild(title);
var meta = document.createElement('div');
meta.className = 'fieldDescription';
meta.textContent =
(item.library || item.library_id || '') +
(item.item_id ? ' · ' + item.item_id : '');
row.appendChild(meta);
var reason = document.createElement('div');
reason.textContent = item.reason || '';
row.appendChild(reason);
container.appendChild(row);
});
page.querySelector('#indexReportMeta').textContent =
reportTotal + ' ' + category + ' item' +
(reportTotal === 1 ? '' : 's') +
(report.finished_at ? ' · last run ' + report.finished_at : '');
page.querySelector('#indexReportMore').style.display =
reportOffset < reportTotal ? '' : 'none';
}).catch(function () {
page.querySelector('#indexReportMeta').textContent =
'Could not load the saved index report.';
});
}
function refreshStatus() {
return ApiClient.getJSON(ApiClient.getUrl('Plugins/SceneSearch/IndexStatus'))
.then(function (status) {
var running = !!(status && status.running);
renderStatus(status);
if (lastIndexRunning && !running) {
loadLibraries();
refreshIndexReportSummary();
}
lastIndexRunning = running;
})
.catch(function () {
renderStatus(null);
});
}
function formatTs(ms) {
var total = Math.floor((ms || 0) / 1000);
var hours = Math.floor(total / 3600);
var minutes = Math.floor((total % 3600) / 60);
var seconds = total % 60;
return [hours, minutes, seconds].map(function (value) {
return String(value).padStart(2, '0');
}).join(':');
}
function renderCaptionStatus(status) {
lastCaptionStatus = status;
var progress = page.querySelector('#captionProgress');
var progressText = page.querySelector('#captionProgressText');
var progressFrames = page.querySelector('#captionProgressFrames');
var container = page.querySelector('#captionStatus');
var detail = page.querySelector('#captionDetail');
var button = page.querySelector('#captionNow');
var stopButton = page.querySelector('#captionStop');
var forceCheckbox = page.querySelector('#forceCaption');
if (!status) {
progress.value = 0;
progressText.textContent = '0%';
progressFrames.textContent = '0 / 0 frames';
container.textContent = 'Caption status unavailable.';
detail.textContent = '';
button.disabled = false;
button.querySelector('span').textContent = 'Start / resume captioning';
stopButton.disabled = true;
forceCheckbox.disabled = false;
return;
}
var percent = Number(status.percent || (status.stage === 'complete' ? 100 : 0));
progress.value = percent;
progressText.textContent = percent.toFixed(1).replace('.0', '') + '%';
progressFrames.textContent =
(status.frames_completed || 0) + ' / ' +
(status.frames_total || 0) + ' ' +
(status.work_unit === 'windows' ? 'windows' : 'frames');
if (status.running) {
var starting = status.stage === 'starting';
var syncing = status.stage === 'syncing' || status.stage === 'sync';
var stopping = !!status.stop_requested;
button.disabled = starting || syncing || stopping;
button.querySelector('span').textContent = starting
? 'Starting...'
: (syncing
? 'Finishing...'
: (stopping
? 'Stopping...'
: ((status.paused || status.pause_requested) ? 'Resume' : 'Pause')));
stopButton.disabled = syncing || stopping;
forceCheckbox.disabled = true;
if (stopping) {
container.textContent = starting
? 'Stop requested; finishing preparation.'
: 'Stop requested; finishing the current frame.';
detail.textContent = status.title || '';
} else if (starting) {
container.textContent = 'Starting captioning.';
detail.textContent =
status.preparing || 'Preparing caption job...';
} else if (status.paused) {
container.textContent = 'Captioning paused.';
detail.textContent =
(status.title || '') +
(status.timestamp_ms != null ? ' at ' + formatTs(status.timestamp_ms) : '') +
' · ' + (status.frames_completed || 0) + '/' +
(status.frames_total || 0) + ' ' +
(status.work_unit === 'windows' ? 'windows' : 'frames') +
' saved.';
} else if (status.pause_requested) {
container.textContent = 'Pause requested; finishing the current ' +
(status.work_unit === 'windows' ? 'window.' : 'frame.');
detail.textContent = status.title || '';
} else if (status.stage === 'routing') {
container.textContent = 'Routing frames to caption models.';
detail.textContent = (status.frames_selected || status.frames_total || 0) + ' frames selected.';
} else if (status.stage === 'syncing' || status.stage === 'sync') {
container.textContent = 'Rebuilding search index: ' + (status.documents_processed || 0);
detail.textContent =
(status.frames_completed || 0) + ' captions saved, ' +
(status.failed || 0) + ' failed.';
} else {
container.textContent = 'Captioning: ' +
(status.title || 'current frame') +
(status.timestamp_ms != null ? ' at ' + formatTs(status.timestamp_ms) : '');
detail.textContent =
(status.model || '') +
(status.route ? ', ' + status.route : '') +
', ' + (status.failed || 0) + ' failed, search updated: ' +
(status.meili_documents_updated || 0) + '.';
}
} else if (status.stage === 'failed') {
button.disabled = false;
button.querySelector('span').textContent = 'Start / resume captioning';
stopButton.disabled = true;
forceCheckbox.disabled = false;
container.textContent = 'Captioning failed: ' + (status.error || 'unknown error');
detail.textContent = '';
} else if (status.stage === 'complete') {
button.disabled = false;
button.querySelector('span').textContent = 'Start / resume captioning';
stopButton.disabled = true;
forceCheckbox.disabled = false;
container.textContent =
'Captioning complete: ' + (status.frames_completed || 0) +
' saved, ' + (status.failed || 0) + ' failed.';
detail.textContent =
(status.retained || 0) + ' existing captions retained, ' +
(status.meili_documents_updated || 0) + ' search documents updated' +
((status.meili_sync_pending || 0)
? ', ' + status.meili_sync_pending + ' search updates still pending'
: '') +
(status.meili_sync_error
? ' · last search sync error: ' + status.meili_sync_error
: '') +
'.';
} else if (status.stage === 'stopped') {
button.disabled = false;
button.querySelector('span').textContent = 'Start / resume captioning';
stopButton.disabled = true;
forceCheckbox.disabled = false;
container.textContent = 'Captioning stopped.';
detail.textContent =
(status.frames_completed || 0) + ' captions saved, ' +
(status.meili_documents_updated || 0) + ' search documents updated' +
((status.meili_sync_pending || 0)
? ', ' + status.meili_sync_pending + ' search updates still pending'
: '') +
'. Start / resume continues the remaining frames.';
} else {
button.disabled = false;
button.querySelector('span').textContent = 'Start / resume captioning';
stopButton.disabled = true;
forceCheckbox.disabled = false;
container.textContent = 'Captioning idle.';
detail.textContent = '';
}
}
function refreshCaptionStatus() {
return ApiClient.getJSON(ApiClient.getUrl('Plugins/SceneSearch/CaptionStatus'))
.then(function (status) {
var running = !!(status && status.running);
renderCaptionStatus(status);
lastCaptionRunning = running;
})
.catch(function () {
renderCaptionStatus(null);
});
}
function loadLibraries() {
return ApiClient.getJSON(ApiClient.getUrl('Plugins/SceneSearch/Libraries'))
.then(renderLibraries)
.catch(function () {
page.querySelector('#libraryList').textContent =
'Could not load libraries. Check the Scene Search API URL/key and that the Python service is running.';
});
}
page.addEventListener('pageshow', function () {
Dashboard.showLoadingMsg();
ApiClient.getPluginConfiguration(pluginId).then(function (config) {
currentConfig = config;
page.querySelector('#enabled').checked = config.Enabled;
page.querySelector('#apiUrl').value = config.ApiUrl || 'http://127.0.0.1:8097';
page.querySelector('#apiKey').value = config.ApiKey || '';
page.querySelector('#searchPrefix').value = config.SearchPrefix || 'scene:';
page.querySelector('#maxResults').value = config.MaxResults || 20;
page.querySelector('#timeoutSeconds').value = config.TimeoutSeconds || 60;
return Promise.all([
loadLibraries(),
refreshStatus(),
refreshCaptionStatus(),
refreshIndexReportSummary()
]);
}).then(function () {
if (!statusTimer) {
statusTimer = setInterval(refreshStatus, 2000);
}
if (!captionTimer) {
captionTimer = setInterval(refreshCaptionStatus, 2000);
}
}).finally(function () {
Dashboard.hideLoadingMsg();
});
});
page.addEventListener('pagehide', function () {
if (statusTimer) {
clearInterval(statusTimer);
statusTimer = null;
}
if (captionTimer) {
clearInterval(captionTimer);
captionTimer = null;
}
});
page.querySelector('#testSearchDiagnostics').addEventListener('click', runSearchDiagnostics);
page.querySelector('#reportFailed').addEventListener('click', function () {
loadIndexReport('failed', false);
});
page.querySelector('#reportRemoved').addEventListener('click', function () {
loadIndexReport('removed', false);
});
page.querySelector('#reportIndexed').addEventListener('click', function () {
loadIndexReport('indexed', false);
});
page.querySelector('#indexReportMore').addEventListener('click', function () {
if (reportCategory) {
loadIndexReport(reportCategory, true);
}
});
page.querySelector('#applyLibraries').addEventListener('click', function () {
var ids = selectedLibraryIds();
if (!ids.length && !window.confirm(
'No libraries are selected. This will remove all Jellyfin-backed Scene Search data from SQLite and Meilisearch. Continue?'
)) {
return;
}
page.querySelector('#indexStatus').textContent = 'Applying library selection...';
ApiClient.getPluginConfiguration(pluginId).then(function (config) {
config.SelectedLibraryIds = ids;
currentConfig = config;
return ApiClient.updatePluginConfiguration(pluginId, config);
}).then(function () {
return ApiClient.ajax({
type: 'POST',
url: ApiClient.getUrl('Plugins/SceneSearch/LibrarySelection'),
contentType: 'application/json',
data: JSON.stringify({
library_ids: ids,
force: false
})
});
}).then(function (result) {
var removedLibraries = Number(result.removed_libraries || 0);
var removedMedia = Number(result.removed_media || 0);
page.querySelector('#indexStatus').textContent = removedLibraries
? 'Selection applied: removed ' + removedLibraries +
' librar' + (removedLibraries === 1 ? 'y' : 'ies') +
' and ' + removedMedia + ' media items. No full search-index rebuild.'
: 'Selection applied: nothing to remove.';
loadLibraries();
refreshIndexReportSummary();
}).catch(function () {
page.querySelector('#indexStatus').textContent =
'Could not apply library selection. Check Jellyfin logs and Scene Search API status.';
});
});
page.querySelector('#indexNow').addEventListener('click', function () {
var ids = selectedLibraryIds();
if (!ids.length && !window.confirm(
'No libraries are selected. This will remove all Jellyfin-backed Scene Search data from SQLite and Meilisearch. Continue?'
)) {
return;
}
page.querySelector('#indexStatus').textContent = 'Saving library selection and starting index…';
ApiClient.getPluginConfiguration(pluginId).then(function (config) {
config.Enabled = page.querySelector('#enabled').checked;
config.ApiUrl = page.querySelector('#apiUrl').value.trim();
config.ApiKey = page.querySelector('#apiKey').value;
config.RequirePrefix = false;
config.SearchPrefix = page.querySelector('#searchPrefix').value.trim();
config.MaxResults = parseInt(page.querySelector('#maxResults').value, 10) || 20;
config.TimeoutSeconds = parseInt(page.querySelector('#timeoutSeconds').value, 10) || 60;
config.SelectedLibraryIds = ids;
currentConfig = config;
return ApiClient.updatePluginConfiguration(pluginId, config);
}).then(function () {
return ApiClient.ajax({
type: 'POST',
url: ApiClient.getUrl('Plugins/SceneSearch/Index'),
contentType: 'application/json',
data: JSON.stringify({
library_ids: ids,
force: page.querySelector('#forceIndex').checked
})
});
}).then(function () {
refreshStatus();
if (!statusTimer) {
statusTimer = setInterval(refreshStatus, 2000);
}
}).catch(function () {
page.querySelector('#indexStatus').textContent =
'Could not start indexing. Check Jellyfin logs and Scene Search API status.';
});
});
page.querySelector('#captionNow').addEventListener('click', function () {
if (lastCaptionStatus && lastCaptionStatus.running) {
if (lastCaptionStatus.stage === 'syncing' || lastCaptionStatus.stage === 'sync') {
return;
}
var resume = lastCaptionStatus.paused || lastCaptionStatus.pause_requested;
ApiClient.ajax({
type: 'POST',
url: ApiClient.getUrl(
resume
? 'Plugins/SceneSearch/CaptionResume'
: 'Plugins/SceneSearch/CaptionPause'
)
}).then(function () {
refreshCaptionStatus();
}).catch(function () {
page.querySelector('#captionStatus').textContent =
'Could not change caption pause state. Check Jellyfin logs and Scene Search API status.';
});
return;
}
var ids = selectedLibraryIds();
if (!ids.length) {
page.querySelector('#captionStatus').textContent = 'Select at least one library first.';
return;
}
page.querySelector('#captionNow').disabled = true;
page.querySelector('#captionNow span').textContent = 'Starting...';
page.querySelector('#captionStop').disabled = true;
page.querySelector('#forceCaption').disabled = true;
page.querySelector('#captionStatus').textContent = 'Starting captioning...';
page.querySelector('#captionDetail').textContent = 'Saving settings and sending start request...';
ApiClient.getPluginConfiguration(pluginId).then(function (config) {
config.SelectedLibraryIds = ids;
currentConfig = config;
return ApiClient.updatePluginConfiguration(pluginId, config);
}).then(function () {
return ApiClient.ajax({
type: 'POST',
url: ApiClient.getUrl('Plugins/SceneSearch/Caption'),
contentType: 'application/json',
data: JSON.stringify({
library_ids: ids,
force: page.querySelector('#forceCaption').checked
})
});
}).then(function () {
refreshCaptionStatus();
if (!captionTimer) {
captionTimer = setInterval(refreshCaptionStatus, 2000);
}
}).catch(function () {
page.querySelector('#captionStatus').textContent =
'Could not start captioning. Check Jellyfin logs and Scene Search API status.';
});
});
page.querySelector('#captionStop').addEventListener('click', function () {
if (!lastCaptionStatus || !lastCaptionStatus.running) {
return;
}
if (lastCaptionStatus.stage === 'syncing' || lastCaptionStatus.stage === 'sync') {
return;
}
ApiClient.ajax({
type: 'POST',
url: ApiClient.getUrl('Plugins/SceneSearch/CaptionStop')
}).then(function () {
refreshCaptionStatus();
}).catch(function () {
page.querySelector('#captionStatus').textContent =
'Could not stop captioning. Check Jellyfin logs and Scene Search API status.';
});
});
page.querySelector('.sceneSearchConfigForm').addEventListener('submit', function (event) {
event.preventDefault();
var ids = selectedLibraryIds();
if (!ids.length && !window.confirm(
'No libraries are selected. Saving will remove all Jellyfin-backed Scene Search data from SQLite and Meilisearch. Continue?'
)) {
return false;
}
Dashboard.showLoadingMsg();
var updateResult = null;
ApiClient.getPluginConfiguration(pluginId).then(function (config) {
config.Enabled = page.querySelector('#enabled').checked;
config.ApiUrl = page.querySelector('#apiUrl').value.trim();
config.ApiKey = page.querySelector('#apiKey').value;
config.RequirePrefix = false;
config.SearchPrefix = page.querySelector('#searchPrefix').value.trim();
config.MaxResults = parseInt(page.querySelector('#maxResults').value, 10) || 20;
config.TimeoutSeconds = parseInt(page.querySelector('#timeoutSeconds').value, 10) || 60;
config.SelectedLibraryIds = ids;
return ApiClient.updatePluginConfiguration(pluginId, config);
}).then(function (result) {
updateResult = result;
return ApiClient.ajax({
type: 'POST',
url: ApiClient.getUrl('Plugins/SceneSearch/LibrarySelection'),
contentType: 'application/json',
data: JSON.stringify({
library_ids: ids,
force: false
})
});
}).then(function () {
currentConfig = currentConfig || {};
currentConfig.SelectedLibraryIds = ids;
loadLibraries();
Dashboard.processPluginConfigurationUpdateResult(updateResult);
}).catch(function () {
Dashboard.hideLoadingMsg();
page.querySelector('#indexStatus').textContent =
'Settings were saved, but Scene Search could not apply the library selection. Try again when indexing/captioning is idle.';
});
return false;
});
})();
</script>
</div>
</body>
</html>