From 5ad0e7a32089694c9a35d9bfd1d75392df5526d0 Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Fri, 31 Dec 2021 19:51:51 +0000 Subject: [PATCH] Create Tdarr_Plugin_0house_filter_by_resolution.js --- ...darr_Plugin_0house_filter_by_resolution.js | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 Community/Tdarr_Plugin_0house_filter_by_resolution.js diff --git a/Community/Tdarr_Plugin_0house_filter_by_resolution.js b/Community/Tdarr_Plugin_0house_filter_by_resolution.js new file mode 100644 index 0000000..ad5e7b9 --- /dev/null +++ b/Community/Tdarr_Plugin_0house_filter_by_resolution.js @@ -0,0 +1,81 @@ +const details = () => ({ + id: 'Tdarr_Plugin_0house_filter_by_resolution', + Stage: 'Pre-processing', + Name: 'Filter by resolution', + Type: 'Video', + Operation: 'Filter', + Description: 'Only allow specified resolutions to be processed \n\n', + Version: '1.00', + Tags: 'filter', + Inputs: [ + { + name: 'resolutionsToProcess', + type: 'string', + defaultValue: '', + inputUI: { + type: 'text', + }, + tooltip: + `Enter a comma separated list of resolutions to be processed. + Leave blank if using resolutionsToNotProcess. + 480p,576p,720p,1080p,4KUHD,DCI4K,8KUHD,Other + `, + }, + { + name: 'resolutionsToNotProcess', + type: 'string', + defaultValue: '', + inputUI: { + type: 'text', + }, + tooltip: + 'Enter a comma separated list of resolutions to be not be processed.' + + ' Leave blank if using resolutionsToProcess', + }, + ], +}); + +// eslint-disable-next-line no-unused-vars +const plugin = (file, librarySettings, inputs, otherArguments) => { + // eslint-disable-next-line global-require + 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 (!file.video_resolution) { + throw new Error('File has no resolution!'); + } + + const fileResolution = file.video_resolution; + + if (inputs.resolutionsToProcess !== '') { + const resolutions = inputs.resolutionsToProcess.split(','); + if (resolutions.includes(fileResolution)) { + response.processFile = true; + response.processFile += 'File is in resolutionsToProcess. Moving to next plugin.'; + } else { + response.processFile = false; + response.processFile += 'File is not in resolutionsToProcess. Breaking out of plugin stack.'; + } + } + + if (inputs.resolutionsToNotProcess !== '') { + const resolutions = inputs.resolutionsToNotProcess.split(','); + if (resolutions.includes(fileResolution)) { + response.processFile = false; + response.processFile += 'File is in resolutionsToNotProcess. Breaking out of plugin stack.'; + } else { + response.processFile = true; + response.processFile += 'File is not in resolutionsToNotProcess. Moving to next plugin.'; + } + } + + return response; +}; + +module.exports.details = details; +module.exports.plugin = plugin;