From 4894a621788cdf383e1c040fbec827254d0f9fa4 Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Thu, 21 Sep 2023 07:55:57 +0100 Subject: [PATCH] Add Check Overall Bitrate --- .../video/checkOverallBitrate/1.0.0/index.js | 94 ++++++++++++++++ .../video/checkOverallBitrate/1.0.0/index.ts | 104 ++++++++++++++++++ 2 files changed, 198 insertions(+) create mode 100644 FlowPlugins/CommunityFlowPlugins/video/checkOverallBitrate/1.0.0/index.js create mode 100644 FlowPluginsTs/CommunityFlowPlugins/video/checkOverallBitrate/1.0.0/index.ts diff --git a/FlowPlugins/CommunityFlowPlugins/video/checkOverallBitrate/1.0.0/index.js b/FlowPlugins/CommunityFlowPlugins/video/checkOverallBitrate/1.0.0/index.js new file mode 100644 index 0000000..7994cd3 --- /dev/null +++ b/FlowPlugins/CommunityFlowPlugins/video/checkOverallBitrate/1.0.0/index.js @@ -0,0 +1,94 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.plugin = exports.details = void 0; +/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */ +var details = function () { return ({ + name: 'Check Overall Bitrate', + description: 'Check if overall file bitrate is within a specific range', + style: { + borderColor: 'orange', + }, + tags: 'video', + isStartPlugin: false, + pType: '', + requiresVersion: '2.11.01', + sidebarPosition: -1, + icon: 'faQuestion', + inputs: [ + { + name: 'unit', + type: 'string', + defaultValue: 'kbps', + inputUI: { + type: 'dropdown', + options: [ + 'bps', + 'kbps', + 'mbps', + ], + }, + tooltip: 'Specify the unit to use', + }, + { + name: 'greaterThan', + type: 'number', + defaultValue: '0', + inputUI: { + type: 'text', + }, + tooltip: 'Specify lower bound', + }, + { + name: 'lessThan', + type: 'number', + defaultValue: '10000', + inputUI: { + type: 'text', + }, + tooltip: 'Specify upper bound', + }, + ], + outputs: [ + { + number: 1, + tooltip: 'File within range', + }, + { + number: 2, + tooltip: 'File not within range', + }, + ], +}); }; +exports.details = details; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +var plugin = function (args) { + var lib = require('../../../../../methods/lib')(); + // eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign + args.inputs = lib.loadDefaultValues(args.inputs, details); + var isWithinRange = false; + var greaterThanBits = Number(args.inputs.greaterThan); + var lessThanBits = Number(args.inputs.lessThan); + if (args.inputs.unit === 'kbps') { + greaterThanBits *= 1000; + lessThanBits *= 1000; + } + else if (args.inputs.unit === 'mbps') { + greaterThanBits *= 1000000; + lessThanBits *= 1000000; + } + args.jobLog("File bitrate is ".concat(args.inputFileObj.bit_rate, " bps")); + args.jobLog("Checking if bitrate is within range ".concat(greaterThanBits, " bps and ").concat(lessThanBits, " bps")); + if (args.inputFileObj.bit_rate >= greaterThanBits && args.inputFileObj.bit_rate <= lessThanBits) { + isWithinRange = true; + args.jobLog('File bitrate is within range'); + } + else { + args.jobLog('File bitrate is not within range'); + } + return { + outputFileObj: args.inputFileObj, + outputNumber: isWithinRange ? 1 : 2, + variables: args.variables, + }; +}; +exports.plugin = plugin; diff --git a/FlowPluginsTs/CommunityFlowPlugins/video/checkOverallBitrate/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/video/checkOverallBitrate/1.0.0/index.ts new file mode 100644 index 0000000..d9bd7ee --- /dev/null +++ b/FlowPluginsTs/CommunityFlowPlugins/video/checkOverallBitrate/1.0.0/index.ts @@ -0,0 +1,104 @@ +import { + IpluginDetails, + IpluginInputArgs, + IpluginOutputArgs, +} from '../../../../FlowHelpers/1.0.0/interfaces/interfaces'; + +/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */ +const details = (): IpluginDetails => ({ + name: 'Check Overall Bitrate', + description: 'Check if overall file bitrate is within a specific range', + style: { + borderColor: 'orange', + }, + tags: 'video', + isStartPlugin: false, + pType: '', + requiresVersion: '2.11.01', + sidebarPosition: -1, + icon: 'faQuestion', + inputs: [ + { + name: 'unit', + type: 'string', + defaultValue: 'kbps', + inputUI: { + type: 'dropdown', + options: [ + 'bps', + 'kbps', + 'mbps', + ], + }, + tooltip: 'Specify the unit to use', + }, + { + name: 'greaterThan', + type: 'number', + defaultValue: '0', + inputUI: { + type: 'text', + }, + tooltip: 'Specify lower bound', + }, + { + name: 'lessThan', + type: 'number', + defaultValue: '10000', + inputUI: { + type: 'text', + }, + tooltip: 'Specify upper bound', + }, + ], + outputs: [ + { + number: 1, + tooltip: 'File within range', + }, + { + number: 2, + tooltip: 'File not within range', + }, + ], +}); + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +const plugin = (args: IpluginInputArgs): IpluginOutputArgs => { + const lib = require('../../../../../methods/lib')(); + // eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign + args.inputs = lib.loadDefaultValues(args.inputs, details); + + let isWithinRange = false; + + let greaterThanBits = Number(args.inputs.greaterThan); + let lessThanBits = Number(args.inputs.lessThan); + + if (args.inputs.unit === 'kbps') { + greaterThanBits *= 1000; + lessThanBits *= 1000; + } else if (args.inputs.unit === 'mbps') { + greaterThanBits *= 1000000; + lessThanBits *= 1000000; + } + + args.jobLog(`File bitrate is ${args.inputFileObj.bit_rate} bps`); + args.jobLog(`Checking if bitrate is within range ${greaterThanBits} bps and ${lessThanBits} bps`); + + if (args.inputFileObj.bit_rate >= greaterThanBits && args.inputFileObj.bit_rate <= lessThanBits) { + isWithinRange = true; + args.jobLog('File bitrate is within range'); + } else { + args.jobLog('File bitrate is not within range'); + } + + return { + outputFileObj: args.inputFileObj, + outputNumber: isWithinRange ? 1 : 2, + variables: args.variables, + }; +}; +export { + details, + plugin, +};