mirror of
https://github.com/gabehf/Tdarr_Plugins.git
synced 2026-03-14 01:36:08 -07:00
Apply auto-build changes
This commit is contained in:
parent
c13d029aa9
commit
97e92c8b98
5 changed files with 612 additions and 632 deletions
|
|
@ -45,8 +45,8 @@ var plugin = function (args) {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||||
var extensions = String(args.inputs.extensions);
|
var extensions = String(args.inputs.extensions);
|
||||||
var extensionArray = extensions.trim().split(',');
|
var extensionArray = extensions.trim().split(',').map(function (row) { return row.toLowerCase(); });
|
||||||
var extension = (0, fileUtils_1.getContainer)(args.inputFileObj._id);
|
var extension = (0, fileUtils_1.getContainer)(args.inputFileObj._id).toLowerCase();
|
||||||
var extensionMatch = false;
|
var extensionMatch = false;
|
||||||
if (extensionArray.includes(extension)) {
|
if (extensionArray.includes(extension)) {
|
||||||
extensionMatch = true;
|
extensionMatch = true;
|
||||||
|
|
|
||||||
|
|
@ -150,33 +150,31 @@ var details = function () { return ({
|
||||||
],
|
],
|
||||||
}); };
|
}); };
|
||||||
exports.details = details;
|
exports.details = details;
|
||||||
var doOperation = function (_a) {
|
var doOperation = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
||||||
var args = _a.args, sourcePath = _a.sourcePath, destinationPath = _a.destinationPath, operation = _a.operation;
|
var args = _b.args, sourcePath = _b.sourcePath, destinationPath = _b.destinationPath, operation = _b.operation;
|
||||||
return __awaiter(void 0, void 0, void 0, function () {
|
return __generator(this, function (_c) {
|
||||||
return __generator(this, function (_b) {
|
switch (_c.label) {
|
||||||
switch (_b.label) {
|
case 0:
|
||||||
case 0:
|
args.jobLog("Input path: ".concat(sourcePath));
|
||||||
args.jobLog("Input path: ".concat(sourcePath));
|
args.jobLog("Output path: ".concat(destinationPath));
|
||||||
args.jobLog("Output path: ".concat(destinationPath));
|
if (!(sourcePath === destinationPath)) return [3 /*break*/, 1];
|
||||||
if (!(sourcePath === destinationPath)) return [3 /*break*/, 1];
|
args.jobLog("Input and output path are the same, skipping ".concat(operation));
|
||||||
args.jobLog("Input and output path are the same, skipping ".concat(operation));
|
return [3 /*break*/, 3];
|
||||||
return [3 /*break*/, 3];
|
case 1:
|
||||||
case 1:
|
args.deps.fsextra.ensureDirSync((0, fileUtils_1.getFileAbosluteDir)(destinationPath));
|
||||||
args.deps.fsextra.ensureDirSync((0, fileUtils_1.getFileAbosluteDir)(destinationPath));
|
return [4 /*yield*/, (0, fileMoveOrCopy_1.default)({
|
||||||
return [4 /*yield*/, (0, fileMoveOrCopy_1.default)({
|
operation: operation,
|
||||||
operation: operation,
|
sourcePath: sourcePath,
|
||||||
sourcePath: sourcePath,
|
destinationPath: destinationPath,
|
||||||
destinationPath: destinationPath,
|
args: args,
|
||||||
args: args,
|
})];
|
||||||
})];
|
case 2:
|
||||||
case 2:
|
_c.sent();
|
||||||
_b.sent();
|
_c.label = 3;
|
||||||
_b.label = 3;
|
case 3: return [2 /*return*/];
|
||||||
case 3: return [2 /*return*/];
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
}); };
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function () {
|
var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function () {
|
||||||
var lib, _a, keepRelativePath, allFiles, sourceDirectory, outputDirectory, copyOrMove, fileExtensions, outputPath, subStem, sourceDir, filesInDir, i;
|
var lib, _a, keepRelativePath, allFiles, sourceDirectory, outputDirectory, copyOrMove, fileExtensions, outputPath, subStem, sourceDir, filesInDir, i;
|
||||||
|
|
|
||||||
|
|
@ -69,260 +69,248 @@ var compareOldNew = function (_a) {
|
||||||
+ " cache file of size ".concat(sourceFileSize));
|
+ " cache file of size ".concat(sourceFileSize));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var tryMove = function (_a) {
|
var tryMove = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
||||||
var sourcePath = _a.sourcePath, destinationPath = _a.destinationPath, sourceFileSize = _a.sourceFileSize, args = _a.args;
|
var error, err_2, destinationSize;
|
||||||
return __awaiter(void 0, void 0, void 0, function () {
|
var sourcePath = _b.sourcePath, destinationPath = _b.destinationPath, sourceFileSize = _b.sourceFileSize, args = _b.args;
|
||||||
var error, err_2, destinationSize;
|
return __generator(this, function (_c) {
|
||||||
return __generator(this, function (_b) {
|
switch (_c.label) {
|
||||||
switch (_b.label) {
|
case 0:
|
||||||
case 0:
|
args.jobLog("Attempting move from ".concat(sourcePath, " to ").concat(destinationPath, ", method 1"));
|
||||||
args.jobLog("Attempting move from ".concat(sourcePath, " to ").concat(destinationPath, ", method 1"));
|
error = false;
|
||||||
error = false;
|
_c.label = 1;
|
||||||
_b.label = 1;
|
case 1:
|
||||||
case 1:
|
_c.trys.push([1, 3, , 4]);
|
||||||
_b.trys.push([1, 3, , 4]);
|
return [4 /*yield*/, fs_1.promises.rename(sourcePath, destinationPath)];
|
||||||
return [4 /*yield*/, fs_1.promises.rename(sourcePath, destinationPath)];
|
case 2:
|
||||||
case 2:
|
_c.sent();
|
||||||
_b.sent();
|
return [3 /*break*/, 4];
|
||||||
return [3 /*break*/, 4];
|
case 3:
|
||||||
case 3:
|
err_2 = _c.sent();
|
||||||
err_2 = _b.sent();
|
error = true;
|
||||||
error = true;
|
args.jobLog("File move error: ".concat(JSON.stringify(err_2)));
|
||||||
args.jobLog("File move error: ".concat(JSON.stringify(err_2)));
|
return [3 /*break*/, 4];
|
||||||
return [3 /*break*/, 4];
|
case 4: return [4 /*yield*/, getSizeBytes(destinationPath)];
|
||||||
case 4: return [4 /*yield*/, getSizeBytes(destinationPath)];
|
case 5:
|
||||||
case 5:
|
destinationSize = _c.sent();
|
||||||
destinationSize = _b.sent();
|
compareOldNew({
|
||||||
compareOldNew({
|
sourceFileSize: sourceFileSize,
|
||||||
sourceFileSize: sourceFileSize,
|
destinationSize: destinationSize,
|
||||||
destinationSize: destinationSize,
|
args: args,
|
||||||
args: args,
|
});
|
||||||
});
|
if (error || destinationSize !== sourceFileSize) {
|
||||||
if (error || destinationSize !== sourceFileSize) {
|
return [2 /*return*/, false];
|
||||||
return [2 /*return*/, false];
|
}
|
||||||
}
|
return [2 /*return*/, true];
|
||||||
return [2 /*return*/, true];
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
}); };
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
var tryMvdir = function (_a) {
|
var tryMvdir = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
||||||
var sourcePath = _a.sourcePath, destinationPath = _a.destinationPath, sourceFileSize = _a.sourceFileSize, args = _a.args;
|
var error, destinationSize;
|
||||||
return __awaiter(void 0, void 0, void 0, function () {
|
var sourcePath = _b.sourcePath, destinationPath = _b.destinationPath, sourceFileSize = _b.sourceFileSize, args = _b.args;
|
||||||
var error, destinationSize;
|
return __generator(this, function (_c) {
|
||||||
return __generator(this, function (_b) {
|
switch (_c.label) {
|
||||||
switch (_b.label) {
|
case 0:
|
||||||
case 0:
|
args.jobLog("Attempting move from ".concat(sourcePath, " to ").concat(destinationPath, ", method 2"));
|
||||||
args.jobLog("Attempting move from ".concat(sourcePath, " to ").concat(destinationPath, ", method 2"));
|
error = false;
|
||||||
error = false;
|
return [4 /*yield*/, new Promise(function (resolve) {
|
||||||
return [4 /*yield*/, new Promise(function (resolve) {
|
// fs-extra and move-file don't work when destination is on windows root of drive
|
||||||
// fs-extra and move-file don't work when destination is on windows root of drive
|
// mvdir will try to move else fall back to copy/unlink
|
||||||
// mvdir will try to move else fall back to copy/unlink
|
// potential bug on unraid
|
||||||
// potential bug on unraid
|
args.deps.mvdir(sourcePath, destinationPath, { overwrite: true })
|
||||||
args.deps.mvdir(sourcePath, destinationPath, { overwrite: true })
|
.then(function () {
|
||||||
.then(function () {
|
resolve(true);
|
||||||
resolve(true);
|
}).catch(function (err) {
|
||||||
}).catch(function (err) {
|
error = true;
|
||||||
error = true;
|
args.jobLog("File move error: ".concat(err));
|
||||||
args.jobLog("File move error: ".concat(err));
|
resolve(err);
|
||||||
resolve(err);
|
});
|
||||||
});
|
})];
|
||||||
})];
|
case 1:
|
||||||
case 1:
|
_c.sent();
|
||||||
_b.sent();
|
return [4 /*yield*/, getSizeBytes(destinationPath)];
|
||||||
return [4 /*yield*/, getSizeBytes(destinationPath)];
|
case 2:
|
||||||
case 2:
|
destinationSize = _c.sent();
|
||||||
destinationSize = _b.sent();
|
compareOldNew({
|
||||||
compareOldNew({
|
sourceFileSize: sourceFileSize,
|
||||||
sourceFileSize: sourceFileSize,
|
destinationSize: destinationSize,
|
||||||
destinationSize: destinationSize,
|
args: args,
|
||||||
args: args,
|
});
|
||||||
});
|
if (error || destinationSize !== sourceFileSize) {
|
||||||
if (error || destinationSize !== sourceFileSize) {
|
return [2 /*return*/, false];
|
||||||
return [2 /*return*/, false];
|
}
|
||||||
}
|
return [2 /*return*/, true];
|
||||||
return [2 /*return*/, true];
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
}); };
|
||||||
// Keep in e.g. https://github.com/HaveAGitGat/Tdarr/issues/858
|
// Keep in e.g. https://github.com/HaveAGitGat/Tdarr/issues/858
|
||||||
var tyNcp = function (_a) {
|
var tyNcp = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
||||||
var sourcePath = _a.sourcePath, destinationPath = _a.destinationPath, sourceFileSize = _a.sourceFileSize, args = _a.args;
|
var error_1, destinationSize;
|
||||||
return __awaiter(void 0, void 0, void 0, function () {
|
var sourcePath = _b.sourcePath, destinationPath = _b.destinationPath, sourceFileSize = _b.sourceFileSize, args = _b.args;
|
||||||
var error_1, destinationSize;
|
return __generator(this, function (_c) {
|
||||||
return __generator(this, function (_b) {
|
switch (_c.label) {
|
||||||
switch (_b.label) {
|
case 0:
|
||||||
case 0:
|
if (!args.deps.ncp) return [3 /*break*/, 3];
|
||||||
if (!args.deps.ncp) return [3 /*break*/, 3];
|
args.jobLog("Attempting copy from ".concat(sourcePath, " to ").concat(destinationPath, " , method 1"));
|
||||||
args.jobLog("Attempting copy from ".concat(sourcePath, " to ").concat(destinationPath, " , method 1"));
|
error_1 = false;
|
||||||
error_1 = false;
|
return [4 /*yield*/, new Promise(function (resolve) {
|
||||||
return [4 /*yield*/, new Promise(function (resolve) {
|
args.deps.ncp(sourcePath, destinationPath, function (err) {
|
||||||
args.deps.ncp(sourcePath, destinationPath, function (err) {
|
if (err) {
|
||||||
if (err) {
|
error_1 = true;
|
||||||
error_1 = true;
|
args.jobLog("File copy error: ".concat(err));
|
||||||
args.jobLog("File copy error: ".concat(err));
|
resolve(err);
|
||||||
resolve(err);
|
}
|
||||||
}
|
else {
|
||||||
else {
|
resolve(true);
|
||||||
resolve(true);
|
}
|
||||||
}
|
});
|
||||||
});
|
})];
|
||||||
})];
|
case 1:
|
||||||
case 1:
|
_c.sent();
|
||||||
_b.sent();
|
return [4 /*yield*/, getSizeBytes(destinationPath)];
|
||||||
return [4 /*yield*/, getSizeBytes(destinationPath)];
|
case 2:
|
||||||
case 2:
|
destinationSize = _c.sent();
|
||||||
destinationSize = _b.sent();
|
compareOldNew({
|
||||||
compareOldNew({
|
sourceFileSize: sourceFileSize,
|
||||||
sourceFileSize: sourceFileSize,
|
destinationSize: destinationSize,
|
||||||
destinationSize: destinationSize,
|
args: args,
|
||||||
args: args,
|
});
|
||||||
});
|
if (error_1 || destinationSize !== sourceFileSize) {
|
||||||
if (error_1 || destinationSize !== sourceFileSize) {
|
return [2 /*return*/, false];
|
||||||
return [2 /*return*/, false];
|
}
|
||||||
}
|
return [2 /*return*/, true];
|
||||||
return [2 /*return*/, true];
|
case 3: return [2 /*return*/, false];
|
||||||
case 3: return [2 /*return*/, false];
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
}); };
|
||||||
var tryNormalCopy = function (_a) {
|
var tryNormalCopy = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
||||||
var sourcePath = _a.sourcePath, destinationPath = _a.destinationPath, sourceFileSize = _a.sourceFileSize, args = _a.args;
|
var error, err_3, destinationSize;
|
||||||
return __awaiter(void 0, void 0, void 0, function () {
|
var sourcePath = _b.sourcePath, destinationPath = _b.destinationPath, sourceFileSize = _b.sourceFileSize, args = _b.args;
|
||||||
var error, err_3, destinationSize;
|
return __generator(this, function (_c) {
|
||||||
return __generator(this, function (_b) {
|
switch (_c.label) {
|
||||||
switch (_b.label) {
|
case 0:
|
||||||
case 0:
|
args.jobLog("Attempting copy from ".concat(sourcePath, " to ").concat(destinationPath, " , method 2"));
|
||||||
args.jobLog("Attempting copy from ".concat(sourcePath, " to ").concat(destinationPath, " , method 2"));
|
error = false;
|
||||||
error = false;
|
_c.label = 1;
|
||||||
_b.label = 1;
|
case 1:
|
||||||
case 1:
|
_c.trys.push([1, 3, , 4]);
|
||||||
_b.trys.push([1, 3, , 4]);
|
return [4 /*yield*/, fs_1.promises.copyFile(sourcePath, destinationPath)];
|
||||||
return [4 /*yield*/, fs_1.promises.copyFile(sourcePath, destinationPath)];
|
case 2:
|
||||||
case 2:
|
_c.sent();
|
||||||
_b.sent();
|
return [3 /*break*/, 4];
|
||||||
return [3 /*break*/, 4];
|
case 3:
|
||||||
case 3:
|
err_3 = _c.sent();
|
||||||
err_3 = _b.sent();
|
error = true;
|
||||||
error = true;
|
args.jobLog("File copy error: ".concat(JSON.stringify(err_3)));
|
||||||
args.jobLog("File copy error: ".concat(JSON.stringify(err_3)));
|
return [3 /*break*/, 4];
|
||||||
return [3 /*break*/, 4];
|
case 4: return [4 /*yield*/, getSizeBytes(destinationPath)];
|
||||||
case 4: return [4 /*yield*/, getSizeBytes(destinationPath)];
|
case 5:
|
||||||
case 5:
|
destinationSize = _c.sent();
|
||||||
destinationSize = _b.sent();
|
compareOldNew({
|
||||||
compareOldNew({
|
sourceFileSize: sourceFileSize,
|
||||||
sourceFileSize: sourceFileSize,
|
destinationSize: destinationSize,
|
||||||
destinationSize: destinationSize,
|
args: args,
|
||||||
args: args,
|
});
|
||||||
});
|
if (error || destinationSize !== sourceFileSize) {
|
||||||
if (error || destinationSize !== sourceFileSize) {
|
return [2 /*return*/, false];
|
||||||
return [2 /*return*/, false];
|
}
|
||||||
}
|
return [2 /*return*/, true];
|
||||||
return [2 /*return*/, true];
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
}); };
|
||||||
var cleanSourceFile = function (_a) {
|
var cleanSourceFile = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
||||||
var args = _a.args, sourcePath = _a.sourcePath;
|
var err_4;
|
||||||
return __awaiter(void 0, void 0, void 0, function () {
|
var args = _b.args, sourcePath = _b.sourcePath;
|
||||||
var err_4;
|
return __generator(this, function (_c) {
|
||||||
return __generator(this, function (_b) {
|
switch (_c.label) {
|
||||||
switch (_b.label) {
|
case 0:
|
||||||
case 0:
|
_c.trys.push([0, 2, , 3]);
|
||||||
_b.trys.push([0, 2, , 3]);
|
args.jobLog("Deleting source file ".concat(sourcePath));
|
||||||
args.jobLog("Deleting source file ".concat(sourcePath));
|
return [4 /*yield*/, fs_1.promises.unlink(sourcePath)];
|
||||||
return [4 /*yield*/, fs_1.promises.unlink(sourcePath)];
|
case 1:
|
||||||
case 1:
|
_c.sent();
|
||||||
_b.sent();
|
return [3 /*break*/, 3];
|
||||||
return [3 /*break*/, 3];
|
case 2:
|
||||||
case 2:
|
err_4 = _c.sent();
|
||||||
err_4 = _b.sent();
|
args.jobLog("Failed to delete source file ".concat(sourcePath, ": ").concat(JSON.stringify(err_4)));
|
||||||
args.jobLog("Failed to delete source file ".concat(sourcePath, ": ").concat(JSON.stringify(err_4)));
|
return [3 /*break*/, 3];
|
||||||
return [3 /*break*/, 3];
|
case 3: return [2 /*return*/];
|
||||||
case 3: return [2 /*return*/];
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
}); };
|
||||||
var fileMoveOrCopy = function (_a) {
|
var fileMoveOrCopy = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
||||||
var operation = _a.operation, sourcePath = _a.sourcePath, destinationPath = _a.destinationPath, args = _a.args;
|
var sourceFileSize, moved, ncpd, copied;
|
||||||
return __awaiter(void 0, void 0, void 0, function () {
|
var operation = _b.operation, sourcePath = _b.sourcePath, destinationPath = _b.destinationPath, args = _b.args;
|
||||||
var sourceFileSize, moved, ncpd, copied;
|
return __generator(this, function (_c) {
|
||||||
return __generator(this, function (_b) {
|
switch (_c.label) {
|
||||||
switch (_b.label) {
|
case 0:
|
||||||
case 0:
|
args.jobLog('Calculating cache file size in bytes');
|
||||||
args.jobLog('Calculating cache file size in bytes');
|
return [4 /*yield*/, getSizeBytes(sourcePath)];
|
||||||
return [4 /*yield*/, getSizeBytes(sourcePath)];
|
case 1:
|
||||||
case 1:
|
sourceFileSize = _c.sent();
|
||||||
sourceFileSize = _b.sent();
|
args.jobLog("".concat(sourceFileSize));
|
||||||
args.jobLog("".concat(sourceFileSize));
|
if (!(operation === 'move')) return [3 /*break*/, 3];
|
||||||
if (!(operation === 'move')) return [3 /*break*/, 3];
|
return [4 /*yield*/, tryMove({
|
||||||
return [4 /*yield*/, tryMove({
|
|
||||||
sourcePath: sourcePath,
|
|
||||||
destinationPath: destinationPath,
|
|
||||||
args: args,
|
|
||||||
sourceFileSize: sourceFileSize,
|
|
||||||
})];
|
|
||||||
case 2:
|
|
||||||
moved = _b.sent();
|
|
||||||
if (moved) {
|
|
||||||
return [2 /*return*/, true];
|
|
||||||
}
|
|
||||||
// disable: https://github.com/HaveAGitGat/Tdarr/issues/885
|
|
||||||
// const mvdird = await tryMvdir({
|
|
||||||
// sourcePath,
|
|
||||||
// destinationPath,
|
|
||||||
// args,
|
|
||||||
// sourceFileSize,
|
|
||||||
// });
|
|
||||||
// if (mvdird) {
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
args.jobLog('Failed to move file, trying copy');
|
|
||||||
_b.label = 3;
|
|
||||||
case 3: return [4 /*yield*/, tyNcp({
|
|
||||||
sourcePath: sourcePath,
|
sourcePath: sourcePath,
|
||||||
destinationPath: destinationPath,
|
destinationPath: destinationPath,
|
||||||
args: args,
|
args: args,
|
||||||
sourceFileSize: sourceFileSize,
|
sourceFileSize: sourceFileSize,
|
||||||
})];
|
})];
|
||||||
case 4:
|
case 2:
|
||||||
ncpd = _b.sent();
|
moved = _c.sent();
|
||||||
if (!ncpd) return [3 /*break*/, 7];
|
if (moved) {
|
||||||
if (!(operation === 'move')) return [3 /*break*/, 6];
|
return [2 /*return*/, true];
|
||||||
return [4 /*yield*/, cleanSourceFile({
|
}
|
||||||
args: args,
|
// disable: https://github.com/HaveAGitGat/Tdarr/issues/885
|
||||||
sourcePath: sourcePath,
|
// const mvdird = await tryMvdir({
|
||||||
})];
|
// sourcePath,
|
||||||
case 5:
|
// destinationPath,
|
||||||
_b.sent();
|
// args,
|
||||||
_b.label = 6;
|
// sourceFileSize,
|
||||||
case 6: return [2 /*return*/, true];
|
// });
|
||||||
case 7: return [4 /*yield*/, tryNormalCopy({
|
// if (mvdird) {
|
||||||
sourcePath: sourcePath,
|
// return true;
|
||||||
destinationPath: destinationPath,
|
// }
|
||||||
|
args.jobLog('Failed to move file, trying copy');
|
||||||
|
_c.label = 3;
|
||||||
|
case 3: return [4 /*yield*/, tyNcp({
|
||||||
|
sourcePath: sourcePath,
|
||||||
|
destinationPath: destinationPath,
|
||||||
|
args: args,
|
||||||
|
sourceFileSize: sourceFileSize,
|
||||||
|
})];
|
||||||
|
case 4:
|
||||||
|
ncpd = _c.sent();
|
||||||
|
if (!ncpd) return [3 /*break*/, 7];
|
||||||
|
if (!(operation === 'move')) return [3 /*break*/, 6];
|
||||||
|
return [4 /*yield*/, cleanSourceFile({
|
||||||
args: args,
|
args: args,
|
||||||
sourceFileSize: sourceFileSize,
|
sourcePath: sourcePath,
|
||||||
})];
|
})];
|
||||||
case 8:
|
case 5:
|
||||||
copied = _b.sent();
|
_c.sent();
|
||||||
if (!copied) return [3 /*break*/, 11];
|
_c.label = 6;
|
||||||
if (!(operation === 'move')) return [3 /*break*/, 10];
|
case 6: return [2 /*return*/, true];
|
||||||
return [4 /*yield*/, cleanSourceFile({
|
case 7: return [4 /*yield*/, tryNormalCopy({
|
||||||
args: args,
|
sourcePath: sourcePath,
|
||||||
sourcePath: sourcePath,
|
destinationPath: destinationPath,
|
||||||
})];
|
args: args,
|
||||||
case 9:
|
sourceFileSize: sourceFileSize,
|
||||||
_b.sent();
|
})];
|
||||||
_b.label = 10;
|
case 8:
|
||||||
case 10: return [2 /*return*/, true];
|
copied = _c.sent();
|
||||||
case 11: throw new Error("Failed to ".concat(operation, " file"));
|
if (!copied) return [3 /*break*/, 11];
|
||||||
}
|
if (!(operation === 'move')) return [3 /*break*/, 10];
|
||||||
});
|
return [4 /*yield*/, cleanSourceFile({
|
||||||
|
args: args,
|
||||||
|
sourcePath: sourcePath,
|
||||||
|
})];
|
||||||
|
case 9:
|
||||||
|
_c.sent();
|
||||||
|
_c.label = 10;
|
||||||
|
case 10: return [2 /*return*/, true];
|
||||||
|
case 11: throw new Error("Failed to ".concat(operation, " file"));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
}); };
|
||||||
exports.default = fileMoveOrCopy;
|
exports.default = fileMoveOrCopy;
|
||||||
|
|
|
||||||
|
|
@ -80,80 +80,78 @@ var getFileSize = function (file) { return __awaiter(void 0, void 0, void 0, fun
|
||||||
});
|
});
|
||||||
}); };
|
}); };
|
||||||
exports.getFileSize = getFileSize;
|
exports.getFileSize = getFileSize;
|
||||||
var moveFileAndValidate = function (_a) {
|
var moveFileAndValidate = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
||||||
var inputPath = _a.inputPath, outputPath = _a.outputPath, args = _a.args;
|
var inputSize, res1, outputSize, err_1, res2, errMessage;
|
||||||
return __awaiter(void 0, void 0, void 0, function () {
|
var inputPath = _b.inputPath, outputPath = _b.outputPath, args = _b.args;
|
||||||
var inputSize, res1, outputSize, err_1, res2, errMessage;
|
return __generator(this, function (_c) {
|
||||||
return __generator(this, function (_b) {
|
switch (_c.label) {
|
||||||
switch (_b.label) {
|
case 0: return [4 /*yield*/, (0, exports.getFileSize)(inputPath)];
|
||||||
case 0: return [4 /*yield*/, (0, exports.getFileSize)(inputPath)];
|
case 1:
|
||||||
case 1:
|
inputSize = _c.sent();
|
||||||
inputSize = _b.sent();
|
args.jobLog("Attempt 1: Moving file from ".concat(inputPath, " to ").concat(outputPath));
|
||||||
args.jobLog("Attempt 1: Moving file from ".concat(inputPath, " to ").concat(outputPath));
|
return [4 /*yield*/, new Promise(function (resolve) {
|
||||||
return [4 /*yield*/, new Promise(function (resolve) {
|
args.deps.gracefulfs.rename(inputPath, outputPath, function (err) {
|
||||||
args.deps.gracefulfs.rename(inputPath, outputPath, function (err) {
|
if (err) {
|
||||||
if (err) {
|
args.jobLog("Failed to move file from ".concat(inputPath, " to ").concat(outputPath));
|
||||||
args.jobLog("Failed to move file from ".concat(inputPath, " to ").concat(outputPath));
|
args.jobLog(JSON.stringify(err));
|
||||||
args.jobLog(JSON.stringify(err));
|
resolve(false);
|
||||||
resolve(false);
|
}
|
||||||
}
|
else {
|
||||||
else {
|
resolve(true);
|
||||||
resolve(true);
|
}
|
||||||
}
|
});
|
||||||
});
|
})];
|
||||||
})];
|
case 2:
|
||||||
case 2:
|
res1 = _c.sent();
|
||||||
res1 = _b.sent();
|
outputSize = 0;
|
||||||
outputSize = 0;
|
_c.label = 3;
|
||||||
_b.label = 3;
|
case 3:
|
||||||
case 3:
|
_c.trys.push([3, 5, , 6]);
|
||||||
_b.trys.push([3, 5, , 6]);
|
return [4 /*yield*/, (0, exports.getFileSize)(outputPath)];
|
||||||
return [4 /*yield*/, (0, exports.getFileSize)(outputPath)];
|
case 4:
|
||||||
case 4:
|
outputSize = _c.sent();
|
||||||
outputSize = _b.sent();
|
return [3 /*break*/, 6];
|
||||||
return [3 /*break*/, 6];
|
case 5:
|
||||||
case 5:
|
err_1 = _c.sent();
|
||||||
err_1 = _b.sent();
|
args.jobLog(JSON.stringify(err_1));
|
||||||
args.jobLog(JSON.stringify(err_1));
|
return [3 /*break*/, 6];
|
||||||
return [3 /*break*/, 6];
|
case 6:
|
||||||
case 6:
|
if (!(!res1 || inputSize !== outputSize)) return [3 /*break*/, 9];
|
||||||
if (!(!res1 || inputSize !== outputSize)) return [3 /*break*/, 9];
|
if (inputSize !== outputSize) {
|
||||||
|
args.jobLog("File sizes do not match, input: ".concat(inputSize, " ")
|
||||||
|
+ "does not equal output: ".concat(outputSize));
|
||||||
|
}
|
||||||
|
args.jobLog("Attempt 1 failed: Moving file from ".concat(inputPath, " to ").concat(outputPath));
|
||||||
|
args.jobLog("Attempt 2: Moving file from ".concat(inputPath, " to ").concat(outputPath));
|
||||||
|
return [4 /*yield*/, new Promise(function (resolve) {
|
||||||
|
args.deps.mvdir(inputPath, outputPath, { overwrite: true })
|
||||||
|
.then(function () {
|
||||||
|
resolve(true);
|
||||||
|
}).catch(function (err) {
|
||||||
|
args.jobLog("Failed to move file from ".concat(inputPath, " to ").concat(outputPath));
|
||||||
|
args.jobLog(JSON.stringify(err));
|
||||||
|
resolve(false);
|
||||||
|
});
|
||||||
|
})];
|
||||||
|
case 7:
|
||||||
|
res2 = _c.sent();
|
||||||
|
return [4 /*yield*/, (0, exports.getFileSize)(outputPath)];
|
||||||
|
case 8:
|
||||||
|
outputSize = _c.sent();
|
||||||
|
if (!res2 || inputSize !== outputSize) {
|
||||||
if (inputSize !== outputSize) {
|
if (inputSize !== outputSize) {
|
||||||
args.jobLog("File sizes do not match, input: ".concat(inputSize, " ")
|
args.jobLog("File sizes do not match, input: ".concat(inputSize, " ")
|
||||||
+ "does not equal output: ".concat(outputSize));
|
+ "does not equal output: ".concat(outputSize));
|
||||||
}
|
}
|
||||||
args.jobLog("Attempt 1 failed: Moving file from ".concat(inputPath, " to ").concat(outputPath));
|
errMessage = "Failed to move file from ".concat(inputPath, " to ").concat(outputPath, ", check errors above");
|
||||||
args.jobLog("Attempt 2: Moving file from ".concat(inputPath, " to ").concat(outputPath));
|
args.jobLog(errMessage);
|
||||||
return [4 /*yield*/, new Promise(function (resolve) {
|
throw new Error(errMessage);
|
||||||
args.deps.mvdir(inputPath, outputPath, { overwrite: true })
|
}
|
||||||
.then(function () {
|
_c.label = 9;
|
||||||
resolve(true);
|
case 9: return [2 /*return*/];
|
||||||
}).catch(function (err) {
|
}
|
||||||
args.jobLog("Failed to move file from ".concat(inputPath, " to ").concat(outputPath));
|
|
||||||
args.jobLog(JSON.stringify(err));
|
|
||||||
resolve(false);
|
|
||||||
});
|
|
||||||
})];
|
|
||||||
case 7:
|
|
||||||
res2 = _b.sent();
|
|
||||||
return [4 /*yield*/, (0, exports.getFileSize)(outputPath)];
|
|
||||||
case 8:
|
|
||||||
outputSize = _b.sent();
|
|
||||||
if (!res2 || inputSize !== outputSize) {
|
|
||||||
if (inputSize !== outputSize) {
|
|
||||||
args.jobLog("File sizes do not match, input: ".concat(inputSize, " ")
|
|
||||||
+ "does not equal output: ".concat(outputSize));
|
|
||||||
}
|
|
||||||
errMessage = "Failed to move file from ".concat(inputPath, " to ").concat(outputPath, ", check errors above");
|
|
||||||
args.jobLog(errMessage);
|
|
||||||
throw new Error(errMessage);
|
|
||||||
}
|
|
||||||
_b.label = 9;
|
|
||||||
case 9: return [2 /*return*/];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
}); };
|
||||||
exports.moveFileAndValidate = moveFileAndValidate;
|
exports.moveFileAndValidate = moveFileAndValidate;
|
||||||
var getPluginWorkDir = function (args) {
|
var getPluginWorkDir = function (args) {
|
||||||
var pluginWorkDir = "".concat(args.workDir, "/").concat(new Date().getTime());
|
var pluginWorkDir = "".concat(args.workDir, "/").concat(new Date().getTime());
|
||||||
|
|
|
||||||
|
|
@ -61,80 +61,78 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.getEncoder = exports.getBestNvencDevice = exports.hasEncoder = void 0;
|
exports.getEncoder = exports.getBestNvencDevice = exports.hasEncoder = void 0;
|
||||||
var os_1 = __importDefault(require("os"));
|
var os_1 = __importDefault(require("os"));
|
||||||
var hasEncoder = function (_a) {
|
var hasEncoder = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
||||||
var ffmpegPath = _a.ffmpegPath, encoder = _a.encoder, inputArgs = _a.inputArgs, outputArgs = _a.outputArgs, filter = _a.filter, args = _a.args;
|
var spawn, isEnabled, commandArr_1, err_1;
|
||||||
return __awaiter(void 0, void 0, void 0, function () {
|
var ffmpegPath = _b.ffmpegPath, encoder = _b.encoder, inputArgs = _b.inputArgs, outputArgs = _b.outputArgs, filter = _b.filter, args = _b.args;
|
||||||
var spawn, isEnabled, commandArr_1, err_1;
|
return __generator(this, function (_c) {
|
||||||
return __generator(this, function (_b) {
|
switch (_c.label) {
|
||||||
switch (_b.label) {
|
case 0:
|
||||||
case 0:
|
spawn = require('child_process').spawn;
|
||||||
spawn = require('child_process').spawn;
|
isEnabled = false;
|
||||||
isEnabled = false;
|
_c.label = 1;
|
||||||
_b.label = 1;
|
case 1:
|
||||||
case 1:
|
_c.trys.push([1, 3, , 4]);
|
||||||
_b.trys.push([1, 3, , 4]);
|
commandArr_1 = __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], inputArgs, true), [
|
||||||
commandArr_1 = __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], inputArgs, true), [
|
'-f',
|
||||||
'-f',
|
'lavfi',
|
||||||
'lavfi',
|
'-i',
|
||||||
'-i',
|
'color=c=black:s=256x256:d=1:r=30'
|
||||||
'color=c=black:s=256x256:d=1:r=30'
|
], false), (filter ? filter.split(' ') : []), true), [
|
||||||
], false), (filter ? filter.split(' ') : []), true), [
|
'-c:v',
|
||||||
'-c:v',
|
encoder
|
||||||
encoder
|
], false), outputArgs, true), [
|
||||||
], false), outputArgs, true), [
|
'-f',
|
||||||
'-f',
|
'null',
|
||||||
'null',
|
'/dev/null',
|
||||||
'/dev/null',
|
], false);
|
||||||
], false);
|
args.jobLog("Checking for encoder ".concat(encoder, " with command:"));
|
||||||
args.jobLog("Checking for encoder ".concat(encoder, " with command:"));
|
args.jobLog("".concat(ffmpegPath, " ").concat(commandArr_1.join(' ')));
|
||||||
args.jobLog("".concat(ffmpegPath, " ").concat(commandArr_1.join(' ')));
|
return [4 /*yield*/, new Promise(function (resolve) {
|
||||||
return [4 /*yield*/, new Promise(function (resolve) {
|
var error = function () {
|
||||||
var error = function () {
|
resolve(false);
|
||||||
resolve(false);
|
};
|
||||||
};
|
var stderr = '';
|
||||||
var stderr = '';
|
try {
|
||||||
try {
|
var thread = spawn(ffmpegPath, commandArr_1);
|
||||||
var thread = spawn(ffmpegPath, commandArr_1);
|
thread.on('error', function () {
|
||||||
thread.on('error', function () {
|
// catches execution error (bad file)
|
||||||
// catches execution error (bad file)
|
|
||||||
error();
|
|
||||||
});
|
|
||||||
thread.stdout.on('data', function (data) {
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
||||||
stderr += data;
|
|
||||||
});
|
|
||||||
thread.stderr.on('data', function (data) {
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
||||||
stderr += data;
|
|
||||||
});
|
|
||||||
thread.on('close', function (code) {
|
|
||||||
if (code !== 0) {
|
|
||||||
error();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
resolve(true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
// catches execution error (no file)
|
|
||||||
error();
|
error();
|
||||||
}
|
});
|
||||||
})];
|
thread.stdout.on('data', function (data) {
|
||||||
case 2:
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
isEnabled = _b.sent();
|
stderr += data;
|
||||||
args.jobLog("Encoder ".concat(encoder, " is ").concat(isEnabled ? 'enabled' : 'disabled'));
|
});
|
||||||
return [3 /*break*/, 4];
|
thread.stderr.on('data', function (data) {
|
||||||
case 3:
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
err_1 = _b.sent();
|
stderr += data;
|
||||||
// eslint-disable-next-line no-console
|
});
|
||||||
console.log(err_1);
|
thread.on('close', function (code) {
|
||||||
return [3 /*break*/, 4];
|
if (code !== 0) {
|
||||||
case 4: return [2 /*return*/, isEnabled];
|
error();
|
||||||
}
|
}
|
||||||
});
|
else {
|
||||||
|
resolve(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
// catches execution error (no file)
|
||||||
|
error();
|
||||||
|
}
|
||||||
|
})];
|
||||||
|
case 2:
|
||||||
|
isEnabled = _c.sent();
|
||||||
|
args.jobLog("Encoder ".concat(encoder, " is ").concat(isEnabled ? 'enabled' : 'disabled'));
|
||||||
|
return [3 /*break*/, 4];
|
||||||
|
case 3:
|
||||||
|
err_1 = _c.sent();
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log(err_1);
|
||||||
|
return [3 /*break*/, 4];
|
||||||
|
case 4: return [2 /*return*/, isEnabled];
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
}); };
|
||||||
exports.hasEncoder = hasEncoder;
|
exports.hasEncoder = hasEncoder;
|
||||||
// credit to UNCode101 for this
|
// credit to UNCode101 for this
|
||||||
var getBestNvencDevice = function (_a) {
|
var getBestNvencDevice = function (_a) {
|
||||||
|
|
@ -207,236 +205,234 @@ var encoderFilter = function (encoder, targetCodec) {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
var getEncoder = function (_a) {
|
var getEncoder = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
||||||
var targetCodec = _a.targetCodec, hardwareEncoding = _a.hardwareEncoding, hardwareType = _a.hardwareType, args = _a.args;
|
var supportedGpuEncoders, gpuEncoders, filteredGpuEncoders, idx, _i, filteredGpuEncoders_1, gpuEncoder, _c, enabledDevices, res;
|
||||||
return __awaiter(void 0, void 0, void 0, function () {
|
var targetCodec = _b.targetCodec, hardwareEncoding = _b.hardwareEncoding, hardwareType = _b.hardwareType, args = _b.args;
|
||||||
var supportedGpuEncoders, gpuEncoders, filteredGpuEncoders, idx, _i, filteredGpuEncoders_1, gpuEncoder, _b, enabledDevices, res;
|
return __generator(this, function (_d) {
|
||||||
return __generator(this, function (_c) {
|
switch (_d.label) {
|
||||||
switch (_c.label) {
|
case 0:
|
||||||
case 0:
|
supportedGpuEncoders = ['hevc', 'h264', 'av1'];
|
||||||
supportedGpuEncoders = ['hevc', 'h264', 'av1'];
|
if (!(args.workerType
|
||||||
if (!(args.workerType
|
&& args.workerType.includes('gpu')
|
||||||
&& args.workerType.includes('gpu')
|
&& hardwareEncoding && (supportedGpuEncoders.includes(targetCodec)))) return [3 /*break*/, 5];
|
||||||
&& hardwareEncoding && (supportedGpuEncoders.includes(targetCodec)))) return [3 /*break*/, 5];
|
gpuEncoders = [
|
||||||
gpuEncoders = [
|
{
|
||||||
{
|
encoder: 'hevc_nvenc',
|
||||||
encoder: 'hevc_nvenc',
|
enabled: false,
|
||||||
enabled: false,
|
inputArgs: [
|
||||||
inputArgs: [
|
'-hwaccel',
|
||||||
'-hwaccel',
|
'cuda',
|
||||||
'cuda',
|
],
|
||||||
],
|
outputArgs: [],
|
||||||
outputArgs: [],
|
filter: '',
|
||||||
filter: '',
|
},
|
||||||
},
|
{
|
||||||
{
|
encoder: 'hevc_amf',
|
||||||
encoder: 'hevc_amf',
|
enabled: false,
|
||||||
enabled: false,
|
inputArgs: [],
|
||||||
inputArgs: [],
|
outputArgs: [],
|
||||||
outputArgs: [],
|
filter: '',
|
||||||
filter: '',
|
},
|
||||||
},
|
{
|
||||||
{
|
encoder: 'hevc_qsv',
|
||||||
encoder: 'hevc_qsv',
|
enabled: false,
|
||||||
enabled: false,
|
inputArgs: [
|
||||||
inputArgs: [
|
'-hwaccel',
|
||||||
'-hwaccel',
|
'qsv',
|
||||||
'qsv',
|
],
|
||||||
],
|
outputArgs: __spreadArray([], (os_1.default.platform() === 'win32' ? ['-load_plugin', 'hevc_hw'] : []), true),
|
||||||
outputArgs: __spreadArray([], (os_1.default.platform() === 'win32' ? ['-load_plugin', 'hevc_hw'] : []), true),
|
filter: '',
|
||||||
filter: '',
|
},
|
||||||
},
|
{
|
||||||
{
|
encoder: 'hevc_vaapi',
|
||||||
encoder: 'hevc_vaapi',
|
inputArgs: [
|
||||||
inputArgs: [
|
'-hwaccel',
|
||||||
'-hwaccel',
|
'vaapi',
|
||||||
'vaapi',
|
'-hwaccel_device',
|
||||||
'-hwaccel_device',
|
'/dev/dri/renderD128',
|
||||||
'/dev/dri/renderD128',
|
'-hwaccel_output_format',
|
||||||
'-hwaccel_output_format',
|
'vaapi',
|
||||||
'vaapi',
|
],
|
||||||
],
|
outputArgs: [],
|
||||||
outputArgs: [],
|
enabled: false,
|
||||||
enabled: false,
|
filter: '-vf format=nv12,hwupload',
|
||||||
filter: '-vf format=nv12,hwupload',
|
},
|
||||||
},
|
{
|
||||||
{
|
encoder: 'hevc_videotoolbox',
|
||||||
encoder: 'hevc_videotoolbox',
|
enabled: false,
|
||||||
enabled: false,
|
inputArgs: [
|
||||||
inputArgs: [
|
'-hwaccel',
|
||||||
'-hwaccel',
|
'videotoolbox',
|
||||||
'videotoolbox',
|
],
|
||||||
],
|
outputArgs: [],
|
||||||
outputArgs: [],
|
filter: '',
|
||||||
filter: '',
|
},
|
||||||
},
|
// h264
|
||||||
// h264
|
{
|
||||||
{
|
encoder: 'h264_nvenc',
|
||||||
encoder: 'h264_nvenc',
|
enabled: false,
|
||||||
enabled: false,
|
inputArgs: [
|
||||||
inputArgs: [
|
'-hwaccel',
|
||||||
'-hwaccel',
|
'cuda',
|
||||||
'cuda',
|
],
|
||||||
],
|
outputArgs: [],
|
||||||
outputArgs: [],
|
filter: '',
|
||||||
filter: '',
|
},
|
||||||
},
|
{
|
||||||
{
|
encoder: 'h264_amf',
|
||||||
encoder: 'h264_amf',
|
enabled: false,
|
||||||
enabled: false,
|
inputArgs: [],
|
||||||
inputArgs: [],
|
outputArgs: [],
|
||||||
outputArgs: [],
|
filter: '',
|
||||||
filter: '',
|
},
|
||||||
},
|
{
|
||||||
{
|
encoder: 'h264_qsv',
|
||||||
encoder: 'h264_qsv',
|
enabled: false,
|
||||||
enabled: false,
|
inputArgs: [
|
||||||
inputArgs: [
|
'-hwaccel',
|
||||||
'-hwaccel',
|
'qsv',
|
||||||
'qsv',
|
],
|
||||||
],
|
outputArgs: [],
|
||||||
outputArgs: [],
|
filter: '',
|
||||||
filter: '',
|
},
|
||||||
},
|
{
|
||||||
{
|
encoder: 'h264_videotoolbox',
|
||||||
encoder: 'h264_videotoolbox',
|
enabled: false,
|
||||||
enabled: false,
|
inputArgs: [
|
||||||
inputArgs: [
|
'-hwaccel',
|
||||||
'-hwaccel',
|
'videotoolbox',
|
||||||
'videotoolbox',
|
],
|
||||||
],
|
outputArgs: [],
|
||||||
outputArgs: [],
|
filter: '',
|
||||||
filter: '',
|
},
|
||||||
},
|
// av1
|
||||||
// av1
|
{
|
||||||
{
|
encoder: 'av1_nvenc',
|
||||||
encoder: 'av1_nvenc',
|
enabled: false,
|
||||||
enabled: false,
|
inputArgs: [],
|
||||||
inputArgs: [],
|
outputArgs: [],
|
||||||
outputArgs: [],
|
filter: '',
|
||||||
filter: '',
|
},
|
||||||
},
|
{
|
||||||
{
|
encoder: 'av1_amf',
|
||||||
encoder: 'av1_amf',
|
enabled: false,
|
||||||
enabled: false,
|
inputArgs: [],
|
||||||
inputArgs: [],
|
outputArgs: [],
|
||||||
outputArgs: [],
|
filter: '',
|
||||||
filter: '',
|
},
|
||||||
},
|
{
|
||||||
{
|
encoder: 'av1_qsv',
|
||||||
encoder: 'av1_qsv',
|
enabled: false,
|
||||||
enabled: false,
|
inputArgs: [],
|
||||||
inputArgs: [],
|
outputArgs: [],
|
||||||
outputArgs: [],
|
filter: '',
|
||||||
filter: '',
|
},
|
||||||
},
|
{
|
||||||
{
|
encoder: 'av1_vaapi',
|
||||||
encoder: 'av1_vaapi',
|
enabled: false,
|
||||||
enabled: false,
|
inputArgs: [],
|
||||||
inputArgs: [],
|
outputArgs: [],
|
||||||
outputArgs: [],
|
filter: '',
|
||||||
filter: '',
|
},
|
||||||
},
|
];
|
||||||
];
|
filteredGpuEncoders = gpuEncoders.filter(function (device) { return encoderFilter(device.encoder, targetCodec); });
|
||||||
filteredGpuEncoders = gpuEncoders.filter(function (device) { return encoderFilter(device.encoder, targetCodec); });
|
if (hardwareEncoding && hardwareType !== 'auto') {
|
||||||
if (hardwareEncoding && hardwareType !== 'auto') {
|
idx = filteredGpuEncoders.findIndex(function (device) { return device.encoder.includes(hardwareType); });
|
||||||
idx = filteredGpuEncoders.findIndex(function (device) { return device.encoder.includes(hardwareType); });
|
if (idx === -1) {
|
||||||
if (idx === -1) {
|
throw new Error("Could not find encoder ".concat(targetCodec, " for hardware ").concat(hardwareType));
|
||||||
throw new Error("Could not find encoder ".concat(targetCodec, " for hardware ").concat(hardwareType));
|
|
||||||
}
|
|
||||||
return [2 /*return*/, __assign(__assign({}, filteredGpuEncoders[idx]), { isGpu: true, enabledDevices: [] })];
|
|
||||||
}
|
}
|
||||||
args.jobLog(JSON.stringify({ filteredGpuEncoders: filteredGpuEncoders }));
|
return [2 /*return*/, __assign(__assign({}, filteredGpuEncoders[idx]), { isGpu: true, enabledDevices: [] })];
|
||||||
_i = 0, filteredGpuEncoders_1 = filteredGpuEncoders;
|
}
|
||||||
_c.label = 1;
|
args.jobLog(JSON.stringify({ filteredGpuEncoders: filteredGpuEncoders }));
|
||||||
case 1:
|
_i = 0, filteredGpuEncoders_1 = filteredGpuEncoders;
|
||||||
if (!(_i < filteredGpuEncoders_1.length)) return [3 /*break*/, 4];
|
_d.label = 1;
|
||||||
gpuEncoder = filteredGpuEncoders_1[_i];
|
case 1:
|
||||||
// eslint-disable-next-line no-await-in-loop
|
if (!(_i < filteredGpuEncoders_1.length)) return [3 /*break*/, 4];
|
||||||
_b = gpuEncoder;
|
gpuEncoder = filteredGpuEncoders_1[_i];
|
||||||
return [4 /*yield*/, (0, exports.hasEncoder)({
|
// eslint-disable-next-line no-await-in-loop
|
||||||
ffmpegPath: args.ffmpegPath,
|
_c = gpuEncoder;
|
||||||
encoder: gpuEncoder.encoder,
|
return [4 /*yield*/, (0, exports.hasEncoder)({
|
||||||
inputArgs: gpuEncoder.inputArgs,
|
ffmpegPath: args.ffmpegPath,
|
||||||
outputArgs: gpuEncoder.outputArgs,
|
encoder: gpuEncoder.encoder,
|
||||||
filter: gpuEncoder.filter,
|
inputArgs: gpuEncoder.inputArgs,
|
||||||
|
outputArgs: gpuEncoder.outputArgs,
|
||||||
|
filter: gpuEncoder.filter,
|
||||||
|
args: args,
|
||||||
|
})];
|
||||||
|
case 2:
|
||||||
|
// eslint-disable-next-line no-await-in-loop
|
||||||
|
_c.enabled = _d.sent();
|
||||||
|
_d.label = 3;
|
||||||
|
case 3:
|
||||||
|
_i++;
|
||||||
|
return [3 /*break*/, 1];
|
||||||
|
case 4:
|
||||||
|
enabledDevices = filteredGpuEncoders.filter(function (device) { return device.enabled === true; });
|
||||||
|
args.jobLog(JSON.stringify({ enabledDevices: enabledDevices }));
|
||||||
|
if (enabledDevices.length > 0) {
|
||||||
|
if (enabledDevices[0].encoder.includes('nvenc')) {
|
||||||
|
res = (0, exports.getBestNvencDevice)({
|
||||||
args: args,
|
args: args,
|
||||||
})];
|
nvencDevice: enabledDevices[0],
|
||||||
case 2:
|
});
|
||||||
// eslint-disable-next-line no-await-in-loop
|
return [2 /*return*/, __assign(__assign({}, res), { isGpu: true, enabledDevices: enabledDevices })];
|
||||||
_b.enabled = _c.sent();
|
|
||||||
_c.label = 3;
|
|
||||||
case 3:
|
|
||||||
_i++;
|
|
||||||
return [3 /*break*/, 1];
|
|
||||||
case 4:
|
|
||||||
enabledDevices = filteredGpuEncoders.filter(function (device) { return device.enabled === true; });
|
|
||||||
args.jobLog(JSON.stringify({ enabledDevices: enabledDevices }));
|
|
||||||
if (enabledDevices.length > 0) {
|
|
||||||
if (enabledDevices[0].encoder.includes('nvenc')) {
|
|
||||||
res = (0, exports.getBestNvencDevice)({
|
|
||||||
args: args,
|
|
||||||
nvencDevice: enabledDevices[0],
|
|
||||||
});
|
|
||||||
return [2 /*return*/, __assign(__assign({}, res), { isGpu: true, enabledDevices: enabledDevices })];
|
|
||||||
}
|
|
||||||
return [2 /*return*/, {
|
|
||||||
encoder: enabledDevices[0].encoder,
|
|
||||||
inputArgs: enabledDevices[0].inputArgs,
|
|
||||||
outputArgs: enabledDevices[0].outputArgs,
|
|
||||||
isGpu: true,
|
|
||||||
enabledDevices: enabledDevices,
|
|
||||||
}];
|
|
||||||
}
|
|
||||||
return [3 /*break*/, 6];
|
|
||||||
case 5:
|
|
||||||
if (!hardwareEncoding) {
|
|
||||||
args.jobLog('Hardware encoding is disabled in plugin input options');
|
|
||||||
}
|
|
||||||
if (!args.workerType || !args.workerType.includes('gpu')) {
|
|
||||||
args.jobLog('Worker type is not GPU');
|
|
||||||
}
|
|
||||||
if (!supportedGpuEncoders.includes(targetCodec)) {
|
|
||||||
args.jobLog("Target codec ".concat(targetCodec, " is not supported for GPU encoding"));
|
|
||||||
}
|
|
||||||
_c.label = 6;
|
|
||||||
case 6:
|
|
||||||
if (targetCodec === 'hevc') {
|
|
||||||
return [2 /*return*/, {
|
|
||||||
encoder: 'libx265',
|
|
||||||
inputArgs: [],
|
|
||||||
outputArgs: [],
|
|
||||||
isGpu: false,
|
|
||||||
enabledDevices: [],
|
|
||||||
}];
|
|
||||||
}
|
|
||||||
if (targetCodec === 'h264') {
|
|
||||||
return [2 /*return*/, {
|
|
||||||
encoder: 'libx264',
|
|
||||||
inputArgs: [],
|
|
||||||
outputArgs: [],
|
|
||||||
isGpu: false,
|
|
||||||
enabledDevices: [],
|
|
||||||
}];
|
|
||||||
}
|
|
||||||
if (targetCodec === 'av1') {
|
|
||||||
return [2 /*return*/, {
|
|
||||||
encoder: 'libsvtav1',
|
|
||||||
inputArgs: [],
|
|
||||||
outputArgs: [],
|
|
||||||
isGpu: false,
|
|
||||||
enabledDevices: [],
|
|
||||||
}];
|
|
||||||
}
|
}
|
||||||
return [2 /*return*/, {
|
return [2 /*return*/, {
|
||||||
encoder: targetCodec,
|
encoder: enabledDevices[0].encoder,
|
||||||
|
inputArgs: enabledDevices[0].inputArgs,
|
||||||
|
outputArgs: enabledDevices[0].outputArgs,
|
||||||
|
isGpu: true,
|
||||||
|
enabledDevices: enabledDevices,
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
return [3 /*break*/, 6];
|
||||||
|
case 5:
|
||||||
|
if (!hardwareEncoding) {
|
||||||
|
args.jobLog('Hardware encoding is disabled in plugin input options');
|
||||||
|
}
|
||||||
|
if (!args.workerType || !args.workerType.includes('gpu')) {
|
||||||
|
args.jobLog('Worker type is not GPU');
|
||||||
|
}
|
||||||
|
if (!supportedGpuEncoders.includes(targetCodec)) {
|
||||||
|
args.jobLog("Target codec ".concat(targetCodec, " is not supported for GPU encoding"));
|
||||||
|
}
|
||||||
|
_d.label = 6;
|
||||||
|
case 6:
|
||||||
|
if (targetCodec === 'hevc') {
|
||||||
|
return [2 /*return*/, {
|
||||||
|
encoder: 'libx265',
|
||||||
inputArgs: [],
|
inputArgs: [],
|
||||||
outputArgs: [],
|
outputArgs: [],
|
||||||
isGpu: false,
|
isGpu: false,
|
||||||
enabledDevices: [],
|
enabledDevices: [],
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
});
|
if (targetCodec === 'h264') {
|
||||||
|
return [2 /*return*/, {
|
||||||
|
encoder: 'libx264',
|
||||||
|
inputArgs: [],
|
||||||
|
outputArgs: [],
|
||||||
|
isGpu: false,
|
||||||
|
enabledDevices: [],
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
if (targetCodec === 'av1') {
|
||||||
|
return [2 /*return*/, {
|
||||||
|
encoder: 'libsvtav1',
|
||||||
|
inputArgs: [],
|
||||||
|
outputArgs: [],
|
||||||
|
isGpu: false,
|
||||||
|
enabledDevices: [],
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
return [2 /*return*/, {
|
||||||
|
encoder: targetCodec,
|
||||||
|
inputArgs: [],
|
||||||
|
outputArgs: [],
|
||||||
|
isGpu: false,
|
||||||
|
enabledDevices: [],
|
||||||
|
}];
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
}); };
|
||||||
exports.getEncoder = getEncoder;
|
exports.getEncoder = getEncoder;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue