mirror of
https://github.com/gabehf/Tdarr_Plugins.git
synced 2026-03-09 07:29:04 -07:00
Use templating
This commit is contained in:
parent
8472813c74
commit
4eac4ad8d2
2 changed files with 94 additions and 60 deletions
|
|
@ -19,11 +19,11 @@ var details = function () { return ({
|
|||
label: 'Variable',
|
||||
name: 'variable',
|
||||
type: 'string',
|
||||
defaultValue: '',
|
||||
defaultValue: '{{{args.librarySettings._id}}}',
|
||||
inputUI: {
|
||||
type: 'text',
|
||||
},
|
||||
tooltip: "Variable to check. For example , \n \n \\nExample\\n\n args.librarySettings._id\n \n \\nExample\\n\n args.inputFileObj._id\n\n \\nExample\\n\n args.userVariables.library.test\n\n \\nExample\\n\n args.userVariables.global.test\n ",
|
||||
tooltip: "Variable to check using templating. \n \\n\n \\n\n https://docs.tdarr.io/docs/plugins/flow-plugins/basics#plugin-variable-templating\n \n \\n\n \\n\n For example , \n \n \\nExample\\n\n {{{args.librarySettings._id}}}\n \n \\nExample\\n\n {{{args.inputFileObj._id}}}\n\n \\nExample\\n\n {{{args.userVariables.library.test}}}\n\n \\nExample\\n\n {{{args.userVariables.global.test\n\n \\nExample\\n\n {{{args.inputFileObj.mediaInfo.track.0.IsStreamable}}}\n\n \\nExample\\n\n {{{args.inputFileObj.ffProbeData.format.nb_streams}}}\n\n \\nExample\\n\n {{{args.inputFileObj.ffProbeData.streams.1.codec_name}}}\n ",
|
||||
},
|
||||
{
|
||||
label: 'Condition',
|
||||
|
|
@ -68,36 +68,44 @@ var plugin = function (args) {
|
|||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||
var variable = String(args.inputs.variable).trim();
|
||||
var targetValue;
|
||||
var condition = String(args.inputs.condition);
|
||||
var value = String(args.inputs.value);
|
||||
// variable could be e.g. args.librarySettings._id or args.inputFileObj._id
|
||||
// condition could be e.g. '==' or '!='
|
||||
var variableParts = variable.split('.');
|
||||
var 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: ".concat(variable));
|
||||
// comment to force mediaInfo scan
|
||||
args.jobLog("variable = ".concat(JSON.stringify(variable)));
|
||||
if (variable.startsWith('args.')) {
|
||||
// variable could be e.g. args.librarySettings._id or args.inputFileObj._id
|
||||
// condition could be e.g. '==' or '!='
|
||||
var 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: ".concat(variable));
|
||||
}
|
||||
}
|
||||
else {
|
||||
targetValue = variable;
|
||||
}
|
||||
targetValue = String(targetValue);
|
||||
args.jobLog("targetValue = ".concat(targetValue));
|
||||
var outputNumber = 1;
|
||||
var valuesArr = value.trim().split(',');
|
||||
if (condition === '==') {
|
||||
|
|
|
|||
|
|
@ -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(',');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue