mirror of
https://github.com/MrSleeps/jellyfin-scene-search.git
synced 2026-11-20 00:33:36 +00:00
Add pause and resume controls to web captioning
This commit is contained in:
@@ -101,6 +101,7 @@
|
||||
<div id="captionDetail" class="muted"></div>
|
||||
<div class="row" style="margin-top:14px">
|
||||
<button id="captionNow" type="button">Start / resume captioning</button>
|
||||
<button id="captionPause" type="button" class="secondary" disabled>Pause</button>
|
||||
<label><input id="forceCaption" type="checkbox"> Force recaption</label>
|
||||
</div>
|
||||
</section>
|
||||
@@ -121,6 +122,7 @@
|
||||
const $ = id => document.getElementById(id);
|
||||
let statusTimer = null;
|
||||
let captionTimer = null;
|
||||
let captionLastStatus = null;
|
||||
let thumbnailUrls = [];
|
||||
|
||||
$('apiKey').value = localStorage.getItem('sceneSearchApiKey') || '';
|
||||
@@ -255,6 +257,7 @@
|
||||
}
|
||||
|
||||
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','') + '%';
|
||||
@@ -262,8 +265,20 @@
|
||||
|
||||
if (s.running) {
|
||||
$('captionNow').disabled = true;
|
||||
$('captionPause').disabled = s.stage === 'syncing' || s.stage === 'sync';
|
||||
$('captionPause').textContent = s.paused
|
||||
? 'Resume'
|
||||
: (s.pause_requested ? 'Cancel pause' : 'Pause');
|
||||
$('captionStatus').className = 'status';
|
||||
if (s.stage === 'routing') {
|
||||
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') {
|
||||
@@ -281,11 +296,15 @@
|
||||
}
|
||||
} else if (s.stage === 'failed') {
|
||||
$('captionNow').disabled = false;
|
||||
$('captionPause').disabled = true;
|
||||
$('captionPause').textContent = 'Pause';
|
||||
$('captionStatus').className = 'status error';
|
||||
$('captionStatus').textContent = 'Failed: ' + (s.error || 'unknown error');
|
||||
$('captionDetail').textContent = '';
|
||||
} else if (s.stage === 'complete') {
|
||||
$('captionNow').disabled = false;
|
||||
$('captionPause').disabled = true;
|
||||
$('captionPause').textContent = 'Pause';
|
||||
$('captionStatus').className = 'status ok';
|
||||
$('captionStatus').textContent =
|
||||
'Complete: ' + (s.frames_completed || 0) + ' saved, ' + (s.failed || 0) + ' failed';
|
||||
@@ -293,6 +312,8 @@
|
||||
(s.retained || 0) + ' existing captions retained';
|
||||
} else {
|
||||
$('captionNow').disabled = false;
|
||||
$('captionPause').disabled = true;
|
||||
$('captionPause').textContent = 'Pause';
|
||||
$('captionStatus').className = 'status muted';
|
||||
$('captionStatus').textContent = 'Idle';
|
||||
$('captionDetail').textContent = '';
|
||||
@@ -338,6 +359,20 @@
|
||||
}
|
||||
}
|
||||
|
||||
async function toggleCaptionPause() {
|
||||
if (!captionLastStatus || !captionLastStatus.running) return;
|
||||
const resume = captionLastStatus.paused || captionLastStatus.pause_requested;
|
||||
try {
|
||||
const s = await api(resume ? '/api/caption/resume' : '/api/caption/pause', {
|
||||
method:'POST'
|
||||
});
|
||||
renderCaptionStatus(s);
|
||||
} 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);
|
||||
@@ -400,6 +435,7 @@
|
||||
$('selectAll').onclick = () => document.querySelectorAll('.libraryCheck').forEach(x => x.checked = true);
|
||||
$('indexNow').onclick = startIndex;
|
||||
$('captionNow').onclick = startCaption;
|
||||
$('captionPause').onclick = toggleCaptionPause;
|
||||
$('searchButton').onclick = search;
|
||||
$('searchQuery').addEventListener('keydown', e => { if (e.key === 'Enter') search(); });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user