From 4eac4ad8d224ebfc1ebf6ef40759831ed8abd5c1 Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Wed, 8 May 2024 09:12:32 +0100 Subject: [PATCH] Use templating --- .../tools/checkFlowVariable/1.0.0/index.js | 64 +++++++------ .../tools/checkFlowVariable/1.0.0/index.ts | 90 ++++++++++++------- 2 files changed, 94 insertions(+), 60 deletions(-) diff --git a/FlowPlugins/CommunityFlowPlugins/tools/checkFlowVariable/1.0.0/index.js b/FlowPlugins/CommunityFlowPlugins/tools/checkFlowVariable/1.0.0/index.js index 7ef26ce..51c6e25 100644 --- a/FlowPlugins/CommunityFlowPlugins/tools/checkFlowVariable/1.0.0/index.js +++ b/FlowPlugins/CommunityFlowPlugins/tools/checkFlowVariable/1.0.0/index.js @@ -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 === '==') { diff --git a/FlowPluginsTs/CommunityFlowPlugins/tools/checkFlowVariable/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/tools/checkFlowVariable/1.0.0/index.ts index 844c6e1..c5d1e5c 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/tools/checkFlowVariable/1.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/tools/checkFlowVariable/1.0.0/index.ts @@ -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}}} + + \\nExample\\n + {{{args.userVariables.global.test + + \\nExample\\n + {{{args.inputFileObj.mediaInfo.track.0.IsStreamable}}} \\nExample\\n - args.userVariables.library.test + {{{args.inputFileObj.ffProbeData.format.nb_streams}}} \\nExample\\n - args.userVariables.global.test + {{{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(',');