Files
jellyfin-scene-search/jellyfin-plugin/Jellyfin.Plugin.SceneSearch/Configuration/configPage.html
T

487 lines
26 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. Applying this selection removes deselected libraries from Scene Search SQLite and Meilisearch. 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="indexNow" class="raised">
<span>Apply library selection / index</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:1.5em;"></div>
<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="captionPause" class="raised" disabled>
<span>Pause</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 lastCaptionStatus = null;
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, '&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 refreshStatus() {
return ApiClient.getJSON(ApiClient.getUrl('Plugins/SceneSearch/IndexStatus'))
.then(function (status) {
renderStatus(status);
if (status && status.running) {
if (!statusTimer) {
statusTimer = setInterval(refreshStatus, 2000);
}
} else if (statusTimer) {
clearInterval(statusTimer);
statusTimer = null;
loadLibraries();
}
})
.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 pauseButton = page.querySelector('#captionPause');
if (!status) {
progress.value = 0;
progressText.textContent = '0%';
progressFrames.textContent = '0 / 0 frames';
container.textContent = 'Caption status unavailable.';
detail.textContent = '';
button.disabled = false;
pauseButton.disabled = true;
pauseButton.querySelector('span').textContent = 'Pause';
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) {
button.disabled = true;
pauseButton.disabled = status.stage === 'syncing' || status.stage === 'sync';
pauseButton.querySelector('span').textContent = status.paused
? 'Resume'
: (status.pause_requested ? 'Cancel pause' : 'Pause');
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;
pauseButton.disabled = true;
pauseButton.querySelector('span').textContent = 'Pause';
container.textContent = 'Captioning failed: ' + (status.error || 'unknown error');
detail.textContent = '';
} else if (status.stage === 'complete') {
button.disabled = false;
pauseButton.disabled = true;
pauseButton.querySelector('span').textContent = 'Pause';
container.textContent =
'Captioning complete: ' + (status.frames_completed || 0) +
' saved, ' + (status.failed || 0) + ' failed.';
detail.textContent =
(status.retained || 0) + ' existing captions retained.';
} else {
button.disabled = false;
pauseButton.disabled = true;
pauseButton.querySelector('span').textContent = 'Pause';
container.textContent = 'Captioning idle.';
detail.textContent = '';
}
}
function refreshCaptionStatus() {
return ApiClient.getJSON(ApiClient.getUrl('Plugins/SceneSearch/CaptionStatus'))
.then(function (status) {
renderCaptionStatus(status);
if (status && status.running) {
if (!captionTimer) {
captionTimer = setInterval(refreshCaptionStatus, 2000);
}
} else if (captionTimer) {
clearInterval(captionTimer);
captionTimer = null;
}
})
.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()]);
}).finally(function () {
Dashboard.hideLoadingMsg();
});
});
page.addEventListener('pagehide', function () {
if (statusTimer) {
clearInterval(statusTimer);
statusTimer = null;
}
if (captionTimer) {
clearInterval(captionTimer);
captionTimer = null;
}
});
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();
}).catch(function () {
page.querySelector('#indexStatus').textContent =
'Could not start indexing. Check Jellyfin logs and Scene Search API status.';
});
});
page.querySelector('#captionNow').addEventListener('click', function () {
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();
}).catch(function () {
page.querySelector('#captionStatus').textContent =
'Could not start captioning. Check Jellyfin logs and Scene Search API status.';
});
});
page.querySelector('#captionPause').addEventListener('click', function () {
if (!lastCaptionStatus || !lastCaptionStatus.running) {
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.';
});
});
page.querySelector('.sceneSearchConfigForm').addEventListener('submit', function (event) {
event.preventDefault();
Dashboard.showLoadingMsg();
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 = selectedLibraryIds();
return ApiClient.updatePluginConfiguration(pluginId, config);
}).then(function (result) {
Dashboard.processPluginConfigurationUpdateResult(result);
});
return false;
});
})();
</script>
</div>
</body>
</html>