From 317d74520b6f1d990f124a72207f7ce14387acf0 Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Sun, 5 Mar 2023 21:32:41 +0000 Subject: [PATCH 1/3] Add Tdarr_Plugin_00td_filter_by_stream_tag --- .../Tdarr_Plugin_00td_filter_by_stream_tag.js | 117 +++++++++++ .../Tdarr_Plugin_00td_filter_by_stream_tag.js | 190 ++++++++++++++++++ 2 files changed, 307 insertions(+) create mode 100644 Community/Tdarr_Plugin_00td_filter_by_stream_tag.js create mode 100644 tests/Community/Tdarr_Plugin_00td_filter_by_stream_tag.js diff --git a/Community/Tdarr_Plugin_00td_filter_by_stream_tag.js b/Community/Tdarr_Plugin_00td_filter_by_stream_tag.js new file mode 100644 index 0000000..19dcc0c --- /dev/null +++ b/Community/Tdarr_Plugin_00td_filter_by_stream_tag.js @@ -0,0 +1,117 @@ +const details = () => ({ + id: 'Tdarr_Plugin_00td_filter_by_stream_tag', + Stage: 'Pre-processing', + Name: 'Filter by stream tag', + Type: 'Video', + Operation: 'Filter', + Description: `Filter by stream tag value. Will check all streams. Useful for when e.g. trying to force transcoding + from hevc to hevc. In this circumstance, newly transcoded files can have say COPYRIGHT tag set to 'processed' using + '-metadata:s:v:0 COPYRIGHT=processed' and this filter will then break out of the plugin stack cycling + after transcoding.`, + Version: '1.00', + Tags: 'filter', + Inputs: [ + { + name: 'tagName', + type: 'string', + defaultValue: 'COPYRIGHT', + inputUI: { + type: 'text', + }, + tooltip: + 'Enter the stream tag to check', + }, + { + name: 'tagValues', + type: 'string', + defaultValue: 'processed', + inputUI: { + type: 'text', + }, + tooltip: + 'Enter a comma separated list of tag values to check for.', + }, + { + name: 'continueIfTagFound', + type: 'boolean', + defaultValue: false, + inputUI: { + type: 'dropdown', + options: [ + false, + true, + ], + }, + tooltip: + 'Specify whether to continue the plugin stack if the tag is found.', + }, + ], +}); + +// eslint-disable-next-line no-unused-vars +const plugin = (file, librarySettings, inputs, otherArguments) => { + const lib = require('../methods/lib')(); + // eslint-disable-next-line no-unused-vars,no-param-reassign + inputs = lib.loadDefaultValues(inputs, details); + const response = { + processFile: false, + infoLog: '', + }; + + if (inputs.tagName.trim() === '') { + response.infoLog += 'No input tagName entered in plugin, skipping \n'; + return response; + } + + const tagName = inputs.tagName.trim(); + + if (inputs.tagValues.trim() === '') { + response.infoLog += 'No input tagValues entered in plugin, skipping \n'; + return response; + } + + const tagValues = inputs.tagValues.trim().split(','); + + let streamContainsTag = false; + try { + try { + for (let i = 0; i < file.ffProbeData.streams.length; i += 1) { + if (tagValues.includes(file.ffProbeData.streams[i]?.tags[tagName])) { + streamContainsTag = true; + } + } + } catch (err) { + // err + } + + const message = `A stream with tag name ${tagName} containing ${tagValues.join(',')} has`; + + if (inputs.continueIfTagFound === true) { + if (streamContainsTag === true) { + response.processFile = true; + response.infoLog += `${message} been found, continuing to next plugin \n`; + } else { + response.processFile = false; + response.infoLog += `${message} not been found, breaking out of stack \n`; + } + } else if (inputs.continueIfTagFound === false) { + if (streamContainsTag === true) { + response.processFile = false; + response.infoLog += `${message} been found, breaking out of stack \n`; + } else { + response.processFile = true; + response.infoLog += `${message} not been found, continuing to next plugin \n`; + } + } + } catch (err) { + // eslint-disable-next-line no-console + console.log(err); + response.infoLog += err; + response.processFile = false; + } + + return response; +}; + +module.exports.details = details; +module.exports.plugin = plugin; diff --git a/tests/Community/Tdarr_Plugin_00td_filter_by_stream_tag.js b/tests/Community/Tdarr_Plugin_00td_filter_by_stream_tag.js new file mode 100644 index 0000000..3c0a36e --- /dev/null +++ b/tests/Community/Tdarr_Plugin_00td_filter_by_stream_tag.js @@ -0,0 +1,190 @@ +/* eslint max-len: 0 */ +const _ = require('lodash'); +const run = require('../helpers/run'); + +const tests = [ + { + input: { + file: _.cloneDeep(require('../sampleData/media/sampleH264_2.json')), + librarySettings: {}, + inputs: {}, + otherArguments: {}, + }, + output: { + processFile: true, + infoLog: 'A stream with tag name COPYRIGHT containing processed has not been found, continuing to next plugin \n', + }, + }, + + { + input: { + file: _.cloneDeep(require('../sampleData/media/sampleH264_2.json')), + librarySettings: {}, + inputs: { + tagName: 'COPYRIGHT', + tagValues: 'processed', + continueIfTagFound: false, + + }, + otherArguments: {}, + }, + output: { + processFile: true, + infoLog: 'A stream with tag name COPYRIGHT containing processed has not been found, continuing to next plugin \n', + }, + }, + + { + input: { + file: (() => { + const file = _.cloneDeep(require('../sampleData/media/sampleH265_1.json')); + file.ffProbeData.streams[0].tags.COPYRIGHT = 'processed'; + return file; + })(), + librarySettings: {}, + inputs: { + tagName: 'COPYRIGHT', + tagValues: 'processed', + continueIfTagFound: false, + + }, + otherArguments: {}, + }, + output: { + processFile: false, + infoLog: 'A stream with tag name COPYRIGHT containing processed has been found, breaking out of stack \n', + }, + }, + + { + input: { + file: (() => { + const file = _.cloneDeep(require('../sampleData/media/sampleH265_1.json')); + file.ffProbeData.streams[1].tags.COPYRIGHT = 'processed'; + return file; + })(), + librarySettings: {}, + inputs: { + tagName: 'COPYRIGHT', + tagValues: 'proc,processed', + continueIfTagFound: false, + + }, + otherArguments: {}, + }, + output: { + processFile: false, + infoLog: 'A stream with tag name COPYRIGHT containing proc,processed has been found, breaking out of stack \n', + }, + }, + + { + input: { + file: (() => { + const file = _.cloneDeep(require('../sampleData/media/sampleH265_1.json')); + file.ffProbeData.streams[0].tags.COPYRIGHT = 'processed'; + return file; + })(), + librarySettings: {}, + inputs: { + tagName: 'COPYRIGHT', + tagValues: 'proc,proce', + continueIfTagFound: false, + + }, + otherArguments: {}, + }, + output: { + processFile: true, + infoLog: 'A stream with tag name COPYRIGHT containing proc,proce has not been found, continuing to next plugin \n', + }, + }, + + // continueIfTagFound: true + + { + input: { + file: _.cloneDeep(require('../sampleData/media/sampleH264_2.json')), + librarySettings: {}, + inputs: { + tagName: 'COPYRIGHT', + tagValues: 'processed', + continueIfTagFound: true, + + }, + otherArguments: {}, + }, + output: { + processFile: false, + infoLog: 'A stream with tag name COPYRIGHT containing processed has not been found, breaking out of stack \n', + }, + }, + + { + input: { + file: (() => { + const file = _.cloneDeep(require('../sampleData/media/sampleH265_1.json')); + file.ffProbeData.streams[0].tags.COPYRIGHT = 'processed'; + return file; + })(), + librarySettings: {}, + inputs: { + tagName: 'COPYRIGHT', + tagValues: 'processed', + continueIfTagFound: true, + + }, + otherArguments: {}, + }, + output: { + processFile: true, + infoLog: 'A stream with tag name COPYRIGHT containing processed has been found, continuing to next plugin \n', + }, + }, + + { + input: { + file: (() => { + const file = _.cloneDeep(require('../sampleData/media/sampleH265_1.json')); + file.ffProbeData.streams[1].tags.COPYRIGHT = 'processed'; + return file; + })(), + librarySettings: {}, + inputs: { + tagName: 'COPYRIGHT', + tagValues: 'proc,processed', + continueIfTagFound: true, + + }, + otherArguments: {}, + }, + output: { + processFile: true, + infoLog: 'A stream with tag name COPYRIGHT containing proc,processed has been found, continuing to next plugin \n', + }, + }, + + { + input: { + file: (() => { + const file = _.cloneDeep(require('../sampleData/media/sampleH265_1.json')); + file.ffProbeData.streams[0].tags.COPYRIGHT = 'processed'; + return file; + })(), + librarySettings: {}, + inputs: { + tagName: 'COPYRIGHT', + tagValues: 'proc,proce', + continueIfTagFound: true, + + }, + otherArguments: {}, + }, + output: { + processFile: false, + infoLog: 'A stream with tag name COPYRIGHT containing proc,proce has not been found, breaking out of stack \n', + }, + }, +]; + +run(tests); From cdfde9b99d74a6db0cadc008916773730b064b68 Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Sun, 5 Mar 2023 21:45:39 +0000 Subject: [PATCH 2/3] Update tests --- tests/checkPlugins.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/checkPlugins.js b/tests/checkPlugins.js index 13bab9d..c98e96e 100644 --- a/tests/checkPlugins.js +++ b/tests/checkPlugins.js @@ -186,6 +186,12 @@ module.exports.plugin = plugin;`; } else if (inputs[j].defaultValue === undefined) { console.log(chalk.red(`Plugin Input does not have a default value: '${folder}/${files[i]}' : ${inputs[j].name}`)); errorEncountered = true; + } else if (inputs[j].inputUI.type === 'dropdown' && !Array.isArray(inputs[j].inputUI.options)) { + console.log(chalk.red(`Plugin Input is dropdown but does not have dropdown array: '${folder}/${files[i]}' : ${inputs[j].name}`)); + errorEncountered = true; + } else if (Array.isArray(inputs[j].inputUI.options) && inputs[j].inputUI.options.some((option) => typeof option === 'boolean')) { + console.log(chalk.red(`Plugin Input has a boolean dropdown input: '${folder}/${files[i]}' : ${inputs[j].name}`)); + errorEncountered = true; } const count = read.split(inputs[j].name).length - 1; From a50c3c7e5183cc6c71c2a4aded862878b22dc11d Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Sun, 5 Mar 2023 21:45:48 +0000 Subject: [PATCH 3/3] Fix option type --- Community/Tdarr_Plugin_00td_filter_by_stream_tag.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Community/Tdarr_Plugin_00td_filter_by_stream_tag.js b/Community/Tdarr_Plugin_00td_filter_by_stream_tag.js index 19dcc0c..be4ec3e 100644 --- a/Community/Tdarr_Plugin_00td_filter_by_stream_tag.js +++ b/Community/Tdarr_Plugin_00td_filter_by_stream_tag.js @@ -38,8 +38,8 @@ const details = () => ({ inputUI: { type: 'dropdown', options: [ - false, - true, + 'false', + 'true', ], }, tooltip: