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
+99
-23
No files matched your search
@@ -1,43 +1,92 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
/**
|
/**
|
||||||
* Local mock of Tdarr FlowHelpers/1.0.0/cliUtils.js
|
* Local fallback/mock of Tdarr FlowHelpers/1.0.0/cliUtils.js
|
||||||
* Used only for local testing — on real Tdarr this file comes from the server.
|
* Used for local testing and as safe fallback.
|
||||||
*
|
*
|
||||||
* Matches the real Tdarr CLI constructor signature:
|
* Matches the real Tdarr CLI constructor signature:
|
||||||
* new CLI({ cli, spawnArgs, WorkDir, jobLog, inputFileObj, updateWorker })
|
* new CLI({ cli, spawnArgs, spawnOpts, WorkDir, jobLog, inputFileObj, updateWorker, logFullCliOutput })
|
||||||
* - 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).
|
|
||||||
*/
|
*/
|
||||||
const { spawn } = require('child_process');
|
const { spawn } = require('child_process');
|
||||||
|
|
||||||
class CLI {
|
class CLI {
|
||||||
constructor(config) {
|
constructor(config) {
|
||||||
this.config = config;
|
this.config = config || {};
|
||||||
}
|
}
|
||||||
|
|
||||||
runCli() {
|
runCli() {
|
||||||
return new Promise((resolve) => {
|
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 opts = {
|
||||||
|
cwd: spawnOpts.cwd || WorkDir || process.cwd(),
|
||||||
const proc = spawn(cli, spawnArgs, {
|
|
||||||
cwd: WorkDir || process.cwd(),
|
|
||||||
stdio: ['ignore', 'pipe', 'pipe'],
|
stdio: ['ignore', 'pipe', 'pipe'],
|
||||||
shell: false,
|
shell: false,
|
||||||
});
|
...spawnOpts,
|
||||||
|
};
|
||||||
|
|
||||||
proc.stdout.on('data', (d) => { if (jobLog) jobLog(d.toString()); });
|
if (jobLog) jobLog(`Running ${cli} ${spawnArgs.join(' ')}\n`);
|
||||||
proc.stderr.on('data', (d) => { if (jobLog) jobLog(d.toString()); });
|
|
||||||
|
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) => {
|
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) => {
|
proc.on('error', (err) => {
|
||||||
if (jobLog) jobLog(`[CLI] Error: ${err.message}\n`);
|
if (jobLog) jobLog(`Error executing binary: ${cli}: ${err.message}\n`);
|
||||||
resolve({ cliExitCode: 1 });
|
resolve({ cliExitCode: 1, errorLogFull });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -47,3 +96,4 @@ const getFFmpegVar = () => {};
|
|||||||
|
|
||||||
module.exports = { CLI, getFFmpegVar };
|
module.exports = { CLI, getFFmpegVar };
|
||||||
|
|
||||||
|
|
||||||
@@ -74,10 +74,13 @@ const plugin = async (args) => {
|
|||||||
'-c:a', 'copy',
|
'-c:a', 'copy',
|
||||||
outFile,
|
outFile,
|
||||||
],
|
],
|
||||||
|
spawnOpts: { cwd: workDir },
|
||||||
WorkDir: workDir,
|
WorkDir: workDir,
|
||||||
jobLog,
|
jobLog,
|
||||||
|
outputFilePath: outFile,
|
||||||
inputFileObj,
|
inputFileObj,
|
||||||
updateWorker,
|
updateWorker,
|
||||||
|
logFullCliOutput: args.logFullCliOutput || false,
|
||||||
args,
|
args,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -97,12 +97,14 @@ const getMkvExtract = (args) => {
|
|||||||
const runCLI = async (cliBin, spawnArgs, args) => {
|
const runCLI = async (cliBin, spawnArgs, args) => {
|
||||||
const { CLI } = require('../../../../FlowHelpers/1.0.0/cliUtils');
|
const { CLI } = require('../../../../FlowHelpers/1.0.0/cliUtils');
|
||||||
const cli = new CLI({
|
const cli = new CLI({
|
||||||
cli: cliBin,
|
cli: cliBin,
|
||||||
spawnArgs,
|
spawnArgs,
|
||||||
WorkDir: args.workDir,
|
spawnOpts: { cwd: args.workDir },
|
||||||
jobLog: args.jobLog,
|
WorkDir: args.workDir,
|
||||||
inputFileObj: args.inputFileObj,
|
jobLog: args.jobLog,
|
||||||
updateWorker: args.updateWorker,
|
inputFileObj: args.inputFileObj,
|
||||||
|
updateWorker: args.updateWorker,
|
||||||
|
logFullCliOutput: args.logFullCliOutput || false,
|
||||||
args,
|
args,
|
||||||
});
|
});
|
||||||
return cli.runCli();
|
return cli.runCli();
|
||||||
|
|||||||
@@ -50,10 +50,12 @@ const plugin = async (args) => {
|
|||||||
const cli = new CLI({
|
const cli = new CLI({
|
||||||
cli: mkvExtract,
|
cli: mkvExtract,
|
||||||
spawnArgs: [inputFile, 'chapters', xmlPath],
|
spawnArgs: [inputFile, 'chapters', xmlPath],
|
||||||
|
spawnOpts: { cwd: workDir },
|
||||||
WorkDir: workDir,
|
WorkDir: workDir,
|
||||||
jobLog,
|
jobLog,
|
||||||
inputFileObj,
|
inputFileObj,
|
||||||
updateWorker,
|
updateWorker,
|
||||||
|
logFullCliOutput: args.logFullCliOutput || false,
|
||||||
args,
|
args,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -266,10 +266,13 @@ const plugin = async (args) => {
|
|||||||
'-sn',
|
'-sn',
|
||||||
outFile,
|
outFile,
|
||||||
],
|
],
|
||||||
|
spawnOpts: { cwd: workDir },
|
||||||
WorkDir: workDir,
|
WorkDir: workDir,
|
||||||
jobLog,
|
jobLog,
|
||||||
|
outputFilePath: outFile,
|
||||||
inputFileObj,
|
inputFileObj,
|
||||||
updateWorker,
|
updateWorker,
|
||||||
|
logFullCliOutput: args.logFullCliOutput || false,
|
||||||
args,
|
args,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -310,10 +313,12 @@ const plugin = async (args) => {
|
|||||||
'-f', 'null',
|
'-f', 'null',
|
||||||
nullDev,
|
nullDev,
|
||||||
],
|
],
|
||||||
|
spawnOpts: { cwd: workDir },
|
||||||
WorkDir: workDir,
|
WorkDir: workDir,
|
||||||
jobLog,
|
jobLog,
|
||||||
inputFileObj,
|
inputFileObj,
|
||||||
updateWorker,
|
updateWorker,
|
||||||
|
logFullCliOutput: args.logFullCliOutput || false,
|
||||||
args,
|
args,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -345,10 +350,13 @@ const plugin = async (args) => {
|
|||||||
'-sn',
|
'-sn',
|
||||||
outFile,
|
outFile,
|
||||||
],
|
],
|
||||||
|
spawnOpts: { cwd: workDir },
|
||||||
WorkDir: workDir,
|
WorkDir: workDir,
|
||||||
jobLog,
|
jobLog,
|
||||||
|
outputFilePath: outFile,
|
||||||
inputFileObj,
|
inputFileObj,
|
||||||
updateWorker,
|
updateWorker,
|
||||||
|
logFullCliOutput: args.logFullCliOutput || false,
|
||||||
args,
|
args,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+11
@@ -105,6 +105,17 @@ download_flow_helpers() {
|
|||||||
curl -fsSL "$official_fu" -o "${dest}/fileUtils.js" || true
|
curl -fsSL "$official_fu" -o "${dest}/fileUtils.js" || true
|
||||||
fi
|
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
|
# Download our custom copyWithProgress helper
|
||||||
local url="${RAW}/FlowHelpers/1.0.0/copyWithProgress.js"
|
local url="${RAW}/FlowHelpers/1.0.0/copyWithProgress.js"
|
||||||
if curl -fsSL "$url" -o "${dest}/copyWithProgress.js"; then
|
if curl -fsSL "$url" -o "${dest}/copyWithProgress.js"; then
|
||||||
|
|||||||
Reference in new issue
Block a user