mirror of
https://github.com/MrSleeps/jellyfin-scene-search.git
synced 2026-11-20 08:43:36 +00:00
711 lines
38 KiB
HTML
711 lines
38 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>Connect Jellyfin search to the local semantic scene-search service.</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>
|
|
|
|
<label class="checkboxContainer">
|
|
<input is="emby-checkbox" type="checkbox" id="requirePrefix" />
|
|
<span>Require a search prefix</span>
|
|
</label>
|
|
|
|
<div class="inputContainer">
|
|
<input is="emby-input" type="text" id="searchPrefix" label="Search Prefix" />
|
|
<div class="fieldDescription">Default: scene:. Example: scene: woman standing outside</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>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 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, '"') + '"' + checked + ' />' +
|
|
'<span>' + library.name.replace(/</g, '<').replace(/>/g, '>') + '</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) + ' frames';
|
|
|
|
if (status.running) {
|
|
var syncing = status.stage === 'syncing' || status.stage === 'sync';
|
|
var stopping = !!status.stop_requested;
|
|
button.disabled = syncing || stopping;
|
|
button.querySelector('span').textContent = syncing
|
|
? 'Finishing...'
|
|
: (stopping
|
|
? 'Stopping...'
|
|
: ((status.paused || status.pause_requested) ? 'Resume' : 'Pause'));
|
|
stopButton.disabled = syncing || stopping;
|
|
forceCheckbox.disabled = true;
|
|
|
|
if (stopping) {
|
|
container.textContent = 'Stop requested; finishing the current frame.';
|
|
detail.textContent = status.title || '';
|
|
} 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) + ' frames saved.';
|
|
} else if (status.pause_requested) {
|
|
container.textContent = 'Pause requested; finishing the current 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.';
|
|
}
|
|
} 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.';
|
|
} 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. Start / resume continues the remaining frames; search updates after a later completed run.';
|
|
} 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('#requirePrefix').checked = config.RequirePrefix;
|
|
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('#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 = page.querySelector('#requirePrefix').checked;
|
|
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('#captionStatus').textContent = 'Saving settings and starting captioning...';
|
|
|
|
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 = page.querySelector('#requirePrefix').checked;
|
|
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>
|