From 1b16da3009a614b42b2a98cdf47c89603f878557 Mon Sep 17 00:00:00 2001 From: Tailslide <5757188+Tailslide@users.noreply.github.com> Date: Thu, 16 Feb 2023 21:36:37 -0700 Subject: [PATCH] Plugin to filter by modified date age --- .../Tdarr_Plugin_tsld_filter_modified_date.js | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 Community/Tdarr_Plugin_tsld_filter_modified_date.js diff --git a/Community/Tdarr_Plugin_tsld_filter_modified_date.js b/Community/Tdarr_Plugin_tsld_filter_modified_date.js new file mode 100644 index 0000000..6e8d56f --- /dev/null +++ b/Community/Tdarr_Plugin_tsld_filter_modified_date.js @@ -0,0 +1,61 @@ +const details = () => ({ + id: 'Tdarr_Plugin_tsld_filter_modified_date', + Stage: 'Pre-processing', + Name: 'Filter modified date', + Type: 'Video', + Operation: 'Filter', + Description: 'This plugin prevents processing files older than 30 days \n\n', + Version: '1.00', + Tags: '', + Inputs: [ + // (Optional) Inputs you'd like the user to enter to allow your plugin to be easily configurable from the UI + { + name: 'minModifiedDaysOld', + type: 'number', + defaultValue: '30', + inputUI: { + type: 'number', + }, + tooltip: `Enter minimum number of days since modified since now file must be. + + \\nExample:\\n + 365 + + \\nExample:\\n + 30` + }, + ] +}); + +// 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: '', + }; + //response.infoLog += `Filter preventing processing. File mod time ${file.statSync.mtimeMs}`; + //response.infoLog += ` Now ${Date.now()}`; + const age = Date.now() - file.statSync.mtimeMs; + const reqage = Number(inputs.minModifiedDaysOld) * 86400000; + // response.infoLog += ` Age ${age} Require Min Age: ${reqage}`; + if (reqage < age) + { + // response.infoLog += " Old enough, lets do this!"; + response.processFile = true; + } + else + { + response.infoLog += " Skipping, file modified date not old enough"; + response.processFile = false; + } + + + return response; +}; + +module.exports.details = details; +module.exports.plugin = plugin; +