Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Flow Plugin - checkFileDuration #696

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
"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 File Duration',
description: 'Check duration of file in seconds. Do something differently if above threshold.',
style: {
borderColor: 'orange',
},
tags: '',
isStartPlugin: false,
pType: '',
requiresVersion: '2.11.01',
sidebarPosition: -1,
icon: 'faQuestion',
inputs: [
{
label: 'Threshold (in seconds)',
name: 'thresholdSecs',
type: 'number',
defaultValue: '3900',
inputUI: {
type: 'text',
},
tooltip: 'Specify Threshold.'
+ ' Default value is 3,900 seconds (65 minutes).',
},
],
outputs: [
{
number: 1,
tooltip: 'Working file duration is below threshold',
},
{
number: 2,
tooltip: 'Working file duration is above threshold',
},
],
}); };
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 getData = function (obj) {
var _a, _b;
try {
if ((_b = (_a = obj === null || obj === void 0 ? void 0 : obj.ffProbeData) === null || _a === void 0 ? void 0 : _a.format) === null || _b === void 0 ? void 0 : _b.duration) {
var dur = Number(obj.ffProbeData.format.duration);
if (dur > 0) {
return dur;
}
}
}
catch (err) {
// err
}
return 0;
};
var origFileDuration = getData(args.originalLibraryFile);
args.jobLog("origFileDuration: ".concat(origFileDuration));
var thresholdSecs = Number(args.inputs.thresholdSecs);
var durationText = "File has duration is ".concat(origFileDuration.toFixed(3), " seconds");
var belowText = 'File duration is below threshold.';
var aboveText = 'File duration is above threshold.';
var outputNumber = 1;
if (origFileDuration < thresholdSecs) {
args.jobLog("".concat(belowText, " ").concat(durationText, ", threshold is ").concat(thresholdSecs, " seconds"));
outputNumber = 1;
}
else if (origFileDuration >= thresholdSecs) {
args.jobLog("".concat(aboveText, " ").concat(durationText, ", threshold is ").concat(thresholdSecs, " seconds"));
outputNumber = 2;
}
else {
args.jobLog(durationText);
}
return {
outputFileObj: args.inputFileObj,
outputNumber: outputNumber,
variables: args.variables,
};
};
exports.plugin = plugin;
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import {
IpluginDetails,
IpluginInputArgs,
IpluginOutputArgs,
} from '../../../../FlowHelpers/1.0.0/interfaces/interfaces';
import { IFileObject } from '../../../../FlowHelpers/1.0.0/interfaces/synced/IFileObject';

/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
const details = (): IpluginDetails => ({
name: 'Check File Duration',
description: 'Check duration of file in seconds. Do something differently if above threshold.',
style: {
borderColor: 'orange',
},
tags: '',
isStartPlugin: false,
pType: '',
requiresVersion: '2.11.01',
sidebarPosition: -1,
icon: 'faQuestion',
inputs: [
{
label: 'Threshold (in seconds)',
name: 'thresholdSecs',
type: 'number',
defaultValue: '3900',
inputUI: {
type: 'text',
},
tooltip: 'Specify Threshold.'
+ ' Default value is 3,900 seconds (65 minutes).',
},
],
outputs: [
{
number: 1,
tooltip: 'Working file duration is below threshold',
},
{
number: 2,
tooltip: 'Working file duration is above threshold',
},
],
});

// 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 getData = (obj:IFileObject) => {
try {
if (obj?.ffProbeData?.format?.duration) {
const dur = Number(obj.ffProbeData.format.duration);

if (dur > 0) {
return dur;
}
}
} catch (err) {
// err
}
return 0;
};

const origFileDuration: number = getData(args.originalLibraryFile);

args.jobLog(`origFileDuration: ${origFileDuration}`);

const thresholdSecs = Number(args.inputs.thresholdSecs);
const durationText = `File has duration is ${origFileDuration.toFixed(3)} seconds`;
const belowText = 'File duration is below threshold.';
const aboveText = 'File duration is above threshold.';

let outputNumber = 1;

if (origFileDuration < thresholdSecs) {
args.jobLog(`${belowText} ${durationText}, threshold is ${thresholdSecs} seconds`);
outputNumber = 1;
} else if (origFileDuration >= thresholdSecs) {
args.jobLog(`${aboveText} ${durationText}, threshold is ${thresholdSecs} seconds`);
outputNumber = 2;
} else {
args.jobLog(durationText);
}

return {
outputFileObj: args.inputFileObj,
outputNumber,
variables: args.variables,
};
};
export {
details,
plugin,
};