From f3615a01ce91d754a990200cf2c2623c278c57bc Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Thu, 16 Nov 2023 07:10:28 +0000 Subject: [PATCH] Add Basic Video or Audio Settings --- .../basic/basicVideoOrAudio/1.0.0/index.ts | 381 ++++++++++++++++++ .../1.0.0/interfaces/interfaces.ts | 47 ++- 2 files changed, 414 insertions(+), 14 deletions(-) create mode 100644 FlowPluginsTs/CommunityFlowPlugins/basic/basicVideoOrAudio/1.0.0/index.ts diff --git a/FlowPluginsTs/CommunityFlowPlugins/basic/basicVideoOrAudio/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/basic/basicVideoOrAudio/1.0.0/index.ts new file mode 100644 index 000000000..c6623ad21 --- /dev/null +++ b/FlowPluginsTs/CommunityFlowPlugins/basic/basicVideoOrAudio/1.0.0/index.ts @@ -0,0 +1,381 @@ +import { CLI } from '../../../../FlowHelpers/1.0.0/cliUtils'; +import { + IpluginDetails, + IpluginInputArgs, + IpluginOutputArgs, +} from '../../../../FlowHelpers/1.0.0/interfaces/interfaces'; +import { getContainer, getFileName, getPluginWorkDir } from '../../../../FlowHelpers/1.0.0/fileUtils'; + +/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */ +const details = (): IpluginDetails => ({ + name: 'Basic Video or Audio Settings', + description: `Basic Video or Audio settings designed to replicate + the \'Basic Video\' or \'Basic Audio \' settings in the library settings + `, + style: { + borderColor: 'green', + }, + tags: '', + isStartPlugin: false, + pType: '', + requiresVersion: '2.11.01', + sidebarPosition: -1, + icon: '', + inputs: [ + { + label: 'Basic Settings Type', + name: 'basicSettingsType', + type: 'string', + defaultValue: 'video', + inputUI: { + type: 'dropdown', + options: [ + 'video', + 'audio', + ], + }, + tooltip: 'Specify the basic settings type for the type of files being processed', + }, + { + label: 'Output File Container', + name: 'outputFileContainer', + type: 'string', + defaultValue: 'mkv', + inputUI: { + type: 'text', + }, + tooltip: 'Specify the output file container', + }, + { + label: 'CLI Tool', + name: 'cliTool', + type: 'string', + defaultValue: 'handbrake', + inputUI: { + type: 'dropdown', + options: [ + 'handbrake', + 'ffmpeg', + ], + }, + tooltip: 'Specify the CLI tool to use', + }, + { + label: 'CLI Arguments', + name: 'cliArguments', + type: 'string', + defaultValue: '-Z "Very Fast 1080p30"', + inputUI: { + type: 'text', + }, + tooltip: 'Specify HandBrake or FFmpeg arguments', + }, + { + label: 'Codec Filter', + name: 'codecFilter', + type: 'string', + defaultValue: 'ignore', + inputUI: { + type: 'dropdown', + options: [ + 'ignore', + 'allow', + ], + }, + tooltip: 'Specify whether to ignore or allow the following codecs', + }, + { + label: 'Codecs', + name: 'codecs', + type: 'string', + defaultValue: '', + inputUI: { + type: 'text', + }, + tooltip: 'Specify comma separated list of codecs to ignore or allow', + }, + { + label: 'File Size Range Min MB', + name: 'fileSizeRangeMinMB', + type: 'number', + defaultValue: '0', + inputUI: { + type: 'text', + }, + tooltip: 'Specify minimum file size in MB of files to process', + }, + { + label: 'File Size Range Max MB', + name: 'fileSizeRangeMaxMB', + type: 'number', + defaultValue: '200000', + inputUI: { + type: 'text', + }, + tooltip: 'Specify maximum file size in MB of files to process', + }, + + { + label: 'Video Height Range Min', + name: 'videoHeightRangeMin', + type: 'number', + defaultValue: '0', + inputUI: { + type: 'text', + displayConditions: { + logic: 'AND', + sets: [ + { + logic: 'AND', + inputs: [ + { + name: 'basicSettingsType', + value: 'video', + condition: '===', + }, + ], + }, + ], + }, + }, + tooltip: 'Specify minimum video height in pixels of files to process', + }, + { + label: 'Video Height Range Max', + name: 'videoHeightRangeMax', + type: 'number', + defaultValue: '5000', + inputUI: { + type: 'text', + displayConditions: { + logic: 'AND', + sets: [ + { + logic: 'AND', + inputs: [ + { + name: 'basicSettingsType', + value: 'video', + condition: '===', + }, + ], + }, + ], + }, + }, + tooltip: 'Specify maximum video height in pixels of files to process', + }, + { + label: 'Video Width Range Min', + name: 'videoWidthRangeMin', + type: 'number', + defaultValue: '0', + inputUI: { + type: 'text', + displayConditions: { + logic: 'AND', + sets: [ + { + logic: 'AND', + inputs: [ + { + name: 'basicSettingsType', + value: 'video', + condition: '===', + }, + ], + }, + ], + }, + }, + tooltip: 'Specify minimum video width in pixels of files to process', + }, + { + label: 'Video Width Range Max', + name: 'videoWidthRangeMax', + type: 'number', + defaultValue: '8000', + inputUI: { + type: 'text', + displayConditions: { + logic: 'AND', + sets: [ + { + logic: 'AND', + inputs: [ + { + name: 'basicSettingsType', + value: 'video', + condition: '===', + }, + ], + }, + ], + }, + }, + tooltip: 'Specify maximum video width in pixels of files to process', + }, + ], + outputs: [ + { + number: 1, + tooltip: 'Continue to next plugin', + }, + ], +}); + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +const plugin = async (args: IpluginInputArgs): Promise => { + 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 basicSettingsType = String(args.inputs.basicSettingsType); + let container = String(args.inputs.outputFileContainer).split('.').join(''); + const cliTool = String(args.inputs.cliTool); + const cliArguments = String(args.inputs.cliArguments); + const codecFilter = String(args.inputs.codecFilter); + const codecs = String(args.inputs.codecs).split(',').map((codec) => codec.trim()); + const fileSizeRangeMinMB = Number(args.inputs.fileSizeRangeMinMB); + const fileSizeRangeMaxMB = Number(args.inputs.fileSizeRangeMaxMB); + const videoHeightRangeMin = Number(args.inputs.videoHeightRangeMin); + const videoHeightRangeMax = Number(args.inputs.videoHeightRangeMax); + const videoWidthRangeMin = Number(args.inputs.videoWidthRangeMin); + const videoWidthRangeMax = Number(args.inputs.videoWidthRangeMax); + + const noTranscodeResponse = { + outputFileObj: { + _id: args.inputFileObj._id, + }, + outputNumber: 1, + variables: args.variables, + }; + + const size = args.inputFileObj.file_size; + + if (size < fileSizeRangeMinMB || size > fileSizeRangeMaxMB) { + args.jobLog(`Skipping ${args.inputFileObj._id} due to size ${size}MB not in ` + + `range ${fileSizeRangeMinMB}MB to ${fileSizeRangeMaxMB}MB`); + return noTranscodeResponse; + } + args.jobLog(`Processing ${args.inputFileObj._id} due to size ${size}MB in ` + + `range ${fileSizeRangeMinMB}MB to ${fileSizeRangeMaxMB}MB`); + + if (!args.inputFileObj.ffProbeData.streams) { + throw new Error('No streams found in file FFprobe data'); + } + + const mainStream = args.inputFileObj.ffProbeData.streams.find((stream) => stream.codec_type === basicSettingsType); + + if (!mainStream) { + throw new Error(`No ${basicSettingsType} stream found in file FFprobe data`); + } + + if (basicSettingsType === 'video') { + const height = mainStream.height || 0; + const width = mainStream.width || 0; + if (height < videoHeightRangeMin || height > videoHeightRangeMax) { + args.jobLog(`Skipping ${args.inputFileObj._id} due to height ${height} not in ` + + `range ${videoHeightRangeMin} to ${videoHeightRangeMax}`); + return noTranscodeResponse; + } + args.jobLog(`Processing ${args.inputFileObj._id} due to height ${height} in ` + + `range ${videoHeightRangeMin} to ${videoHeightRangeMax}`); + + if (width < videoWidthRangeMin || width > videoWidthRangeMax) { + args.jobLog(`Skipping ${args.inputFileObj._id} due to width ${width} not in ` + + `range ${videoWidthRangeMin} to ${videoWidthRangeMax}`); + return noTranscodeResponse; + } + args.jobLog(`Processing ${args.inputFileObj._id} due to width ${width} in ` + + `range ${videoWidthRangeMin} to ${videoWidthRangeMax}`); + } + + const codec = mainStream.codec_name; + if (codecFilter === 'allow') { + if (!codecs.includes(codec)) { + args.jobLog(`Skipping ${args.inputFileObj._id} due to codec ${codec} not in list ${codecs}`); + return noTranscodeResponse; + } + args.jobLog(`Processing ${args.inputFileObj._id} due to codec ${codec} in list ${codecs}`); + } else { + if (codecs.includes(codec)) { + args.jobLog(`Skipping ${args.inputFileObj._id} due to codec ${codec} in list ${codecs}`); + return noTranscodeResponse; + } + args.jobLog(`Processing ${args.inputFileObj._id} due to codec ${codec} not in list ${codecs}`); + } + + if (container === 'original') { + container = getContainer(args.inputFileObj._id); + } + + const outputFilePath = `${getPluginWorkDir(args)}/${getFileName(args.inputFileObj._id)}.${container}`; + + let cliArgs:string[] = []; + let cliPath = ''; + + if (cliTool === 'handbrake') { + cliPath = args.handbrakePath; + cliArgs = [ + '-i', + `${args.inputFileObj._id}`, + '-o', + `${outputFilePath}`, + ...args.deps.parseArgsStringToArgv(cliArguments, '', ''), + ]; + } else { + cliPath = args.ffmpegPath; + let argsSplit; + if (cliArguments.includes('')) { + argsSplit = cliArguments.split(''); + } else { + argsSplit = cliArguments.split(','); + } + + cliArgs = [ + ...args.deps.parseArgsStringToArgv(argsSplit[0], '', ''), + '-i', + `${args.inputFileObj._id}`, + ...args.deps.parseArgsStringToArgv(argsSplit[1], '', ''), + `${outputFilePath}`, + ]; + } + + args.updateWorker({ + CLIType: cliPath, + preset: cliArgs.join(' '), + }); + + const cli = new CLI({ + cli: cliPath, + spawnArgs: cliArgs, + spawnOpts: {}, + jobLog: args.jobLog, + outputFilePath, + inputFileObj: args.inputFileObj, + logFullCliOutput: args.logFullCliOutput, + updateWorker: args.updateWorker, + }); + + const res = await cli.runCli(); + + if (res.cliExitCode !== 0) { + args.jobLog(`Running ${cliTool} failed`); + throw new Error(`Running ${cliTool} failed`); + } + + args.logOutcome('tSuc'); + + return { + outputFileObj: { + _id: outputFilePath, + }, + outputNumber: 1, + variables: args.variables, + }; +}; +export { + details, + plugin, +}; diff --git a/FlowPluginsTs/FlowHelpers/1.0.0/interfaces/interfaces.ts b/FlowPluginsTs/FlowHelpers/1.0.0/interfaces/interfaces.ts index e3e80a717..7fc42fed0 100644 --- a/FlowPluginsTs/FlowHelpers/1.0.0/interfaces/interfaces.ts +++ b/FlowPluginsTs/FlowHelpers/1.0.0/interfaces/interfaces.ts @@ -2,19 +2,37 @@ import { IFileObject, Istreams } from './synced/IFileObject'; import Ijob from './synced/jobInterface'; export interface IpluginInputUi { - type: 'dropdown' | 'text' | 'textarea' | 'directory', + type: 'dropdown' | 'text' | 'textarea' | 'directory' | 'slider', options?: string[], - style?:Record, + sliderOptions?: {max: number, min: number, } + style?: Record, onSelect?: { - 'hevc': { - update: { - quality: '28', - }, + [index: string]: { + [index: string]: string, } - }, + }, + displayConditions?: { + // if logic is 'AND' then all sets must be true for element to be displayed + // if logic is 'OR' then at least one set must be true for element to be displayed + logic: 'AND' | 'OR', + sets: { + // if logic is 'AND' then all inputs conditions must be true for set to be true + // if logic is 'OR' then at least one input condition must be true for set to be true + logic: 'OR' | 'AND', + inputs: { + // the name of the input to check + name: string, + // the value to check against + value: string, + // the condition to check against + condition: '===' | '!==' | '>' | '>=' | '<' | '<=' | 'includes' | 'notIncludes', + }[], + }[] + }, } export interface IpluginInputs { + label?: string, name: string, type: 'string' | 'boolean' | 'number', defaultValue: string, @@ -24,9 +42,9 @@ export interface IpluginInputs { export interface IpluginDetails { name: string, - nameUI?:{ + nameUI?: { type: 'text' | 'textarea', - style?:Record, + style?: Record, } description: string, style: { @@ -79,6 +97,7 @@ export interface IffmpegCommand { export interface Ivariables { ffmpegCommand: IffmpegCommand, flowFailed: boolean, + inFlow: Record, } export interface IpluginOutputArgs { @@ -86,7 +105,7 @@ export interface IpluginOutputArgs { outputFileObj: { _id: string, }, - variables: Ivariables + variables: Ivariables, } export interface IpluginInputArgs { @@ -137,9 +156,9 @@ export interface IpluginInputArgs { // eslint-disable-next-line @typescript-eslint/no-explicit-any axios: any, // eslint-disable-next-line @typescript-eslint/no-explicit-any - crudTransDBN: (collection: string, mode: string, docID: string, obj: any)=> any, - configVars:{ - config:{ + crudTransDBN: (collection: string, mode: string, docID: string, obj: any) => any, + configVars: { + config: { serverIP: string, serverPort: string, } @@ -154,7 +173,7 @@ export interface IflowTemplate { description: string, tags: string, // eslint-disable-next-line @typescript-eslint/no-explicit-any - flowPlugins:any[], + flowPlugins: any[], // eslint-disable-next-line @typescript-eslint/no-explicit-any flowEdges: any[], }