fix(transcode): restore official cliUtils and fix transcode progress and log flooding
This commit is contained in:
1 parent
88ecf9a847
commit
2daa75df60
6 files changed
+94
-18
No files matched your search
@@ -1,43 +1,92 @@
|
||||
'use strict';
|
||||
/**
|
||||
* Local mock of Tdarr FlowHelpers/1.0.0/cliUtils.js
|
||||
* Used only for local testing — on real Tdarr this file comes from the server.
|
||||
* Local fallback/mock of Tdarr FlowHelpers/1.0.0/cliUtils.js
|
||||
* Used for local testing and as safe fallback.
|
||||
*
|
||||
* Matches the real Tdarr CLI constructor signature:
|
||||
* new CLI({ cli, spawnArgs, WorkDir, jobLog, inputFileObj, updateWorker })
|
||||
* - inputFileObj : used by real Tdarr for ffprobe-based progress tracking
|
||||
* - updateWorker : callback used by real Tdarr to push progress to the UI
|
||||
* Both are accepted but unused here (local mock just logs to stdout).
|
||||
* new CLI({ cli, spawnArgs, spawnOpts, WorkDir, jobLog, inputFileObj, updateWorker, logFullCliOutput })
|
||||
*/
|
||||
const { spawn } = require('child_process');
|
||||
|
||||
class CLI {
|
||||
constructor(config) {
|
||||
this.config = config;
|
||||
this.config = config || {};
|
||||
}
|
||||
|
||||
runCli() {
|
||||
return new Promise((resolve) => {
|
||||
const { cli, spawnArgs, WorkDir, jobLog } = this.config;
|
||||
const {
|
||||
cli,
|
||||
spawnArgs = [],
|
||||
spawnOpts = {},
|
||||
WorkDir,
|
||||
jobLog,
|
||||
updateWorker,
|
||||
logFullCliOutput = false,
|
||||
} = this.config;
|
||||
|
||||
if (jobLog) jobLog(`[CLI] Running: ${cli} ${spawnArgs.join(' ')}\n`);
|
||||
|
||||
const proc = spawn(cli, spawnArgs, {
|
||||
cwd: WorkDir || process.cwd(),
|
||||
const opts = {
|
||||
cwd: spawnOpts.cwd || WorkDir || process.cwd(),
|
||||
stdio: ['ignore', 'pipe', 'pipe'],
|
||||
shell: false,
|
||||
});
|
||||
...spawnOpts,
|
||||
};
|
||||
|
||||
proc.stdout.on('data', (d) => { if (jobLog) jobLog(d.toString()); });
|
||||
proc.stderr.on('data', (d) => { if (jobLog) jobLog(d.toString()); });
|
||||
if (jobLog) jobLog(`Running ${cli} ${spawnArgs.join(' ')}\n`);
|
||||
|
||||
const proc = spawn(cli, spawnArgs, opts);
|
||||
const errorLogFull = [];
|
||||
|
||||
const handleData = (data) => {
|
||||
const str = data.toString();
|
||||
errorLogFull.push(str);
|
||||
|
||||
if (logFullCliOutput && jobLog) {
|
||||
jobLog(str);
|
||||
}
|
||||
|
||||
if (typeof updateWorker === 'function') {
|
||||
// ffmpeg progress matching: time=HH:MM:SS
|
||||
const fpsMatch = str.match(/fps=\s*(\d+(?:\.\d+)?)/);
|
||||
if (fpsMatch) {
|
||||
updateWorker({ fps: parseFloat(fpsMatch[1]) });
|
||||
}
|
||||
|
||||
const timeMatch = str.match(/time=(\d{2}):(\d{2}):(\d{2}(?:\.\d+)?)/);
|
||||
if (timeMatch) {
|
||||
const curSec = parseInt(timeMatch[1], 10) * 3600
|
||||
+ parseInt(timeMatch[2], 10) * 60
|
||||
+ parseFloat(timeMatch[3]);
|
||||
const duration = this.config.inputFileObj?.meta?.Duration
|
||||
|| parseFloat(this.config.inputFileObj?.ffProbeData?.format?.duration)
|
||||
|| 0;
|
||||
if (duration > 0) {
|
||||
const perc = Math.min(100, Math.max(0, +((curSec / duration) * 100).toFixed(1)));
|
||||
updateWorker({ percentage: perc });
|
||||
}
|
||||
} else if (str.includes('%')) {
|
||||
// mkvextract progress matching (e.g. "Progress: 45%" or "Progresso: 45%")
|
||||
const pMatch = str.match(/(?:Progress|Progresso):\s*(\d+)%/i);
|
||||
if (pMatch) {
|
||||
updateWorker({ percentage: parseInt(pMatch[1], 10) });
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
proc.stdout.on('data', handleData);
|
||||
proc.stderr.on('data', handleData);
|
||||
|
||||
proc.on('close', (code) => {
|
||||
resolve({ cliExitCode: code || 0 });
|
||||
if (!logFullCliOutput && jobLog) {
|
||||
jobLog(errorLogFull.slice(-1000).join(''));
|
||||
}
|
||||
resolve({ cliExitCode: code || 0, errorLogFull });
|
||||
});
|
||||
|
||||
proc.on('error', (err) => {
|
||||
if (jobLog) jobLog(`[CLI] Error: ${err.message}\n`);
|
||||
resolve({ cliExitCode: 1 });
|
||||
if (jobLog) jobLog(`Error executing binary: ${cli}: ${err.message}\n`);
|
||||
resolve({ cliExitCode: 1, errorLogFull });
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -47,3 +96,4 @@ const getFFmpegVar = () => {};
|
||||
|
||||
module.exports = { CLI, getFFmpegVar };
|
||||
|
||||
|
||||
@@ -74,10 +74,13 @@ const plugin = async (args) => {
|
||||
'-c:a', 'copy',
|
||||
outFile,
|
||||
],
|
||||
spawnOpts: { cwd: workDir },
|
||||
WorkDir: workDir,
|
||||
jobLog,
|
||||
outputFilePath: outFile,
|
||||
inputFileObj,
|
||||
updateWorker,
|
||||
logFullCliOutput: args.logFullCliOutput || false,
|
||||
args,
|
||||
});
|
||||
|
||||
|
||||
@@ -99,10 +99,12 @@ const runCLI = async (cliBin, spawnArgs, args) => {
|
||||
const cli = new CLI({
|
||||
cli: cliBin,
|
||||
spawnArgs,
|
||||
spawnOpts: { cwd: args.workDir },
|
||||
WorkDir: args.workDir,
|
||||
jobLog: args.jobLog,
|
||||
inputFileObj: args.inputFileObj,
|
||||
updateWorker: args.updateWorker,
|
||||
logFullCliOutput: args.logFullCliOutput || false,
|
||||
args,
|
||||
});
|
||||
return cli.runCli();
|
||||
|
||||
@@ -50,10 +50,12 @@ const plugin = async (args) => {
|
||||
const cli = new CLI({
|
||||
cli: mkvExtract,
|
||||
spawnArgs: [inputFile, 'chapters', xmlPath],
|
||||
spawnOpts: { cwd: workDir },
|
||||
WorkDir: workDir,
|
||||
jobLog,
|
||||
inputFileObj,
|
||||
updateWorker,
|
||||
logFullCliOutput: args.logFullCliOutput || false,
|
||||
args,
|
||||
});
|
||||
|
||||
|
||||
@@ -266,10 +266,13 @@ const plugin = async (args) => {
|
||||
'-sn',
|
||||
outFile,
|
||||
],
|
||||
spawnOpts: { cwd: workDir },
|
||||
WorkDir: workDir,
|
||||
jobLog,
|
||||
outputFilePath: outFile,
|
||||
inputFileObj,
|
||||
updateWorker,
|
||||
logFullCliOutput: args.logFullCliOutput || false,
|
||||
args,
|
||||
});
|
||||
|
||||
@@ -310,10 +313,12 @@ const plugin = async (args) => {
|
||||
'-f', 'null',
|
||||
nullDev,
|
||||
],
|
||||
spawnOpts: { cwd: workDir },
|
||||
WorkDir: workDir,
|
||||
jobLog,
|
||||
inputFileObj,
|
||||
updateWorker,
|
||||
logFullCliOutput: args.logFullCliOutput || false,
|
||||
args,
|
||||
});
|
||||
|
||||
@@ -345,10 +350,13 @@ const plugin = async (args) => {
|
||||
'-sn',
|
||||
outFile,
|
||||
],
|
||||
spawnOpts: { cwd: workDir },
|
||||
WorkDir: workDir,
|
||||
jobLog,
|
||||
outputFilePath: outFile,
|
||||
inputFileObj,
|
||||
updateWorker,
|
||||
logFullCliOutput: args.logFullCliOutput || false,
|
||||
args,
|
||||
});
|
||||
|
||||
|
||||
+11
@@ -105,6 +105,17 @@ download_flow_helpers() {
|
||||
curl -fsSL "$official_fu" -o "${dest}/fileUtils.js" || true
|
||||
fi
|
||||
|
||||
# Restore official Tdarr cliUtils.js if it was previously overwritten by a mock
|
||||
local official_cu="https://raw.githubusercontent.com/HaveAGitGat/Tdarr_Plugins/master/FlowPlugins/FlowHelpers/1.0.0/cliUtils.js"
|
||||
if [[ -f "${dest}/cliUtils.js" ]]; then
|
||||
if grep -q "Local mock of Tdarr" "${dest}/cliUtils.js" || ! grep -q "ffmpegParser" "${dest}/cliUtils.js"; then
|
||||
echo " 🔄 Restoring official Tdarr cliUtils.js..."
|
||||
curl -fsSL "$official_cu" -o "${dest}/cliUtils.js" || true
|
||||
fi
|
||||
else
|
||||
curl -fsSL "$official_cu" -o "${dest}/cliUtils.js" || true
|
||||
fi
|
||||
|
||||
# Download our custom copyWithProgress helper
|
||||
local url="${RAW}/FlowHelpers/1.0.0/copyWithProgress.js"
|
||||
if curl -fsSL "$url" -o "${dest}/copyWithProgress.js"; then
|
||||
|
||||
Reference in new issue
Block a user