diff --git a/FlowPlugins/CommunityFlowPlugins/ffmpegCommand/ffmpegCommandSetDefaultAudioStream/1.0.0/index.js b/FlowPlugins/CommunityFlowPlugins/ffmpegCommand/ffmpegCommandSetDefaultAudioStream/1.0.0/index.js index 0b9e897f3..31c5369c1 100644 --- a/FlowPlugins/CommunityFlowPlugins/ffmpegCommand/ffmpegCommandSetDefaultAudioStream/1.0.0/index.js +++ b/FlowPlugins/CommunityFlowPlugins/ffmpegCommand/ffmpegCommandSetDefaultAudioStream/1.0.0/index.js @@ -103,6 +103,14 @@ var getFFMPEGDisposition = function (isDefault, dispositions) { .join('+') || '0'; }; +var getIsDescriptiveAudioStream = function (stream) { + var _a; + return Boolean(stream.disposition + && (stream.disposition.comment + || stream.disposition.descriptions + || stream.disposition.visual_impaired + || /\b(commentary|description|descriptive)\b/gi.test(((_a = stream.tags) === null || _a === void 0 ? void 0 : _a.title) || ''))); +}; // eslint-disable-next-line @typescript-eslint/no-unused-vars var plugin = function (args) { var _a, _b, _c, _d; @@ -112,6 +120,7 @@ var plugin = function (args) { (0, flowUtils_1.checkFfmpegCommandInit)(args); // const streams: IffmpegCommandStream[] = JSON.parse(JSON.stringify(args.variables.ffmpegCommand.streams)); var streams = args.variables.ffmpegCommand.streams; + var shouldProcess = false; var defaultSet = false; // Sets the language code used to determine the default audio stream var languageCode = args.inputs.language; @@ -127,22 +136,28 @@ var plugin = function (args) { args.jobLog("Channels ".concat(channels, " determined has being the highest match")); } streams.forEach(function (stream, index) { - var _a, _b, _c; + var _a, _b, _c, _d, _e; if (stream.codec_type === 'audio') { var dispositions = stream.disposition; + var isDescriptiveAudioStream = getIsDescriptiveAudioStream(stream); if (((_b = (_a = stream.tags) === null || _a === void 0 ? void 0 : _a.language) !== null && _b !== void 0 ? _b : '') === languageCode && ((_c = stream.channels) !== null && _c !== void 0 ? _c : 0) === channels + && ((_d = dispositions === null || dispositions === void 0 ? void 0 : dispositions.default) !== null && _d !== void 0 ? _d : 0) === 0 + && !isDescriptiveAudioStream && !defaultSet) { - args.jobLog("Setting stream ".concat(index, " (language ").concat(languageCode, ", channels ").concat(channels, ") has default")); + args.jobLog("Stream ".concat(index, " (language ").concat(languageCode, ", channels ").concat(channels, ") set has default")); stream.outputArgs.push("-c:".concat(index), 'copy', "-disposition:".concat(index), getFFMPEGDisposition(true, dispositions)); defaultSet = true; + shouldProcess = true; } - else { + else if (((_e = dispositions === null || dispositions === void 0 ? void 0 : dispositions.default) !== null && _e !== void 0 ? _e : 0) === 1) { + args.jobLog("Stream ".concat(index, " (language ").concat(languageCode, ", channels ").concat(channels, ", \n descriptive ").concat(isDescriptiveAudioStream, ") set has not default")); stream.outputArgs.push("-c:".concat(index), 'copy', "-disposition:".concat(index), getFFMPEGDisposition(false, dispositions)); + shouldProcess = true; } } }); - if (defaultSet) { + if (shouldProcess) { // eslint-disable-next-line no-param-reassign args.variables.ffmpegCommand.shouldProcess = true; // eslint-disable-next-line no-param-reassign @@ -152,7 +167,7 @@ var plugin = function (args) { args.jobLog('No matching stream was found'); return { outputFileObj: args.inputFileObj, - outputNumber: defaultSet ? 1 : 2, + outputNumber: shouldProcess ? 1 : 2, variables: args.variables, }; }; diff --git a/FlowPluginsTs/CommunityFlowPlugins/ffmpegCommand/ffmpegCommandSetDefaultAudioStream/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/ffmpegCommand/ffmpegCommandSetDefaultAudioStream/1.0.0/index.ts index dbcde8dc5..8cd36b92d 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/ffmpegCommand/ffmpegCommandSetDefaultAudioStream/1.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/ffmpegCommand/ffmpegCommandSetDefaultAudioStream/1.0.0/index.ts @@ -81,6 +81,7 @@ const details = (): IpluginDetails => ({ }); interface IDisposition { + default: number, dub: number, original: number, comment: number, @@ -101,6 +102,7 @@ interface IDisposition { interface IStreamDisposition { disposition?: IDisposition + tags?: { title?: string } } const getFFMPEGDisposition = (isDefault: boolean, dispositions?: IDisposition): string => { @@ -123,6 +125,12 @@ const getFFMPEGDisposition = (isDefault: boolean, dispositions?: IDisposition): || '0'; }; +const getIsDescriptiveAudioStream = (stream: IStreamDisposition): boolean => Boolean(stream.disposition + && (stream.disposition.comment + || stream.disposition.descriptions + || stream.disposition.visual_impaired + || /\b(commentary|description|descriptive)\b/gi.test(stream.tags?.title || ''))); + // eslint-disable-next-line @typescript-eslint/no-unused-vars const plugin = (args: IpluginInputArgs): IpluginOutputArgs => { const lib = require('../../../../../methods/lib')(); @@ -134,6 +142,7 @@ const plugin = (args: IpluginInputArgs): IpluginOutputArgs => { // const streams: IffmpegCommandStream[] = JSON.parse(JSON.stringify(args.variables.ffmpegCommand.streams)); const { streams } = args.variables.ffmpegCommand; + let shouldProcess = false; let defaultSet = false; // Sets the language code used to determine the default audio stream @@ -158,10 +167,13 @@ const plugin = (args: IpluginInputArgs): IpluginOutputArgs => { streams.forEach((stream, index) => { if (stream.codec_type === 'audio') { const dispositions = (stream as IStreamDisposition).disposition; + const isDescriptiveAudioStream = getIsDescriptiveAudioStream(stream as IStreamDisposition); if ((stream.tags?.language ?? '') === languageCode && (stream.channels ?? 0) === channels + && (dispositions?.default ?? 0) === 0 + && !isDescriptiveAudioStream && !defaultSet) { - args.jobLog(`Setting stream ${index} (language ${languageCode}, channels ${channels}) has default`); + args.jobLog(`Stream ${index} (language ${languageCode}, channels ${channels}) set has default`); stream.outputArgs.push( `-c:${index}`, 'copy', @@ -169,18 +181,22 @@ const plugin = (args: IpluginInputArgs): IpluginOutputArgs => { getFFMPEGDisposition(true, dispositions), ); defaultSet = true; - } else { + shouldProcess = true; + } else if ((dispositions?.default ?? 0) === 1) { + args.jobLog(`Stream ${index} (language ${languageCode}, channels ${channels}, + descriptive ${isDescriptiveAudioStream}) set has not default`); stream.outputArgs.push( `-c:${index}`, 'copy', `-disposition:${index}`, getFFMPEGDisposition(false, dispositions), ); + shouldProcess = true; } } }); - if (defaultSet) { + if (shouldProcess) { // eslint-disable-next-line no-param-reassign args.variables.ffmpegCommand.shouldProcess = true; // eslint-disable-next-line no-param-reassign @@ -189,7 +205,7 @@ const plugin = (args: IpluginInputArgs): IpluginOutputArgs => { return { outputFileObj: args.inputFileObj, - outputNumber: defaultSet ? 1 : 2, + outputNumber: shouldProcess ? 1 : 2, variables: args.variables, }; };