Merge branch 'master' into pr/589

This commit is contained in:
HaveAGitGat 2024-05-08 06:35:49 +01:00
commit 1bc2afb4bc
18 changed files with 1970 additions and 994 deletions

View file

@ -6,7 +6,7 @@ import {
import { getFfType } from '../../../../FlowHelpers/1.0.0/fileUtils';
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
const details = () :IpluginDetails => ({
const details = (): IpluginDetails => ({
name: 'Set Video Bitrate',
description: 'Set Video Bitrate',
style: {
@ -19,6 +19,67 @@ const details = () :IpluginDetails => ({
sidebarPosition: -1,
icon: '',
inputs: [
{
label: 'Use % of Input Bitrate',
name: 'useInputBitrate',
type: 'boolean',
defaultValue: 'false',
inputUI: {
type: 'switch',
},
tooltip: 'Specify whether to use a % of input bitrate as the output bitrate',
},
{
label: 'Target Bitrate %',
name: 'targetBitratePercent',
type: 'string',
defaultValue: '50',
inputUI: {
type: 'text',
displayConditions: {
logic: 'AND',
sets: [
{
logic: 'AND',
inputs: [
{
name: 'useInputBitrate',
value: 'true',
condition: '===',
},
],
},
],
},
},
tooltip: 'Specify the target bitrate as a % of the input bitrate',
},
{
label: 'Fallback Bitrate',
name: 'fallbackBitrate',
type: 'string',
defaultValue: '4000',
inputUI: {
type: 'text',
displayConditions: {
logic: 'AND',
sets: [
{
logic: 'AND',
inputs: [
{
name: 'useInputBitrate',
value: 'true',
condition: '===',
},
],
},
],
},
},
tooltip: 'Specify fallback bitrate in kbps if input bitrate is not available',
},
{
label: 'Bitrate',
name: 'bitrate',
@ -26,6 +87,21 @@ const details = () :IpluginDetails => ({
defaultValue: '5000',
inputUI: {
type: 'text',
displayConditions: {
logic: 'AND',
sets: [
{
logic: 'AND',
inputs: [
{
name: 'useInputBitrate',
value: 'true',
condition: '!==',
},
],
},
],
},
},
tooltip: 'Specify bitrate in kbps',
},
@ -39,15 +115,40 @@ const details = () :IpluginDetails => ({
});
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const plugin = (args:IpluginInputArgs):IpluginOutputArgs => {
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 { useInputBitrate } = args.inputs;
const targetBitratePercent = String(args.inputs.targetBitratePercent);
const fallbackBitrate = String(args.inputs.fallbackBitrate);
const bitrate = String(args.inputs.bitrate);
args.variables.ffmpegCommand.streams.forEach((stream) => {
if (stream.codec_type === 'video') {
const ffType = getFfType(stream.codec_type);
stream.outputArgs.push(`-b:${ffType}:{outputTypeIndex}`, `${String(args.inputs.bitrate)}k`);
if (useInputBitrate) {
args.jobLog('Attempting to use % of input bitrate as output bitrate');
// check if input bitrate is available
const mediainfoIndex = stream.index + 1;
let inputBitrate = args?.inputFileObj?.mediaInfo?.track?.[mediainfoIndex]?.BitRate;
if (inputBitrate) {
args.jobLog(`Found input bitrate: ${inputBitrate}`);
// @ts-expect-error type
inputBitrate = parseInt(inputBitrate, 10) / 1000;
const targetBitrate = (inputBitrate * (parseInt(targetBitratePercent, 10) / 100));
args.jobLog(`Setting video bitrate as ${targetBitrate}k`);
stream.outputArgs.push(`-b:${ffType}:{outputTypeIndex}`, `${targetBitrate}k`);
} else {
args.jobLog(`Unable to find input bitrate, setting fallback bitrate as ${fallbackBitrate}k`);
stream.outputArgs.push(`-b:${ffType}:{outputTypeIndex}`, `${fallbackBitrate}k`);
}
} else {
args.jobLog(`Using fixed bitrate. Setting video bitrate as ${bitrate}k`);
stream.outputArgs.push(`-b:${ffType}:{outputTypeIndex}`, `${bitrate}k`);
}
}
});

View file

@ -49,9 +49,9 @@ const plugin = (args: IpluginInputArgs): IpluginOutputArgs => {
args.inputs = lib.loadDefaultValues(args.inputs, details);
const extensions = String(args.inputs.extensions);
const extensionArray = extensions.trim().split(',');
const extensionArray = extensions.trim().split(',').map((row) => row.toLowerCase());
const extension = getContainer(args.inputFileObj._id);
const extension = getContainer(args.inputFileObj._id).toLowerCase();
let extensionMatch = false;

View file

@ -23,12 +23,10 @@ const details = (): IpluginDetails => ({
label: 'Terms',
name: 'terms',
type: 'string',
// eslint-disable-next-line no-template-curly-in-string
defaultValue: '_720p,_1080p',
inputUI: {
type: 'text',
},
// eslint-disable-next-line no-template-curly-in-string
tooltip: 'Specify terms to check for in file name using comma seperated list e.g. _720p,_1080p',
},
],

View file

@ -0,0 +1,105 @@
import { getContainer, getFileName } from '../../../../FlowHelpers/1.0.0/fileUtils';
import {
IpluginDetails,
IpluginInputArgs,
IpluginOutputArgs,
} from '../../../../FlowHelpers/1.0.0/interfaces/interfaces';
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
const details = (): IpluginDetails => ({
name: 'Check File Name Includes',
description: 'Check if a file name includes specific terms. Only needs to match one term',
style: {
borderColor: 'orange',
},
tags: 'video',
isStartPlugin: false,
pType: '',
requiresVersion: '2.11.01',
sidebarPosition: -1,
icon: 'faQuestion',
inputs: [
{
label: 'Terms',
name: 'terms',
type: 'string',
defaultValue: '_720p,_1080p',
inputUI: {
type: 'text',
},
tooltip: 'Specify terms to check for in file name using comma seperated list e.g. _720p,_1080p',
},
{
label: 'Pattern (regular expression)',
name: 'pattern',
type: 'string',
defaultValue: '',
inputUI: {
type: 'text',
},
tooltip: 'Specify the pattern (regex) to check for in file name e.g. ^Pattern.*mkv$',
},
{
label: 'Include file directory in check',
name: 'includeFileDirectory',
type: 'boolean',
defaultValue: 'false',
inputUI: {
type: 'switch',
},
tooltip: 'Should the terms and patterns be evaluated against the file directory e.g. false, true',
},
],
outputs: [
{
number: 1,
tooltip: 'File name contains terms or patterns',
},
{
number: 2,
tooltip: 'File name does not contain any of the terms or patterns',
},
],
});
// 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 terms = String(args.inputs.terms);
const pattern = String(args.inputs.pattern);
const { includeFileDirectory } = args.inputs;
const fileName = includeFileDirectory
? args.inputFileObj._id
: `${getFileName(args.inputFileObj._id)}.${getContainer(args.inputFileObj._id)}`;
const searchCriteriasArray = terms.trim().split(',')
.map((term) => term.replace(/[\\^$*+?.()|[\]{}]/g, '\\$&')); // https://github.com/tc39/proposal-regex-escaping
if (pattern) {
searchCriteriasArray.push(pattern);
}
const searchCriteriaMatched = searchCriteriasArray
.find((searchCriteria) => new RegExp(searchCriteria).test(fileName));
const isAMatch = searchCriteriaMatched !== undefined;
if (isAMatch) {
args.jobLog(`'${fileName}' includes '${searchCriteriaMatched}'`);
} else {
args.jobLog(`'${fileName}' does not include any of the terms or patterns`);
}
return {
outputFileObj: args.inputFileObj,
outputNumber: isAMatch ? 1 : 2,
variables: args.variables,
};
};
export {
details,
plugin,
};

View file

@ -64,7 +64,8 @@ const details = (): IpluginDetails => ({
inputUI: {
type: 'text',
},
tooltip: 'Value of variable to check',
tooltip: `Value of variable to check.
You can specify multiple values separated by comma. For example: value1,value2,value3`,
},
],
outputs: [
@ -122,20 +123,21 @@ const plugin = (args: IpluginInputArgs): IpluginOutputArgs => {
targetValue = String(targetValue);
let outputNumber = 1;
const valuesArr = value.trim().split(',');
if (condition === '==') {
if (targetValue === value) {
args.jobLog(`Variable ${variable} of value ${targetValue} matches condition ${condition} ${value}`);
if (valuesArr.includes(targetValue)) {
args.jobLog(`Variable ${variable} of value ${targetValue} matches condition ${condition} ${valuesArr}`);
outputNumber = 1;
} else {
args.jobLog(`Variable ${variable} of value ${targetValue} does not match condition ${condition} ${value}`);
args.jobLog(`Variable ${variable} of value ${targetValue} does not match condition ${condition} ${valuesArr}`);
outputNumber = 2;
}
} else if (condition === '!=') {
if (targetValue !== value) {
args.jobLog(`Variable ${variable} of value ${targetValue} matches condition ${condition} ${value}`);
if (!valuesArr.includes(targetValue)) {
args.jobLog(`Variable ${variable} of value ${targetValue} matches condition ${condition} ${valuesArr}`);
outputNumber = 1;
} else {
args.jobLog(`Variable ${variable} of value ${targetValue} does not match condition ${condition} ${value}`);
args.jobLog(`Variable ${variable} of value ${targetValue} does not match condition ${condition} ${valuesArr}`);
outputNumber = 2;
}
}