Fix copy progress, remove v2.0.0, fix subtitle default naming, enforce strict no-upcoding on audio
Build / Lint & Test (push) Successful in 3m15s
Build / Lint & Test (push) Successful in 3m15s
This commit is contained in:
1 parent
7ee5a5bc48
commit
86448988ed
12 files changed
+470
-348
No files matched your search
@@ -2,12 +2,13 @@
|
||||
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const { copyWithProgress } = require('../../../../FlowHelpers/1.0.0/copyWithProgress');
|
||||
|
||||
/* eslint-disable no-param-reassign */
|
||||
|
||||
/**
|
||||
* copyToWorkDir
|
||||
* Copies the source file to the worker's local workDir before processing.
|
||||
* Copies the source file into the worker's local workDir before processing.
|
||||
*
|
||||
* Use this plugin BEFORE any transcode/extract plugin when:
|
||||
* - The source file lives on a network share / mapped drive
|
||||
@@ -15,21 +16,20 @@ const fs = require('fs');
|
||||
* - The network path is slow or unreliable during long encodes
|
||||
*
|
||||
* Flow:
|
||||
* 1. Copies source → workDir/<basename>_old<ext> (streams, no RAM load)
|
||||
* 1. Copies source -> workDir/<basename>_old<ext> (streamed with real-time progress)
|
||||
* 2. Updates outputFileObj._id to the local copy path
|
||||
* 3. Downstream plugins operate on the local copy
|
||||
* 4. Tdarr replaces the original with the final output as usual
|
||||
* 4. Tdarr replaces the original with the final output via replaceOriginalFile
|
||||
*/
|
||||
|
||||
const details = () => ({
|
||||
name: 'Copy Source to Work Dir',
|
||||
description:
|
||||
'Copies the source file into the worker local workDir before processing. '
|
||||
+ 'Use before transcode plugins when the source is on a slow network share '
|
||||
+ 'to avoid I/O bottleneck during encode. '
|
||||
+ 'The local copy is used by all subsequent plugins in this flow.',
|
||||
'Copies the source file into the worker local workDir using a streamed, verified copy '
|
||||
+ 'with real-time progress, speed, and ETA tracking. Use before transcode plugins '
|
||||
+ 'when the source is on a network share to avoid I/O bottlenecks during encoding.',
|
||||
style: { borderColor: '#607D8B' },
|
||||
tags: 'utility',
|
||||
tags: 'utility,copy,progress',
|
||||
isStartPlugin: false,
|
||||
pType: '',
|
||||
requiresVersion: '2.11.01',
|
||||
@@ -55,27 +55,35 @@ const details = () => ({
|
||||
],
|
||||
});
|
||||
|
||||
// ─── Plugin ───────────────────────────────────────────────────────────────────
|
||||
|
||||
const plugin = async (args) => {
|
||||
const { jobLog, inputFileObj, variables, workDir } = args;
|
||||
const { jobLog, inputFileObj, variables, workDir, updateWorker } = args;
|
||||
|
||||
const inputFile = inputFileObj._id;
|
||||
const ext = path.extname(inputFile);
|
||||
const baseName = path.basename(inputFile, ext);
|
||||
const localCopy = path.join(workDir, `${baseName}_old${ext}`);
|
||||
const skipIfLocal = (args.inputs.skipIfLocal || 'true') === 'true';
|
||||
|
||||
jobLog(`[copyToWorkDir] Source : ${inputFile}\n`);
|
||||
jobLog(`[copyToWorkDir] WorkDir: ${workDir}\n`);
|
||||
|
||||
// ── Skip only if file is already located inside workDir ──────────────────
|
||||
const skipIfLocal = (args.inputs.skipIfLocal || 'true') === 'true';
|
||||
if (skipIfLocal && inputFile.startsWith(workDir)) {
|
||||
// Skip if source file is already inside workDir
|
||||
const relativeInput = path.relative(path.resolve(workDir), path.resolve(inputFile));
|
||||
if (
|
||||
skipIfLocal
|
||||
&& relativeInput !== '..'
|
||||
&& !relativeInput.startsWith(`..${path.sep}`)
|
||||
&& !path.isAbsolute(relativeInput)
|
||||
) {
|
||||
jobLog('[copyToWorkDir] Source file is already inside workDir — skipping copy.\n');
|
||||
return { outputNumber: 1, outputFileObj: inputFileObj, variables };
|
||||
}
|
||||
|
||||
// ── Preserve original library paths for downstream plugins ──────────────
|
||||
if (!fs.existsSync(inputFile)) {
|
||||
throw new Error(`[copyToWorkDir] Source file not found: ${inputFile}`);
|
||||
}
|
||||
|
||||
// Preserve original library paths for downstream plugins
|
||||
if (!variables.originalLibraryFile) {
|
||||
variables.originalLibraryFile = inputFile;
|
||||
variables.originalLibraryDir = path.dirname(inputFile);
|
||||
@@ -83,43 +91,16 @@ const plugin = async (args) => {
|
||||
variables.workDirSourceBaseName = baseName;
|
||||
variables.workDirCopyApplied = 'true';
|
||||
|
||||
// ── Copy using streams (no RAM spike for large files) ────────────────────
|
||||
const sourceSize = fs.statSync(inputFile).size;
|
||||
const sourceSizeMb = (sourceSize / 1024 / 1024).toFixed(1);
|
||||
jobLog(`[copyToWorkDir] Copying ${sourceSizeMb} MB to: ${localCopy}\n`);
|
||||
|
||||
const startMs = Date.now();
|
||||
let copiedBytes = 0;
|
||||
let nextProgressPercent = 10;
|
||||
|
||||
await new Promise((resolve, reject) => {
|
||||
const rd = fs.createReadStream(inputFile);
|
||||
const wr = fs.createWriteStream(localCopy);
|
||||
|
||||
rd.on('error', reject);
|
||||
wr.on('error', reject);
|
||||
wr.on('finish', resolve);
|
||||
rd.on('data', (chunk) => {
|
||||
copiedBytes += chunk.length;
|
||||
if (sourceSize <= 0) return;
|
||||
|
||||
const percent = Math.floor((copiedBytes / sourceSize) * 100);
|
||||
if (percent < nextProgressPercent) return;
|
||||
|
||||
const elapsedSeconds = Math.max((Date.now() - startMs) / 1000, 0.1);
|
||||
const copiedMb = (copiedBytes / 1024 / 1024).toFixed(1);
|
||||
const speedMbPerSecond = (copiedBytes / 1024 / 1024 / elapsedSeconds).toFixed(1);
|
||||
jobLog(`[copyToWorkDir] Progress: ${Math.min(percent, 100)}% (${copiedMb}/${sourceSizeMb} MB, ${speedMbPerSecond} MB/s)\n`);
|
||||
nextProgressPercent = (Math.floor(percent / 10) + 1) * 10;
|
||||
});
|
||||
rd.pipe(wr);
|
||||
jobLog(`[copyToWorkDir] Copying ${inputFile} to ${localCopy}\n`);
|
||||
await copyWithProgress({
|
||||
source: inputFile,
|
||||
destination: localCopy,
|
||||
jobLog,
|
||||
updateWorker,
|
||||
updateProgress: args.updateProgress,
|
||||
label: 'copyToWorkDir',
|
||||
});
|
||||
|
||||
const elapsed = ((Date.now() - startMs) / 1000).toFixed(1);
|
||||
const sizeMb = (fs.statSync(localCopy).size / 1024 / 1024).toFixed(1);
|
||||
jobLog(`[copyToWorkDir] Done: ${sizeMb} MB copied in ${elapsed}s\n`);
|
||||
|
||||
// Return updated inputFileObj pointing to the local copy
|
||||
return {
|
||||
outputNumber: 1,
|
||||
outputFileObj: { ...inputFileObj, _id: localCopy },
|
||||
|
||||
Reference in new issue
Block a user