mirror of
https://github.com/gabehf/Tdarr_Plugins.git
synced 2026-03-09 23:48:15 -07:00
Refactor use runClassicPlugin()
This commit is contained in:
parent
0e3ffd5471
commit
d271bb02b6
6 changed files with 296 additions and 330 deletions
|
|
@ -1,13 +1,10 @@
|
|||
import { promises as fs } from 'fs';
|
||||
import { CLI } from '../../../../FlowHelpers/1.0.0/cliUtils';
|
||||
import {
|
||||
getContainer, getFileName, getPluginWorkDir, getScanTypes,
|
||||
} from '../../../../FlowHelpers/1.0.0/fileUtils';
|
||||
import {
|
||||
IpluginDetails,
|
||||
IpluginInputArgs,
|
||||
IpluginOutputArgs,
|
||||
} from '../../../../FlowHelpers/1.0.0/interfaces/interfaces';
|
||||
import { runClassicPlugin } from '../../../../FlowHelpers/1.0.0/classicPlugins';
|
||||
|
||||
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||
const details = (): IpluginDetails => ({
|
||||
|
|
@ -50,92 +47,14 @@ const replaceContainer = (filePath:string, container:string): string => {
|
|||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
||||
const path = require('path');
|
||||
const lib = require('../../../../../methods/lib')();
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||
|
||||
const pluginSourceId = String(args.inputs.pluginSourceId);
|
||||
const parts = pluginSourceId.split(':');
|
||||
const pluginSource = parts[0];
|
||||
const pluginId = parts[1];
|
||||
const outcome = await runClassicPlugin(args, 'transcode');
|
||||
const { result, absolutePath } = outcome;
|
||||
|
||||
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(
|
||||
pluginInputFileObj,
|
||||
args.librarySettings,
|
||||
args.inputs,
|
||||
otherArguments,
|
||||
);
|
||||
let { cacheFilePath } = outcome;
|
||||
|
||||
args.jobLog(JSON.stringify(result, null, 2));
|
||||
|
||||
|
|
@ -190,11 +109,15 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
|||
|
||||
const customArgs = result?.custom?.args;
|
||||
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) {
|
||||
cacheFilePath = replaceContainer(cacheFilePath, result.container);
|
||||
} else {
|
||||
// @ts-expect-error type
|
||||
cacheFilePath = result.custom.outputPath;
|
||||
}
|
||||
|
||||
|
|
@ -209,6 +132,7 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
|||
let cliPath = '';
|
||||
|
||||
if (isCustomConfig) {
|
||||
// @ts-expect-error cliPath
|
||||
cliPath = result?.custom?.cliPath;
|
||||
|
||||
if (Array.isArray(customArgs)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue