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 1/3] 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 0000000..c6623ad --- /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 e3e80a7..7fc42fe 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[], } From afc401576c7a4e11a87c1ca6402bfdaed14c29bf Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Thu, 16 Nov 2023 07:13:07 +0000 Subject: [PATCH 2/3] Fix lint error --- .../CommunityFlowPlugins/basic/basicVideoOrAudio/1.0.0/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FlowPluginsTs/CommunityFlowPlugins/basic/basicVideoOrAudio/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/basic/basicVideoOrAudio/1.0.0/index.ts index c6623ad..2f1a1c1 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/basic/basicVideoOrAudio/1.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/basic/basicVideoOrAudio/1.0.0/index.ts @@ -10,7 +10,7 @@ import { getContainer, getFileName, getPluginWorkDir } from '../../../../FlowHel 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 + the Basic Video or Basic Audio settings in the library settings `, style: { borderColor: 'green', From 48677471a29e61d5abf106403368ad8f1c807d85 Mon Sep 17 00:00:00 2001 From: HaveAGitGat Date: Thu, 16 Nov 2023 07:14:54 +0000 Subject: [PATCH 3/3] Apply auto-build changes --- .../basic/basicVideoOrAudio/1.0.0/index.js | 405 ++++++++++++++++++ 1 file changed, 405 insertions(+) create mode 100644 FlowPlugins/CommunityFlowPlugins/basic/basicVideoOrAudio/1.0.0/index.js diff --git a/FlowPlugins/CommunityFlowPlugins/basic/basicVideoOrAudio/1.0.0/index.js b/FlowPlugins/CommunityFlowPlugins/basic/basicVideoOrAudio/1.0.0/index.js new file mode 100644 index 0000000..a46fbba --- /dev/null +++ b/FlowPlugins/CommunityFlowPlugins/basic/basicVideoOrAudio/1.0.0/index.js @@ -0,0 +1,405 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { + if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { + if (ar || !(i in from)) { + if (!ar) ar = Array.prototype.slice.call(from, 0, i); + ar[i] = from[i]; + } + } + return to.concat(ar || Array.prototype.slice.call(from)); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.plugin = exports.details = void 0; +var cliUtils_1 = require("../../../../FlowHelpers/1.0.0/cliUtils"); +var fileUtils_1 = require("../../../../FlowHelpers/1.0.0/fileUtils"); +/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */ +var details = function () { return ({ + name: 'Basic Video or Audio Settings', + description: "Basic Video or Audio settings designed to replicate\n the Basic Video or Basic Audio settings in the library settings\n ", + 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', + }, + ], +}); }; +exports.details = details; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function () { + var lib, basicSettingsType, container, cliTool, cliArguments, codecFilter, codecs, fileSizeRangeMinMB, fileSizeRangeMaxMB, videoHeightRangeMin, videoHeightRangeMax, videoWidthRangeMin, videoWidthRangeMax, noTranscodeResponse, size, mainStream, height, width, codec, outputFilePath, cliArgs, cliPath, argsSplit, cli, res; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + lib = require('../../../../../methods/lib')(); + // eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign + args.inputs = lib.loadDefaultValues(args.inputs, details); + basicSettingsType = String(args.inputs.basicSettingsType); + container = String(args.inputs.outputFileContainer).split('.').join(''); + cliTool = String(args.inputs.cliTool); + cliArguments = String(args.inputs.cliArguments); + codecFilter = String(args.inputs.codecFilter); + codecs = String(args.inputs.codecs).split(',').map(function (codec) { return codec.trim(); }); + fileSizeRangeMinMB = Number(args.inputs.fileSizeRangeMinMB); + fileSizeRangeMaxMB = Number(args.inputs.fileSizeRangeMaxMB); + videoHeightRangeMin = Number(args.inputs.videoHeightRangeMin); + videoHeightRangeMax = Number(args.inputs.videoHeightRangeMax); + videoWidthRangeMin = Number(args.inputs.videoWidthRangeMin); + videoWidthRangeMax = Number(args.inputs.videoWidthRangeMax); + noTranscodeResponse = { + outputFileObj: { + _id: args.inputFileObj._id, + }, + outputNumber: 1, + variables: args.variables, + }; + size = args.inputFileObj.file_size; + if (size < fileSizeRangeMinMB || size > fileSizeRangeMaxMB) { + args.jobLog("Skipping ".concat(args.inputFileObj._id, " due to size ").concat(size, "MB not in ") + + "range ".concat(fileSizeRangeMinMB, "MB to ").concat(fileSizeRangeMaxMB, "MB")); + return [2 /*return*/, noTranscodeResponse]; + } + args.jobLog("Processing ".concat(args.inputFileObj._id, " due to size ").concat(size, "MB in ") + + "range ".concat(fileSizeRangeMinMB, "MB to ").concat(fileSizeRangeMaxMB, "MB")); + if (!args.inputFileObj.ffProbeData.streams) { + throw new Error('No streams found in file FFprobe data'); + } + mainStream = args.inputFileObj.ffProbeData.streams.find(function (stream) { return stream.codec_type === basicSettingsType; }); + if (!mainStream) { + throw new Error("No ".concat(basicSettingsType, " stream found in file FFprobe data")); + } + if (basicSettingsType === 'video') { + height = mainStream.height || 0; + width = mainStream.width || 0; + if (height < videoHeightRangeMin || height > videoHeightRangeMax) { + args.jobLog("Skipping ".concat(args.inputFileObj._id, " due to height ").concat(height, " not in ") + + "range ".concat(videoHeightRangeMin, " to ").concat(videoHeightRangeMax)); + return [2 /*return*/, noTranscodeResponse]; + } + args.jobLog("Processing ".concat(args.inputFileObj._id, " due to height ").concat(height, " in ") + + "range ".concat(videoHeightRangeMin, " to ").concat(videoHeightRangeMax)); + if (width < videoWidthRangeMin || width > videoWidthRangeMax) { + args.jobLog("Skipping ".concat(args.inputFileObj._id, " due to width ").concat(width, " not in ") + + "range ".concat(videoWidthRangeMin, " to ").concat(videoWidthRangeMax)); + return [2 /*return*/, noTranscodeResponse]; + } + args.jobLog("Processing ".concat(args.inputFileObj._id, " due to width ").concat(width, " in ") + + "range ".concat(videoWidthRangeMin, " to ").concat(videoWidthRangeMax)); + } + codec = mainStream.codec_name; + if (codecFilter === 'allow') { + if (!codecs.includes(codec)) { + args.jobLog("Skipping ".concat(args.inputFileObj._id, " due to codec ").concat(codec, " not in list ").concat(codecs)); + return [2 /*return*/, noTranscodeResponse]; + } + args.jobLog("Processing ".concat(args.inputFileObj._id, " due to codec ").concat(codec, " in list ").concat(codecs)); + } + else { + if (codecs.includes(codec)) { + args.jobLog("Skipping ".concat(args.inputFileObj._id, " due to codec ").concat(codec, " in list ").concat(codecs)); + return [2 /*return*/, noTranscodeResponse]; + } + args.jobLog("Processing ".concat(args.inputFileObj._id, " due to codec ").concat(codec, " not in list ").concat(codecs)); + } + if (container === 'original') { + container = (0, fileUtils_1.getContainer)(args.inputFileObj._id); + } + outputFilePath = "".concat((0, fileUtils_1.getPluginWorkDir)(args), "/").concat((0, fileUtils_1.getFileName)(args.inputFileObj._id), ".").concat(container); + cliArgs = []; + cliPath = ''; + if (cliTool === 'handbrake') { + cliPath = args.handbrakePath; + cliArgs = __spreadArray([ + '-i', + "".concat(args.inputFileObj._id), + '-o', + "".concat(outputFilePath) + ], args.deps.parseArgsStringToArgv(cliArguments, '', ''), true); + } + else { + cliPath = args.ffmpegPath; + argsSplit = void 0; + if (cliArguments.includes('')) { + argsSplit = cliArguments.split(''); + } + else { + argsSplit = cliArguments.split(','); + } + cliArgs = __spreadArray(__spreadArray(__spreadArray(__spreadArray([], args.deps.parseArgsStringToArgv(argsSplit[0], '', ''), true), [ + '-i', + "".concat(args.inputFileObj._id) + ], false), args.deps.parseArgsStringToArgv(argsSplit[1], '', ''), true), [ + "".concat(outputFilePath), + ], false); + } + args.updateWorker({ + CLIType: cliPath, + preset: cliArgs.join(' '), + }); + cli = new cliUtils_1.CLI({ + cli: cliPath, + spawnArgs: cliArgs, + spawnOpts: {}, + jobLog: args.jobLog, + outputFilePath: outputFilePath, + inputFileObj: args.inputFileObj, + logFullCliOutput: args.logFullCliOutput, + updateWorker: args.updateWorker, + }); + return [4 /*yield*/, cli.runCli()]; + case 1: + res = _a.sent(); + if (res.cliExitCode !== 0) { + args.jobLog("Running ".concat(cliTool, " failed")); + throw new Error("Running ".concat(cliTool, " failed")); + } + args.logOutcome('tSuc'); + return [2 /*return*/, { + outputFileObj: { + _id: outputFilePath, + }, + outputNumber: 1, + variables: args.variables, + }]; + } + }); +}); }; +exports.plugin = plugin;