From e17e44f290033934e5806da4a884e1d419d9bfb0 Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Sun, 28 Aug 2022 03:02:44 +0100 Subject: [PATCH] Add Tdarr_Plugin_00td_filter_break_stack_if_processed --- ...in_00td_filter_break_stack_if_processed.js | 36 +++++++++++++++++ ...in_00td_filter_break_stack_if_processed.js | 40 +++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 Community/Tdarr_Plugin_00td_filter_break_stack_if_processed.js create mode 100644 tests/Community/Tdarr_Plugin_00td_filter_break_stack_if_processed.js diff --git a/Community/Tdarr_Plugin_00td_filter_break_stack_if_processed.js b/Community/Tdarr_Plugin_00td_filter_break_stack_if_processed.js new file mode 100644 index 0000000..942de91 --- /dev/null +++ b/Community/Tdarr_Plugin_00td_filter_break_stack_if_processed.js @@ -0,0 +1,36 @@ +const details = () => ({ + id: 'Tdarr_Plugin_00td_filter_break_stack_if_processed', + Stage: 'Pre-processing', + Name: 'Filter - break out of plugin stack if processed', + Type: 'Video', + Operation: 'Filter', + Description: `This plugin will break out of the plugin stack if the file has been processed + (i.e. if a new file has been created). In general, place it before your transcode plugin + (for example when trying to force h264 to h264 transcoding which is difficult to do with normal plugins)`, + Version: '1.00', + Tags: 'filter', + Inputs: [], +}); + +// 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: true, + infoLog: '', + }; + + if (file.file !== otherArguments.originalLibraryFile.file) { + response.processFile = false; + response.infoLog = 'File has been processed, breaking out of plugin stack.'; + } else { + response.infoLog = 'File has not been processed yet. Continuing to next plugin.'; + } + + return response; +}; + +module.exports.details = details; +module.exports.plugin = plugin; diff --git a/tests/Community/Tdarr_Plugin_00td_filter_break_stack_if_processed.js b/tests/Community/Tdarr_Plugin_00td_filter_break_stack_if_processed.js new file mode 100644 index 0000000..0d59019 --- /dev/null +++ b/tests/Community/Tdarr_Plugin_00td_filter_break_stack_if_processed.js @@ -0,0 +1,40 @@ +/* eslint max-len: 0 */ +const _ = require('lodash'); +const run = require('../helpers/run'); + +const tests = [ + { + input: { + file: _.cloneDeep(require('../sampleData/media/sampleH265_1.json')), + librarySettings: {}, + inputs: {}, + otherArguments: { + originalLibraryFile: _.cloneDeep(require('../sampleData/media/sampleH265_1.json')), + }, + }, + output: { + processFile: true, + infoLog: 'File has not been processed yet. Continuing to next plugin.', + }, + }, + { + input: { + file: _.cloneDeep(require('../sampleData/media/sampleH265_1.json')), + librarySettings: {}, + inputs: {}, + otherArguments: { + originalLibraryFile: (() => { + const file = _.cloneDeep(require('../sampleData/media/sampleH265_1.json')); + file.file += 'test'; + return file; + })(), + }, + }, + output: { + processFile: false, + infoLog: 'File has been processed, breaking out of plugin stack.', + }, + }, +]; + +run(tests);