Skip to content

Commit

Permalink
Added shouldProcess true and logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Marnalas committed Jan 10, 2025
1 parent 7989127 commit 38dd9bd
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,18 @@ var plugin = function (args) {
var streams = args.variables.ffmpegCommand.streams;
var defaultSet = false;
// Sets the language code used to determine the default audio stream
var languageCode = args.inputs.useRadarrOrSonarr
? args.variables.user.ArrOriginalLanguageCode
: args.inputs.language;
var languageCode = args.inputs.language;
if (args.inputs.useRadarrOrSonarr) {
languageCode = args.variables.user.ArrOriginalLanguageCode;
args.jobLog("Language ".concat(languageCode, " read from flow variables"));
}
// Sets the channels used to determine the default audio stream
var channels = args.inputs.useHightestNumberOfChannels
? (_d = (_c = (_b = (_a = streams
.filter(function (stream) { var _a, _b; return stream.codec_type === 'audio' && ((_b = (_a = stream.tags) === null || _a === void 0 ? void 0 : _a.language) !== null && _b !== void 0 ? _b : languageCode === ''); })) === null || _a === void 0 ? void 0 : _a.sort(function (stream1, stream2) { var _a, _b; return (((_a = stream1.channels) !== null && _a !== void 0 ? _a : 0) > ((_b = stream2.channels) !== null && _b !== void 0 ? _b : 0) ? 1 : -1); })) === null || _b === void 0 ? void 0 : _b.at(0)) === null || _c === void 0 ? void 0 : _c.channels) !== null && _d !== void 0 ? _d : 0
: args.inputs.channels;
var channels = args.inputs.channels;
if (args.inputs.useHightestNumberOfChannels) {
channels = (_d = (_c = (_b = (_a = streams
.filter(function (stream) { var _a, _b; return stream.codec_type === 'audio' && ((_b = (_a = stream.tags) === null || _a === void 0 ? void 0 : _a.language) !== null && _b !== void 0 ? _b : languageCode === ''); })) === null || _a === void 0 ? void 0 : _a.sort(function (stream1, stream2) { var _a, _b; return (((_a = stream1.channels) !== null && _a !== void 0 ? _a : 0) > ((_b = stream2.channels) !== null && _b !== void 0 ? _b : 0) ? 1 : -1); })) === null || _b === void 0 ? void 0 : _b.at(0)) === null || _c === void 0 ? void 0 : _c.channels) !== null && _d !== void 0 ? _d : 0;
args.jobLog("Channels ".concat(channels, " determined has being the highest channels"));
}
streams.forEach(function (stream, index) {
var _a, _b, _c;
if (stream.codec_type === 'audio') {
Expand All @@ -110,6 +114,12 @@ var plugin = function (args) {
stream.outputArgs.push("-disposition:".concat(index), '0');
}
});
if (defaultSet) {
// eslint-disable-next-line no-param-reassign
args.variables.ffmpegCommand.shouldProcess = true;
// eslint-disable-next-line no-param-reassign
args.variables.ffmpegCommand.streams = streams;
}
return {
outputFileObj: args.inputFileObj,
outputNumber: defaultSet ? 1 : 2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,32 +94,43 @@ const plugin = (args: IpluginInputArgs): IpluginOutputArgs => {
let defaultSet = false;

// Sets the language code used to determine the default audio stream
const languageCode = args.inputs.useRadarrOrSonarr
? args.variables.user.ArrOriginalLanguageCode
: args.inputs.language;
let languageCode = args.inputs.language;
if (args.inputs.useRadarrOrSonarr) {
languageCode = args.variables.user.ArrOriginalLanguageCode;
args.jobLog(`Language ${languageCode} read from flow variables`);
}

// Sets the channels used to determine the default audio stream
const channels = args.inputs.useHightestNumberOfChannels
? streams
let { channels } = args.inputs;
if (args.inputs.useHightestNumberOfChannels) {
channels = streams
.filter((stream) => stream.codec_type === 'audio' && (stream.tags?.language ?? languageCode === ''))
?.sort((stream1, stream2) => ((stream1.channels ?? 0) > (stream2.channels ?? 0) ? 1 : -1))
?.at(0)
?.channels
?? 0
: args.inputs.channels;
?? 0;
args.jobLog(`Channels ${channels} determined has being the highest channels`);
}

streams.forEach((stream, index) => {
if (stream.codec_type === 'audio') {
if ((stream.tags?.language ?? '') === languageCode
&& (stream.channels ?? 0) === channels
&& !defaultSet) {
&& (stream.channels ?? 0) === channels
&& !defaultSet) {
args.jobLog(`Setting stream ${index} (language ${languageCode}, channels ${channels}) has default`);
stream.outputArgs.push(`-disposition:${index}`, 'default');
defaultSet = true;
} else stream.outputArgs.push(`-disposition:${index}`, '0');
}
});

if (defaultSet) {
// eslint-disable-next-line no-param-reassign
args.variables.ffmpegCommand.shouldProcess = true;
// eslint-disable-next-line no-param-reassign
args.variables.ffmpegCommand.streams = streams;
}

return {
outputFileObj: args.inputFileObj,
outputNumber: defaultSet ? 1 : 2,
Expand Down

0 comments on commit 38dd9bd

Please sign in to comment.