mirror of
https://github.com/gabehf/Tdarr_Plugins.git
synced 2026-03-09 07:29:04 -07:00
Add exactMatch option to property filters
This commit is contained in:
parent
c00dfa7d9e
commit
62ef9e7ad8
5 changed files with 109 additions and 15 deletions
|
|
@ -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`;
|
||||
|
|
|
|||
|
|
@ -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`;
|
||||
|
|
|
|||
23
methods/utils.js
Normal file
23
methods/utils.js
Normal file
|
|
@ -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,
|
||||
};
|
||||
|
|
@ -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: {},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue