feat: add 06_pgs2srt_OCR_Strip for PGS OCR integration
This commit is contained in:
parent
595112b652
commit
f0dbb273f8
1 changed files with 93 additions and 0 deletions
93
fileflows/scripts/06_pgs2srt_OCR_Strip.js
Normal file
93
fileflows/scripts/06_pgs2srt_OCR_Strip.js
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
/**
|
||||
* @name 06_pgs2srt_OCR_Strip
|
||||
* @description Ruft pgs2srt OCR+Strip auf der Zieldatei nach Finalize_Move auf.
|
||||
* Extrahiert PGS/Bild-Untertitel als SRT-Sidecars und entfernt sie aus dem MKV.
|
||||
* Fehlertolerant: bei OCR-Fehler bleibt die MKV unveraendert, Import wird nicht blockiert.
|
||||
* Voraussetzung: pgs2srt-Container hat /tdarr-Volume gemountet.
|
||||
* @author Sascha + Trulla
|
||||
* @revision 1
|
||||
* @output OK (OCR abgeschlossen oder keine Subs)
|
||||
* @output Fehler (MKV unveraendert, Import fortsetzen)
|
||||
* @param {string} Pgs2srtUrl pgs2srt API URL (Default http://10.2.1.104:8095)
|
||||
* @param {string} Langs Komma-getrennte Sprachen (Default ger,eng)
|
||||
*/
|
||||
function Script(Pgs2srtUrl, Langs)
|
||||
{
|
||||
Pgs2srtUrl = Pgs2srtUrl || 'http://10.2.1.104:8095';
|
||||
Langs = Langs || 'ger,eng';
|
||||
|
||||
let workingFile = Variables['file.FullName'] || Flow.WorkingFile;
|
||||
if (!workingFile) {
|
||||
Logger.ELog('pgs2srt: keine Working File');
|
||||
return 2;
|
||||
}
|
||||
|
||||
// pgs2srt sieht das /tdarr-Volume. FileFlows sieht ebenfalls /tdarr.
|
||||
// Die Pfade sollten identisch sein. Wenn nicht, ist das ein Konfigurationsfehler.
|
||||
// Pruefe ob der Pfad unter /tdarr liegt (typisch nach Finalize_Move).
|
||||
if (workingFile.indexOf('/tdarr/') !== 0) {
|
||||
Logger.WLog('pgs2srt: Working File liegt nicht unter /tdarr/ (' + workingFile + ') - Skip OCR');
|
||||
return 1;
|
||||
}
|
||||
|
||||
let langArray = Langs.split(',').map(function(s) { return s.trim(); });
|
||||
|
||||
// HTTP-Request an pgs2srt: POST /api/ocr-and-strip
|
||||
// Body: {"path": "<workingFile>", "langs": ["ger","eng"]}
|
||||
let body = JSON.stringify({ path: workingFile, langs: langArray });
|
||||
|
||||
Logger.ILog('pgs2srt: OCR+Strip fuer ' + workingFile + ' (langs=' + Langs + ')');
|
||||
|
||||
// FileFlows Flow.Execute kann keine HTTP-Requests direkt.
|
||||
// Verwende curl als Command.
|
||||
let curlPath = '/usr/bin/curl';
|
||||
let args = [
|
||||
'-sS',
|
||||
'-X', 'POST',
|
||||
'-H', 'Content-Type: application/json',
|
||||
'-d', body,
|
||||
'--max-time', '600',
|
||||
Pgs2srtUrl + '/api/ocr-and-strip'
|
||||
];
|
||||
|
||||
let result = Flow.Execute({
|
||||
command: curlPath,
|
||||
argumentList: args
|
||||
});
|
||||
|
||||
if (!result || result.exitCode !== 0) {
|
||||
Logger.WLog('pgs2srt: HTTP-Request fehlgeschlagen (exit=' + (result ? result.exitCode : '?') + ') - MKV bleibt unveraendert');
|
||||
if (result && result.standardError) Logger.WLog(result.standardError);
|
||||
return 2;
|
||||
}
|
||||
|
||||
// Antwort parsen
|
||||
let responseText = result.standardOutput || result.output || '';
|
||||
Logger.ILog('pgs2srt: Response: ' + responseText.substring(0, 500));
|
||||
|
||||
var response;
|
||||
try {
|
||||
response = JSON.parse(responseText);
|
||||
} catch (e) {
|
||||
Logger.WLog('pgs2srt: JSON-Parse-Fehler - MKV bleibt unveraendert');
|
||||
return 2;
|
||||
}
|
||||
|
||||
let status = response.status || '';
|
||||
if (status === 'ok') {
|
||||
Logger.ILog('pgs2srt: OCR erfolgreich (' + response.message + ')');
|
||||
return 1;
|
||||
} else if (status === 'no_subs') {
|
||||
Logger.ILog('pgs2srt: keine Untertitel gefunden - OK');
|
||||
return 1;
|
||||
} else if (status === 'partial') {
|
||||
Logger.WLog('pgs2srt: Teilweise erfolgreich (' + response.message + ') - MKV verarbeitet, einige Subs fehlen');
|
||||
return 1;
|
||||
} else if (status === 'error') {
|
||||
Logger.WLog('pgs2srt: Fehler (' + (response.message || '?') + ') - MKV bleibt unveraendert');
|
||||
return 2;
|
||||
} else {
|
||||
Logger.WLog('pgs2srt: Unbekannte Antwort (' + status + ') - MKV bleibt unveraendert');
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue