Merge pull request #406 from HaveAGitGat/filter_by_file_property_amend

Add exactMatch option to property filters
make-only-subtitle-default
HaveAGitGat 3 years ago committed by GitHub
commit efd12b23cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -31,6 +31,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',
@ -50,6 +65,7 @@ const details = () => ({
// eslint-disable-next-line no-unused-vars
const plugin = (file, librarySettings, inputs, otherArguments) => {
const { strHasValue } = require('../methods/utils');
const lib = require('../methods/lib')();
// eslint-disable-next-line no-unused-vars,no-param-reassign
inputs = lib.loadDefaultValues(inputs, details);
@ -72,19 +88,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`;

@ -31,6 +31,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',
@ -50,6 +65,7 @@ const details = () => ({
// eslint-disable-next-line no-unused-vars
const plugin = (file, librarySettings, inputs, otherArguments) => {
const { strHasValue } = require('../methods/utils');
const lib = require('../methods/lib')();
// eslint-disable-next-line no-unused-vars,no-param-reassign
inputs = lib.loadDefaultValues(inputs, details);
@ -76,12 +92,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`;

@ -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…
Cancel
Save