mirror of
https://github.com/gabehf/Tdarr_Plugins.git
synced 2026-03-14 17:55:55 -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',
|
label: 'Variable',
|
||||||
name: 'variable',
|
name: 'variable',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
defaultValue: '',
|
defaultValue: '{{{args.librarySettings._id}}}',
|
||||||
inputUI: {
|
inputUI: {
|
||||||
type: 'text',
|
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',
|
label: 'Condition',
|
||||||
|
|
@ -68,36 +68,44 @@ 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 variable = String(args.inputs.variable).trim();
|
var variable = String(args.inputs.variable).trim();
|
||||||
|
var targetValue;
|
||||||
var condition = String(args.inputs.condition);
|
var condition = String(args.inputs.condition);
|
||||||
var value = String(args.inputs.value);
|
var value = String(args.inputs.value);
|
||||||
// variable could be e.g. args.librarySettings._id or args.inputFileObj._id
|
// comment to force mediaInfo scan
|
||||||
// condition could be e.g. '==' or '!='
|
args.jobLog("variable = ".concat(JSON.stringify(variable)));
|
||||||
var variableParts = variable.split('.');
|
if (variable.startsWith('args.')) {
|
||||||
var targetValue;
|
// variable could be e.g. args.librarySettings._id or args.inputFileObj._id
|
||||||
switch (variableParts.length) {
|
// condition could be e.g. '==' or '!='
|
||||||
case 1:
|
var variableParts = variable.split('.');
|
||||||
targetValue = args;
|
switch (variableParts.length) {
|
||||||
break;
|
case 1:
|
||||||
case 2:
|
targetValue = args;
|
||||||
// @ts-expect-error index
|
break;
|
||||||
targetValue = args[variableParts[1]];
|
case 2:
|
||||||
break;
|
// @ts-expect-error index
|
||||||
case 3:
|
targetValue = args[variableParts[1]];
|
||||||
// @ts-expect-error index
|
break;
|
||||||
targetValue = args[variableParts[1]][variableParts[2]];
|
case 3:
|
||||||
break;
|
// @ts-expect-error index
|
||||||
case 4:
|
targetValue = args[variableParts[1]][variableParts[2]];
|
||||||
// @ts-expect-error index
|
break;
|
||||||
targetValue = args[variableParts[1]][variableParts[2]][variableParts[3]];
|
case 4:
|
||||||
break;
|
// @ts-expect-error index
|
||||||
case 5:
|
targetValue = args[variableParts[1]][variableParts[2]][variableParts[3]];
|
||||||
// @ts-expect-error index
|
break;
|
||||||
targetValue = args[variableParts[1]][variableParts[2]][variableParts[3]][variableParts[4]];
|
case 5:
|
||||||
break;
|
// @ts-expect-error index
|
||||||
default:
|
targetValue = args[variableParts[1]][variableParts[2]][variableParts[3]][variableParts[4]];
|
||||||
throw new Error("Invalid variable: ".concat(variable));
|
break;
|
||||||
|
default:
|
||||||
|
throw new Error("Invalid variable: ".concat(variable));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
targetValue = variable;
|
||||||
}
|
}
|
||||||
targetValue = String(targetValue);
|
targetValue = String(targetValue);
|
||||||
|
args.jobLog("targetValue = ".concat(targetValue));
|
||||||
var outputNumber = 1;
|
var outputNumber = 1;
|
||||||
var valuesArr = value.trim().split(',');
|
var valuesArr = value.trim().split(',');
|
||||||
if (condition === '==') {
|
if (condition === '==') {
|
||||||
|
|
|
||||||
|
|
@ -22,23 +22,39 @@ const details = (): IpluginDetails => ({
|
||||||
label: 'Variable',
|
label: 'Variable',
|
||||||
name: 'variable',
|
name: 'variable',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
defaultValue: '',
|
defaultValue: '{{{args.librarySettings._id}}}',
|
||||||
inputUI: {
|
inputUI: {
|
||||||
type: 'text',
|
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
|
\\nExample\\n
|
||||||
args.librarySettings._id
|
{{{args.librarySettings._id}}}
|
||||||
|
|
||||||
\\nExample\\n
|
\\nExample\\n
|
||||||
args.inputFileObj._id
|
{{{args.inputFileObj._id}}}
|
||||||
|
|
||||||
\\nExample\\n
|
\\nExample\\n
|
||||||
args.userVariables.library.test
|
{{{args.userVariables.library.test}}}
|
||||||
|
|
||||||
\\nExample\\n
|
\\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);
|
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||||
|
|
||||||
const variable = String(args.inputs.variable).trim();
|
const variable = String(args.inputs.variable).trim();
|
||||||
|
let targetValue;
|
||||||
const condition = String(args.inputs.condition);
|
const condition = String(args.inputs.condition);
|
||||||
const value = String(args.inputs.value);
|
const value = String(args.inputs.value);
|
||||||
|
|
||||||
// variable could be e.g. args.librarySettings._id or args.inputFileObj._id
|
// comment to force mediaInfo scan
|
||||||
// condition could be e.g. '==' or '!='
|
|
||||||
|
|
||||||
const variableParts = variable.split('.');
|
args.jobLog(`variable = ${JSON.stringify(variable)}`);
|
||||||
|
|
||||||
let targetValue;
|
if (variable.startsWith('args.')) {
|
||||||
switch (variableParts.length) {
|
// variable could be e.g. args.librarySettings._id or args.inputFileObj._id
|
||||||
case 1:
|
// condition could be e.g. '==' or '!='
|
||||||
targetValue = args;
|
|
||||||
break;
|
const variableParts = variable.split('.');
|
||||||
case 2:
|
switch (variableParts.length) {
|
||||||
// @ts-expect-error index
|
case 1:
|
||||||
targetValue = args[variableParts[1]];
|
targetValue = args;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 2:
|
||||||
// @ts-expect-error index
|
// @ts-expect-error index
|
||||||
targetValue = args[variableParts[1]][variableParts[2]];
|
targetValue = args[variableParts[1]];
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 3:
|
||||||
// @ts-expect-error index
|
// @ts-expect-error index
|
||||||
targetValue = args[variableParts[1]][variableParts[2]][variableParts[3]];
|
targetValue = args[variableParts[1]][variableParts[2]];
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 4:
|
||||||
// @ts-expect-error index
|
// @ts-expect-error index
|
||||||
targetValue = args[variableParts[1]][variableParts[2]][variableParts[3]][variableParts[4]];
|
targetValue = args[variableParts[1]][variableParts[2]][variableParts[3]];
|
||||||
break;
|
break;
|
||||||
default:
|
case 5:
|
||||||
throw new Error(`Invalid variable: ${variable}`);
|
// @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);
|
targetValue = String(targetValue);
|
||||||
|
|
||||||
|
args.jobLog(`targetValue = ${targetValue}`);
|
||||||
|
|
||||||
let outputNumber = 1;
|
let outputNumber = 1;
|
||||||
|
|
||||||
const valuesArr = value.trim().split(',');
|
const valuesArr = value.trim().split(',');
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue