From 6af54253ba3bed94e915bddd0476d88e6498a8b7 Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Mon, 9 Oct 2023 08:44:58 +0100 Subject: [PATCH] Rename plugin, throw error if no video streams found --- .../1.0.0/index.js | 16 +++++++++++----- .../1.0.0/index.ts | 16 ++++++++++------ 2 files changed, 21 insertions(+), 11 deletions(-) rename FlowPlugins/CommunityFlowPlugins/video/{CheckVideoChannelsAmount => checkVideoStreamsCount}/1.0.0/index.js (76%) rename FlowPluginsTs/CommunityFlowPlugins/video/{CheckVideoChannelsAmount => checkVideoStreamsCount}/1.0.0/index.ts (76%) diff --git a/FlowPlugins/CommunityFlowPlugins/video/CheckVideoChannelsAmount/1.0.0/index.js b/FlowPlugins/CommunityFlowPlugins/video/checkVideoStreamsCount/1.0.0/index.js similarity index 76% rename from FlowPlugins/CommunityFlowPlugins/video/CheckVideoChannelsAmount/1.0.0/index.js rename to FlowPlugins/CommunityFlowPlugins/video/checkVideoStreamsCount/1.0.0/index.js index 4c2cafb..8eb66f7 100644 --- a/FlowPlugins/CommunityFlowPlugins/video/CheckVideoChannelsAmount/1.0.0/index.js +++ b/FlowPlugins/CommunityFlowPlugins/video/checkVideoStreamsCount/1.0.0/index.js @@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.plugin = exports.details = void 0; /* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */ var details = function () { return ({ - name: 'Check Multiple Video Streams', - description: 'This plugin checks if an input file has more than one video stream.', + name: 'Check Video Streams Count', + description: 'This plugin checks if the number of video streams is 1 or more.', style: { borderColor: 'orange', }, @@ -32,14 +32,20 @@ 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 outputNumber = 2; // Default to 'Special case' (> 1 video tracks) var ffProbeData = args.inputFileObj.ffProbeData; if (!ffProbeData || !ffProbeData.streams) { throw new Error('ffProbeData or ffProbeData.streams is not available.'); } var videoStreams = ffProbeData.streams.filter(function (stream) { return stream.codec_type === 'video'; }).length; - if (videoStreams === 1) { - outputNumber = 1; // 'Success' (has exactly one video stream) + var outputNumber = 1; // Default to one video stream + if (videoStreams === 0) { + throw new Error('No video streams found in file.'); + } + else if (videoStreams === 1) { + outputNumber = 1; // One video stream + } + else if (videoStreams > 1) { + outputNumber = 3; // More than one video stream } return { outputFileObj: args.inputFileObj, diff --git a/FlowPluginsTs/CommunityFlowPlugins/video/CheckVideoChannelsAmount/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/video/checkVideoStreamsCount/1.0.0/index.ts similarity index 76% rename from FlowPluginsTs/CommunityFlowPlugins/video/CheckVideoChannelsAmount/1.0.0/index.ts rename to FlowPluginsTs/CommunityFlowPlugins/video/checkVideoStreamsCount/1.0.0/index.ts index 940aa2a..5f6f1c2 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/video/CheckVideoChannelsAmount/1.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/video/checkVideoStreamsCount/1.0.0/index.ts @@ -6,8 +6,8 @@ import { /* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */ const details = (): IpluginDetails => ({ - name: 'Check Multiple Video Streams', - description: 'This plugin checks if an input file has more than one video stream.', + name: 'Check Video Streams Count', + description: 'This plugin checks if the number of video streams is 1 or more.', style: { borderColor: 'orange', }, @@ -36,8 +36,6 @@ const plugin = (args: IpluginInputArgs): IpluginOutputArgs => { // eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign args.inputs = lib.loadDefaultValues(args.inputs, details); - let outputNumber = 2; // Default to 'Special case' (> 1 video tracks) - const { ffProbeData } = args.inputFileObj; if (!ffProbeData || !ffProbeData.streams) { @@ -46,8 +44,14 @@ const plugin = (args: IpluginInputArgs): IpluginOutputArgs => { const videoStreams = ffProbeData.streams.filter((stream) => stream.codec_type === 'video').length; - if (videoStreams === 1) { - outputNumber = 1; // 'Success' (has exactly one video stream) + let outputNumber = 1; // Default to one video stream + + if (videoStreams === 0) { + throw new Error('No video streams found in file.'); + } else if (videoStreams === 1) { + outputNumber = 1; // One video stream + } else if (videoStreams > 1) { + outputNumber = 2; // More than one video stream } return {