mirror of
https://github.com/gabehf/Tdarr_Plugins.git
synced 2026-03-13 09:20:27 -07:00
Merge pull request #406 from HaveAGitGat/filter_by_file_property_amend
Add exactMatch option to property filters
This commit is contained in:
commit
efd12b23cb
5 changed files with 107 additions and 15 deletions
|
|
@ -31,6 +31,21 @@ const details = () => ({
|
||||||
tooltip:
|
tooltip:
|
||||||
'Enter a comma separated list of values to check for.',
|
'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',
|
name: 'continueIfPropertyFound',
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
|
|
@ -50,6 +65,7 @@ const details = () => ({
|
||||||
|
|
||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
const plugin = (file, librarySettings, inputs, otherArguments) => {
|
const plugin = (file, librarySettings, inputs, otherArguments) => {
|
||||||
|
const { strHasValue } = require('../methods/utils');
|
||||||
const lib = require('../methods/lib')();
|
const lib = require('../methods/lib')();
|
||||||
// eslint-disable-next-line no-unused-vars,no-param-reassign
|
// eslint-disable-next-line no-unused-vars,no-param-reassign
|
||||||
inputs = lib.loadDefaultValues(inputs, details);
|
inputs = lib.loadDefaultValues(inputs, details);
|
||||||
|
|
@ -72,19 +88,8 @@ const plugin = (file, librarySettings, inputs, otherArguments) => {
|
||||||
|
|
||||||
const propertyValues = inputs.propertyValues.trim().split(',');
|
const propertyValues = inputs.propertyValues.trim().split(',');
|
||||||
|
|
||||||
let fileContainsProperty = false;
|
|
||||||
try {
|
try {
|
||||||
for (let i = 0; i < propertyValues.length; i += 1) {
|
const fileContainsProperty = strHasValue(propertyValues, file[propertyName], inputs.exactMatch);
|
||||||
try {
|
|
||||||
if (file[propertyName].includes(propertyValues[i])) {
|
|
||||||
fileContainsProperty = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.log(err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const message = `File property ${propertyName} of ${file[propertyName]}`
|
const message = `File property ${propertyName} of ${file[propertyName]}`
|
||||||
+ ` being one of ${propertyValues.join(',')} has`;
|
+ ` being one of ${propertyValues.join(',')} has`;
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,21 @@ const details = () => ({
|
||||||
tooltip:
|
tooltip:
|
||||||
'Enter a comma separated list of tag values to check for.',
|
'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',
|
name: 'continueIfTagFound',
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
|
|
@ -50,6 +65,7 @@ const details = () => ({
|
||||||
|
|
||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
const plugin = (file, librarySettings, inputs, otherArguments) => {
|
const plugin = (file, librarySettings, inputs, otherArguments) => {
|
||||||
|
const { strHasValue } = require('../methods/utils');
|
||||||
const lib = require('../methods/lib')();
|
const lib = require('../methods/lib')();
|
||||||
// eslint-disable-next-line no-unused-vars,no-param-reassign
|
// eslint-disable-next-line no-unused-vars,no-param-reassign
|
||||||
inputs = lib.loadDefaultValues(inputs, details);
|
inputs = lib.loadDefaultValues(inputs, details);
|
||||||
|
|
@ -76,12 +92,14 @@ const plugin = (file, librarySettings, inputs, otherArguments) => {
|
||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
for (let i = 0; i < file.ffProbeData.streams.length; i += 1) {
|
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;
|
streamContainsTag = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// err
|
// eslint-disable-next-line no-console
|
||||||
|
console.log(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
const message = `A stream with tag name ${tagName} containing ${tagValues.join(',')} has`;
|
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',
|
propertyName: 'file',
|
||||||
propertyValues: 'Source Folder/h264.mkv',
|
propertyValues: 'Source Folder/h264.mkv',
|
||||||
continueIfPropertyFound: false,
|
continueIfPropertyFound: false,
|
||||||
|
exactMatch: false,
|
||||||
|
|
||||||
},
|
},
|
||||||
otherArguments: {},
|
otherArguments: {},
|
||||||
|
|
@ -188,7 +189,7 @@ const tests = [
|
||||||
propertyName: 'file',
|
propertyName: 'file',
|
||||||
propertyValues: 'Source Folder/h264.mkv',
|
propertyValues: 'Source Folder/h264.mkv',
|
||||||
continueIfPropertyFound: true,
|
continueIfPropertyFound: true,
|
||||||
|
exactMatch: false,
|
||||||
},
|
},
|
||||||
otherArguments: {},
|
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
|
// 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',
|
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);
|
run(tests);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue