Clear removed subtitle progress and refresh model on requeue

This commit is contained in:
Dymas committed 2026-10-13 20:46:23 +02:00
1 parent 8d90b0a66b
commit 9d5e6c55b9
8 files changed
+186 -46

No files matched your search

+6
View File
@@ -1,5 +1,11 @@
# Changelog
## 0.54.10 - 2026-10-13
- Removing an AI subtitle queue card now clears checkpoints and progress for its failed or canceled files, while retaining completed sidecars and queue logs. Requeuing those files starts at cue 1 with the current Config provider, endpoint and model; older already-removed cards receive the same reset when requeued.
- Added **Clear saved progress** to stopped and failed files on the AI Subtitles page. Direct resume still retains the original job settings, while **Restart from beginning** now uses current Config settings.
- Added regression coverage for model changes, legacy removed jobs, grouped jobs and the clear route. Checked all three anime providers against upstream; no updates were needed.
## 0.54.9 - 2026-10-13
- Added a dedicated Ollama chat adapter for `17slever17/translate-gemma-4-sub-*` models. It follows the fine-tune's one-cue `[CURRENT_SOURCE]` format, supplies preceding bilingual subtitle context, and avoids the generic batch markers that this model dropped.
+4 -4
View File
@@ -157,15 +157,15 @@ Choose **Anime TV Shows** or **Anime Movies**. Titles appear in a compact list w
Click a title, then **Queue file**, **Queue season**, or **Queue full series / Queue movie**. English tracks are translated to Czech; Czech tracks (`cs`, `ces`, `cze`, `cz`, or detected Czech text) remain catalogued and are skipped. Language labels come from filename suffixes or a conservative English/Czech text estimate. Confirm or correct uncertain labels using the language dropdown before queueing. Other languages are catalogued but not translated by this English-to-Czech workflow. Existing Czech sidecars for the same track are also skipped, including across supported catalog formats.
In **Config → AI Subtitles**, choose Ollama or OpenAI API, then set the endpoint and model. **Load available models** fetches the current model names; you can also enter a custom name. Ollama defaults to `http://192.168.88.15:11434` and `translategemma:4b`; install that model with `ollama pull translategemma:4b` if needed. `KAIZOKU_OLLAMA_URL` and `KAIZOKU_SUBTITLE_MODEL` supply initial defaults for existing deployments, while saved Config values take precedence. OpenAI defaults to `https://api.openai.com/v1` and `gpt-4.1-mini` and requires an API token. The token is stored in `.kaizoku` config, omitted from config API responses, and can be replaced or cleared from Config. The OpenAI API uses separate billing from a ChatGPT subscription. New jobs retain their chosen provider, endpoint and model for resuming; OpenAI jobs read the current saved API token when they run.
In **Config → AI Subtitles**, choose Ollama or OpenAI API, then set the endpoint and model. **Load available models** fetches the current model names; you can also enter a custom name. Ollama defaults to `http://192.168.88.15:11434` and `translategemma:4b`; install that model with `ollama pull translategemma:4b` if needed. `KAIZOKU_OLLAMA_URL` and `KAIZOKU_SUBTITLE_MODEL` supply initial defaults for existing deployments, while saved Config values take precedence. OpenAI defaults to `https://api.openai.com/v1` and `gpt-4.1-mini` and requires an API token. The token is stored in `.kaizoku` config, omitted from config API responses, and can be replaced or cleared from Config. The OpenAI API uses separate billing from a ChatGPT subscription. **Resume / retry** retains the job's original provider, endpoint, model and saved cues; clearing or removing an unfinished job discards its cues so the next queue request uses current Config settings. OpenAI jobs read the current saved API token when they run.
Gemma 4 models use Ollama's chat endpoint so translation instructions are separate from subtitle dialogue; other Ollama models continue using the generate endpoint. Obvious instruction echoes and identical long responses to different cues are rejected before they become checkpoints. If an older saved cue contains an instruction echo, the job stops and identifies the cue; open **Review** on the failed job, correct that cue, then retry. Already completed Czech sidecars are not changed automatically.
The `17slever17/translate-gemma-4-sub-*` Ollama fine-tune uses its documented single-segment chat prompt (`[CURRENT_SOURCE]` with optional previous source/translation context). Kaizoku saves each cue separately for this model, so a failed cue resumes without redoing earlier cues. Its [model card](https://huggingface.co/17slever17/translate-gemma-4-sub-e4b-GGUF/blob/main/README.md) says Czech was not among its specifically fine-tuned or extensively evaluated languages; review Czech output carefully. Existing saved cues are retained when changing models or retrying; use **Restart from beginning** to discard bad partial output.
The `17slever17/translate-gemma-4-sub-*` Ollama fine-tune uses its documented single-segment chat prompt (`[CURRENT_SOURCE]` with optional previous source/translation context). Kaizoku saves each cue separately for this model, so a failed cue resumes without redoing earlier cues. Its [model card](https://huggingface.co/17slever17/translate-gemma-4-sub-e4b-GGUF/blob/main/README.md) says Czech was not among its specifically fine-tuned or extensively evaluated languages; review Czech output carefully. Existing saved cues are retained on direct retry; use **Restart from beginning** to discard bad partial output and apply the current Config model.
For a paused, stopped or failed file with saved cues, **Restart from beginning** on the AI Subtitles file row discards that file's saved Czech cues and immediately queues it again from cue 1. **Resume / retry** still keeps progress. Restart does not change the English source, completed Czech sidecars, or other files in a season/series job; the queue log records the reset. The action is unavailable while a file is actively translating or after it has completed.
For a paused, stopped or failed file with saved cues, **Restart from beginning** on the AI Subtitles file row discards that file's saved Czech cues and immediately queues it again from cue 1 using the current Config provider/model. **Resume / retry** still keeps progress and the original provider/model. **Clear saved progress** on a stopped or failed file discards its checkpoints without starting a translation; the file then shows as **Not queued** and can be queued using current Config settings. These actions do not change the English source, completed Czech sidecars, or other files in a season/series job; the queue log records the reset. They are unavailable while a file is actively translating or after it has completed.
The **Queue → AI Subtitles** tab shows one job for each new single-file request or season/full-series request, with per-file status, combined cue progress and persistent logs for batch saves, retries, splits, failures and completion. **Pause** keeps a job ready to resume; **Stop** marks its unfinished files canceled, prevents further subtitle output, and makes **Remove** available. An in-flight model request may take up to three minutes to return, but its result is discarded after Stop. Remove hides the queue card without deleting checkpoints, logs, or completed sidecars. Stopped jobs can also be retried before removal, and **Remove finished** clears stopped cards. Existing jobs from earlier versions are preserved as individual queue entries because their original request grouping was not recorded.
The **Queue → AI Subtitles** tab shows one job for each new single-file request or season/full-series request, with per-file status, combined cue progress and persistent logs for batch saves, retries, splits, failures and completion. **Pause** keeps a job ready to resume; **Stop** marks its unfinished files canceled, prevents further subtitle output, and makes **Remove** available. An in-flight model request may take up to three minutes to return, but its result is discarded after Stop. Remove hides the queue card and clears saved cues for its failed or canceled files; completed sidecars and translation history remain intact. Requeue a cleared file to start from cue 1 with the current Config provider/model. Stopped jobs can also be retried before removal, and **Remove finished** clears stopped cards. Existing jobs from earlier versions are preserved as individual queue entries because their original request grouping was not recorded.
After a rescan marks a subtitle missing, **Remove missing** hides its stale catalog entry. Pause any queued/running translation first. This action never deletes library files, checkpoints or queue history. A file that reappears is restored to the catalog on the next scan.
+1 -1
View File
@@ -1 +1 @@
0.54.9
0.54.10
+99 -40
View File
@@ -525,7 +525,10 @@ class SubtitleService:
for row in rows:
row['warnings'] = json.loads(row['warnings'] or '[]')
row['filename'] = Path(row['path']).name
row['review_id'] = row['id'] if row['language']=='en' and row['job_id'] else review_sources.get(row['path'])
if row['status'] == 'cleared':
row['total'] = 0
row['review_id'] = (row['id'] if row['language']=='en' and row['job_id'] and row['status']!='cleared'
else review_sources.get(row['path']))
config = self.config_getter() or {}
backend = config.get('ai_subtitle_backend', 'ollama')
return {'subtitles': rows, 'terminology': notes, 'scanning': self.scan_lock.locked(),
@@ -556,6 +559,24 @@ class SubtitleService:
with self.lock:
return self._queue_locked(selection)
def provider_settings(self):
config = self.config_getter() or {}
backend = config.get('ai_subtitle_backend', 'ollama')
endpoint = provider_url(config.get('ai_subtitle_openai_url' if backend == 'openai' else 'ai_subtitle_ollama_url') or
('https://api.openai.com/v1' if backend == 'openai' else os.environ.get('KAIZOKU_OLLAMA_URL', 'http://192.168.88.15:11434')), backend)
model = str(config.get('ai_subtitle_openai_model' if backend == 'openai' else 'ai_subtitle_ollama_model') or
('gpt-4.1-mini' if backend == 'openai' else os.environ.get('KAIZOKU_SUBTITLE_MODEL', 'translategemma:4b')))
if backend == 'openai' and not config.get('ai_subtitle_openai_api_key'):
raise ValueError('Set an OpenAI API token in Config before queuing translations.')
return backend, endpoint, model
@staticmethod
def clear_unfinished(db, job_id):
"""Discard an unfinished file's checkpoints without deleting its queue log."""
db.execute('DELETE FROM translations WHERE job_id=?', (job_id,))
db.execute("""UPDATE jobs SET status='cleared',progress=0,error='',warnings='[]',output='',
generation=generation+1 WHERE id=?""", (job_id,))
def _queue_locked(self, selection):
if not any(k in selection for k in ('id', 'title')):
raise ValueError('Select a subtitle, season or title.')
@@ -580,31 +601,41 @@ class SubtitleService:
if old and old['status'] in {'pending', 'running', 'completed'}:
skipped += 1
continue
if old and old['fingerprint'] != row['fingerprint']:
fresh = bool(old and old['status'] == 'cleared')
if old and not fresh and old['status'] in {'failed', 'canceled'}:
# Older versions hid removed cards but left their per-file job intact.
fresh = not db.execute('''SELECT 1 FROM batch_jobs b JOIN batches a ON a.id=b.batch_id
WHERE b.job_id=? AND a.hidden=0 LIMIT 1''', (old['id'],)).fetchone()
if old and not fresh and old['fingerprint'] != row['fingerprint']:
raise ValueError('Source changed since translation started. Restore the original or use a new filename; saved progress was preserved.')
notes = db.execute('SELECT notes FROM terminology WHERE kind=? AND title=?', (row['kind'],row['title'])).fetchone()
candidates.append((row, notes[0] if notes else ''))
candidates.append((row, notes[0] if notes else '', fresh))
if candidates:
created_at = datetime.now(timezone.utc).isoformat()
config = self.config_getter() or {}
backend = config.get('ai_subtitle_backend', 'ollama')
endpoint = provider_url(config.get('ai_subtitle_openai_url' if backend == 'openai' else 'ai_subtitle_ollama_url') or
('https://api.openai.com/v1' if backend == 'openai' else os.environ.get('KAIZOKU_OLLAMA_URL', 'http://192.168.88.15:11434')), backend)
model = str(config.get('ai_subtitle_openai_model' if backend == 'openai' else 'ai_subtitle_ollama_model') or
('gpt-4.1-mini' if backend == 'openai' else os.environ.get('KAIZOKU_SUBTITLE_MODEL', 'translategemma:4b')))
if backend == 'openai' and not config.get('ai_subtitle_openai_api_key'):
raise ValueError('Set an OpenAI API token in Config before queuing translations.')
backend, endpoint, model = self.provider_settings()
with self.db() as db:
job_ids = []
for row, notes in candidates:
for row, notes, fresh in candidates:
if fresh:
old = db.execute('SELECT id,status FROM jobs WHERE subtitle_id=?', (row['id'],)).fetchone()
if old and old['status'] != 'cleared':
self.clear_unfinished(db, old['id'])
db.execute('''INSERT INTO jobs(subtitle_id,status,fingerprint,total,glossary,backend,endpoint,model) VALUES(?,'pending',?,?,?,?,?,?)
ON CONFLICT(subtitle_id) DO UPDATE SET status='pending',error='' ''',
ON CONFLICT(subtitle_id) DO UPDATE SET status='pending',error='',
fingerprint=excluded.fingerprint,total=excluded.total,
glossary=CASE WHEN jobs.status='cleared' THEN excluded.glossary ELSE jobs.glossary END,
backend=CASE WHEN jobs.status='cleared' THEN excluded.backend ELSE jobs.backend END,
endpoint=CASE WHEN jobs.status='cleared' THEN excluded.endpoint ELSE jobs.endpoint END,
model=CASE WHEN jobs.status='cleared' THEN excluded.model ELSE jobs.model END,
generation=jobs.generation+1''',
(row['id'],row['fingerprint'],row['cues'],notes,backend,endpoint,model))
job_id = db.execute('SELECT id FROM jobs WHERE subtitle_id=?', (row['id'],)).fetchone()[0]
job_ids.append(job_id)
db.execute('INSERT INTO job_logs(job_id,created_at,message) VALUES(?,?,?)',
(job_id,created_at,'Queued translation; saved batches will be reused.'))
existing = db.execute('SELECT batch_id FROM batch_jobs WHERE job_id=? ORDER BY batch_id DESC LIMIT 1', (job_ids[0],)).fetchone()
(job_id,created_at,('Queued fresh translation with current provider settings.' if fresh
else 'Queued translation; saved batches will be reused.')))
existing = db.execute('''SELECT b.batch_id FROM batch_jobs b JOIN batches a ON a.id=b.batch_id
WHERE b.job_id=? AND a.hidden=0 ORDER BY b.batch_id DESC LIMIT 1''', (job_ids[0],)).fetchone()
if 'id' in selection and existing:
db.execute('UPDATE batches SET hidden=0 WHERE id=?', (existing[0],))
else:
@@ -750,7 +781,8 @@ class SubtitleService:
JOIN batch_jobs b ON b.job_id=l.job_id JOIN jobs j ON j.id=l.job_id JOIN subtitles s ON s.id=j.subtitle_id
WHERE b.batch_id=? ORDER BY l.id DESC LIMIT 250''', (batch_id,)).fetchall()[::-1]
statuses = {row['status'] for row in rows}
status = next((state for state in ('running','pending','failed','paused','canceled') if state in statuses), 'done')
status = next((state for state in ('running','pending','failed','paused','canceled') if state in statuses),
'canceled' if 'cleared' in statuses else 'done')
completed = sum(r['status'] in {'completed','skipped'} for r in rows)
total = sum(r['total'] for r in rows)
progress = sum(r['total'] if r['status']=='skipped' else r['progress'] for r in rows)
@@ -771,31 +803,56 @@ class SubtitleService:
return int(identifier.rsplit('-',1)[1])
def queue_action(self, identifier, action):
batch = self.get_queue_job(identifier)
batch_id = self.batch_id(identifier)
with self.db() as db:
ids = [r[0] for r in db.execute('SELECT job_id FROM batch_jobs WHERE batch_id=?', (batch_id,))]
if action == 'remove':
active = db.execute('''SELECT 1 FROM jobs j JOIN batch_jobs b ON b.job_id=j.id
WHERE b.batch_id=? AND j.status IN ('pending','running','paused') LIMIT 1''', (batch_id,)).fetchone()
if active:
raise ValueError('Stop the active or paused files before removing this job.')
db.execute('UPDATE batches SET hidden=1 WHERE id=?', (batch_id,))
elif action in {'pause','retry','stop'}:
for job_id in ids:
if action == 'pause':
db.execute("UPDATE jobs SET status='paused' WHERE id=? AND status IN ('pending','running')", (job_id,))
elif action == 'stop':
db.execute("UPDATE jobs SET status='canceled' WHERE id=? AND status IN ('pending','running','paused','failed')", (job_id,))
else:
db.execute("UPDATE jobs SET status='pending',error='' WHERE id=? AND status IN ('paused','failed','canceled')", (job_id,))
else:
raise ValueError('Unknown AI subtitle queue action.')
for job_id in ids:
self.log(job_id, f'Queue action: {action}. Checkpoints retained.')
with self.lock:
self.get_queue_job(identifier)
batch_id = self.batch_id(identifier)
with self.db() as db:
rows = db.execute('''SELECT j.id,j.status,j.output FROM jobs j JOIN batch_jobs b ON b.job_id=j.id
WHERE b.batch_id=?''', (batch_id,)).fetchall()
ids = [row['id'] for row in rows]
if action == 'remove':
if any(row['status'] in {'pending','running','paused'} for row in rows):
raise ValueError('Stop the active or paused files before removing this job.')
for row in rows:
if row['status'] in {'failed','canceled'} and not row['output']:
self.clear_unfinished(db, row['id'])
db.execute('UPDATE batches SET hidden=1 WHERE id=?', (batch_id,))
elif action in {'pause','retry','stop'}:
for job_id in ids:
if action == 'pause':
db.execute("UPDATE jobs SET status='paused' WHERE id=? AND status IN ('pending','running')", (job_id,))
elif action == 'stop':
db.execute("UPDATE jobs SET status='canceled' WHERE id=? AND status IN ('pending','running','paused','failed')", (job_id,))
else:
db.execute("""UPDATE jobs SET status='pending',error='',generation=generation+1
WHERE id=? AND status IN ('paused','failed','canceled')""", (job_id,))
else:
raise ValueError('Unknown AI subtitle queue action.')
for row in rows:
detail = ('Saved cues cleared.' if action == 'remove' and row['status'] in {'failed','canceled'} and not row['output']
else 'Checkpoints retained.')
self.log(row['id'], f'Queue action: {action}. {detail}')
self.wake.set()
return {'ok': True}
def clear_file(self, subtitle_id):
"""Clear a canceled or failed file from the catalog without touching its source."""
with self.lock:
with self.db() as db:
row = db.execute('''SELECT j.id,j.status,j.output,s.path FROM jobs j
JOIN subtitles s ON s.id=j.subtitle_id WHERE s.id=?''', (subtitle_id,)).fetchone()
if row is None:
raise KeyError('Translation job not found.')
if row['status'] not in {'canceled','failed'} or row['output']:
raise ValueError('Only stopped or failed unfinished translations can be cleared.')
self.clear_unfinished(db, row['id'])
# A single-file card no longer represents an active translation.
db.execute('''UPDATE batches SET hidden=1 WHERE id IN (
SELECT b.batch_id FROM batch_jobs b WHERE b.job_id=? AND
(SELECT COUNT(*) FROM batch_jobs WHERE batch_id=b.batch_id)=1)''', (row['id'],))
self.log(row['id'], 'Cleared from AI Subtitles; saved Czech cues discarded.')
return {'message': f'Cleared {Path(row["path"]).name}; saved Czech cues discarded.'}
def clear_queue(self, statuses):
jobs = [j for j in self.list_queue_jobs() if j['status'] in statuses]
for job in jobs:
@@ -822,6 +879,7 @@ class SubtitleService:
def restart_file(self, subtitle_id):
"""Discard one unfinished file's checkpoints and queue it from cue one."""
with self.lock:
backend, endpoint, model = self.provider_settings()
with self.db() as db:
row = db.execute('''SELECT s.*,j.id job_id,j.status,j.output FROM subtitles s
JOIN jobs j ON j.subtitle_id=s.id WHERE s.id=?''', (subtitle_id,)).fetchone()
@@ -840,8 +898,9 @@ class SubtitleService:
cues = len(SubtitleDocument(raw).cues)
db.execute('DELETE FROM translations WHERE job_id=?', (row['job_id'],))
db.execute('''UPDATE jobs SET status='pending',progress=0,total=?,error='',warnings='[]',
fingerprint=?,generation=generation+1 WHERE id=?''', (cues,row['fingerprint'],row['job_id']))
self.log(row['job_id'], 'Restarted from cue 1; saved Czech cues discarded.')
fingerprint=?,backend=?,endpoint=?,model=?,generation=generation+1 WHERE id=?''',
(cues,row['fingerprint'],backend,endpoint,model,row['job_id']))
self.log(row['job_id'], f'Restarted from cue 1 with {model}; saved Czech cues discarded.')
self.wake.set()
self.ensure_worker()
return {'message': f'Restarted {path.name} from cue 1; saved Czech cues discarded.'}
+1 -1
View File
@@ -106,7 +106,7 @@ for(const key of ['All','0-9',...'ABCDEFGHIJKLMNOPQRSTUVWXYZ']){
}
$('tv-view').onclick=()=>selectView('tv');$('movie-view').onclick=()=>selectView('movie');$('page-size').onchange=()=>{libraryPage=1;renderLibrary();};
function renderDetail(){if(!selected)return;const host=$('seasons');const open=new Set([...host.querySelectorAll('details[open]')].map(n=>n.dataset.season));const initial=!host.children.length;host.replaceChildren();const groups=new Map();for(const row of data.subtitles.filter(r=>r.kind===selected.kind&&r.title===selected.title)){const key=row.season||'Movie subtitles';if(!groups.has(key))groups.set(key,[]);groups.get(key).push(row);}for(const [season,rows] of groups){const section=el('details');section.className='panel';section.dataset.season=season;section.open=initial||open.has(season);section.append(el('summary',`${season} · ${rows.length} tracks`));if(selected.kind==='tv')section.append(button('Queue season',()=>action('queue',{...selection(),season})));const wrap=el('div',undefined,'table-wrap'),table=el('table'),head=el('tr');for(const label of ['Subtitle','Language','Translation','Actions'])head.append(el('th',label));const thead=el('thead');thead.append(head);table.append(thead);const tbody=el('tbody');for(const row of rows){const tr=el('tr'),file=el('td',row.filename);if(!row.present)file.append(el('small','Missing from last scan','warning'));if(row.error)file.append(el('small',row.error,'error'));const lang=el('td');const select=el('select');select.setAttribute('aria-label','Language for '+row.filename);const langs=[['en','English'],['cs','Czech'],['und','Unknown']];if(!langs.some(l=>l[0]===row.language))langs.push([row.language,row.language]);for(const [code,label]of langs){const opt=el('option',label);opt.value=code;opt.selected=row.language===code;select.append(opt);}select.disabled=['running','pending'].includes(row.status);select.onchange=()=>action('language',{id:row.id,language:select.value});lang.append(select,el('small',row.language_source));const state=el('td');state.append(el('span',row.language==='cs'?'Czech · skipped':row.status||'Not queued','state'));if(row.total){const progress=el('progress');progress.max=row.total;progress.value=row.progress||0;state.append(progress,el('small',`${row.progress||0} / ${row.total} cues`));}if(row.job_error)state.append(el('small',row.job_error,'error'));if(row.output)state.append(el('small',row.output));if(row.warnings.length)state.append(el('small',`Review length: cue positions ${row.warnings.join(', ')}`,'warning'));const controls=el('td');if(row.review_id&&row.present)controls.append(button('Review',()=>reviewSubtitle(row.review_id)));if(row.progress>0&&['paused','failed','canceled'].includes(row.status)&&row.language==='en'&&row.present&&!row.output)controls.append(button('Restart from beginning',()=>action('restart',{id:row.id})));if(!row.present)controls.append(button('Remove missing',()=>action('remove-missing',{id:row.id})));if(['pending','running'].includes(row.status))controls.append(button('Pause',()=>action('pause',{job_id:row.job_id})));else if(row.language==='en'&&row.present&&!row.error&&row.status!=='completed')controls.append(button(['paused','failed','canceled'].includes(row.status)?'Resume / retry':'Queue file',()=>action('queue',{id:row.id})));tr.append(file,lang,state,controls);tbody.append(tr);}table.append(tbody);wrap.append(table);section.append(wrap);host.append(section);}}
function renderDetail(){if(!selected)return;const host=$('seasons');const open=new Set([...host.querySelectorAll('details[open]')].map(n=>n.dataset.season));const initial=!host.children.length;host.replaceChildren();const groups=new Map();for(const row of data.subtitles.filter(r=>r.kind===selected.kind&&r.title===selected.title)){const key=row.season||'Movie subtitles';if(!groups.has(key))groups.set(key,[]);groups.get(key).push(row);}for(const [season,rows] of groups){const section=el('details');section.className='panel';section.dataset.season=season;section.open=initial||open.has(season);section.append(el('summary',`${season} · ${rows.length} tracks`));if(selected.kind==='tv')section.append(button('Queue season',()=>action('queue',{...selection(),season})));const wrap=el('div',undefined,'table-wrap'),table=el('table'),head=el('tr');for(const label of ['Subtitle','Language','Translation','Actions'])head.append(el('th',label));const thead=el('thead');thead.append(head);table.append(thead);const tbody=el('tbody');for(const row of rows){const tr=el('tr'),file=el('td',row.filename);if(!row.present)file.append(el('small','Missing from last scan','warning'));if(row.error)file.append(el('small',row.error,'error'));const lang=el('td');const select=el('select');select.setAttribute('aria-label','Language for '+row.filename);const langs=[['en','English'],['cs','Czech'],['und','Unknown']];if(!langs.some(l=>l[0]===row.language))langs.push([row.language,row.language]);for(const [code,label]of langs){const opt=el('option',label);opt.value=code;opt.selected=row.language===code;select.append(opt);}select.disabled=['running','pending'].includes(row.status);select.onchange=()=>action('language',{id:row.id,language:select.value});lang.append(select,el('small',row.language_source));const state=el('td');state.append(el('span',row.language==='cs'?'Czech · skipped':row.status==='cleared'?'Not queued':row.status||'Not queued','state'));if(row.total){const progress=el('progress');progress.max=row.total;progress.value=row.progress||0;state.append(progress,el('small',`${row.progress||0} / ${row.total} cues`));}if(row.job_error)state.append(el('small',row.job_error,'error'));if(row.output)state.append(el('small',row.output));if(row.warnings.length)state.append(el('small',`Review length: cue positions ${row.warnings.join(', ')}`,'warning'));const controls=el('td');if(row.review_id&&row.present)controls.append(button('Review',()=>reviewSubtitle(row.review_id)));if(row.progress>0&&['paused','failed','canceled'].includes(row.status)&&row.language==='en'&&row.present&&!row.output)controls.append(button('Restart from beginning',()=>action('restart',{id:row.id})));if(['canceled','failed'].includes(row.status)&&!row.output)controls.append(button('Clear saved progress',()=>action('clear',{id:row.id})));if(!row.present)controls.append(button('Remove missing',()=>action('remove-missing',{id:row.id})));if(['pending','running'].includes(row.status))controls.append(button('Pause',()=>action('pause',{job_id:row.job_id})));else if(row.language==='en'&&row.present&&!row.error&&row.status!=='completed')controls.append(button(['paused','failed','canceled'].includes(row.status)?'Resume / retry':'Queue file',()=>action('queue',{id:row.id})));tr.append(file,lang,state,controls);tbody.append(tr);}table.append(tbody);wrap.append(table);section.append(wrap);host.append(section);}}
async function refresh(){data=await api('/api/ai-subtitles');$('connection').textContent=`${data.backend==='openai'?'OpenAI API':'Ollama'} · ${data.model} · ${data.endpoint} · TV: ${data.roots.tv} · Movies: ${data.roots.movie}`;$('scan').disabled=data.scanning;$('scan').textContent=data.scanning?'Scanning…':'Scan libraries';$('scan-errors').textContent=data.scan_errors.join(' ');renderLibrary();renderDetail();}
$('scan').onclick=()=>action('scan');$('filter').oninput=()=>{libraryPage=1;renderLibrary();};$('back').onclick=()=>{selected=null;$('library').hidden=false;$('detail').hidden=true;$('seasons').replaceChildren();};$('queue-title').onclick=()=>action('queue',selection());$('save-notes').onclick=()=>action('terminology',{...selection(),notes:$('notes').value});
refresh().catch(e=>message(e.message,true));startSerialPoll(async()=>{if(!busy&&!['SELECT','TEXTAREA'].includes(document.activeElement.tagName)){try{await refresh();}catch(e){message(e.message,true);}}},4000);
+2
View File
@@ -826,6 +826,8 @@ class Handler(BaseHTTPRequestHandler):
self.json(service.pause(int(payload["job_id"])))
elif action == "restart":
self.json(service.restart_file(int(payload["id"])))
elif action == "clear":
self.json(service.clear_file(int(payload["id"])))
elif action == "remove-missing":
self.json(service.remove_missing(int(payload["id"])))
elif action == "language":
+64
View File
@@ -412,6 +412,10 @@ class ServiceTests(unittest.TestCase):
self.service.queue_action(group,'remove')
self.service.process(self.job()['id'])
self.assertTrue(output_path(first).exists())
with self.service.db() as db:
other = db.execute("SELECT id FROM jobs WHERE id<>?", (self.job()['id'],)).fetchone()[0]
db.execute('INSERT INTO translations VALUES(?,?,?,?)', (other,0,'Hello there.','Bad partial cue.'))
db.execute('UPDATE jobs SET progress=1 WHERE id=?', (other,))
self.service.queue_action(group,'stop')
stopped=self.service.get_queue_job(group)
self.assertEqual(stopped['status'],'canceled')
@@ -422,6 +426,63 @@ class ServiceTests(unittest.TestCase):
self.assertTrue(output_path(first).exists())
with self.service.db() as db:
self.assertEqual(db.execute('SELECT COUNT(*) FROM translations').fetchone()[0],2)
self.assertEqual(db.execute('SELECT progress,status FROM jobs WHERE id=?',(other,)).fetchone()[:],(0,'cleared'))
def test_remove_failed_job_clears_progress_and_next_queue_uses_current_model(self):
path=self.file()
self.config['ai_subtitle_ollama_model']='old-model'
self.scan_queue()
first_group=self.service.list_queue_jobs()[0]['id']
with self.service.db() as db:
db.execute('INSERT INTO translations VALUES(1,0,?,?)', ('Hello there.','Wrong Czech.'))
db.execute("UPDATE jobs SET status='failed',progress=1,error='bad output' WHERE id=1")
self.config['ai_subtitle_ollama_model']='new-model'
self.service.queue_action(first_group,'remove')
self.assertEqual(self.service.list_queue_jobs(),[])
self.assertEqual((self.job()['status'],self.job()['progress']),('cleared',0))
with self.service.db() as db:
self.assertEqual(db.execute('SELECT COUNT(*) FROM translations WHERE job_id=1').fetchone()[0],0)
self.assertEqual(path.read_bytes(),SRT)
self.service.queue({'id':1})
self.assertEqual(self.job()['model'],'new-model')
self.assertEqual(self.job()['progress'],0)
self.assertNotEqual(self.service.list_queue_jobs()[0]['id'],first_group)
def test_older_hidden_removed_job_is_fresh_on_next_queue(self):
self.file();self.config['ai_subtitle_ollama_model']='old-model';self.scan_queue()
with self.service.db() as db:
db.execute('INSERT INTO translations VALUES(1,0,?,?)', ('Hello there.','Wrong Czech.'))
db.execute("UPDATE jobs SET status='failed',progress=1 WHERE id=1")
db.execute('UPDATE batches SET hidden=1')
self.config['ai_subtitle_ollama_model']='new-model'
self.service.queue({'id':1})
self.assertEqual((self.job()['model'],self.job()['progress']),('new-model',0))
with self.service.db() as db:
self.assertEqual(db.execute('SELECT COUNT(*) FROM translations WHERE job_id=1').fetchone()[0],0)
def test_clear_canceled_file_keeps_source_and_allows_new_model(self):
path=self.file()
self.config['ai_subtitle_ollama_model']='old-model';self.scan_queue()
with self.service.db() as db:
db.execute('INSERT INTO translations VALUES(1,0,?,?)', ('Hello there.','Wrong Czech.'))
db.execute("UPDATE jobs SET status='canceled',progress=1 WHERE id=1")
self.service.clear_file(1)
self.assertEqual(self.service.snapshot()['subtitles'][0]['status'],'cleared')
self.assertEqual(self.service.snapshot()['subtitles'][0]['review_id'],None)
self.assertEqual(self.service.list_queue_jobs(),[])
self.assertEqual(path.read_bytes(),SRT)
self.config['ai_subtitle_ollama_model']='new-model'
self.service.queue({'id':1})
self.assertEqual((self.job()['model'],self.job()['progress']),('new-model',0))
self.assertNotIn('Wrong Czech.',str(self.service.review(1)))
def test_direct_resume_keeps_original_model(self):
self.file();self.config['ai_subtitle_ollama_model']='old-model';self.scan_queue()
with self.service.db() as db:
db.execute("UPDATE jobs SET status='failed' WHERE id=1")
self.config['ai_subtitle_ollama_model']='new-model'
self.service.queue({'id':1})
self.assertEqual(self.job()['model'],'old-model')
def test_stop_running_job_discards_inflight_model_result_and_can_retry(self):
path=self.file()
@@ -449,16 +510,19 @@ class ServiceTests(unittest.TestCase):
def test_restart_file_discards_saved_cues_and_translates_from_start(self):
path=self.file()
self.config['ai_subtitle_ollama_model']='old-model'
self.scan_queue()
with self.service.db() as db:
db.execute('INSERT INTO translations VALUES(1,0,?,?)', ('Hello there.', 'Špatně.'))
db.execute("UPDATE jobs SET status='canceled',progress=1,warnings='[1]' WHERE id=1")
self.config['ai_subtitle_ollama_model']='new-model'
with patch.object(self.service, 'ensure_worker'):
result=self.service.restart_file(1)
self.assertIn('cue 1',result['message'])
self.assertEqual(self.job()['status'],'pending')
self.assertEqual(self.job()['progress'],0)
self.assertEqual(self.job()['warnings'],'[]')
self.assertEqual(self.job()['model'],'new-model')
with self.service.db() as db:
self.assertEqual(db.execute('SELECT COUNT(*) FROM translations WHERE job_id=1').fetchone()[0],0)
self.process()
+9
View File
@@ -4422,6 +4422,15 @@ class HandlerRouteTests(unittest.TestCase):
APP.Handler.do_POST(handler)
service.restart_file.assert_called_once_with(42)
def test_ai_subtitles_clear_route_targets_one_file(self):
service = mock.Mock()
service.clear_file.return_value = {"message": "Saved cues cleared."}
body = b'{"id":42}'
handler = DummyHandler("/api/ai-subtitles/clear", body=body, content_length=len(body))
with mock.patch.object(APP, "AI_SUBTITLES", service):
APP.Handler.do_POST(handler)
service.clear_file.assert_called_once_with(42)
def test_ai_subtitle_review_edit_route_passes_expected_cue_and_fingerprint(self):
service = mock.Mock()
service.edit_cue.return_value = {"message":"Cue 2 saved."}