From 1456e4548022dcd7f8e03b0232c01edef52d85e0 Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Tue, 30 Nov 2021 08:05:30 +0000 Subject: [PATCH] Add example size check plugin --- .../Tdarr_Plugin_a9he_New_file_size_check.js | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 examples/Tdarr_Plugin_a9he_New_file_size_check.js diff --git a/examples/Tdarr_Plugin_a9he_New_file_size_check.js b/examples/Tdarr_Plugin_a9he_New_file_size_check.js new file mode 100644 index 0000000..15bcee3 --- /dev/null +++ b/examples/Tdarr_Plugin_a9he_New_file_size_check.js @@ -0,0 +1,37 @@ +module.exports.details = function details() { + return { + id: 'Tdarr_Plugin_a9he_New_file_size_check', + Stage: 'Pre-processing', + Name: 'New file size check', + Type: 'Video', + Operation: 'Transcode', + Description: 'Give an error if new file is larger than the original \n\n', + Version: '1.00', + Link: '', + Tags: '', + }; +}; + +module.exports.plugin = function plugin(file, librarySettings, inputs, otherArguments) { + // Must return this object at some point in the function else plugin will fail. + const response = { + processFile: false, + preset: '', + handBrakeMode: false, + FFmpegMode: true, + reQueueAfter: true, + infoLog: '', + }; + + const newSize = file.file_size; + const oldSize = otherArguments.originalLibraryFile.file_size; + if (newSize > oldSize) { + // Item will be errored in UI + throw new Error(`Error! New file has size ${newSize} which is larger than original file ${oldSize}`); + } else if (newSize < oldSize) { + response.infoLog += `New file has size ${newSize} which is smaller than original file ${oldSize}`; + } + // if file sizes are exactly the same then file has not been transcoded yet + + return response; +};