Merge pull request #398 from HaveAGitGat/Tdarr_Plugin_00td_filter_by_file_property
Add Tdarr_Plugin_00td_filter_by_file_propertymake-only-subtitle-default
commit
9e871c858f
@ -0,0 +1,116 @@
|
||||
const details = () => ({
|
||||
id: 'Tdarr_Plugin_00td_filter_by_file_property',
|
||||
Stage: 'Pre-processing',
|
||||
Name: 'Filter by file property',
|
||||
Type: 'Video',
|
||||
Operation: 'Filter',
|
||||
Description: `Filter by a top level file property.
|
||||
For example, container, video_resolution, video_codec_name, fileMedium.
|
||||
Click on a file name on the Tdarr tab or Search tab to see top-level file properties.
|
||||
`,
|
||||
Version: '1.00',
|
||||
Tags: 'filter',
|
||||
Inputs: [
|
||||
{
|
||||
name: 'propertyName',
|
||||
type: 'string',
|
||||
defaultValue: 'container',
|
||||
inputUI: {
|
||||
type: 'text',
|
||||
},
|
||||
tooltip:
|
||||
'Enter the file property to check',
|
||||
},
|
||||
{
|
||||
name: 'propertyValues',
|
||||
type: 'string',
|
||||
defaultValue: 'mkv,mp4',
|
||||
inputUI: {
|
||||
type: 'text',
|
||||
},
|
||||
tooltip:
|
||||
'Enter a comma separated list of values to check for.',
|
||||
},
|
||||
{
|
||||
name: 'continueIfPropertyFound',
|
||||
type: 'boolean',
|
||||
defaultValue: false,
|
||||
inputUI: {
|
||||
type: 'dropdown',
|
||||
options: [
|
||||
'false',
|
||||
'true',
|
||||
],
|
||||
},
|
||||
tooltip:
|
||||
'Specify whether to continue the plugin stack if the property is found.',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const plugin = (file, librarySettings, inputs, otherArguments) => {
|
||||
const lib = require('../methods/lib')();
|
||||
// eslint-disable-next-line no-unused-vars,no-param-reassign
|
||||
inputs = lib.loadDefaultValues(inputs, details);
|
||||
const response = {
|
||||
processFile: false,
|
||||
infoLog: '',
|
||||
};
|
||||
|
||||
if (inputs.propertyName.trim() === '') {
|
||||
response.infoLog += 'No input propertyName entered in plugin, skipping \n';
|
||||
return response;
|
||||
}
|
||||
|
||||
const propertyName = inputs.propertyName.trim();
|
||||
|
||||
if (inputs.propertyValues.trim() === '') {
|
||||
response.infoLog += 'No input propertyValues entered in plugin, skipping \n';
|
||||
return response;
|
||||
}
|
||||
|
||||
const propertyValues = inputs.propertyValues.trim().split(',');
|
||||
|
||||
let fileContainsProperty = false;
|
||||
try {
|
||||
try {
|
||||
if (propertyValues.includes(file[propertyName])) {
|
||||
fileContainsProperty = true;
|
||||
}
|
||||
} catch (err) {
|
||||
// err
|
||||
}
|
||||
|
||||
const message = `File property ${propertyName} of ${file[propertyName]}`
|
||||
+ ` being one of ${propertyValues.join(',')} has`;
|
||||
|
||||
if (inputs.continueIfPropertyFound === true) {
|
||||
if (fileContainsProperty === true) {
|
||||
response.processFile = true;
|
||||
response.infoLog += `${message} been found, continuing to next plugin \n`;
|
||||
} else {
|
||||
response.processFile = false;
|
||||
response.infoLog += `${message} not been found, breaking out of stack \n`;
|
||||
}
|
||||
} else if (inputs.continueIfPropertyFound === false) {
|
||||
if (fileContainsProperty === true) {
|
||||
response.processFile = false;
|
||||
response.infoLog += `${message} been found, breaking out of stack \n`;
|
||||
} else {
|
||||
response.processFile = true;
|
||||
response.infoLog += `${message} not been found, continuing to next plugin \n`;
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(err);
|
||||
response.infoLog += err;
|
||||
response.processFile = false;
|
||||
}
|
||||
|
||||
return response;
|
||||
};
|
||||
|
||||
module.exports.details = details;
|
||||
module.exports.plugin = plugin;
|
||||
@ -0,0 +1,166 @@
|
||||
/* eslint max-len: 0 */
|
||||
const _ = require('lodash');
|
||||
const run = require('../helpers/run');
|
||||
|
||||
const tests = [
|
||||
{
|
||||
input: {
|
||||
file: _.cloneDeep(require('../sampleData/media/sampleH264_2.json')),
|
||||
librarySettings: {},
|
||||
inputs: {},
|
||||
otherArguments: {},
|
||||
},
|
||||
output: {
|
||||
processFile: false,
|
||||
infoLog: 'File property container of mkv being one of mkv,mp4 has been found, breaking out of stack \n',
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
input: {
|
||||
file: _.cloneDeep(require('../sampleData/media/sampleH264_2.json')),
|
||||
librarySettings: {},
|
||||
inputs: {
|
||||
propertyName: 'container',
|
||||
propertyValues: 'avi',
|
||||
continueIfPropertyFound: false,
|
||||
|
||||
},
|
||||
otherArguments: {},
|
||||
},
|
||||
output: {
|
||||
processFile: true,
|
||||
infoLog: 'File property container of mkv being one of avi has not been found, continuing to next plugin \n',
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
input: {
|
||||
file: _.cloneDeep(require('../sampleData/media/sampleH264_2.json')),
|
||||
librarySettings: {},
|
||||
inputs: {
|
||||
propertyName: 'container',
|
||||
propertyValues: 'mkv',
|
||||
continueIfPropertyFound: false,
|
||||
|
||||
},
|
||||
otherArguments: {},
|
||||
},
|
||||
output: {
|
||||
processFile: false,
|
||||
infoLog: 'File property container of mkv being one of mkv has been found, breaking out of stack \n',
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
input: {
|
||||
file: _.cloneDeep(require('../sampleData/media/sampleH264_2.json')),
|
||||
librarySettings: {},
|
||||
inputs: {
|
||||
propertyName: 'video_resolution',
|
||||
propertyValues: '720p,1080p',
|
||||
continueIfPropertyFound: false,
|
||||
|
||||
},
|
||||
otherArguments: {},
|
||||
},
|
||||
output: {
|
||||
processFile: false,
|
||||
infoLog: 'File property video_resolution of 1080p being one of 720p,1080p has been found, breaking out of stack \n',
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
input: {
|
||||
file: _.cloneDeep(require('../sampleData/media/sampleH264_2.json')),
|
||||
librarySettings: {},
|
||||
inputs: {
|
||||
propertyName: 'video_resolution',
|
||||
propertyValues: '721p,1081p',
|
||||
continueIfPropertyFound: false,
|
||||
|
||||
},
|
||||
otherArguments: {},
|
||||
},
|
||||
output: {
|
||||
processFile: true,
|
||||
infoLog: 'File property video_resolution of 1080p being one of 721p,1081p has not been found, continuing to next plugin \n',
|
||||
},
|
||||
},
|
||||
|
||||
// // continueIfPropertyFound: true
|
||||
|
||||
{
|
||||
input: {
|
||||
file: _.cloneDeep(require('../sampleData/media/sampleH264_2.json')),
|
||||
librarySettings: {},
|
||||
inputs: {
|
||||
propertyName: 'container',
|
||||
propertyValues: 'avi',
|
||||
continueIfPropertyFound: true,
|
||||
|
||||
},
|
||||
otherArguments: {},
|
||||
},
|
||||
output: {
|
||||
processFile: false,
|
||||
infoLog: 'File property container of mkv being one of avi has not been found, breaking out of stack \n',
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
input: {
|
||||
file: _.cloneDeep(require('../sampleData/media/sampleH264_2.json')),
|
||||
librarySettings: {},
|
||||
inputs: {
|
||||
propertyName: 'container',
|
||||
propertyValues: 'mkv',
|
||||
continueIfPropertyFound: true,
|
||||
|
||||
},
|
||||
otherArguments: {},
|
||||
},
|
||||
output: {
|
||||
processFile: true,
|
||||
infoLog: 'File property container of mkv being one of mkv has been found, continuing to next plugin \n',
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
input: {
|
||||
file: _.cloneDeep(require('../sampleData/media/sampleH264_2.json')),
|
||||
librarySettings: {},
|
||||
inputs: {
|
||||
propertyName: 'container',
|
||||
propertyValues: 'mkv,mp4',
|
||||
continueIfPropertyFound: true,
|
||||
|
||||
},
|
||||
otherArguments: {},
|
||||
},
|
||||
output: {
|
||||
processFile: true,
|
||||
infoLog: 'File property container of mkv being one of mkv,mp4 has been found, continuing to next plugin \n',
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
input: {
|
||||
file: _.cloneDeep(require('../sampleData/media/sampleH264_2.json')),
|
||||
librarySettings: {},
|
||||
inputs: {
|
||||
propertyName: 'video_resolution',
|
||||
propertyValues: '721p,1081p',
|
||||
continueIfPropertyFound: true,
|
||||
|
||||
},
|
||||
otherArguments: {},
|
||||
},
|
||||
output: {
|
||||
processFile: false,
|
||||
infoLog: 'File property video_resolution of 1080p being one of 721p,1081p has not been found, breaking out of stack \n',
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
run(tests);
|
||||
Loading…
Reference in new issue