Use templating

This commit is contained in:
HaveAGitGat 2024-05-08 09:12:32 +01:00
parent 8472813c74
commit 4eac4ad8d2
2 changed files with 94 additions and 60 deletions

View file

@ -22,23 +22,39 @@ const details = (): IpluginDetails => ({
label: 'Variable',
name: 'variable',
type: 'string',
defaultValue: '',
defaultValue: '{{{args.librarySettings._id}}}',
inputUI: {
type: 'text',
},
tooltip: `Variable to check. For example ,
tooltip: `Variable to check using templating.
\\n
\\n
https://docs.tdarr.io/docs/plugins/flow-plugins/basics#plugin-variable-templating
\\n
\\n
For example ,
\\nExample\\n
args.librarySettings._id
{{{args.librarySettings._id}}}
\\nExample\\n
args.inputFileObj._id
{{{args.inputFileObj._id}}}
\\nExample\\n
args.userVariables.library.test
{{{args.userVariables.library.test}}}
\\nExample\\n
args.userVariables.global.test
{{{args.userVariables.global.test
\\nExample\\n
{{{args.inputFileObj.mediaInfo.track.0.IsStreamable}}}
\\nExample\\n
{{{args.inputFileObj.ffProbeData.format.nb_streams}}}
\\nExample\\n
{{{args.inputFileObj.ffProbeData.streams.1.codec_name}}}
`,
},
{
@ -87,40 +103,50 @@ const plugin = (args: IpluginInputArgs): IpluginOutputArgs => {
args.inputs = lib.loadDefaultValues(args.inputs, details);
const variable = String(args.inputs.variable).trim();
let targetValue;
const condition = String(args.inputs.condition);
const value = String(args.inputs.value);
// variable could be e.g. args.librarySettings._id or args.inputFileObj._id
// condition could be e.g. '==' or '!='
// comment to force mediaInfo scan
const variableParts = variable.split('.');
args.jobLog(`variable = ${JSON.stringify(variable)}`);
let targetValue;
switch (variableParts.length) {
case 1:
targetValue = args;
break;
case 2:
// @ts-expect-error index
targetValue = args[variableParts[1]];
break;
case 3:
// @ts-expect-error index
targetValue = args[variableParts[1]][variableParts[2]];
break;
case 4:
// @ts-expect-error index
targetValue = args[variableParts[1]][variableParts[2]][variableParts[3]];
break;
case 5:
// @ts-expect-error index
targetValue = args[variableParts[1]][variableParts[2]][variableParts[3]][variableParts[4]];
break;
default:
throw new Error(`Invalid variable: ${variable}`);
if (variable.startsWith('args.')) {
// variable could be e.g. args.librarySettings._id or args.inputFileObj._id
// condition could be e.g. '==' or '!='
const variableParts = variable.split('.');
switch (variableParts.length) {
case 1:
targetValue = args;
break;
case 2:
// @ts-expect-error index
targetValue = args[variableParts[1]];
break;
case 3:
// @ts-expect-error index
targetValue = args[variableParts[1]][variableParts[2]];
break;
case 4:
// @ts-expect-error index
targetValue = args[variableParts[1]][variableParts[2]][variableParts[3]];
break;
case 5:
// @ts-expect-error index
targetValue = args[variableParts[1]][variableParts[2]][variableParts[3]][variableParts[4]];
break;
default:
throw new Error(`Invalid variable: ${variable}`);
}
} else {
targetValue = variable;
}
targetValue = String(targetValue);
args.jobLog(`targetValue = ${targetValue}`);
let outputNumber = 1;
const valuesArr = value.trim().split(',');