Merge pull request #427 from HaveAGitGat/add_conditions

Add condition input
make-only-subtitle-default
HaveAGitGat 2 years ago committed by GitHub
commit f4f8192806
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -32,19 +32,27 @@ const details = () => ({
'Enter a comma separated list of values to check for.', 'Enter a comma separated list of values to check for.',
}, },
{ {
name: 'exactMatch', name: 'condition',
type: 'boolean', type: 'string',
defaultValue: true, defaultValue: '==',
inputUI: { inputUI: {
type: 'dropdown', type: 'dropdown',
options: [ options: [
'false', '==',
'true', '!=',
'>',
'>=',
'<',
'<=',
'includes',
'not includes',
], ],
}, },
tooltip: tooltip:
'Specify true if the property value must be an exact match,' 'Specify the condition to use when comparing the property value to the input value. \\n'
+ ' false if the property value must contain the value.', + ' The property value is on the left hand side of the comparison. For example \\n'
+ ' property value includes input \\n'
+ ' property value >= input \\n',
}, },
{ {
name: 'continueIfPropertyFound', name: 'continueIfPropertyFound',
@ -63,9 +71,88 @@ const details = () => ({
], ],
}); });
const conditionMet = (response, inputsArr, value, condition) => {
for (let j = 0; j < inputsArr.length; j += 1) {
try {
let v = value;
let i = inputsArr[j];
if (
condition === '>'
|| condition === '>='
|| condition === '<'
|| condition === '<='
) {
v = Number(value);
i = Number(inputsArr[j]);
} else if (
condition === '=='
|| condition === '!='
|| condition === 'includes'
|| condition === 'not includes'
) {
v = String(value);
i = String(inputsArr[j]);
}
response.infoLog += ` Checking property value of ${v} ${condition} input value of ${i} \n`;
switch (condition) {
case '==':
if (v === i) {
return true;
}
break;
case '!=':
if (v !== i) {
return true;
}
break;
case '>':
if (v > i) {
return true;
}
break;
case '>=':
if (v >= i) {
return true;
}
break;
case '<':
if (v < i) {
return true;
}
break;
case '<=':
if (v <= i) {
return true;
}
break;
case 'includes':
if (v.includes(i)) {
return true;
}
break;
case 'not includes':
if (!v.includes(i)) {
return true;
}
break;
default:
}
} catch (err) {
// eslint-disable-next-line no-console
console.log(err);
}
}
return false;
};
// 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);
@ -86,29 +173,34 @@ const plugin = (file, librarySettings, inputs, otherArguments) => {
return response; return response;
} }
// legacy
if (inputs.exactMatch === false && inputs.condition === '==') {
// eslint-disable-next-line no-param-reassign
inputs.condition = 'includes';
}
const propertyValues = inputs.propertyValues.trim().split(','); const propertyValues = inputs.propertyValues.trim().split(',');
try { try {
const fileContainsProperty = strHasValue(propertyValues, file[propertyName], inputs.exactMatch); const isConditionMet = conditionMet(response, propertyValues, file[propertyName], inputs.condition);
const message = `File property ${propertyName} of ${file[propertyName]}`
+ ` being one of ${propertyValues.join(',')} has`;
response.infoLog += ` isConditionMet: ${isConditionMet} \n`;
response.infoLog += ` continueIfPropertyFound: ${inputs.continueIfPropertyFound} \n`;
if (inputs.continueIfPropertyFound === true) { if (inputs.continueIfPropertyFound === true) {
if (fileContainsProperty === true) { if (isConditionMet === true) {
response.processFile = true; response.processFile = true;
response.infoLog += `${message} been found, continuing to next plugin \n`; response.infoLog += 'Continuing to next plugin \n';
} else { } else {
response.processFile = false; response.processFile = false;
response.infoLog += `${message} not been found, breaking out of stack \n`; response.infoLog += 'Breaking out of stack \n';
} }
} else if (inputs.continueIfPropertyFound === false) { } else if (inputs.continueIfPropertyFound === false) {
if (fileContainsProperty === true) { if (isConditionMet === true) {
response.processFile = false; response.processFile = false;
response.infoLog += `${message} been found, breaking out of stack \n`; response.infoLog += 'Breaking out of stack \n';
} else { } else {
response.processFile = true; response.processFile = true;
response.infoLog += `${message} not been found, continuing to next plugin \n`; response.infoLog += 'Continuing to next plugin \n';
} }
} }
} catch (err) { } catch (err) {

@ -22,9 +22,9 @@ const details = () => ({
365 365
\\nExample:\\n \\nExample:\\n
30` 30`,
}, },
] ],
}); });
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
@ -36,26 +36,21 @@ const plugin = (file, librarySettings, inputs, otherArguments) => {
processFile: true, processFile: true,
infoLog: '', infoLog: '',
}; };
//response.infoLog += `Filter preventing processing. File mod time ${file.statSync.mtimeMs}`; // response.infoLog += `Filter preventing processing. File mod time ${file.statSync.mtimeMs}`;
//response.infoLog += ` Now ${Date.now()}`; // response.infoLog += ` Now ${Date.now()}`;
const age = Date.now() - file.statSync.mtimeMs; const age = Date.now() - file.statSync.mtimeMs;
const reqage = Number(inputs.minModifiedDaysOld) * 86400000; const reqage = Number(inputs.minModifiedDaysOld) * 86400000;
// response.infoLog += ` Age ${age} Require Min Age: ${reqage}`; // response.infoLog += ` Age ${age} Require Min Age: ${reqage}`;
if (reqage < age) if (reqage < age) {
{ response.infoLog += 'File modified date old enough. Moving to next plugin.';
response.infoLog += "File modified date old enough. Moving to next plugin."; response.processFile = true;
response.processFile = true; } else {
response.infoLog += 'Skipping, file modified date not old enough';
response.processFile = false;
} }
else
{
response.infoLog += "Skipping, file modified date not old enough";
response.processFile = false;
}
return response; return response;
}; };
module.exports.details = details; module.exports.details = details;
module.exports.plugin = plugin; module.exports.plugin = plugin;

