mirror of
https://github.com/MrSleeps/jellyfin-scene-search.git
synced 2026-11-17 07:21:28 +00:00
Add pause and resume controls to Jellyfin captioning
This commit is contained in:
@@ -77,6 +77,9 @@
|
||||
<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>
|
||||
@@ -106,6 +109,7 @@
|
||||
var currentConfig = null;
|
||||
var statusTimer = null;
|
||||
var captionTimer = null;
|
||||
var lastCaptionStatus = null;
|
||||
|
||||
function selectedLibraryIds() {
|
||||
return Array.prototype.slice.call(
|
||||
@@ -221,12 +225,14 @@
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -235,6 +241,8 @@
|
||||
container.textContent = 'Caption status unavailable.';
|
||||
detail.textContent = '';
|
||||
button.disabled = false;
|
||||
pauseButton.disabled = true;
|
||||
pauseButton.querySelector('span').textContent = 'Pause';
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -247,7 +255,22 @@
|
||||
|
||||
if (status.running) {
|
||||
button.disabled = true;
|
||||
if (status.stage === 'routing') {
|
||||
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') {
|
||||
@@ -266,10 +289,14 @@
|
||||
}
|
||||
} 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.';
|
||||
@@ -277,6 +304,8 @@
|
||||
(status.retained || 0) + ' existing captions retained.';
|
||||
} else {
|
||||
button.disabled = false;
|
||||
pauseButton.disabled = true;
|
||||
pauseButton.querySelector('span').textContent = 'Pause';
|
||||
container.textContent = 'Captioning idle.';
|
||||
detail.textContent = '';
|
||||
}
|
||||
@@ -407,6 +436,27 @@
|
||||
});
|
||||
});
|
||||
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user