Refactor use runClassicPlugin()

make-only-subtitle-default
HaveAGitGat 2 years ago
parent 0e3ffd5471
commit d271bb02b6

@ -37,8 +37,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
}; };
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.plugin = exports.details = void 0; exports.plugin = exports.details = void 0;
var fs_1 = require("fs"); var classicPlugins_1 = require("../../../../FlowHelpers/1.0.0/classicPlugins");
var fileUtils_1 = require("../../../../FlowHelpers/1.0.0/fileUtils");
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */ /* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
var details = function () { return ({ var details = function () { return ({
name: 'Run Classic Filter Plugin', name: 'Run Classic Filter Plugin',
@ -78,89 +77,17 @@ var details = function () { return ({
exports.details = details; exports.details = details;
// 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 path, lib, pluginSourceId, parts, pluginSource, pluginId, relativePluginPath, absolutePath, classicPlugin, pluginSrcStr, res, container, cacheFilePath, otherArguments, scanTypes, pluginInputFileObj, result, outputNumber; var lib, outcome, result, outputNumber;
return __generator(this, function (_a) { return __generator(this, function (_a) {
switch (_a.label) { switch (_a.label) {
case 0: case 0:
path = require('path');
lib = require('../../../../../methods/lib')(); lib = require('../../../../../methods/lib')();
// 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);
pluginSourceId = String(args.inputs.pluginSourceId); return [4 /*yield*/, (0, classicPlugins_1.runClassicPlugin)(args, 'filter')];
parts = pluginSourceId.split(':');
pluginSource = parts[0];
pluginId = parts[1];
relativePluginPath = "../../../../../".concat(pluginSource, "/").concat(pluginId, ".js");
absolutePath = path.resolve(__dirname, relativePluginPath);
pluginSrcStr = '';
if (!(pluginSource === 'Community')) return [3 /*break*/, 2];
classicPlugin = args.deps.importFresh(relativePluginPath);
return [4 /*yield*/, fs_1.promises.readFile(absolutePath, 'utf8')];
case 1: case 1:
pluginSrcStr = _a.sent(); outcome = _a.sent();
return [3 /*break*/, 4]; result = outcome.result;
case 2: return [4 /*yield*/, args.deps.axiosMiddleware('api/v2/read-plugin', {
plugin: {
id: pluginId,
source: pluginSource,
},
})];
case 3:
res = _a.sent();
classicPlugin = args.deps.requireFromString(res.pluginRaw, absolutePath);
pluginSrcStr = res.pluginRaw;
_a.label = 4;
case 4:
if (classicPlugin.details().Operation !== 'Filter') {
throw new Error("".concat('This plugin is meant for classic plugins that have '
+ 'Operation: Filter. This classic plugin has Operation: ').concat(classicPlugin.details().Operation)
+ 'Please use the Run Classic Transcode Flow Plugin plugin instead.');
}
if (!Array.isArray(classicPlugin.dependencies)) return [3 /*break*/, 8];
if (!args.installClassicPluginDeps) return [3 /*break*/, 6];
args.jobLog("Installing dependencies for ".concat(pluginSourceId));
return [4 /*yield*/, args.installClassicPluginDeps(classicPlugin.dependencies)];
case 5:
_a.sent();
return [3 /*break*/, 7];
case 6:
args.jobLog("Not installing dependencies for ".concat(pluginSourceId, ", please update Tdarr"));
_a.label = 7;
case 7: return [3 /*break*/, 9];
case 8:
args.jobLog("No depedencies to install for ".concat(pluginSourceId));
_a.label = 9;
case 9:
container = (0, fileUtils_1.getContainer)(args.inputFileObj._id);
cacheFilePath = "".concat((0, fileUtils_1.getPluginWorkDir)(args), "/").concat((0, fileUtils_1.getFileName)(args.inputFileObj._id), ".").concat(container);
otherArguments = {
handbrakePath: args.handbrakePath,
ffmpegPath: args.ffmpegPath,
mkvpropeditPath: args.mkvpropeditPath,
originalLibraryFile: args.originalLibraryFile,
nodeHardwareType: args.nodeHardwareType,
pluginCycle: 0,
workerType: args.workerType,
version: args.config.version,
platform_arch_isdocker: args.platform_arch_isdocker,
cacheFilePath: cacheFilePath,
job: args.job,
};
scanTypes = (0, fileUtils_1.getScanTypes)([pluginSrcStr]);
return [4 /*yield*/, args.deps.axiosMiddleware('api/v2/scan-individual-file', {
file: {
_id: args.inputFileObj._id,
file: args.inputFileObj.file,
DB: args.inputFileObj.DB,
footprintId: args.inputFileObj.footprintId,
},
scanTypes: scanTypes,
})];
case 10:
pluginInputFileObj = _a.sent();
return [4 /*yield*/, classicPlugin.plugin(pluginInputFileObj, args.librarySettings, args.inputs, otherArguments)];
case 11:
result = _a.sent();
args.jobLog(JSON.stringify(result, null, 2)); args.jobLog(JSON.stringify(result, null, 2));
outputNumber = (result === null || result === void 0 ? void 0 : result.processFile) ? 1 : 2; outputNumber = (result === null || result === void 0 ? void 0 : result.processFile) ? 1 : 2;
return [2 /*return*/, { return [2 /*return*/, {

@ -46,9 +46,8 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
}; };
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.plugin = exports.details = void 0; exports.plugin = exports.details = void 0;
var fs_1 = require("fs");
var cliUtils_1 = require("../../../../FlowHelpers/1.0.0/cliUtils"); var cliUtils_1 = require("../../../../FlowHelpers/1.0.0/cliUtils");
var fileUtils_1 = require("../../../../FlowHelpers/1.0.0/fileUtils"); var classicPlugins_1 = require("../../../../FlowHelpers/1.0.0/classicPlugins");
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */ /* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
var details = function () { return ({ var details = function () { return ({
name: 'Run Classic Transcode Plugin', name: 'Run Classic Transcode Plugin',
@ -89,90 +88,19 @@ var replaceContainer = function (filePath, container) {
}; };
// 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 path, lib, pluginSourceId, parts, pluginSource, pluginId, relativePluginPath, absolutePath, classicPlugin, pluginSrcStr, res_1, container, cacheFilePath, otherArguments, scanTypes, pluginInputFileObj, result, cliPath_1, customArgs, isCustomConfig, presetSplit, workerCommand, cliPath, cli, res; var lib, outcome, result, absolutePath, cacheFilePath, cliPath_1, customArgs, isCustomConfig, presetSplit, workerCommand, cliPath, cli, res;
var _a, _b, _c; var _a, _b, _c;
return __generator(this, function (_d) { return __generator(this, function (_d) {
switch (_d.label) { switch (_d.label) {
case 0: case 0:
path = require('path');
lib = require('../../../../../methods/lib')(); lib = require('../../../../../methods/lib')();
// 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);
pluginSourceId = String(args.inputs.pluginSourceId); return [4 /*yield*/, (0, classicPlugins_1.runClassicPlugin)(args, 'transcode')];
parts = pluginSourceId.split(':');
pluginSource = parts[0];
pluginId = parts[1];
relativePluginPath = "../../../../../".concat(pluginSource, "/").concat(pluginId, ".js");
absolutePath = path.resolve(__dirname, relativePluginPath);
pluginSrcStr = '';
if (!(pluginSource === 'Community')) return [3 /*break*/, 2];
classicPlugin = args.deps.importFresh(relativePluginPath);
return [4 /*yield*/, fs_1.promises.readFile(absolutePath, 'utf8')];
case 1: case 1:
pluginSrcStr = _d.sent(); outcome = _d.sent();
return [3 /*break*/, 4]; result = outcome.result, absolutePath = outcome.absolutePath;
case 2: return [4 /*yield*/, args.deps.axiosMiddleware('api/v2/read-plugin', { cacheFilePath = outcome.cacheFilePath;
plugin: {
id: pluginId,
source: pluginSource,
},
})];
case 3:
res_1 = _d.sent();
classicPlugin = args.deps.requireFromString(res_1.pluginRaw, absolutePath);
pluginSrcStr = res_1.pluginRaw;
_d.label = 4;
case 4:
if (classicPlugin.details().Operation === 'Filter') {
throw new Error("".concat('This plugin is meant for classic plugins that have '
+ 'Operation: Transcode. This classic plugin has Operation: ').concat(classicPlugin.details().Operation)
+ 'Please use the Run Classic Filter Flow Plugin plugin instead.');
}
if (!Array.isArray(classicPlugin.dependencies)) return [3 /*break*/, 8];
if (!args.installClassicPluginDeps) return [3 /*break*/, 6];
args.jobLog("Installing dependencies for ".concat(pluginSourceId));
return [4 /*yield*/, args.installClassicPluginDeps(classicPlugin.dependencies)];
case 5:
_d.sent();
return [3 /*break*/, 7];
case 6:
args.jobLog("Not installing dependencies for ".concat(pluginSourceId, ", please update Tdarr"));
_d.label = 7;
case 7: return [3 /*break*/, 9];
case 8:
args.jobLog("No depedencies to install for ".concat(pluginSourceId));
_d.label = 9;
case 9:
container = (0, fileUtils_1.getContainer)(args.inputFileObj._id);
cacheFilePath = "".concat((0, fileUtils_1.getPluginWorkDir)(args), "/").concat((0, fileUtils_1.getFileName)(args.inputFileObj._id), ".").concat(container);
otherArguments = {
handbrakePath: args.handbrakePath,
ffmpegPath: args.ffmpegPath,
mkvpropeditPath: args.mkvpropeditPath,
originalLibraryFile: args.originalLibraryFile,
nodeHardwareType: args.nodeHardwareType,
pluginCycle: 0,
workerType: args.workerType,
version: args.config.version,
platform_arch_isdocker: args.platform_arch_isdocker,
cacheFilePath: cacheFilePath,
job: args.job,
};
scanTypes = (0, fileUtils_1.getScanTypes)([pluginSrcStr]);
return [4 /*yield*/, args.deps.axiosMiddleware('api/v2/scan-individual-file', {
file: {
_id: args.inputFileObj._id,
file: args.inputFileObj.file,
DB: args.inputFileObj.DB,
footprintId: args.inputFileObj.footprintId,
},
scanTypes: scanTypes,
})];
case 10:
pluginInputFileObj = _d.sent();
return [4 /*yield*/, classicPlugin.plugin(pluginInputFileObj, args.librarySettings, args.inputs, otherArguments)];
case 11:
result = _d.sent();
args.jobLog(JSON.stringify(result, null, 2)); args.jobLog(JSON.stringify(result, null, 2));
if (!result) { if (!result) {
args.jobLog('No result from classic plugin. Continuing to next flow plugin.'); args.jobLog('No result from classic plugin. Continuing to next flow plugin.');
@ -225,11 +153,15 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function
} }
customArgs = (_b = result === null || result === void 0 ? void 0 : result.custom) === null || _b === void 0 ? void 0 : _b.args; customArgs = (_b = result === null || result === void 0 ? void 0 : result.custom) === null || _b === void 0 ? void 0 : _b.args;
isCustomConfig = (Array.isArray(customArgs) && customArgs.length > 0) isCustomConfig = (Array.isArray(customArgs) && customArgs.length > 0)
|| (typeof customArgs === 'string' && customArgs.length > 0); || (typeof customArgs === 'string'
// @ts-expect-error length
&& customArgs.length
> 0);
if (!isCustomConfig) { if (!isCustomConfig) {
cacheFilePath = replaceContainer(cacheFilePath, result.container); cacheFilePath = replaceContainer(cacheFilePath, result.container);
} }
else { else {
// @ts-expect-error type
cacheFilePath = result.custom.outputPath; cacheFilePath = result.custom.outputPath;
} }
if (result.preset.includes('<io>')) { if (result.preset.includes('<io>')) {
@ -241,6 +173,7 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function
workerCommand = []; workerCommand = [];
cliPath = ''; cliPath = '';
if (isCustomConfig) { if (isCustomConfig) {
// @ts-expect-error cliPath
cliPath = (_c = result === null || result === void 0 ? void 0 : result.custom) === null || _c === void 0 ? void 0 : _c.cliPath; cliPath = (_c = result === null || result === void 0 ? void 0 : result.custom) === null || _c === void 0 ? void 0 : _c.cliPath;
if (Array.isArray(customArgs)) { if (Array.isArray(customArgs)) {
workerCommand = customArgs; workerCommand = customArgs;
@ -285,7 +218,7 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function
updateWorker: args.updateWorker, updateWorker: args.updateWorker,
}); });
return [4 /*yield*/, cli.runCli()]; return [4 /*yield*/, cli.runCli()];
case 12: case 2:
res = _d.sent(); res = _d.sent();
if (res.cliExitCode !== 0) { if (res.cliExitCode !== 0) {
args.jobLog("Running ".concat(cliPath, " failed")); args.jobLog("Running ".concat(cliPath, " failed"));

@ -0,0 +1,136 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.runClassicPlugin = void 0;
var fs_1 = require("fs");
var fileUtils_1 = require("./fileUtils");
var runClassicPlugin = function (args, type) { return __awaiter(void 0, void 0, void 0, function () {
var path, pluginSourceId, parts, pluginSource, pluginId, relativePluginPath, absolutePath, classicPlugin, pluginSrcStr, res, container, cacheFilePath, otherArguments, scanTypes, pluginInputFileObj, result;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
path = require('path');
pluginSourceId = String(args.inputs.pluginSourceId);
parts = pluginSourceId.split(':');
pluginSource = parts[0];
pluginId = parts[1];
relativePluginPath = "../../../".concat(pluginSource, "/").concat(pluginId, ".js");
absolutePath = path.resolve(__dirname, relativePluginPath);
pluginSrcStr = '';
if (!(pluginSource === 'Community')) return [3 /*break*/, 2];
classicPlugin = args.deps.importFresh(relativePluginPath);
return [4 /*yield*/, fs_1.promises.readFile(absolutePath, 'utf8')];
case 1:
pluginSrcStr = _a.sent();
return [3 /*break*/, 4];
case 2: return [4 /*yield*/, args.deps.axiosMiddleware('api/v2/read-plugin', {
plugin: {
id: pluginId,
source: pluginSource,
},
})];
case 3:
res = _a.sent();
classicPlugin = args.deps.requireFromString(res.pluginRaw, absolutePath);
pluginSrcStr = res.pluginRaw;
_a.label = 4;
case 4:
if (type === 'filter' && classicPlugin.details().Operation !== 'Filter') {
throw new Error("".concat('This plugin is meant for classic plugins that have '
+ 'Operation: Filter. This classic plugin has Operation: ').concat(classicPlugin.details().Operation)
+ '. Please use the Run Classic Transcode Flow Plugin plugin instead.');
}
if (type !== 'filter' && classicPlugin.details().Operation === 'Filter') {
throw new Error("".concat('This plugin is meant for classic plugins that have '
+ 'Operation: Transcode. This classic plugin has Operation: ').concat(classicPlugin.details().Operation)
+ 'Please use the Run Classic Filter Flow Plugin plugin instead.');
}
if (!Array.isArray(classicPlugin.dependencies)) return [3 /*break*/, 8];
if (!args.installClassicPluginDeps) return [3 /*break*/, 6];
args.jobLog("Installing dependencies for ".concat(pluginSourceId));
return [4 /*yield*/, args.installClassicPluginDeps(classicPlugin.dependencies)];
case 5:
_a.sent();
return [3 /*break*/, 7];
case 6:
args.jobLog("Not installing dependencies for ".concat(pluginSourceId, ", please update Tdarr"));
_a.label = 7;
case 7: return [3 /*break*/, 9];
case 8:
args.jobLog("No depedencies to install for ".concat(pluginSourceId));
_a.label = 9;
case 9:
container = (0, fileUtils_1.getContainer)(args.inputFileObj._id);
cacheFilePath = "".concat((0, fileUtils_1.getPluginWorkDir)(args), "/").concat((0, fileUtils_1.getFileName)(args.inputFileObj._id), ".").concat(container);
otherArguments = {
handbrakePath: args.handbrakePath,
ffmpegPath: args.ffmpegPath,
mkvpropeditPath: args.mkvpropeditPath,
originalLibraryFile: args.originalLibraryFile,
nodeHardwareType: args.nodeHardwareType,
pluginCycle: 0,
workerType: args.workerType,
version: args.config.version,
platform_arch_isdocker: args.platform_arch_isdocker,
cacheFilePath: cacheFilePath,
job: args.job,
};
scanTypes = (0, fileUtils_1.getScanTypes)([pluginSrcStr]);
return [4 /*yield*/, args.deps.axiosMiddleware('api/v2/scan-individual-file', {
file: {
_id: args.inputFileObj._id,
file: args.inputFileObj.file,
DB: args.inputFileObj.DB,
footprintId: args.inputFileObj.footprintId,
},
scanTypes: scanTypes,
})];
case 10:
pluginInputFileObj = _a.sent();
return [4 /*yield*/, classicPlugin.plugin(pluginInputFileObj, args.librarySettings, args.inputs, otherArguments)];
case 11:
result = _a.sent();
return [2 /*return*/, {
result: result,
cacheFilePath: cacheFilePath,
absolutePath: absolutePath,
}];
}
});
}); };
exports.runClassicPlugin = runClassicPlugin;

@ -1,12 +1,9 @@
import { promises as fs } from 'fs';
import {
getContainer, getFileName, getPluginWorkDir, getScanTypes,
} from '../../../../FlowHelpers/1.0.0/fileUtils';
import { import {
IpluginDetails, IpluginDetails,
IpluginInputArgs, IpluginInputArgs,
IpluginOutputArgs, IpluginOutputArgs,
} from '../../../../FlowHelpers/1.0.0/interfaces/interfaces'; } from '../../../../FlowHelpers/1.0.0/interfaces/interfaces';
import { runClassicPlugin } from '../../../../FlowHelpers/1.0.0/classicPlugins';
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */ /* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
const details = (): IpluginDetails => ({ const details = (): IpluginDetails => ({
@ -47,92 +44,12 @@ const details = (): IpluginDetails => ({
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => { const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
const path = require('path');
const lib = require('../../../../../methods/lib')(); const lib = require('../../../../../methods/lib')();
// 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);
const pluginSourceId = String(args.inputs.pluginSourceId); const outcome = await runClassicPlugin(args, 'filter');
const parts = pluginSourceId.split(':'); const { result } = outcome;
const pluginSource = parts[0];
const pluginId = parts[1];
const relativePluginPath = `../../../../../${pluginSource}/${pluginId}.js`;
const absolutePath = path.resolve(__dirname, relativePluginPath);
let classicPlugin;
let pluginSrcStr = '';
if (pluginSource === 'Community') {
classicPlugin = args.deps.importFresh(relativePluginPath);
pluginSrcStr = await fs.readFile(absolutePath, 'utf8');
} else {
// eslint-disable-next-line no-await-in-loop
const res = await args.deps.axiosMiddleware('api/v2/read-plugin', {
plugin: {
id: pluginId,
source: pluginSource,
},
});
classicPlugin = args.deps.requireFromString(res.pluginRaw, absolutePath);
pluginSrcStr = res.pluginRaw;
}
if (classicPlugin.details().Operation !== 'Filter') {
throw new Error(
`${'This plugin is meant for classic plugins that have '
+ 'Operation: Filter. This classic plugin has Operation: '}${classicPlugin.details().Operation}`
+ 'Please use the Run Classic Transcode Flow Plugin plugin instead.'
,
);
}
if (Array.isArray(classicPlugin.dependencies)) {
if (args.installClassicPluginDeps) {
args.jobLog(`Installing dependencies for ${pluginSourceId}`);
await args.installClassicPluginDeps(classicPlugin.dependencies);
} else {
args.jobLog(`Not installing dependencies for ${pluginSourceId}, please update Tdarr`);
}
} else {
args.jobLog(`No depedencies to install for ${pluginSourceId}`);
}
const container = getContainer(args.inputFileObj._id);
const cacheFilePath = `${getPluginWorkDir(args)}/${getFileName(args.inputFileObj._id)}.${container}`;
const otherArguments = {
handbrakePath: args.handbrakePath,
ffmpegPath: args.ffmpegPath,
mkvpropeditPath: args.mkvpropeditPath,
originalLibraryFile: args.originalLibraryFile,
nodeHardwareType: args.nodeHardwareType,
pluginCycle: 0,
workerType: args.workerType,
version: args.config.version,
platform_arch_isdocker: args.platform_arch_isdocker,
cacheFilePath,
job: args.job,
};
const scanTypes = getScanTypes([pluginSrcStr]);
const pluginInputFileObj = await args.deps.axiosMiddleware('api/v2/scan-individual-file', {
file: {
_id: args.inputFileObj._id,
file: args.inputFileObj.file,
DB: args.inputFileObj.DB,
footprintId: args.inputFileObj.footprintId,
},
scanTypes,
});
const result = await classicPlugin.plugin(
pluginInputFileObj,
args.librarySettings,
args.inputs,
otherArguments,
);
args.jobLog(JSON.stringify(result, null, 2)); args.jobLog(JSON.stringify(result, null, 2));

@ -1,13 +1,10 @@
import { promises as fs } from 'fs';
import { CLI } from '../../../../FlowHelpers/1.0.0/cliUtils'; import { CLI } from '../../../../FlowHelpers/1.0.0/cliUtils';
import {
getContainer, getFileName, getPluginWorkDir, getScanTypes,
} from '../../../../FlowHelpers/1.0.0/fileUtils';
import { import {
IpluginDetails, IpluginDetails,
IpluginInputArgs, IpluginInputArgs,
IpluginOutputArgs, IpluginOutputArgs,
} from '../../../../FlowHelpers/1.0.0/interfaces/interfaces'; } from '../../../../FlowHelpers/1.0.0/interfaces/interfaces';
import { runClassicPlugin } from '../../../../FlowHelpers/1.0.0/classicPlugins';
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */ /* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
const details = (): IpluginDetails => ({ const details = (): IpluginDetails => ({
@ -50,92 +47,14 @@ const replaceContainer = (filePath:string, container:string): string => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => { const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
const path = require('path');
const lib = require('../../../../../methods/lib')(); const lib = require('../../../../../methods/lib')();
// 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);
const pluginSourceId = String(args.inputs.pluginSourceId); const outcome = await runClassicPlugin(args, 'transcode');
const parts = pluginSourceId.split(':'); const { result, absolutePath } = outcome;
const pluginSource = parts[0];
const pluginId = parts[1];
const relativePluginPath = `../../../../../${pluginSource}/${pluginId}.js`;
const absolutePath = path.resolve(__dirname, relativePluginPath);
let classicPlugin;
let pluginSrcStr = '';
if (pluginSource === 'Community') {
classicPlugin = args.deps.importFresh(relativePluginPath);
pluginSrcStr = await fs.readFile(absolutePath, 'utf8');
} else {
// eslint-disable-next-line no-await-in-loop
const res = await args.deps.axiosMiddleware('api/v2/read-plugin', {
plugin: {
id: pluginId,
source: pluginSource,
},
});
classicPlugin = args.deps.requireFromString(res.pluginRaw, absolutePath);
pluginSrcStr = res.pluginRaw;
}
if (classicPlugin.details().Operation === 'Filter') {
throw new Error(
`${'This plugin is meant for classic plugins that have '
+ 'Operation: Transcode. This classic plugin has Operation: '}${classicPlugin.details().Operation}`
+ 'Please use the Run Classic Filter Flow Plugin plugin instead.'
,
);
}
if (Array.isArray(classicPlugin.dependencies)) {
if (args.installClassicPluginDeps) {
args.jobLog(`Installing dependencies for ${pluginSourceId}`);
await args.installClassicPluginDeps(classicPlugin.dependencies);
} else {
args.jobLog(`Not installing dependencies for ${pluginSourceId}, please update Tdarr`);
}
} else {
args.jobLog(`No depedencies to install for ${pluginSourceId}`);
}
const container = getContainer(args.inputFileObj._id);
let cacheFilePath = `${getPluginWorkDir(args)}/${getFileName(args.inputFileObj._id)}.${container}`;
const otherArguments = {
handbrakePath: args.handbrakePath,
ffmpegPath: args.ffmpegPath,
mkvpropeditPath: args.mkvpropeditPath,
originalLibraryFile: args.originalLibraryFile,
nodeHardwareType: args.nodeHardwareType,
pluginCycle: 0,
workerType: args.workerType,
version: args.config.version,
platform_arch_isdocker: args.platform_arch_isdocker,
cacheFilePath,
job: args.job,
};
const scanTypes = getScanTypes([pluginSrcStr]);
const pluginInputFileObj = await args.deps.axiosMiddleware('api/v2/scan-individual-file', {
file: {
_id: args.inputFileObj._id,
file: args.inputFileObj.file,
DB: args.inputFileObj.DB,
footprintId: args.inputFileObj.footprintId,
},
scanTypes,
});
const result = await classicPlugin.plugin( let { cacheFilePath } = outcome;
pluginInputFileObj,
args.librarySettings,
args.inputs,
otherArguments,
);
args.jobLog(JSON.stringify(result, null, 2)); args.jobLog(JSON.stringify(result, null, 2));
@ -190,11 +109,15 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
const customArgs = result?.custom?.args; const customArgs = result?.custom?.args;
const isCustomConfig = (Array.isArray(customArgs) && customArgs.length > 0) const isCustomConfig = (Array.isArray(customArgs) && customArgs.length > 0)
|| (typeof customArgs === 'string' && customArgs.length > 0); || (typeof customArgs === 'string'
// @ts-expect-error length
&& customArgs.length
> 0);
if (!isCustomConfig) { if (!isCustomConfig) {
cacheFilePath = replaceContainer(cacheFilePath, result.container); cacheFilePath = replaceContainer(cacheFilePath, result.container);
} else { } else {
// @ts-expect-error type
cacheFilePath = result.custom.outputPath; cacheFilePath = result.custom.outputPath;
} }
@ -209,6 +132,7 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
let cliPath = ''; let cliPath = '';
if (isCustomConfig) { if (isCustomConfig) {
// @ts-expect-error cliPath
cliPath = result?.custom?.cliPath; cliPath = result?.custom?.cliPath;
if (Array.isArray(customArgs)) { if (Array.isArray(customArgs)) {

@ -0,0 +1,129 @@
import { promises as fs } from 'fs';
import {
getContainer, getFileName, getPluginWorkDir, getScanTypes,
} from './fileUtils';
import { IpluginInputArgs } from './interfaces/interfaces';
export interface IrunClassicPlugin {
result:{
processFile: boolean,
handBrakeMode?: boolean,
handbrakeMode?: boolean,
FFmpegMode?: boolean,
ffmpegMode?: boolean,
cliToUse?: string,
custom?: {
cliPath?: string,
args: string[],
outputPath: string,
},
workerLog?: string,
transcodeSettingsLog?: string,
error?: string,
container: string,
preset: string,
};
cacheFilePath:string;
absolutePath:string;
}
export const runClassicPlugin = async (args:IpluginInputArgs, type:'filter'|'transcode'):Promise<IrunClassicPlugin> => {
const path = require('path');
const pluginSourceId = String(args.inputs.pluginSourceId);
const parts = pluginSourceId.split(':');
const pluginSource = parts[0];
const pluginId = parts[1];
const relativePluginPath = `../../../${pluginSource}/${pluginId}.js`;
const absolutePath = path.resolve(__dirname, relativePluginPath);
let classicPlugin;
let pluginSrcStr = '';
if (pluginSource === 'Community') {
classicPlugin = args.deps.importFresh(relativePluginPath);
pluginSrcStr = await fs.readFile(absolutePath, 'utf8');
} else {
// eslint-disable-next-line no-await-in-loop
const res = await args.deps.axiosMiddleware('api/v2/read-plugin', {
plugin: {
id: pluginId,
source: pluginSource,
},
});
classicPlugin = args.deps.requireFromString(res.pluginRaw, absolutePath);
pluginSrcStr = res.pluginRaw;
}
if (type === 'filter' && classicPlugin.details().Operation !== 'Filter') {
throw new Error(
`${'This plugin is meant for classic plugins that have '
+ 'Operation: Filter. This classic plugin has Operation: '}${classicPlugin.details().Operation}`
+ '. Please use the Run Classic Transcode Flow Plugin plugin instead.'
,
);
}
if (type !== 'filter' && classicPlugin.details().Operation === 'Filter') {
throw new Error(
`${'This plugin is meant for classic plugins that have '
+ 'Operation: Transcode. This classic plugin has Operation: '}${classicPlugin.details().Operation}`
+ 'Please use the Run Classic Filter Flow Plugin plugin instead.'
,
);
}
if (Array.isArray(classicPlugin.dependencies)) {
if (args.installClassicPluginDeps) {
args.jobLog(`Installing dependencies for ${pluginSourceId}`);
await args.installClassicPluginDeps(classicPlugin.dependencies);
} else {
args.jobLog(`Not installing dependencies for ${pluginSourceId}, please update Tdarr`);
}
} else {
args.jobLog(`No depedencies to install for ${pluginSourceId}`);
}
const container = getContainer(args.inputFileObj._id);
const cacheFilePath = `${getPluginWorkDir(args)}/${getFileName(args.inputFileObj._id)}.${container}`;
const otherArguments = {
handbrakePath: args.handbrakePath,
ffmpegPath: args.ffmpegPath,
mkvpropeditPath: args.mkvpropeditPath,
originalLibraryFile: args.originalLibraryFile,
nodeHardwareType: args.nodeHardwareType,
pluginCycle: 0,
workerType: args.workerType,
version: args.config.version,
platform_arch_isdocker: args.platform_arch_isdocker,
cacheFilePath,
job: args.job,
};
const scanTypes = getScanTypes([pluginSrcStr]);
const pluginInputFileObj = await args.deps.axiosMiddleware('api/v2/scan-individual-file', {
file: {
_id: args.inputFileObj._id,
file: args.inputFileObj.file,
DB: args.inputFileObj.DB,
footprintId: args.inputFileObj.footprintId,
},
scanTypes,
});
const result = await classicPlugin.plugin(
pluginInputFileObj,
args.librarySettings,
args.inputs,
otherArguments,
);
return {
result,
cacheFilePath,
absolutePath,
};
};
Loading…
Cancel
Save