@ -12,7 +12,10 @@ const tests = [
}, },
output: { output: {
processFile: false, processFile: false,
infoLog: 'File property container of mkv being one of mkv,mp4 has been found, breaking out of stack \n', infoLog: ' Checking property value of mkv == input value of mkv \n'
+ ' isConditionMet: true \n'
+ ' continueIfPropertyFound: false \n'
+ 'Breaking out of stack \n',
}, },
}, },
@ -30,7 +33,10 @@ const tests = [
}, },
output: { output: {
processFile: true, processFile: true,
infoLog: 'File property container of mkv being one of avi has not been found, continuing to next plugin \n', infoLog: ' Checking property value of mkv == input value of avi \n'
+ ' isConditionMet: false \n'
+ ' continueIfPropertyFound: false \n'
+ 'Continuing to next plugin \n',
}, },
}, },
@ -48,7 +54,10 @@ const tests = [
}, },
output: { output: {
processFile: false, processFile: false,
infoLog: 'File property container of mkv being one of mkv has been found, breaking out of stack \n', infoLog: ' Checking property value of mkv == input value of mkv \n'
+ ' isConditionMet: true \n'
+ ' continueIfPropertyFound: false \n'
+ 'Breaking out of stack \n',
}, },
}, },
@ -66,7 +75,11 @@ const tests = [
}, },
output: { output: {
processFile: false, processFile: false,
infoLog: 'File property video_resolution of 1080p being one of 720p,1080p has been found, breaking out of stack \n', infoLog: ' Checking property value of 1080p == input value of 720p \n'
+ ' Checking property value of 1080p == input value of 1080p \n'
+ ' isConditionMet: true \n'
+ ' continueIfPropertyFound: false \n'
+ 'Breaking out of stack \n',
}, },
}, },
@ -84,7 +97,11 @@ const tests = [
}, },
output: { output: {
processFile: true, processFile: true,
infoLog: 'File property video_resolution of 1080p being one of 721p,1081p has not been found, continuing to next plugin \n', infoLog: ' Checking property value of 1080p == input value of 721p \n'
+ ' Checking property value of 1080p == input value of 1081p \n'
+ ' isConditionMet: false \n'
+ ' continueIfPropertyFound: false \n'
+ 'Continuing to next plugin \n',
}, },
}, },
@ -103,7 +120,10 @@ const tests = [
}, },
output: { output: {
processFile: false, processFile: false,
infoLog: 'File property file of C:/Transcode/Source Folder/h264.mkv being one of Source Folder/h264.mkv has been found, breaking out of stack \n', infoLog: ' Checking property value of C:/Transcode/Source Folder/h264.mkv includes input value of Source Folder/h264.mkv \n'
+ ' isConditionMet: true \n'
+ ' continueIfPropertyFound: false \n'
+ 'Breaking out of stack \n',
}, },
}, },
@ -123,7 +143,10 @@ const tests = [
}, },
output: { output: {
processFile: false, processFile: false,
infoLog: 'File property container of mkv being one of avi has not been found, breaking out of stack \n', infoLog: ' Checking property value of mkv == input value of avi \n'
+ ' isConditionMet: false \n'
+ ' continueIfPropertyFound: true \n'
+ 'Breaking out of stack \n',
}, },
}, },
@ -141,7 +164,10 @@ const tests = [
}, },
output: { output: {
processFile: true, processFile: true,
infoLog: 'File property container of mkv being one of mkv has been found, continuing to next plugin \n', infoLog: ' Checking property value of mkv == input value of mkv \n'
+ ' isConditionMet: true \n'
+ ' continueIfPropertyFound: true \n'
+ 'Continuing to next plugin \n',
}, },
}, },
@ -159,7 +185,10 @@ const tests = [
}, },
output: { output: {
processFile: true, processFile: true,
infoLog: 'File property container of mkv being one of mkv,mp4 has been found, continuing to next plugin \n', infoLog: ' Checking property value of mkv == input value of mkv \n'
+ ' isConditionMet: true \n'
+ ' continueIfPropertyFound: true \n'
+ 'Continuing to next plugin \n',
}, },
}, },
@ -177,7 +206,11 @@ const tests = [
}, },
output: { output: {
processFile: false, processFile: false,
infoLog: 'File property video_resolution of 1080p being one of 721p,1081p has not been found, breaking out of stack \n', infoLog: ' Checking property value of 1080p == input value of 721p \n'
+ ' Checking property value of 1080p == input value of 1081p \n'
+ ' isConditionMet: false \n'
+ ' continueIfPropertyFound: true \n'
+ 'Breaking out of stack \n',
}, },
}, },
@ -195,7 +228,306 @@ const tests = [
}, },
output: { output: {
processFile: true, processFile: true,
infoLog: 'File property file of C:/Transcode/Source Folder/h264.mkv being one of Source Folder/h264.mkv has been found, continuing to next plugin \n', infoLog: ' Checking property value of C:/Transcode/Source Folder/h264.mkv includes input value of Source Folder/h264.mkv \n'
+ ' isConditionMet: true \n'
+ ' continueIfPropertyFound: true \n'
+ 'Continuing to next plugin \n',
},
},
// check other conditions
{
input: {
file: _.cloneDeep(require('../sampleData/media/sampleH264_2.json')),
librarySettings: {},
inputs: {
propertyName: 'container',
propertyValues: 'mkv',
condition: '==',
},
otherArguments: {},
},
output: {
processFile: false,
infoLog: ' Checking property value of mkv == input value of mkv \n'
+ ' isConditionMet: true \n'
+ ' continueIfPropertyFound: false \n'
+ 'Breaking out of stack \n',
},
},
{
input: {
file: _.cloneDeep(require('../sampleData/media/sampleH264_2.json')),
librarySettings: {},
inputs: {
propertyName: 'container',
propertyValues: 'avi',
condition: '==',
},
otherArguments: {},
},
output: {
processFile: true,
infoLog: ' Checking property value of mkv == input value of avi \n'
+ ' isConditionMet: false \n'
+ ' continueIfPropertyFound: false \n'
+ 'Continuing to next plugin \n',
},
},
{
input: {
file: _.cloneDeep(require('../sampleData/media/sampleH264_2.json')),
librarySettings: {},
inputs: {
propertyName: 'file_size',
propertyValues: '60',
condition: '>',
},
otherArguments: {},
},
output: {
processFile: false,
infoLog: ' Checking property value of 64.9300765991211 > input value of 60 \n'
+ ' isConditionMet: true \n'
+ ' continueIfPropertyFound: false \n'
+ 'Breaking out of stack \n',
},
},
{
input: {
file: _.cloneDeep(require('../sampleData/media/sampleH264_2.json')),
librarySettings: {},
inputs: {
propertyName: 'file_size',
propertyValues: '70',
condition: '>',
},
otherArguments: {},
},
output: {
processFile: true,
infoLog: ' Checking property value of 64.9300765991211 > input value of 70 \n'
+ ' isConditionMet: false \n'
+ ' continueIfPropertyFound: false \n'
+ 'Continuing to next plugin \n',
},
},
{
input: {
file: _.cloneDeep(require('../sampleData/media/sampleH264_2.json')),
librarySettings: {},
inputs: {
propertyName: 'file_size',
propertyValues: '60',
condition: '>=',
},
otherArguments: {},
},
output: {
processFile: false,
infoLog: ' Checking property value of 64.9300765991211 >= input value of 60 \n'
+ ' isConditionMet: true \n'
+ ' continueIfPropertyFound: false \n'
+ 'Breaking out of stack \n',
},
},
{
input: {
file: _.cloneDeep(require('../sampleData/media/sampleH264_2.json')),
librarySettings: {},
inputs: {
propertyName: 'file_size',
propertyValues: '70',
condition: '>=',
},
otherArguments: {},
},
output: {
processFile: true,
infoLog: ' Checking property value of 64.9300765991211 >= input value of 70 \n'
+ ' isConditionMet: false \n'
+ ' continueIfPropertyFound: false \n'
+ 'Continuing to next plugin \n',
},
},
{
input: {
file: _.cloneDeep(require('../sampleData/media/sampleH264_2.json')),
librarySettings: {},
inputs: {
propertyName: 'file_size',
propertyValues: '60',
condition: '<',
},
otherArguments: {},
},
output: {
processFile: true,
infoLog: ' Checking property value of 64.9300765991211 < input value of 60 \n'
+ ' isConditionMet: false \n'
+ ' continueIfPropertyFound: false \n'
+ 'Continuing to next plugin \n',
},
},
{
input: {
file: _.cloneDeep(require('../sampleData/media/sampleH264_2.json')),
librarySettings: {},
inputs: {
propertyName: 'file_size',
propertyValues: '70',
condition: '<',
},
otherArguments: {},
},
output: {
processFile: false,
infoLog: ' Checking property value of 64.9300765991211 < input value of 70 \n'
+ ' isConditionMet: true \n'
+ ' continueIfPropertyFound: false \n'
+ 'Breaking out of stack \n',
},
},
{
input: {
file: _.cloneDeep(require('../sampleData/media/sampleH264_2.json')),
librarySettings: {},
inputs: {
propertyName: 'file_size',
propertyValues: '60',
condition: '<=',
},
otherArguments: {},
},
output: {
processFile: true,
infoLog: ' Checking property value of 64.9300765991211 <= input value of 60 \n'
+ ' isConditionMet: false \n'
+ ' continueIfPropertyFound: false \n'
+ 'Continuing to next plugin \n',
},
},
{
input: {
file: _.cloneDeep(require('../sampleData/media/sampleH264_2.json')),
librarySettings: {},
inputs: {
propertyName: 'file_size',
propertyValues: '70',
condition: '<=',
},
otherArguments: {},
},
output: {
processFile: false,
infoLog: ' Checking property value of 64.9300765991211 <= input value of 70 \n'
+ ' isConditionMet: true \n'
+ ' continueIfPropertyFound: false \n'
+ 'Breaking out of stack \n',
},
},
{
input: {
file: _.cloneDeep(require('../sampleData/media/sampleH264_2.json')),
librarySettings: {},
inputs: {
propertyName: 'container',
propertyValues: 'mk',
condition: 'includes',
},
otherArguments: {},
},
output: {
processFile: false,
infoLog: ' Checking property value of mkv includes input value of mk \n'
+ ' isConditionMet: true \n'
+ ' continueIfPropertyFound: false \n'
+ 'Breaking out of stack \n',
},
},
{
input: {
file: _.cloneDeep(require('../sampleData/media/sampleH264_2.json')),
librarySettings: {},
inputs: {
propertyName: 'container',
propertyValues: 'av',
condition: 'includes',
},
otherArguments: {},
},
output: {
processFile: true,
infoLog: ' Checking property value of mkv includes input value of av \n'
+ ' isConditionMet: false \n'
+ ' continueIfPropertyFound: false \n'
+ 'Continuing to next plugin \n',
},
},
{
input: {
file: _.cloneDeep(require('../sampleData/media/sampleH264_2.json')),
librarySettings: {},
inputs: {
propertyName: 'container',
propertyValues: 'mk',
condition: 'not includes',
},
otherArguments: {},
},
output: {
processFile: true,
infoLog: ' Checking property value of mkv not includes input value of mk \n'
+ ' isConditionMet: false \n'
+ ' continueIfPropertyFound: false \n'
+ 'Continuing to next plugin \n',
},
},
{
input: {
file: _.cloneDeep(require('../sampleData/media/sampleH264_2.json')),
librarySettings: {},
inputs: {
propertyName: 'container',
propertyValues: 'av',
condition: 'not includes',
},
otherArguments: {},
},
output: {
processFile: false,
infoLog: ' Checking property value of mkv not includes input value of av \n'
+ ' isConditionMet: true \n'
+ ' continueIfPropertyFound: false \n'
+ 'Breaking out of stack \n',
}, },
}, },
]; ];

@ -7,7 +7,7 @@ const tests = [
file: require('../sampleData/media/sampleH264_2.json'), file: require('../sampleData/media/sampleH264_2.json'),
librarySettings: {}, librarySettings: {},
inputs: { inputs: {
minModifiedDaysOld: 1 minModifiedDaysOld: 1,
}, },
otherArguments: {}, otherArguments: {},
}, },
@ -21,13 +21,13 @@ const tests = [
file: require('../sampleData/media/sampleH264_1.json'), file: require('../sampleData/media/sampleH264_1.json'),
librarySettings: {}, librarySettings: {},
inputs: { inputs: {
minModifiedDaysOld: 9999 minModifiedDaysOld: 9999,
}, },
otherArguments: {}, otherArguments: {},
}, },
output: { output: {
processFile: false, processFile: false,
infoLog: 'Skipping, file modified date not old enough', infoLog: 'Skipping, file modified date not old enough',
}, },
}, },
{ {
@ -35,7 +35,7 @@ const tests = [
file: require('../sampleData/media/sampleH264_1.json'), file: require('../sampleData/media/sampleH264_1.json'),
librarySettings: {}, librarySettings: {},
inputs: { inputs: {
minModifiedDaysOld: 1 minModifiedDaysOld: 1,
}, },
otherArguments: {}, otherArguments: {},
}, },
@ -49,7 +49,7 @@ const tests = [
file: require('../sampleData/media/sampleH264_1.json'), file: require('../sampleData/media/sampleH264_1.json'),
librarySettings: {}, librarySettings: {},
inputs: { inputs: {
minModifiedDaysOld: 9999 minModifiedDaysOld: 9999,
}, },
otherArguments: {}, otherArguments: {},
}, },
@ -60,4 +60,4 @@ const tests = [
}, },
]; ];
run(tests); run(tests);

Loading…
Cancel
Save