mirror of
https://github.com/gabehf/Tdarr_Plugins.git
synced 2026-03-17 11:16:26 -07:00
Add check bitrate
This commit is contained in:
parent
6ef5e2f79f
commit
581deb7ed2
2 changed files with 186 additions and 4 deletions
|
|
@ -40,6 +40,70 @@ var details = function () { return ({
|
||||||
},
|
},
|
||||||
tooltip: 'Specify the codec check for',
|
tooltip: 'Specify the codec check for',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: 'Check Bitrate',
|
||||||
|
name: 'checkBitrate',
|
||||||
|
type: 'boolean',
|
||||||
|
defaultValue: 'false',
|
||||||
|
inputUI: {
|
||||||
|
type: 'dropdown',
|
||||||
|
options: [
|
||||||
|
'false',
|
||||||
|
'true',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
tooltip: 'Toggle whether to check the bitrate of the audio codec is within a range.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Greater Than',
|
||||||
|
name: 'greaterThan',
|
||||||
|
type: 'number',
|
||||||
|
defaultValue: '50000',
|
||||||
|
inputUI: {
|
||||||
|
type: 'text',
|
||||||
|
displayConditions: {
|
||||||
|
logic: 'AND',
|
||||||
|
sets: [
|
||||||
|
{
|
||||||
|
logic: 'AND',
|
||||||
|
inputs: [
|
||||||
|
{
|
||||||
|
name: 'checkBitrate',
|
||||||
|
value: 'true',
|
||||||
|
condition: '===',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
tooltip: 'Specify lower bound.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Less Than',
|
||||||
|
name: 'lessThan',
|
||||||
|
type: 'number',
|
||||||
|
defaultValue: '1000000',
|
||||||
|
inputUI: {
|
||||||
|
type: 'text',
|
||||||
|
displayConditions: {
|
||||||
|
logic: 'AND',
|
||||||
|
sets: [
|
||||||
|
{
|
||||||
|
logic: 'AND',
|
||||||
|
inputs: [
|
||||||
|
{
|
||||||
|
name: 'checkBitrate',
|
||||||
|
value: 'true',
|
||||||
|
condition: '===',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
tooltip: 'Specify upper bound.',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
outputs: [
|
outputs: [
|
||||||
{
|
{
|
||||||
|
|
@ -58,14 +122,39 @@ var plugin = function (args) {
|
||||||
var lib = require('../../../../../methods/lib')();
|
var lib = require('../../../../../methods/lib')();
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||||
|
var checkBitrate = Boolean(args.inputs.checkBitrate);
|
||||||
|
var greaterThan = Number(args.inputs.greaterThan);
|
||||||
|
var lessThan = Number(args.inputs.lessThan);
|
||||||
var hasCodec = false;
|
var hasCodec = false;
|
||||||
if (args.inputFileObj.ffProbeData.streams) {
|
if (args.inputFileObj.ffProbeData.streams) {
|
||||||
args.inputFileObj.ffProbeData.streams.forEach(function (stream) {
|
args.inputFileObj.ffProbeData.streams.forEach(function (stream, index) {
|
||||||
|
var _a, _b, _c;
|
||||||
if (stream.codec_type === 'audio' && stream.codec_name === args.inputs.codec) {
|
if (stream.codec_type === 'audio' && stream.codec_name === args.inputs.codec) {
|
||||||
hasCodec = true;
|
if (!checkBitrate) {
|
||||||
|
args.jobLog("File has codec: ".concat(args.inputs.codec));
|
||||||
|
hasCodec = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var ffprobeBitrate = Number(stream.bit_rate || 0);
|
||||||
|
if (ffprobeBitrate > greaterThan && ffprobeBitrate < lessThan) {
|
||||||
|
args.jobLog("File has codec: ".concat(args.inputs.codec, " with bitrate")
|
||||||
|
+ " ".concat(ffprobeBitrate, " between ").concat(greaterThan, " and ").concat(lessThan));
|
||||||
|
hasCodec = true;
|
||||||
|
}
|
||||||
|
var mediaInfoBitrate = Number(((_c = (_b = (_a = args.inputFileObj.mediaInfo) === null || _a === void 0 ? void 0 : _a.track) === null || _b === void 0 ? void 0 : _b[index + 1]) === null || _c === void 0 ? void 0 : _c.BitRate) || 0);
|
||||||
|
if (mediaInfoBitrate > greaterThan && mediaInfoBitrate < lessThan) {
|
||||||
|
args.jobLog("File has codec: ".concat(args.inputs.codec, " with bitrate")
|
||||||
|
+ " ".concat(mediaInfoBitrate, " between ").concat(greaterThan, " and ").concat(lessThan));
|
||||||
|
hasCodec = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (!hasCodec) {
|
||||||
|
args.jobLog("File does not have codec: ".concat(args.inputs.codec, " ").concat(checkBitrate ? "with "
|
||||||
|
+ "bitrate between ".concat(greaterThan, " and ").concat(lessThan) : ''));
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
outputFileObj: args.inputFileObj,
|
outputFileObj: args.inputFileObj,
|
||||||
outputNumber: hasCodec ? 1 : 2,
|
outputNumber: hasCodec ? 1 : 2,
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,72 @@ const details = ():IpluginDetails => ({
|
||||||
},
|
},
|
||||||
tooltip: 'Specify the codec check for',
|
tooltip: 'Specify the codec check for',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: 'Check Bitrate',
|
||||||
|
name: 'checkBitrate',
|
||||||
|
type: 'boolean',
|
||||||
|
defaultValue: 'false',
|
||||||
|
inputUI: {
|
||||||
|
type: 'dropdown',
|
||||||
|
options: [
|
||||||
|
'false',
|
||||||
|
'true',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
tooltip:
|
||||||
|
'Toggle whether to check the bitrate of the audio codec is within a range.',
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
label: 'Greater Than',
|
||||||
|
name: 'greaterThan',
|
||||||
|
type: 'number',
|
||||||
|
defaultValue: '50000',
|
||||||
|
inputUI: {
|
||||||
|
type: 'text',
|
||||||
|
displayConditions: {
|
||||||
|
logic: 'AND',
|
||||||
|
sets: [
|
||||||
|
{
|
||||||
|
logic: 'AND',
|
||||||
|
inputs: [
|
||||||
|
{
|
||||||
|
name: 'checkBitrate',
|
||||||
|
value: 'true',
|
||||||
|
condition: '===',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
tooltip: 'Specify lower bound.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Less Than',
|
||||||
|
name: 'lessThan',
|
||||||
|
type: 'number',
|
||||||
|
defaultValue: '1000000',
|
||||||
|
inputUI: {
|
||||||
|
type: 'text',
|
||||||
|
displayConditions: {
|
||||||
|
logic: 'AND',
|
||||||
|
sets: [
|
||||||
|
{
|
||||||
|
logic: 'AND',
|
||||||
|
inputs: [
|
||||||
|
{
|
||||||
|
name: 'checkBitrate',
|
||||||
|
value: 'true',
|
||||||
|
condition: '===',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
tooltip: 'Specify upper bound.',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
outputs: [
|
outputs: [
|
||||||
{
|
{
|
||||||
|
|
@ -62,16 +128,43 @@ const plugin = (args:IpluginInputArgs):IpluginOutputArgs => {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||||
|
|
||||||
|
const checkBitrate = Boolean(args.inputs.checkBitrate);
|
||||||
|
const greaterThan = Number(args.inputs.greaterThan);
|
||||||
|
const lessThan = Number(args.inputs.lessThan);
|
||||||
|
|
||||||
let hasCodec = false;
|
let hasCodec = false;
|
||||||
|
|
||||||
if (args.inputFileObj.ffProbeData.streams) {
|
if (args.inputFileObj.ffProbeData.streams) {
|
||||||
args.inputFileObj.ffProbeData.streams.forEach((stream) => {
|
args.inputFileObj.ffProbeData.streams.forEach((stream, index) => {
|
||||||
if (stream.codec_type === 'audio' && stream.codec_name === args.inputs.codec) {
|
if (stream.codec_type === 'audio' && stream.codec_name === args.inputs.codec) {
|
||||||
hasCodec = true;
|
if (!checkBitrate) {
|
||||||
|
args.jobLog(`File has codec: ${args.inputs.codec}`);
|
||||||
|
hasCodec = true;
|
||||||
|
} else {
|
||||||
|
const ffprobeBitrate = Number(stream.bit_rate || 0);
|
||||||
|
if (ffprobeBitrate > greaterThan && ffprobeBitrate < lessThan) {
|
||||||
|
args.jobLog(`File has codec: ${args.inputs.codec} with bitrate`
|
||||||
|
+ ` ${ffprobeBitrate} between ${greaterThan} and ${lessThan}`);
|
||||||
|
hasCodec = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const mediaInfoBitrate = Number(args.inputFileObj.mediaInfo?.track?.[index + 1]?.BitRate || 0);
|
||||||
|
|
||||||
|
if (mediaInfoBitrate > greaterThan && mediaInfoBitrate < lessThan) {
|
||||||
|
args.jobLog(`File has codec: ${args.inputs.codec} with bitrate`
|
||||||
|
+ ` ${mediaInfoBitrate} between ${greaterThan} and ${lessThan}`);
|
||||||
|
hasCodec = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!hasCodec) {
|
||||||
|
args.jobLog(`File does not have codec: ${args.inputs.codec} ${checkBitrate ? 'with '
|
||||||
|
+ `bitrate between ${greaterThan} and ${lessThan}` : ''}`);
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
outputFileObj: args.inputFileObj,
|
outputFileObj: args.inputFileObj,
|
||||||
outputNumber: hasCodec ? 1 : 2,
|
outputNumber: hasCodec ? 1 : 2,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue