From b3abeb20f16c2298fe6ac427936da3e1608dc5e0 Mon Sep 17 00:00:00 2001 From: Spencer Reiter Date: Sat, 11 Apr 2020 17:04:16 -0400 Subject: [PATCH 1/3] Added community plugin to set a default audio stream --- ...Tdarr_Plugin_c0r1_SetDefaultAudioStream.js | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 Community/Tdarr_Plugin_c0r1_SetDefaultAudioStream.js diff --git a/Community/Tdarr_Plugin_c0r1_SetDefaultAudioStream.js b/Community/Tdarr_Plugin_c0r1_SetDefaultAudioStream.js new file mode 100644 index 0000000..a74b89b --- /dev/null +++ b/Community/Tdarr_Plugin_c0r1_SetDefaultAudioStream.js @@ -0,0 +1,109 @@ +module.exports.details = function details() { + + return { + id: "Tdarr_Plugin_c0r1_SetDefaultAudioStream", + Stage: "Pre-processing", + Name: "Set Default Audio Stream", + Type: "Audio", + Operation: "Transcode", + Description: `This plugin will set an audio channel (2.0, 5.1, 7.1) to default and remove default from all other audio streams \n\n`, + Version: "0.1.0a", + Link: "", + Tags:"audio only", + + Inputs: [ + { + name: 'channels', + tooltip: `Desired audio channel number. + + \\nExample:\\n + + 2 + + \\nExample:\\n + + 6 + + \\nExample:\\n + + 8` + }, + ] + + } + +} + +module.exports.plugin = function plugin(file, librarySettings, inputs) { + var response = { + processFile: false, + preset: '', + container: '.' + file.container, + handBrakeMode: false, + FFmpegMode: true, + infoLog: '', + } + + var shouldProcess = false + var defaultAudioStreams = 0 + var matchingAudioStreams = 0 + var defaultSet = false + var ffmpegCommandInsert = '' + + + // Check if default audio stream matches user's channel selection + for (var i = 0; i < file.ffProbeData.streams.length; i++) { + if(file.ffProbeData.streams[i].codec_type.toLowerCase() === "audio" && + file.ffProbeData.streams[i].channels == inputs.channels) + { + matchingAudioStreams++ + if(file.ffProbeData.streams[i].disposition.default === 1){ + defaultAudioStreams++; + } + } + } + + // build command + for (var i = 0; i < file.ffProbeData.streams.length; i++) { + if(file.ffProbeData.streams[i].codec_type.toLowerCase() === "audio") + { + if(file.ffProbeData.streams[i].channels == inputs.channels) + { + if(!defaultSet){ + ffmpegCommandInsert += `-disposition:${i} default ` + defaultSet = true + } else { + ffmpegCommandInsert += `-disposition:${i} 0 ` + } + } else { + ffmpegCommandInsert += `-disposition:${i} 0 ` + } + } + } + + // Only process when there is a matching stream and + // when there is either no default or more than 1 default stream set + if(matchingAudioStreams >= 1 && defaultAudioStreams !== 1) { + shouldProcess = true; + response.infoLog += "☒ Matching audio stream is not set to default. \n" + } + + if (shouldProcess) { + response.processFile = true; + response.reQueueAfter = true; + response.preset = `,-map 0 -c copy ${ffmpegCommandInsert}`; + response.infoLog += "☒ Setting " + inputs.channels + " channel matching audio stream to default. Remove default from all other audio streams \n" + } else { + if(matchingAudioStreams < 1){ + response.infoLog += "☑ No " + inputs.channels + " channel audio stream exists. \n " + } else if (defaultAudioStreams === 1){ + response.infoLog += "☑ Default " + inputs.channels + " channel audio stream already exists. \n " + } else { + response.infoLog += "☑ Unexpected: Did not process \n " + } + + response.processFile = false; + } + return response + +} \ No newline at end of file From 37bef2eec8e95d9ffa0917566d113cb1136710f6 Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Sun, 12 Apr 2020 08:54:37 +0100 Subject: [PATCH 2/3] Update Tdarr_Plugin_c0r1_SetDefaultAudioStream.js --- Community/Tdarr_Plugin_c0r1_SetDefaultAudioStream.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Community/Tdarr_Plugin_c0r1_SetDefaultAudioStream.js b/Community/Tdarr_Plugin_c0r1_SetDefaultAudioStream.js index a74b89b..6043f48 100644 --- a/Community/Tdarr_Plugin_c0r1_SetDefaultAudioStream.js +++ b/Community/Tdarr_Plugin_c0r1_SetDefaultAudioStream.js @@ -9,7 +9,7 @@ module.exports.details = function details() { Description: `This plugin will set an audio channel (2.0, 5.1, 7.1) to default and remove default from all other audio streams \n\n`, Version: "0.1.0a", Link: "", - Tags:"audio only", + Tags:"audio only,ffmpeg,configurable", Inputs: [ { @@ -106,4 +106,4 @@ module.exports.plugin = function plugin(file, librarySettings, inputs) { } return response -} \ No newline at end of file +} From 47069a71f6f67f6dab5d0f3ca0039325a1de19ec Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Sun, 12 Apr 2020 08:56:15 +0100 Subject: [PATCH 3/3] Update Tdarr_Plugin_c0r1_SetDefaultAudioStream.js --- Community/Tdarr_Plugin_c0r1_SetDefaultAudioStream.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Community/Tdarr_Plugin_c0r1_SetDefaultAudioStream.js b/Community/Tdarr_Plugin_c0r1_SetDefaultAudioStream.js index 6043f48..ac7d0e9 100644 --- a/Community/Tdarr_Plugin_c0r1_SetDefaultAudioStream.js +++ b/Community/Tdarr_Plugin_c0r1_SetDefaultAudioStream.js @@ -3,7 +3,7 @@ module.exports.details = function details() { return { id: "Tdarr_Plugin_c0r1_SetDefaultAudioStream", Stage: "Pre-processing", - Name: "Set Default Audio Stream", + Name: "Set Default Audio Stream (Based On Channel Count)", Type: "Audio", Operation: "Transcode", Description: `This plugin will set an audio channel (2.0, 5.1, 7.1) to default and remove default from all other audio streams \n\n`,