diff --git a/Community/Tdarr_Plugin_00td_filter_by_file_property.js b/Community/Tdarr_Plugin_00td_filter_by_file_property.js index cebdfbd..d8a0c97 100644 --- a/Community/Tdarr_Plugin_00td_filter_by_file_property.js +++ b/Community/Tdarr_Plugin_00td_filter_by_file_property.js @@ -1,3 +1,5 @@ +const { strHasValue } = require('../methods/utils'); + const details = () => ({ id: 'Tdarr_Plugin_00td_filter_by_file_property', Stage: 'Pre-processing', @@ -31,6 +33,21 @@ const details = () => ({ tooltip: 'Enter a comma separated list of values to check for.', }, + { + name: 'exactMatch', + type: 'boolean', + defaultValue: 'true', + inputUI: { + type: 'dropdown', + options: [ + 'false', + 'true', + ], + }, + tooltip: + 'Specify true if the property value must be an exact match,' + + ' false if the property value must contain the value.', + }, { name: 'continueIfPropertyFound', type: 'boolean', @@ -72,19 +89,8 @@ const plugin = (file, librarySettings, inputs, otherArguments) => { const propertyValues = inputs.propertyValues.trim().split(','); - let fileContainsProperty = false; try { - for (let i = 0; i < propertyValues.length; i += 1) { - try { - if (file[propertyName].includes(propertyValues[i])) { - fileContainsProperty = true; - break; - } - } catch (err) { - // eslint-disable-next-line no-console - console.log(err); - } - } + const fileContainsProperty = strHasValue(propertyValues, file[propertyName], inputs.exactMatch); const message = `File property ${propertyName} of ${file[propertyName]}` + ` being one of ${propertyValues.join(',')} has`; diff --git a/Community/Tdarr_Plugin_00td_filter_by_stream_tag.js b/Community/Tdarr_Plugin_00td_filter_by_stream_tag.js index be4ec3e..fbc6a77 100644 --- a/Community/Tdarr_Plugin_00td_filter_by_stream_tag.js +++ b/Community/Tdarr_Plugin_00td_filter_by_stream_tag.js @@ -1,3 +1,5 @@ +const { strHasValue } = require('../methods/utils'); + const details = () => ({ id: 'Tdarr_Plugin_00td_filter_by_stream_tag', Stage: 'Pre-processing', @@ -31,6 +33,21 @@ const details = () => ({ tooltip: 'Enter a comma separated list of tag values to check for.', }, + { + name: 'exactMatch', + type: 'boolean', + defaultValue: 'true', + inputUI: { + type: 'dropdown', + options: [ + 'false', + 'true', + ], + }, + tooltip: + 'Specify true if the property value must be an exact match,' + + ' false if the property value must contain the value.', + }, { name: 'continueIfTagFound', type: 'boolean', @@ -76,12 +93,14 @@ const plugin = (file, librarySettings, inputs, otherArguments) => { try { try { for (let i = 0; i < file.ffProbeData.streams.length; i += 1) { - if (tagValues.includes(file.ffProbeData.streams[i]?.tags[tagName])) { + if (strHasValue(tagValues, file.ffProbeData.streams[i]?.tags[tagName], inputs.exactMatch)) { streamContainsTag = true; + break; } } } catch (err) { - // err + // eslint-disable-next-line no-console + console.log(err); } const message = `A stream with tag name ${tagName} containing ${tagValues.join(',')} has`; diff --git a/methods/utils.js b/methods/utils.js new file mode 100644 index 0000000..11dfdc1 --- /dev/null +++ b/methods/utils.js @@ -0,0 +1,23 @@ +const strHasValue = (inputsArr, value, exactMatch) => { + let contains = false; + + for (let j = 0; j < inputsArr.length; j += 1) { + try { + if ( + (exactMatch && inputsArr[j] === String(value)) + || (!exactMatch && String(value).includes(inputsArr[j]))) { + contains = true; + break; + } + } catch (err) { + // eslint-disable-next-line no-console + console.log(err); + } + } + + return contains; +}; + +module.exports = { + strHasValue, +}; diff --git a/tests/Community/Tdarr_Plugin_00td_filter_by_file_property.js b/tests/Community/Tdarr_Plugin_00td_filter_by_file_property.js index 30cdec6..4911788 100644 --- a/tests/Community/Tdarr_Plugin_00td_filter_by_file_property.js +++ b/tests/Community/Tdarr_Plugin_00td_filter_by_file_property.js @@ -96,6 +96,7 @@ const tests = [ propertyName: 'file', propertyValues: 'Source Folder/h264.mkv', continueIfPropertyFound: false, + exactMatch: false, }, otherArguments: {}, @@ -188,7 +189,7 @@ const tests = [ propertyName: 'file', propertyValues: 'Source Folder/h264.mkv', continueIfPropertyFound: true, - + exactMatch: false, }, otherArguments: {}, }, diff --git a/tests/Community/Tdarr_Plugin_00td_filter_by_stream_tag.js b/tests/Community/Tdarr_Plugin_00td_filter_by_stream_tag.js index 3c0a36e..48e1c99 100644 --- a/tests/Community/Tdarr_Plugin_00td_filter_by_stream_tag.js +++ b/tests/Community/Tdarr_Plugin_00td_filter_by_stream_tag.js @@ -100,6 +100,28 @@ const tests = [ }, }, + { + 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, + exactMatch: false, + }, + otherArguments: {}, + }, + output: { + processFile: false, + infoLog: 'A stream with tag name COPYRIGHT containing proc,proce has been found, breaking out of stack \n', + }, + }, + // continueIfTagFound: true { @@ -185,6 +207,29 @@ const tests = [ infoLog: 'A stream with tag name COPYRIGHT containing proc,proce 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: 'proc,proce', + continueIfTagFound: true, + exactMatch: false, + + }, + otherArguments: {}, + }, + output: { + processFile: true, + infoLog: 'A stream with tag name COPYRIGHT containing proc,proce has been found, continuing to next plugin \n', + }, + }, ]; run(tests);