From 9ac675d4014144b2d5e93b8b6bd60ee8a3cc091f Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Wed, 12 Jun 2024 07:47:05 +0100 Subject: [PATCH 1/4] Compare File Size Ratio Live --- .../audio/normalizeAudio/1.0.0/index.ts | 2 + .../basic/basicVideoOrAudio/1.0.0/index.ts | 1 + .../runClassicTranscodePlugin/1.0.0/index.ts | 1 + .../runClassicTranscodePlugin/2.0.0/index.ts | 1 + .../ffmpegCommandExecute/1.0.0/index.ts | 1 + .../compareFileSizeRatioLive/1.0.0/index.ts | 167 ++++++++++++++++++ .../handbrakeCustomArguments/1.0.0/index.ts | 1 + .../handbrakeCustomArguments/2.0.0/index.ts | 1 + .../tools/apprise/1.0.0/index.ts | 3 +- .../tools/runCli/1.0.0/index.ts | 1 + .../tools/runMkvPropEdit/1.0.0/index.ts | 1 + .../video/runHealthCheck/1.0.0/index.ts | 1 + FlowPluginsTs/FlowHelpers/1.0.0/cliUtils.ts | 94 ++++++++-- .../1.0.0/interfaces/interfaces.ts | 8 + 14 files changed, 265 insertions(+), 18 deletions(-) create mode 100644 FlowPluginsTs/CommunityFlowPlugins/file/compareFileSizeRatioLive/1.0.0/index.ts diff --git a/FlowPluginsTs/CommunityFlowPlugins/audio/normalizeAudio/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/audio/normalizeAudio/1.0.0/index.ts index 7a2c5c6..cc56c2c 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/audio/normalizeAudio/1.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/audio/normalizeAudio/1.0.0/index.ts @@ -99,6 +99,7 @@ const plugin = async (args: IpluginInputArgs): Promise => { inputFileObj: args.inputFileObj, logFullCliOutput: args.logFullCliOutput, updateWorker: args.updateWorker, + args, }); const res = await cli.runCli(); @@ -160,6 +161,7 @@ const plugin = async (args: IpluginInputArgs): Promise => { inputFileObj: args.inputFileObj, logFullCliOutput: args.logFullCliOutput, updateWorker: args.updateWorker, + args, }); const res2 = await cli2.runCli(); diff --git a/FlowPluginsTs/CommunityFlowPlugins/basic/basicVideoOrAudio/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/basic/basicVideoOrAudio/1.0.0/index.ts index a35c295..3ca660e 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/basic/basicVideoOrAudio/1.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/basic/basicVideoOrAudio/1.0.0/index.ts @@ -356,6 +356,7 @@ const plugin = async (args: IpluginInputArgs): Promise => { inputFileObj: args.inputFileObj, logFullCliOutput: args.logFullCliOutput, updateWorker: args.updateWorker, + args, }); const res = await cli.runCli(); diff --git a/FlowPluginsTs/CommunityFlowPlugins/classic/runClassicTranscodePlugin/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/classic/runClassicTranscodePlugin/1.0.0/index.ts index 59d3bfc..70f9ee1 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/classic/runClassicTranscodePlugin/1.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/classic/runClassicTranscodePlugin/1.0.0/index.ts @@ -182,6 +182,7 @@ const plugin = async (args: IpluginInputArgs): Promise => { inputFileObj: args.inputFileObj, logFullCliOutput: args.logFullCliOutput, updateWorker: args.updateWorker, + args, }); const res = await cli.runCli(); diff --git a/FlowPluginsTs/CommunityFlowPlugins/classic/runClassicTranscodePlugin/2.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/classic/runClassicTranscodePlugin/2.0.0/index.ts index 07050fe..2fce826 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/classic/runClassicTranscodePlugin/2.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/classic/runClassicTranscodePlugin/2.0.0/index.ts @@ -187,6 +187,7 @@ const plugin = async (args: IpluginInputArgs): Promise => { inputFileObj: args.inputFileObj, logFullCliOutput: args.logFullCliOutput, updateWorker: args.updateWorker, + args, }); const res = await cli.runCli(); diff --git a/FlowPluginsTs/CommunityFlowPlugins/ffmpegCommand/ffmpegCommandExecute/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/ffmpegCommand/ffmpegCommandExecute/1.0.0/index.ts index 2791d89..3a85dd6 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/ffmpegCommand/ffmpegCommandExecute/1.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/ffmpegCommand/ffmpegCommandExecute/1.0.0/index.ts @@ -168,6 +168,7 @@ const plugin = async (args: IpluginInputArgs): Promise => { inputFileObj: args.inputFileObj, logFullCliOutput: args.logFullCliOutput, updateWorker: args.updateWorker, + args, }); const res = await cli.runCli(); diff --git a/FlowPluginsTs/CommunityFlowPlugins/file/compareFileSizeRatioLive/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/file/compareFileSizeRatioLive/1.0.0/index.ts new file mode 100644 index 0000000..4207b2c --- /dev/null +++ b/FlowPluginsTs/CommunityFlowPlugins/file/compareFileSizeRatioLive/1.0.0/index.ts @@ -0,0 +1,167 @@ +import { + IpluginDetails, + IpluginInputArgs, + IpluginOutputArgs, +} from '../../../../FlowHelpers/1.0.0/interfaces/interfaces'; + +/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */ +const details = (): IpluginDetails => ({ + name: 'Compare File Size Ratio Live', + description: ` + Compare either the estimated final size or current output size to the input size and + give an error if estimated final size or current size surpasses the threshold %. + + Works with 'FfmpegCommand', 'HandBrake Custom Arguments', 'Run Classic Transcode' and other flow plugins + that output a file. + + Can be placed anywhere before a plugin which outputs a new file. + ', + `, + style: { + borderColor: 'orange', + }, + tags: '', + isStartPlugin: false, + pType: '', + requiresVersion: '2.11.01', + sidebarPosition: -1, + icon: 'faQuestion', + inputs: [ + { + label: 'Enabled', + name: 'enabled', + type: 'boolean', + defaultValue: 'true', + inputUI: { + type: 'switch', + }, + tooltip: 'Enable or disable this plugin. For example you may want to enable it for one set of transcoding tests.', + }, + { + label: 'Compare Method', + name: 'compareMethod', + type: 'string', + defaultValue: 'estimatedFinalSize', + inputUI: { + type: 'dropdown', + options: [ + 'estimatedFinalSize', + 'currentSize', + ], + displayConditions: { + logic: 'AND', + sets: [ + { + logic: 'AND', + inputs: [ + { + name: 'enabled', + value: 'true', + condition: '===', + }, + ], + }, + ], + }, + }, + tooltip: `Specify the method to compare. + Estimated Final Size: Compare the estimated final output size to the input size. + Current Size: Compare the current output size to the input size. + `, + }, + { + label: 'Threshold Size %', + name: 'thresholdPerc', + type: 'number', + defaultValue: '60', + inputUI: { + type: 'text', + displayConditions: { + logic: 'AND', + sets: [ + { + logic: 'AND', + inputs: [ + { + name: 'enabled', + value: 'true', + condition: '===', + }, + ], + }, + ], + }, + }, + tooltip: `Enter the threshold size percentage relative to the input size. + An error will be triggered if the estimated or current size exceeds this percentage. + + For example, if the input size is 100MB and the threshold is 60%, the estimated final size or current size + must not surpass 60MB else an error will be given and processing will stop. + `, + }, + { + label: 'Check Delay (seconds)', + name: 'checkDelaySeconds', + type: 'number', + defaultValue: '20', + inputUI: { + type: 'text', + displayConditions: { + logic: 'AND', + sets: [ + { + logic: 'AND', + inputs: [ + { + name: 'enabled', + value: 'true', + condition: '===', + }, + ], + }, + ], + }, + }, + tooltip: ` + Specify the delay in seconds before beginning the comparison. + A larger delay gives more time for the estimated final size to stabilize. + `, + }, + ], + outputs: [ + { + number: 1, + tooltip: 'Continue to next plugin', + }, + ], +}); + +// 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); + + const enabled = Boolean(args.inputs.enabled); + const compareMethod = String(args.inputs.compareMethod); + const thresholdPerc = Number(args.inputs.thresholdPerc); + const checkDelaySeconds = Number(args.inputs.checkDelaySeconds); + + // eslint-disable-next-line no-param-reassign + args.variables.liveSizeCompare = { + enabled, + compareMethod, + thresholdPerc, + checkDelaySeconds, + }; + + return { + outputFileObj: args.inputFileObj, + outputNumber: 1, + variables: args.variables, + }; +}; +export { + details, + plugin, +}; diff --git a/FlowPluginsTs/CommunityFlowPlugins/handbrake/handbrakeCustomArguments/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/handbrake/handbrakeCustomArguments/1.0.0/index.ts index e44dd1b..4250d34 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/handbrake/handbrakeCustomArguments/1.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/handbrake/handbrakeCustomArguments/1.0.0/index.ts @@ -122,6 +122,7 @@ const plugin = async (args:IpluginInputArgs):Promise => { inputFileObj: args.inputFileObj, logFullCliOutput: args.logFullCliOutput, updateWorker: args.updateWorker, + args, }); const res = await cli.runCli(); diff --git a/FlowPluginsTs/CommunityFlowPlugins/handbrake/handbrakeCustomArguments/2.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/handbrake/handbrakeCustomArguments/2.0.0/index.ts index 546517b..48fe1ca 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/handbrake/handbrakeCustomArguments/2.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/handbrake/handbrakeCustomArguments/2.0.0/index.ts @@ -165,6 +165,7 @@ const plugin = async (args: IpluginInputArgs): Promise => { inputFileObj: args.inputFileObj, logFullCliOutput: args.logFullCliOutput, updateWorker: args.updateWorker, + args, }); const res = await cli.runCli(); diff --git a/FlowPluginsTs/CommunityFlowPlugins/tools/apprise/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/tools/apprise/1.0.0/index.ts index 7c4276c..d4e3364 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/tools/apprise/1.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/tools/apprise/1.0.0/index.ts @@ -15,7 +15,7 @@ const details = ():IpluginDetails => ({ tags: '', isStartPlugin: false, pType: '', - requiresVersion: '2.11.01', + requiresVersion: '2.18.01', sidebarPosition: -1, icon: 'faBell', inputs: [ @@ -71,6 +71,7 @@ const plugin = async (args:IpluginInputArgs):Promise => { inputFileObj: args.inputFileObj, logFullCliOutput: args.logFullCliOutput, updateWorker: args.updateWorker, + args, }); const res = await cli.runCli(); diff --git a/FlowPluginsTs/CommunityFlowPlugins/tools/runCli/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/tools/runCli/1.0.0/index.ts index b06893a..cd2e051 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/tools/runCli/1.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/tools/runCli/1.0.0/index.ts @@ -251,6 +251,7 @@ const plugin = async (args: IpluginInputArgs): Promise => { inputFileObj: args.inputFileObj, logFullCliOutput: args.logFullCliOutput, updateWorker: args.updateWorker, + args, }); const res = await cli.runCli(); diff --git a/FlowPluginsTs/CommunityFlowPlugins/tools/runMkvPropEdit/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/tools/runMkvPropEdit/1.0.0/index.ts index 34167d9..cfb9ed7 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/tools/runMkvPropEdit/1.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/tools/runMkvPropEdit/1.0.0/index.ts @@ -48,6 +48,7 @@ const plugin = async (args:IpluginInputArgs):Promise => { inputFileObj: args.inputFileObj, logFullCliOutput: args.logFullCliOutput, updateWorker: args.updateWorker, + args, }); const res = await cli.runCli(); diff --git a/FlowPluginsTs/CommunityFlowPlugins/video/runHealthCheck/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/video/runHealthCheck/1.0.0/index.ts index c1d3244..f8db0c3 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/video/runHealthCheck/1.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/video/runHealthCheck/1.0.0/index.ts @@ -93,6 +93,7 @@ const plugin = async (args:IpluginInputArgs):Promise => { inputFileObj: args.inputFileObj, logFullCliOutput: args.logFullCliOutput, updateWorker: args.updateWorker, + args, }); const res = await cli.runCli(); diff --git a/FlowPluginsTs/FlowHelpers/1.0.0/cliUtils.ts b/FlowPluginsTs/FlowHelpers/1.0.0/cliUtils.ts index 84018e8..f51b4cd 100644 --- a/FlowPluginsTs/FlowHelpers/1.0.0/cliUtils.ts +++ b/FlowPluginsTs/FlowHelpers/1.0.0/cliUtils.ts @@ -2,7 +2,7 @@ import fs from 'fs'; import { editreadyParser, ffmpegParser, getHandBrakeFps, handbrakeParser, } from './cliParsers'; -import { Ilog, IupdateWorker } from './interfaces/interfaces'; +import { Ilog, IpluginInputArgs, IupdateWorker } from './interfaces/interfaces'; import { IFileObject, Istreams } from './interfaces/synced/IFileObject'; import { fileExists } from './fileUtils'; @@ -71,6 +71,7 @@ interface Iconfig { updateWorker: IupdateWorker, logFullCliOutput: boolean, inputFileObj: IFileObject, + args: IpluginInputArgs, } class CLI { @@ -89,6 +90,13 @@ class CLI { hbPass = 0; + // eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/explicit-module-boundary-types + thread: any; + + cancelled = false; + + startTime = new Date().getTime(); + constructor(config: Iconfig) { this.config = config; } @@ -156,6 +164,58 @@ class CLI { this.lastProgCheck = n; this.oldProgress = perc; + + const secondsSinceStart = (new Date().getTime() - this.startTime) / 1000; + + // live size compare + if ( + this.config.args.variables.liveSizeCompare?.enabled + ) { + const { + compareMethod, + thresholdPerc, + checkDelaySeconds, + } = this.config.args.variables.liveSizeCompare; + + if (secondsSinceStart > checkDelaySeconds) { + // MB + const inputFileSize = this.config.inputFileObj.file_size; + const inputFileSizeInGbytes = inputFileSize / 1024; + + const cancel = (ratio:number) => { + this.config.jobLog(`Input file size: ${inputFileSizeInGbytes}GB`); + this.config.jobLog(`Ratio: ${ratio}%`); + + this.config.jobLog(`Ratio is greater than threshold: ${thresholdPerc}%, cancelling job`); + this.cancelled = true; + this.killThread(); + }; + + if ( + compareMethod === 'estimatedFinalSize' + && estSize !== undefined + && estSize > 0 + ) { + const ratio = (estSize / inputFileSizeInGbytes) * 100; + + if (ratio > thresholdPerc) { + this.config.jobLog(`Estimated final size: ${estSize}GB`); + cancel(ratio); + } + } else if ( + compareMethod === 'currentSize' + && outputFileSizeInGbytes !== undefined + && outputFileSizeInGbytes > 0 + ) { + const ratio = (outputFileSizeInGbytes / inputFileSizeInGbytes) * 100; + + if (ratio > thresholdPerc) { + this.config.jobLog(`Current output size: ${outputFileSizeInGbytes}GB`); + cancel(ratio); + } + } + } + } } } } @@ -255,8 +315,7 @@ class CLI { } }; - // eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/explicit-module-boundary-types - killThread = (thread:any): void => { + killThread = (): void => { const killArray = [ 'SIGKILL', 'SIGHUP', @@ -265,14 +324,14 @@ class CLI { ]; try { - thread.kill(); + this.thread.kill(); } catch (err) { // err } killArray.forEach((com: string) => { try { - thread.kill(com); + this.thread.kill(com); } catch (err) { // err } @@ -289,15 +348,12 @@ class CLI { this.config.jobLog(`Running ${this.config.cli} ${this.config.spawnArgs.join(' ')}`); - // eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/explicit-module-boundary-types - let thread: any; - const exitHandler = () => { - if (thread) { + if (this.thread) { try { // eslint-disable-next-line no-console console.log('Main thread exiting, cleaning up running CLI'); - this.killThread(thread); + this.killThread(); } catch (err) { // eslint-disable-next-line no-console console.log('Error running cliUtils on Exit function'); @@ -309,24 +365,24 @@ class CLI { process.on('exit', exitHandler); - const cliExitCode: number = await new Promise((resolve) => { + let cliExitCode: number = await new Promise((resolve) => { try { const opts = this.config.spawnOpts || {}; const spawnArgs = this.config.spawnArgs.map((row) => row.trim()).filter((row) => row !== ''); - thread = childProcess.spawn(this.config.cli, spawnArgs, opts); + this.thread = childProcess.spawn(this.config.cli, spawnArgs, opts); - thread.stdout.on('data', (data: string) => { + this.thread.stdout.on('data', (data: string) => { errorLogFull.push(data.toString()); this.parseOutput(data); }); - thread.stderr.on('data', (data: string) => { + this.thread.stderr.on('data', (data: string) => { // eslint-disable-next-line no-console errorLogFull.push(data.toString()); this.parseOutput(data); }); - thread.on('error', () => { + this.thread.on('error', () => { // catches execution error (bad file) // eslint-disable-next-line no-console console.log(`Error executing binary: ${this.config.cli}`); @@ -336,7 +392,7 @@ class CLI { // thread.stdout.pipe(process.stdout); // thread.stderr.pipe(process.stderr); - thread.on('close', (code: number) => { + this.thread.on('close', (code: number) => { if (code !== 0) { // eslint-disable-next-line no-console console.log(`CLI error code: ${code}`); @@ -355,12 +411,16 @@ class CLI { process.removeListener('exit', exitHandler); - thread = undefined; + this.thread = undefined; if (!this.config.logFullCliOutput) { this.config.jobLog(errorLogFull.slice(-1000).join('')); } + if (this.cancelled) { + cliExitCode = 1; + } + return { cliExitCode, errorLogFull, diff --git a/FlowPluginsTs/FlowHelpers/1.0.0/interfaces/interfaces.ts b/FlowPluginsTs/FlowHelpers/1.0.0/interfaces/interfaces.ts index 1fdf402..0d1c6c8 100644 --- a/FlowPluginsTs/FlowHelpers/1.0.0/interfaces/interfaces.ts +++ b/FlowPluginsTs/FlowHelpers/1.0.0/interfaces/interfaces.ts @@ -96,12 +96,20 @@ export interface IffmpegCommand { overallOuputArguments: string[], } +export interface IliveSizeCompare { + enabled: boolean, + compareMethod: string, + thresholdPerc: number, + checkDelaySeconds: number, +} + export interface Ivariables { ffmpegCommand: IffmpegCommand, flowFailed: boolean, user: Record, healthCheck?: 'Success', queueTags?: string, + liveSizeCompare?: IliveSizeCompare } export interface IpluginOutputArgs { From 5c34353d7a5a3fcbe54f9d98ec1f581d6fd7ae2f Mon Sep 17 00:00:00 2001 From: HaveAGitGat Date: Wed, 12 Jun 2024 06:50:42 +0000 Subject: [PATCH 2/4] Apply auto-build changes --- .../audio/normalizeAudio/1.0.0/index.js | 2 + .../basic/basicVideoOrAudio/1.0.0/index.js | 1 + .../runClassicTranscodePlugin/1.0.0/index.js | 1 + .../runClassicTranscodePlugin/2.0.0/index.js | 1 + .../ffmpegCommandExecute/1.0.0/index.js | 1 + .../compareFileSizeRatioLive/1.0.0/index.js | 138 ++++++++++++++++++ .../handbrakeCustomArguments/1.0.0/index.js | 1 + .../handbrakeCustomArguments/2.0.0/index.js | 1 + .../tools/apprise/1.0.0/index.js | 3 +- .../tools/runCli/1.0.0/index.js | 1 + .../tools/runMkvPropEdit/1.0.0/index.js | 1 + .../video/runHealthCheck/1.0.0/index.js | 1 + FlowPlugins/FlowHelpers/1.0.0/cliUtils.js | 82 ++++++++--- 13 files changed, 212 insertions(+), 22 deletions(-) create mode 100644 FlowPlugins/CommunityFlowPlugins/file/compareFileSizeRatioLive/1.0.0/index.js diff --git a/FlowPlugins/CommunityFlowPlugins/audio/normalizeAudio/1.0.0/index.js b/FlowPlugins/CommunityFlowPlugins/audio/normalizeAudio/1.0.0/index.js index bc0cf7f..a2d331a 100644 --- a/FlowPlugins/CommunityFlowPlugins/audio/normalizeAudio/1.0.0/index.js +++ b/FlowPlugins/CommunityFlowPlugins/audio/normalizeAudio/1.0.0/index.js @@ -128,6 +128,7 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function inputFileObj: args.inputFileObj, logFullCliOutput: args.logFullCliOutput, updateWorker: args.updateWorker, + args: args, }); return [4 /*yield*/, cli.runCli()]; case 1: @@ -181,6 +182,7 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function inputFileObj: args.inputFileObj, logFullCliOutput: args.logFullCliOutput, updateWorker: args.updateWorker, + args: args, }); return [4 /*yield*/, cli2.runCli()]; case 2: diff --git a/FlowPlugins/CommunityFlowPlugins/basic/basicVideoOrAudio/1.0.0/index.js b/FlowPlugins/CommunityFlowPlugins/basic/basicVideoOrAudio/1.0.0/index.js index 95f98ed..885faa7 100644 --- a/FlowPlugins/CommunityFlowPlugins/basic/basicVideoOrAudio/1.0.0/index.js +++ b/FlowPlugins/CommunityFlowPlugins/basic/basicVideoOrAudio/1.0.0/index.js @@ -383,6 +383,7 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function inputFileObj: args.inputFileObj, logFullCliOutput: args.logFullCliOutput, updateWorker: args.updateWorker, + args: args, }); return [4 /*yield*/, cli.runCli()]; case 1: diff --git a/FlowPlugins/CommunityFlowPlugins/classic/runClassicTranscodePlugin/1.0.0/index.js b/FlowPlugins/CommunityFlowPlugins/classic/runClassicTranscodePlugin/1.0.0/index.js index d9491a5..9610ea6 100644 --- a/FlowPlugins/CommunityFlowPlugins/classic/runClassicTranscodePlugin/1.0.0/index.js +++ b/FlowPlugins/CommunityFlowPlugins/classic/runClassicTranscodePlugin/1.0.0/index.js @@ -217,6 +217,7 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function inputFileObj: args.inputFileObj, logFullCliOutput: args.logFullCliOutput, updateWorker: args.updateWorker, + args: args, }); return [4 /*yield*/, cli.runCli()]; case 2: diff --git a/FlowPlugins/CommunityFlowPlugins/classic/runClassicTranscodePlugin/2.0.0/index.js b/FlowPlugins/CommunityFlowPlugins/classic/runClassicTranscodePlugin/2.0.0/index.js index 3fc0541..8748219 100644 --- a/FlowPlugins/CommunityFlowPlugins/classic/runClassicTranscodePlugin/2.0.0/index.js +++ b/FlowPlugins/CommunityFlowPlugins/classic/runClassicTranscodePlugin/2.0.0/index.js @@ -222,6 +222,7 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function inputFileObj: args.inputFileObj, logFullCliOutput: args.logFullCliOutput, updateWorker: args.updateWorker, + args: args, }); return [4 /*yield*/, cli.runCli()]; case 2: diff --git a/FlowPlugins/CommunityFlowPlugins/ffmpegCommand/ffmpegCommandExecute/1.0.0/index.js b/FlowPlugins/CommunityFlowPlugins/ffmpegCommand/ffmpegCommandExecute/1.0.0/index.js index 73d3ebb..49605db 100644 --- a/FlowPlugins/CommunityFlowPlugins/ffmpegCommand/ffmpegCommandExecute/1.0.0/index.js +++ b/FlowPlugins/CommunityFlowPlugins/ffmpegCommand/ffmpegCommandExecute/1.0.0/index.js @@ -183,6 +183,7 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function inputFileObj: args.inputFileObj, logFullCliOutput: args.logFullCliOutput, updateWorker: args.updateWorker, + args: args, }); return [4 /*yield*/, cli.runCli()]; case 1: diff --git a/FlowPlugins/CommunityFlowPlugins/file/compareFileSizeRatioLive/1.0.0/index.js b/FlowPlugins/CommunityFlowPlugins/file/compareFileSizeRatioLive/1.0.0/index.js new file mode 100644 index 0000000..16cb1b6 --- /dev/null +++ b/FlowPlugins/CommunityFlowPlugins/file/compareFileSizeRatioLive/1.0.0/index.js @@ -0,0 +1,138 @@ +"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: 'Compare File Size Ratio Live', + description: "\n Compare either the estimated final size or current output size to the input size and \n give an error if estimated final size or current size surpasses the threshold %.\n\n Works with 'FfmpegCommand', 'HandBrake Custom Arguments', 'Run Classic Transcode' and other flow plugins \n that output a file.\n\n Can be placed anywhere before a plugin which outputs a new file.\n ',\n ", + style: { + borderColor: 'orange', + }, + tags: '', + isStartPlugin: false, + pType: '', + requiresVersion: '2.11.01', + sidebarPosition: -1, + icon: 'faQuestion', + inputs: [ + { + label: 'Enabled', + name: 'enabled', + type: 'boolean', + defaultValue: 'true', + inputUI: { + type: 'switch', + }, + tooltip: 'Enable or disable this plugin. For example you may want to enable it for one set of transcoding tests.', + }, + { + label: 'Compare Method', + name: 'compareMethod', + type: 'string', + defaultValue: 'estimatedFinalSize', + inputUI: { + type: 'dropdown', + options: [ + 'estimatedFinalSize', + 'currentSize', + ], + displayConditions: { + logic: 'AND', + sets: [ + { + logic: 'AND', + inputs: [ + { + name: 'enabled', + value: 'true', + condition: '===', + }, + ], + }, + ], + }, + }, + tooltip: "Specify the method to compare.\n Estimated Final Size: Compare the estimated final output size to the input size.\n Current Size: Compare the current output size to the input size.\n ", + }, + { + label: 'Threshold Size %', + name: 'thresholdPerc', + type: 'number', + defaultValue: '60', + inputUI: { + type: 'text', + displayConditions: { + logic: 'AND', + sets: [ + { + logic: 'AND', + inputs: [ + { + name: 'enabled', + value: 'true', + condition: '===', + }, + ], + }, + ], + }, + }, + tooltip: "Enter the threshold size percentage relative to the input size. \n An error will be triggered if the estimated or current size exceeds this percentage.\n\n For example, if the input size is 100MB and the threshold is 60%, the estimated final size or current size\n must not surpass 60MB else an error will be given and processing will stop.\n ", + }, + { + label: 'Check Delay (seconds)', + name: 'checkDelaySeconds', + type: 'number', + defaultValue: '20', + inputUI: { + type: 'text', + displayConditions: { + logic: 'AND', + sets: [ + { + logic: 'AND', + inputs: [ + { + name: 'enabled', + value: 'true', + condition: '===', + }, + ], + }, + ], + }, + }, + tooltip: "\n Specify the delay in seconds before beginning the comparison.\n A larger delay gives more time for the estimated final size to stabilize.\n ", + }, + ], + outputs: [ + { + number: 1, + tooltip: 'Continue to next plugin', + }, + ], +}); }; +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 enabled = Boolean(args.inputs.enabled); + var compareMethod = String(args.inputs.compareMethod); + var thresholdPerc = Number(args.inputs.thresholdPerc); + var checkDelaySeconds = Number(args.inputs.checkDelaySeconds); + // eslint-disable-next-line no-param-reassign + args.variables.liveSizeCompare = { + enabled: enabled, + compareMethod: compareMethod, + thresholdPerc: thresholdPerc, + checkDelaySeconds: checkDelaySeconds, + }; + return { + outputFileObj: args.inputFileObj, + outputNumber: 1, + variables: args.variables, + }; +}; +exports.plugin = plugin; diff --git a/FlowPlugins/CommunityFlowPlugins/handbrake/handbrakeCustomArguments/1.0.0/index.js b/FlowPlugins/CommunityFlowPlugins/handbrake/handbrakeCustomArguments/1.0.0/index.js index d1eedf8..7e72d26 100644 --- a/FlowPlugins/CommunityFlowPlugins/handbrake/handbrakeCustomArguments/1.0.0/index.js +++ b/FlowPlugins/CommunityFlowPlugins/handbrake/handbrakeCustomArguments/1.0.0/index.js @@ -153,6 +153,7 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function inputFileObj: args.inputFileObj, logFullCliOutput: args.logFullCliOutput, updateWorker: args.updateWorker, + args: args, }); return [4 /*yield*/, cli.runCli()]; case 4: diff --git a/FlowPlugins/CommunityFlowPlugins/handbrake/handbrakeCustomArguments/2.0.0/index.js b/FlowPlugins/CommunityFlowPlugins/handbrake/handbrakeCustomArguments/2.0.0/index.js index acdc8ac..6c396a7 100644 --- a/FlowPlugins/CommunityFlowPlugins/handbrake/handbrakeCustomArguments/2.0.0/index.js +++ b/FlowPlugins/CommunityFlowPlugins/handbrake/handbrakeCustomArguments/2.0.0/index.js @@ -197,6 +197,7 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function inputFileObj: args.inputFileObj, logFullCliOutput: args.logFullCliOutput, updateWorker: args.updateWorker, + args: args, }); return [4 /*yield*/, cli.runCli()]; case 4: diff --git a/FlowPlugins/CommunityFlowPlugins/tools/apprise/1.0.0/index.js b/FlowPlugins/CommunityFlowPlugins/tools/apprise/1.0.0/index.js index 479fc4b..6bfce81 100644 --- a/FlowPlugins/CommunityFlowPlugins/tools/apprise/1.0.0/index.js +++ b/FlowPlugins/CommunityFlowPlugins/tools/apprise/1.0.0/index.js @@ -57,7 +57,7 @@ var details = function () { return ({ tags: '', isStartPlugin: false, pType: '', - requiresVersion: '2.11.01', + requiresVersion: '2.18.01', sidebarPosition: -1, icon: 'faBell', inputs: [ @@ -104,6 +104,7 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function inputFileObj: args.inputFileObj, logFullCliOutput: args.logFullCliOutput, updateWorker: args.updateWorker, + args: args, }); return [4 /*yield*/, cli.runCli()]; case 1: diff --git a/FlowPlugins/CommunityFlowPlugins/tools/runCli/1.0.0/index.js b/FlowPlugins/CommunityFlowPlugins/tools/runCli/1.0.0/index.js index ffbc93c..ac1909a 100644 --- a/FlowPlugins/CommunityFlowPlugins/tools/runCli/1.0.0/index.js +++ b/FlowPlugins/CommunityFlowPlugins/tools/runCli/1.0.0/index.js @@ -262,6 +262,7 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function inputFileObj: args.inputFileObj, logFullCliOutput: args.logFullCliOutput, updateWorker: args.updateWorker, + args: args, }); return [4 /*yield*/, cli.runCli()]; case 1: diff --git a/FlowPlugins/CommunityFlowPlugins/tools/runMkvPropEdit/1.0.0/index.js b/FlowPlugins/CommunityFlowPlugins/tools/runMkvPropEdit/1.0.0/index.js index 16cd806..06e74ee 100644 --- a/FlowPlugins/CommunityFlowPlugins/tools/runMkvPropEdit/1.0.0/index.js +++ b/FlowPlugins/CommunityFlowPlugins/tools/runMkvPropEdit/1.0.0/index.js @@ -83,6 +83,7 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function inputFileObj: args.inputFileObj, logFullCliOutput: args.logFullCliOutput, updateWorker: args.updateWorker, + args: args, }); return [4 /*yield*/, cli.runCli()]; case 1: diff --git a/FlowPlugins/CommunityFlowPlugins/video/runHealthCheck/1.0.0/index.js b/FlowPlugins/CommunityFlowPlugins/video/runHealthCheck/1.0.0/index.js index f5c38ee..dfc2d4a 100644 --- a/FlowPlugins/CommunityFlowPlugins/video/runHealthCheck/1.0.0/index.js +++ b/FlowPlugins/CommunityFlowPlugins/video/runHealthCheck/1.0.0/index.js @@ -122,6 +122,7 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function inputFileObj: args.inputFileObj, logFullCliOutput: args.logFullCliOutput, updateWorker: args.updateWorker, + args: args, }); return [4 /*yield*/, cli.runCli()]; case 1: diff --git a/FlowPlugins/FlowHelpers/1.0.0/cliUtils.js b/FlowPlugins/FlowHelpers/1.0.0/cliUtils.js index 0205188..f62fa85 100644 --- a/FlowPlugins/FlowHelpers/1.0.0/cliUtils.js +++ b/FlowPlugins/FlowHelpers/1.0.0/cliUtils.js @@ -97,10 +97,14 @@ var CLI = /** @class */ (function () { this.oldProgress = 0; this.lastProgCheck = 0; this.hbPass = 0; + this.cancelled = false; + this.startTime = new Date().getTime(); this.updateETA = function (perc) { return __awaiter(_this, void 0, void 0, function () { - var n, secsSinceLastCheck, eta, sum, avg, estSize, outputFileSizeInGbytes, singleFileSize, err_1; - return __generator(this, function (_a) { - switch (_a.label) { + var n, secsSinceLastCheck, eta, sum, avg, estSize, outputFileSizeInGbytes, singleFileSize, err_1, secondsSinceStart, _a, compareMethod, thresholdPerc_1, checkDelaySeconds, inputFileSize, inputFileSizeInGbytes_1, cancel, ratio, ratio; + var _this = this; + var _b; + return __generator(this, function (_c) { + switch (_c.label) { case 0: if (!(perc > 0)) return [3 /*break*/, 6]; if (!(this.lastProgCheck === 0)) return [3 /*break*/, 1]; @@ -122,12 +126,12 @@ var CLI = /** @class */ (function () { avg = sum / this.progAVG.length; estSize = 0; outputFileSizeInGbytes = void 0; - _a.label = 2; + _c.label = 2; case 2: - _a.trys.push([2, 4, , 5]); + _c.trys.push([2, 4, , 5]); return [4 /*yield*/, (0, fileUtils_1.fileExists)(this.config.outputFilePath)]; case 3: - if (_a.sent()) { + if (_c.sent()) { singleFileSize = fs_1.default.statSync(this.config.outputFilePath); // @ts-expect-error type singleFileSize = singleFileSize.size; @@ -142,7 +146,7 @@ var CLI = /** @class */ (function () { } return [3 /*break*/, 5]; case 4: - err_1 = _a.sent(); + err_1 = _c.sent(); // eslint-disable-next-line no-console console.log(err_1); return [3 /*break*/, 5]; @@ -157,7 +161,41 @@ var CLI = /** @class */ (function () { } this.lastProgCheck = n; this.oldProgress = perc; - _a.label = 6; + secondsSinceStart = (new Date().getTime() - this.startTime) / 1000; + // live size compare + if ((_b = this.config.args.variables.liveSizeCompare) === null || _b === void 0 ? void 0 : _b.enabled) { + _a = this.config.args.variables.liveSizeCompare, compareMethod = _a.compareMethod, thresholdPerc_1 = _a.thresholdPerc, checkDelaySeconds = _a.checkDelaySeconds; + if (secondsSinceStart > checkDelaySeconds) { + inputFileSize = this.config.inputFileObj.file_size; + inputFileSizeInGbytes_1 = inputFileSize / 1024; + cancel = function (ratio) { + _this.config.jobLog("Input file size: ".concat(inputFileSizeInGbytes_1, "GB")); + _this.config.jobLog("Ratio: ".concat(ratio, "%")); + _this.config.jobLog("Ratio is greater than threshold: ".concat(thresholdPerc_1, "%, cancelling job")); + _this.cancelled = true; + _this.killThread(); + }; + if (compareMethod === 'estimatedFinalSize' + && estSize !== undefined + && estSize > 0) { + ratio = (estSize / inputFileSizeInGbytes_1) * 100; + if (ratio > thresholdPerc_1) { + this.config.jobLog("Estimated final size: ".concat(estSize, "GB")); + cancel(ratio); + } + } + else if (compareMethod === 'currentSize' + && outputFileSizeInGbytes !== undefined + && outputFileSizeInGbytes > 0) { + ratio = (outputFileSizeInGbytes / inputFileSizeInGbytes_1) * 100; + if (ratio > thresholdPerc_1) { + this.config.jobLog("Current output size: ".concat(outputFileSizeInGbytes, "GB")); + cancel(ratio); + } + } + } + } + _c.label = 6; case 6: return [2 /*return*/]; } }); @@ -247,8 +285,7 @@ var CLI = /** @class */ (function () { } } }; - // eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/explicit-module-boundary-types - this.killThread = function (thread) { + this.killThread = function () { var killArray = [ 'SIGKILL', 'SIGHUP', @@ -256,14 +293,14 @@ var CLI = /** @class */ (function () { 'SIGINT', ]; try { - thread.kill(); + _this.thread.kill(); } catch (err) { // err } killArray.forEach(function (com) { try { - thread.kill(com); + _this.thread.kill(com); } catch (err) { // err @@ -271,7 +308,7 @@ var CLI = /** @class */ (function () { }); }; this.runCli = function () { return __awaiter(_this, void 0, void 0, function () { - var childProcess, errorLogFull, thread, exitHandler, cliExitCode; + var childProcess, errorLogFull, exitHandler, cliExitCode; var _this = this; return __generator(this, function (_a) { switch (_a.label) { @@ -280,11 +317,11 @@ var CLI = /** @class */ (function () { errorLogFull = []; this.config.jobLog("Running ".concat(this.config.cli, " ").concat(this.config.spawnArgs.join(' '))); exitHandler = function () { - if (thread) { + if (_this.thread) { try { // eslint-disable-next-line no-console console.log('Main thread exiting, cleaning up running CLI'); - _this.killThread(thread); + _this.killThread(); } catch (err) { // eslint-disable-next-line no-console @@ -299,17 +336,17 @@ var CLI = /** @class */ (function () { try { var opts = _this.config.spawnOpts || {}; var spawnArgs = _this.config.spawnArgs.map(function (row) { return row.trim(); }).filter(function (row) { return row !== ''; }); - thread = childProcess.spawn(_this.config.cli, spawnArgs, opts); - thread.stdout.on('data', function (data) { + _this.thread = childProcess.spawn(_this.config.cli, spawnArgs, opts); + _this.thread.stdout.on('data', function (data) { errorLogFull.push(data.toString()); _this.parseOutput(data); }); - thread.stderr.on('data', function (data) { + _this.thread.stderr.on('data', function (data) { // eslint-disable-next-line no-console errorLogFull.push(data.toString()); _this.parseOutput(data); }); - thread.on('error', function () { + _this.thread.on('error', function () { // catches execution error (bad file) // eslint-disable-next-line no-console console.log("Error executing binary: ".concat(_this.config.cli)); @@ -318,7 +355,7 @@ var CLI = /** @class */ (function () { }); // thread.stdout.pipe(process.stdout); // thread.stderr.pipe(process.stderr); - thread.on('close', function (code) { + _this.thread.on('close', function (code) { if (code !== 0) { // eslint-disable-next-line no-console console.log("CLI error code: ".concat(code)); @@ -338,10 +375,13 @@ var CLI = /** @class */ (function () { case 1: cliExitCode = _a.sent(); process.removeListener('exit', exitHandler); - thread = undefined; + this.thread = undefined; if (!this.config.logFullCliOutput) { this.config.jobLog(errorLogFull.slice(-1000).join('')); } + if (this.cancelled) { + cliExitCode = 1; + } return [2 /*return*/, { cliExitCode: cliExitCode, errorLogFull: errorLogFull, From af24dca66a9e2c91bb72848ca76a62fcfdb29227 Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Wed, 12 Jun 2024 07:52:26 +0100 Subject: [PATCH 3/4] Update tooltip --- .../file/compareFileSizeRatioLive/1.0.0/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/FlowPluginsTs/CommunityFlowPlugins/file/compareFileSizeRatioLive/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/file/compareFileSizeRatioLive/1.0.0/index.ts index 4207b2c..c603920 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/file/compareFileSizeRatioLive/1.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/file/compareFileSizeRatioLive/1.0.0/index.ts @@ -35,7 +35,9 @@ const details = (): IpluginDetails => ({ inputUI: { type: 'switch', }, - tooltip: 'Enable or disable this plugin. For example you may want to enable it for one set of transcoding tests.', + tooltip: `Enable or disable this plugin. For example you may want to enable it for one transcoding block and then + disable it for another block. + `, }, { label: 'Compare Method', From eeee40c00b358686d68d91f9bf33d43ce7dade30 Mon Sep 17 00:00:00 2001 From: HaveAGitGat Date: Wed, 12 Jun 2024 06:54:22 +0000 Subject: [PATCH 4/4] Apply auto-build changes --- .../file/compareFileSizeRatioLive/1.0.0/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FlowPlugins/CommunityFlowPlugins/file/compareFileSizeRatioLive/1.0.0/index.js b/FlowPlugins/CommunityFlowPlugins/file/compareFileSizeRatioLive/1.0.0/index.js index 16cb1b6..7269f67 100644 --- a/FlowPlugins/CommunityFlowPlugins/file/compareFileSizeRatioLive/1.0.0/index.js +++ b/FlowPlugins/CommunityFlowPlugins/file/compareFileSizeRatioLive/1.0.0/index.js @@ -23,7 +23,7 @@ var details = function () { return ({ inputUI: { type: 'switch', }, - tooltip: 'Enable or disable this plugin. For example you may want to enable it for one set of transcoding tests.', + tooltip: "Enable or disable this plugin. For example you may want to enable it for one transcoding block and then\n disable it for another block.\n ", }, { label: 'Compare Method',