From 0c1501a798980e6da491de861517f64296762438 Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Thu, 3 Aug 2023 08:07:40 +0100 Subject: [PATCH 1/5] Add downmix_single_track input and update tests --- .../Tdarr_Plugin_MC93_Migz5ConvertAudio.js | 32 +++- .../Tdarr_Plugin_MC93_Migz5ConvertAudio.js | 152 ++++++++++++++++++ 2 files changed, 176 insertions(+), 8 deletions(-) diff --git a/Community/Tdarr_Plugin_MC93_Migz5ConvertAudio.js b/Community/Tdarr_Plugin_MC93_Migz5ConvertAudio.js index f3cfd11..c3de08e 100644 --- a/Community/Tdarr_Plugin_MC93_Migz5ConvertAudio.js +++ b/Community/Tdarr_Plugin_MC93_Migz5ConvertAudio.js @@ -39,6 +39,19 @@ const details = () => ({ \\nExample:\\n false`, }, + { + name: 'downmix_single_track', + type: 'boolean', + defaultValue: false, + inputUI: { + type: 'dropdown', + options: [ + 'false', + 'true', + ], + }, + tooltip: '', + }, ], }); @@ -77,8 +90,9 @@ const plugin = (file, librarySettings, inputs, otherArguments) => { let audioIdx = 0; let has2Channel = false; let has6Channel = false; - let has8Channel = false; let convert = false; + let is2channelAdded = false; + let is6channelAdded = false; // Go through each stream in the file. for (let i = 0; i < file.ffProbeData.streams.length; i++) { @@ -91,9 +105,6 @@ const plugin = (file, librarySettings, inputs, otherArguments) => { if (file.ffProbeData.streams[i].channels === 6) { has6Channel = true; } - if (file.ffProbeData.streams[i].channels === 8) { - has8Channel = true; - } } } catch (err) { // Error @@ -110,23 +121,28 @@ const plugin = (file, librarySettings, inputs, otherArguments) => { if (inputs.downmix.toLowerCase() === 'true') { // Check if file has 8 channel audio but no 6 channel, if so then create extra downmix from the 8 channel. if ( - has8Channel === true + file.ffProbeData.streams[i].channels === 8 && has6Channel === false - && file.ffProbeData.streams[i].channels === 8 + && (inputs.downmix_single_track === false + || (inputs.downmix_single_track === true && is6channelAdded === false)) + ) { ffmpegCommandInsert += `-map 0:${i} -c:a:${audioIdx} ac3 -ac 6 -metadata:s:a:${audioIdx} title="5.1" `; response.infoLog += '☒Audio track is 8 channel, no 6 channel exists. Creating 6 channel from 8 channel. \n'; convert = true; + is6channelAdded = true; } // Check if file has 6 channel audio but no 2 channel, if so then create extra downmix from the 6 channel. if ( - has6Channel === true + file.ffProbeData.streams[i].channels === 6 && has2Channel === false - && file.ffProbeData.streams[i].channels === 6 + && (inputs.downmix_single_track === false + || (inputs.downmix_single_track === true && is2channelAdded === false)) ) { ffmpegCommandInsert += `-map 0:${i} -c:a:${audioIdx} aac -ac 2 -metadata:s:a:${audioIdx} title="2.0" `; response.infoLog += '☒Audio track is 6 channel, no 2 channel exists. Creating 2 channel from 6 channel. \n'; convert = true; + is2channelAdded = true; } } } catch (err) { diff --git a/tests/Community/Tdarr_Plugin_MC93_Migz5ConvertAudio.js b/tests/Community/Tdarr_Plugin_MC93_Migz5ConvertAudio.js index 9d9497c..bde178e 100644 --- a/tests/Community/Tdarr_Plugin_MC93_Migz5ConvertAudio.js +++ b/tests/Community/Tdarr_Plugin_MC93_Migz5ConvertAudio.js @@ -85,6 +85,158 @@ const tests = [ }, }, + { + input: { + file: (() => { + const file = _.cloneDeep(require('../sampleData/media/sampleH264_2.json')); + file.ffProbeData.streams[1].channels = 8; + file.ffProbeData.streams[2].channels = 8; + return file; + })(), + librarySettings: {}, + inputs: { + aac_stereo: 'false', + downmix: 'true', + }, + otherArguments: {}, + }, + output: { + processFile: true, + container: '.mkv', + handBrakeMode: false, + FFmpegMode: true, + reQueueAfter: true, + infoLog: '☒Audio track is 8 channel, no 6 channel exists. Creating 6 channel from 8 channel. \n' + + '☒Audio track is 8 channel, no 6 channel exists. Creating 6 channel from 8 channel. \n', + preset: ', -map 0 -c:v copy -c:a copy -map 0:1 -c:a:0 ac3 -ac 6 -metadata:s:a:0 title="5.1" -map 0:2 -c:a:1 ac3 -ac 6 -metadata:s:a:1 title="5.1" -strict -2 -c:s copy -max_muxing_queue_size 9999 ', + }, + }, + + { + input: { + file: (() => { + const file = _.cloneDeep(require('../sampleData/media/sampleH264_2.json')); + file.ffProbeData.streams[1].channels = 8; + file.ffProbeData.streams[2].channels = 8; + file.ffProbeData.streams[3].channels = 6; + file.ffProbeData.streams[4].channels = 6; + file.ffProbeData.streams[5].channels = 6; + return file; + })(), + librarySettings: {}, + inputs: { + aac_stereo: 'false', + downmix: 'true', + }, + otherArguments: {}, + }, + output: { + processFile: true, + container: '.mkv', + handBrakeMode: false, + FFmpegMode: true, + reQueueAfter: true, + infoLog: '☒Audio track is 6 channel, no 2 channel exists. Creating 2 channel from 6 channel. \n' + + '☒Audio track is 6 channel, no 2 channel exists. Creating 2 channel from 6 channel. \n' + + '☒Audio track is 6 channel, no 2 channel exists. Creating 2 channel from 6 channel. \n', + preset: ', -map 0 -c:v copy -c:a copy -map 0:3 -c:a:2 aac -ac 2 -metadata:s:a:2 title="2.0" -map 0:4 -c:a:3 aac -ac 2 -metadata:s:a:3 title="2.0" -map 0:5 -c:a:4 aac -ac 2 -metadata:s:a:4 title="2.0" -strict -2 -c:s copy -max_muxing_queue_size 9999 ', + }, + }, + + { + input: { + file: (() => { + const file = _.cloneDeep(require('../sampleData/media/sampleH264_2.json')); + file.ffProbeData.streams[1].channels = 8; + file.ffProbeData.streams[2].channels = 8; + file.ffProbeData.streams[3].channels = 8; + file.ffProbeData.streams[4].channels = 6; + file.ffProbeData.streams[5].channels = 6; + return file; + })(), + librarySettings: {}, + inputs: { + aac_stereo: 'false', + downmix: 'true', + downmix_single_track: 'true', + }, + otherArguments: {}, + }, + output: { + processFile: true, + container: '.mkv', + handBrakeMode: false, + FFmpegMode: true, + reQueueAfter: true, + infoLog: '☒Audio track is 6 channel, no 2 channel exists. Creating 2 channel from 6 channel. \n', + preset: ', -map 0 -c:v copy -c:a copy -map 0:4 -c:a:3 aac -ac 2 -metadata:s:a:3 title="2.0" -strict -2 -c:s copy -max_muxing_queue_size 9999 ', + }, + }, + + { + input: { + file: (() => { + const file = _.cloneDeep(require('../sampleData/media/sampleH264_2.json')); + file.ffProbeData.streams[1].channels = 8; + file.ffProbeData.streams[2].channels = 8; + file.ffProbeData.streams[3].channels = 8; + file.ffProbeData.streams[4].channels = 8; + file.ffProbeData.streams[5].channels = 8; + return file; + })(), + librarySettings: {}, + inputs: { + aac_stereo: 'false', + downmix: 'true', + downmix_single_track: 'false', + }, + otherArguments: {}, + }, + output: { + processFile: true, + container: '.mkv', + handBrakeMode: false, + FFmpegMode: true, + reQueueAfter: true, + infoLog: '☒Audio track is 8 channel, no 6 channel exists. Creating 6 channel from 8 channel. \n' + + '☒Audio track is 8 channel, no 6 channel exists. Creating 6 channel from 8 channel. \n' + + '☒Audio track is 8 channel, no 6 channel exists. Creating 6 channel from 8 channel. \n' + + '☒Audio track is 8 channel, no 6 channel exists. Creating 6 channel from 8 channel. \n' + + '☒Audio track is 8 channel, no 6 channel exists. Creating 6 channel from 8 channel. \n', + preset: ', -map 0 -c:v copy -c:a copy -map 0:1 -c:a:0 ac3 -ac 6 -metadata:s:a:0 title="5.1" -map 0:2 -c:a:1 ac3 -ac 6 -metadata:s:a:1 title="5.1" -map 0:3 -c:a:2 ac3 -ac 6 -metadata:s:a:2 title="5.1" -map 0:4 -c:a:3 ac3 -ac 6 -metadata:s:a:3 title="5.1" -map 0:5 -c:a:4 ac3 -ac 6 -metadata:s:a:4 title="5.1" -strict -2 -c:s copy -max_muxing_queue_size 9999 ', + + }, + }, + + { + input: { + file: (() => { + const file = _.cloneDeep(require('../sampleData/media/sampleH264_2.json')); + file.ffProbeData.streams[1].channels = 8; + file.ffProbeData.streams[2].channels = 8; + file.ffProbeData.streams[3].channels = 8; + file.ffProbeData.streams[4].channels = 8; + file.ffProbeData.streams[5].channels = 8; + return file; + })(), + librarySettings: {}, + inputs: { + aac_stereo: 'false', + downmix: 'true', + downmix_single_track: 'true', + }, + otherArguments: {}, + }, + output: { + processFile: true, + container: '.mkv', + handBrakeMode: false, + FFmpegMode: true, + reQueueAfter: true, + infoLog: '☒Audio track is 8 channel, no 6 channel exists. Creating 6 channel from 8 channel. \n', + preset: ', -map 0 -c:v copy -c:a copy -map 0:1 -c:a:0 ac3 -ac 6 -metadata:s:a:0 title="5.1" -strict -2 -c:s copy -max_muxing_queue_size 9999 ', + }, + }, ]; run(tests); From 5f33b981c2516e885861ddcb9042870edfcc2e20 Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Thu, 3 Aug 2023 08:10:17 +0100 Subject: [PATCH 2/5] Update tooltip --- Community/Tdarr_Plugin_MC93_Migz5ConvertAudio.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Community/Tdarr_Plugin_MC93_Migz5ConvertAudio.js b/Community/Tdarr_Plugin_MC93_Migz5ConvertAudio.js index c3de08e..6a1d8bc 100644 --- a/Community/Tdarr_Plugin_MC93_Migz5ConvertAudio.js +++ b/Community/Tdarr_Plugin_MC93_Migz5ConvertAudio.js @@ -50,7 +50,8 @@ const details = () => ({ 'true', ], }, - tooltip: '', + tooltip: 'By default this plugin will downmix each track. So four 6 channel tracks will result in four 2 channel tracks.' + + ' Enable this option to only downmix a single track.', }, ], }); From e429966de22c72a22f9b7645d2927d9b97d5a780 Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Thu, 3 Aug 2023 08:11:26 +0100 Subject: [PATCH 3/5] Fix lint issues --- Community/Tdarr_Plugin_MC93_Migz5ConvertAudio.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Community/Tdarr_Plugin_MC93_Migz5ConvertAudio.js b/Community/Tdarr_Plugin_MC93_Migz5ConvertAudio.js index 6a1d8bc..beda146 100644 --- a/Community/Tdarr_Plugin_MC93_Migz5ConvertAudio.js +++ b/Community/Tdarr_Plugin_MC93_Migz5ConvertAudio.js @@ -50,7 +50,8 @@ const details = () => ({ 'true', ], }, - tooltip: 'By default this plugin will downmix each track. So four 6 channel tracks will result in four 2 channel tracks.' + tooltip: 'By default this plugin will downmix each track. ' + + 'So four 6 channel tracks will result in four 2 channel tracks.' + ' Enable this option to only downmix a single track.', }, ], From 2f10ece96ea4f72b6f9b2148d1a445a1b82c45b7 Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Tue, 8 Aug 2023 05:23:57 +0100 Subject: [PATCH 4/5] Add dropdowns to plugin and update tests --- .../Tdarr_Plugin_MC93_Migz5ConvertAudio.js | 25 +++++++++++-------- .../Tdarr_Plugin_MC93_Migz5ConvertAudio.js | 2 +- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/Community/Tdarr_Plugin_MC93_Migz5ConvertAudio.js b/Community/Tdarr_Plugin_MC93_Migz5ConvertAudio.js index beda146..39fdd6d 100644 --- a/Community/Tdarr_Plugin_MC93_Migz5ConvertAudio.js +++ b/Community/Tdarr_Plugin_MC93_Migz5ConvertAudio.js @@ -10,11 +10,12 @@ const details = () => ({ Tags: 'pre-processing,ffmpeg,audio only,configurable', Inputs: [{ name: 'aac_stereo', - type: 'string', - defaultValue: '', - inputUI: { - type: 'text', - }, + type: 'boolean', + defaultValue: false, + options: [ + 'false', + 'true', + ], tooltip: `Specify if any 2.0 audio tracks should be converted to aac for maximum compatability with devices. \\nOptional. \\nExample:\\n @@ -25,10 +26,14 @@ const details = () => ({ }, { name: 'downmix', - type: 'string', - defaultValue: '', + type: 'boolean', + defaultValue: false, inputUI: { - type: 'text', + type: 'dropdown', + options: [ + 'false', + 'true', + ], }, tooltip: `Specify if downmixing should be used to create extra audio tracks. \\nI.e if you have an 8ch but no 2ch or 6ch, create the missing audio tracks from the 8 ch. @@ -120,7 +125,7 @@ const plugin = (file, librarySettings, inputs, otherArguments) => { // Catch error here incase user left inputs.downmix empty. try { // Check if inputs.downmix is set to true. - if (inputs.downmix.toLowerCase() === 'true') { + if (inputs.downmix === true) { // Check if file has 8 channel audio but no 6 channel, if so then create extra downmix from the 8 channel. if ( file.ffProbeData.streams[i].channels === 8 @@ -154,7 +159,7 @@ const plugin = (file, librarySettings, inputs, otherArguments) => { // Catch error here incase user left inputs.downmix empty. try { // Check if inputs.aac_stereo is set to true. - if (inputs.aac_stereo === 'true') { + if (inputs.aac_stereo === true) { // Check if codec_name for stream is NOT aac AND check if channel ammount is 2. if ( file.ffProbeData.streams[i].codec_name !== 'aac' diff --git a/tests/Community/Tdarr_Plugin_MC93_Migz5ConvertAudio.js b/tests/Community/Tdarr_Plugin_MC93_Migz5ConvertAudio.js index bde178e..b8b4a14 100644 --- a/tests/Community/Tdarr_Plugin_MC93_Migz5ConvertAudio.js +++ b/tests/Community/Tdarr_Plugin_MC93_Migz5ConvertAudio.js @@ -16,7 +16,7 @@ const tests = [ handBrakeMode: false, FFmpegMode: true, reQueueAfter: true, - infoLog: '☒Plugin has not been configured, please configure required options. Skipping this plugin. \n', + infoLog: '☑File contains all required audio formats. \n', }, }, From 7c92b2236e6d76bc45afe7c4a28433f0bf5301c4 Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Tue, 8 Aug 2023 05:27:15 +0100 Subject: [PATCH 5/5] Fix inputUI --- Community/Tdarr_Plugin_MC93_Migz5ConvertAudio.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Community/Tdarr_Plugin_MC93_Migz5ConvertAudio.js b/Community/Tdarr_Plugin_MC93_Migz5ConvertAudio.js index 39fdd6d..dae6c01 100644 --- a/Community/Tdarr_Plugin_MC93_Migz5ConvertAudio.js +++ b/Community/Tdarr_Plugin_MC93_Migz5ConvertAudio.js @@ -12,10 +12,13 @@ const details = () => ({ name: 'aac_stereo', type: 'boolean', defaultValue: false, - options: [ - 'false', - 'true', - ], + inputUI: { + type: 'dropdown', + options: [ + 'false', + 'true', + ], + }, tooltip: `Specify if any 2.0 audio tracks should be converted to aac for maximum compatability with devices. \\nOptional. \\nExample:\\n