mirror of
https://github.com/gabehf/Tdarr_Plugins.git
synced 2026-03-09 07:29:04 -07:00
commit
642924168f
4 changed files with 201 additions and 2 deletions
|
|
@ -0,0 +1,89 @@
|
|||
"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',
|
||||
description: 'Compare file size ratio of working file compared to original file using percentage.',
|
||||
style: {
|
||||
borderColor: 'orange',
|
||||
},
|
||||
tags: '',
|
||||
isStartPlugin: false,
|
||||
pType: '',
|
||||
requiresVersion: '2.11.01',
|
||||
sidebarPosition: -1,
|
||||
icon: 'faQuestion',
|
||||
inputs: [
|
||||
{
|
||||
name: 'greaterThan',
|
||||
type: 'number',
|
||||
defaultValue: '40',
|
||||
inputUI: {
|
||||
type: 'text',
|
||||
},
|
||||
tooltip: 'Specify lower bound.'
|
||||
+ 'Default value is 40% so new file size must be at least 40% of original file size.',
|
||||
},
|
||||
{
|
||||
name: 'lessThan',
|
||||
type: 'number',
|
||||
defaultValue: '110',
|
||||
inputUI: {
|
||||
type: 'text',
|
||||
},
|
||||
tooltip: 'Specify upper bound.'
|
||||
+ ' Default value is 110% so new file size must be at most 110% of original file size.',
|
||||
},
|
||||
],
|
||||
outputs: [
|
||||
{
|
||||
number: 1,
|
||||
tooltip: 'Working file size % is within range',
|
||||
},
|
||||
{
|
||||
number: 2,
|
||||
tooltip: 'Working file size % is smaller than lower bound',
|
||||
},
|
||||
{
|
||||
number: 3,
|
||||
tooltip: 'Working file size % is larger than upper bound',
|
||||
},
|
||||
],
|
||||
}); };
|
||||
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 newFileSizeBytes = args.inputFileObj.file_size;
|
||||
var origFileSizeBytes = args.originalLibraryFile.file_size;
|
||||
var greaterThanPerc = Number(args.inputs.greaterThan);
|
||||
var lessThanPerc = Number(args.inputs.lessThan);
|
||||
var ratio = (newFileSizeBytes / origFileSizeBytes) * 100;
|
||||
var sizeText = "New file has size ".concat(newFileSizeBytes.toFixed(3), " MB which is ").concat(ratio, "% ")
|
||||
+ "of original file size: ".concat(origFileSizeBytes.toFixed(3), " MB");
|
||||
var getBound = function (bound) { return (bound / 100) * origFileSizeBytes; };
|
||||
var outputNumber = 1;
|
||||
var errText = 'New file size not within limits.';
|
||||
if (newFileSizeBytes > getBound(lessThanPerc)) {
|
||||
// Item will be errored in UI
|
||||
args.jobLog("".concat(errText, " ").concat(sizeText, ". upperBound is ").concat(lessThanPerc, "%"));
|
||||
outputNumber = 3;
|
||||
}
|
||||
else if (newFileSizeBytes < getBound(greaterThanPerc)) {
|
||||
// // Item will be errored in UI
|
||||
args.jobLog("".concat(errText, " ").concat(sizeText, ". lowerBound is ").concat(greaterThanPerc, "%"));
|
||||
outputNumber = 2;
|
||||
}
|
||||
else {
|
||||
args.jobLog(sizeText);
|
||||
}
|
||||
return {
|
||||
outputFileObj: args.inputFileObj,
|
||||
outputNumber: outputNumber,
|
||||
variables: args.variables,
|
||||
};
|
||||
};
|
||||
exports.plugin = plugin;
|
||||
|
|
@ -37,7 +37,9 @@ var plugin = function (args) {
|
|||
if (Array.isArray((_b = (_a = args === null || args === void 0 ? void 0 : args.inputFileObj) === null || _a === void 0 ? void 0 : _a.ffProbeData) === null || _b === void 0 ? void 0 : _b.streams)) {
|
||||
for (var i = 0; i < args.inputFileObj.ffProbeData.streams.length; i += 1) {
|
||||
var stream = args.inputFileObj.ffProbeData.streams[i];
|
||||
if (stream.codec_type === 'video' && stream.bits_per_raw_sample === 10) {
|
||||
if (stream.codec_type === 'video'
|
||||
&& (stream.bits_per_raw_sample === 10
|
||||
|| stream.pix_fmt === 'yuv420p10le')) {
|
||||
is10Bit = true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,102 @@
|
|||
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',
|
||||
description: 'Compare file size ratio of working file compared to original file using percentage.',
|
||||
style: {
|
||||
borderColor: 'orange',
|
||||
},
|
||||
tags: '',
|
||||
|
||||
isStartPlugin: false,
|
||||
pType: '',
|
||||
requiresVersion: '2.11.01',
|
||||
sidebarPosition: -1,
|
||||
icon: 'faQuestion',
|
||||
inputs: [
|
||||
{
|
||||
name: 'greaterThan',
|
||||
type: 'number',
|
||||
defaultValue: '40',
|
||||
inputUI: {
|
||||
type: 'text',
|
||||
},
|
||||
tooltip: 'Specify lower bound.'
|
||||
+ 'Default value is 40% so new file size must be at least 40% of original file size.',
|
||||
},
|
||||
{
|
||||
name: 'lessThan',
|
||||
type: 'number',
|
||||
defaultValue: '110',
|
||||
inputUI: {
|
||||
type: 'text',
|
||||
},
|
||||
tooltip: 'Specify upper bound.'
|
||||
+ ' Default value is 110% so new file size must be at most 110% of original file size.',
|
||||
},
|
||||
],
|
||||
outputs: [
|
||||
{
|
||||
number: 1,
|
||||
tooltip: 'Working file size % is within range',
|
||||
},
|
||||
{
|
||||
number: 2,
|
||||
tooltip: 'Working file size % is smaller than lower bound',
|
||||
},
|
||||
{
|
||||
number: 3,
|
||||
tooltip: 'Working file size % is larger than upper bound',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
// 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 newFileSizeBytes = args.inputFileObj.file_size;
|
||||
const origFileSizeBytes = args.originalLibraryFile.file_size;
|
||||
|
||||
const greaterThanPerc = Number(args.inputs.greaterThan);
|
||||
const lessThanPerc = Number(args.inputs.lessThan);
|
||||
|
||||
const ratio = (newFileSizeBytes / origFileSizeBytes) * 100;
|
||||
|
||||
const sizeText = `New file has size ${newFileSizeBytes.toFixed(3)} MB which is ${ratio}% `
|
||||
+ `of original file size: ${origFileSizeBytes.toFixed(3)} MB`;
|
||||
|
||||
const getBound = (bound:number) => (bound / 100) * origFileSizeBytes;
|
||||
|
||||
let outputNumber = 1;
|
||||
|
||||
const errText = 'New file size not within limits.';
|
||||
if (newFileSizeBytes > getBound(lessThanPerc)) {
|
||||
// Item will be errored in UI
|
||||
args.jobLog(`${errText} ${sizeText}. upperBound is ${lessThanPerc}%`);
|
||||
outputNumber = 3;
|
||||
} else if (newFileSizeBytes < getBound(greaterThanPerc)) {
|
||||
// // Item will be errored in UI
|
||||
args.jobLog(`${errText} ${sizeText}. lowerBound is ${greaterThanPerc}%`);
|
||||
outputNumber = 2;
|
||||
} else {
|
||||
args.jobLog(sizeText);
|
||||
}
|
||||
|
||||
return {
|
||||
outputFileObj: args.inputFileObj,
|
||||
outputNumber,
|
||||
variables: args.variables,
|
||||
};
|
||||
};
|
||||
export {
|
||||
details,
|
||||
plugin,
|
||||
};
|
||||
|
|
@ -41,7 +41,13 @@ const plugin = (args: IpluginInputArgs): IpluginOutputArgs => {
|
|||
if (Array.isArray(args?.inputFileObj?.ffProbeData?.streams)) {
|
||||
for (let i = 0; i < args.inputFileObj.ffProbeData.streams.length; i += 1) {
|
||||
const stream = args.inputFileObj.ffProbeData.streams[i];
|
||||
if (stream.codec_type === 'video' && stream.bits_per_raw_sample === 10) {
|
||||
if (
|
||||
stream.codec_type === 'video'
|
||||
&& (
|
||||
stream.bits_per_raw_sample === 10
|
||||
|| stream.pix_fmt === 'yuv420p10le'
|
||||
)
|
||||
) {
|
||||
is10Bit = true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue