From aa840354ff903d247d54521c5e54e8e89523dfe5 Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Wed, 25 May 2022 08:47:36 +0100 Subject: [PATCH] Fix bug when video is not first --- ...darr_Plugin_076a_re_order_audio_streams.js | 4 +- ...darr_Plugin_076a_re_order_audio_streams.js | 53 +++++++++++++++++-- 2 files changed, 51 insertions(+), 6 deletions(-) diff --git a/Community/Tdarr_Plugin_076a_re_order_audio_streams.js b/Community/Tdarr_Plugin_076a_re_order_audio_streams.js index 77835ca..8b3ecc7 100644 --- a/Community/Tdarr_Plugin_076a_re_order_audio_streams.js +++ b/Community/Tdarr_Plugin_076a_re_order_audio_streams.js @@ -100,9 +100,7 @@ const plugin = (file, librarySettings, inputs, otherArguments) => { var ffmpegCommand = ", -c copy"; - if (file.ffProbeData.streams[0].codec_type.toLowerCase() == "video") { - ffmpegCommand += ` -map 0:v `; - } + ffmpegCommand += ` -map 0:v? `; var allAudioTracks = file.ffProbeData.streams.filter( (stream) => stream.codec_type.toLowerCase() == "audio" diff --git a/tests/Community/Tdarr_Plugin_076a_re_order_audio_streams.js b/tests/Community/Tdarr_Plugin_076a_re_order_audio_streams.js index 95a1b47..2f226dc 100644 --- a/tests/Community/Tdarr_Plugin_076a_re_order_audio_streams.js +++ b/tests/Community/Tdarr_Plugin_076a_re_order_audio_streams.js @@ -1,10 +1,11 @@ /* eslint max-len: 0 */ +const _ = require('lodash'); const run = require('../helpers/run'); const tests = [ { input: { - file: require('../sampleData/media/sampleH264_2.json'), + file: _.cloneDeep(require('../sampleData/media/sampleH264_2.json')), librarySettings: {}, inputs: {}, otherArguments: {}, @@ -21,7 +22,7 @@ const tests = [ }, { input: { - file: require('../sampleData/media/sampleH264_2.json'), + file: _.cloneDeep(require('../sampleData/media/sampleH264_2.json')), librarySettings: {}, inputs: { preferred_language: 'fre', @@ -30,7 +31,53 @@ const tests = [ }, output: { processFile: true, - preset: ', -c copy -map 0:v -map 0:a:3 -disposition:a:0 default -map 0:a:0 -map 0:a:1 -disposition:a:1 0 -map 0:a:2 -disposition:a:2 0 -disposition:a:3 0 -map 0:a:4 -disposition:a:4 0 -map 0:s? -map 0:d? ', + preset: ', -c copy -map 0:v? -map 0:a:3 -disposition:a:0 default -map 0:a:0 -map 0:a:1 -disposition:a:1 0 -map 0:a:2 -disposition:a:2 0 -disposition:a:3 0 -map 0:a:4 -disposition:a:4 0 -map 0:s? -map 0:d? ', + container: '.mkv', + handBrakeMode: false, + FFmpegMode: true, + reQueueAfter: true, + infoLog: '☒ Desired audio lang is not first audio stream, moving! \n', + }, + }, + { + input: { + file: (() => { + const file = _.cloneDeep(require('../sampleData/media/sampleH264_2.json')); + file.ffProbeData.streams[0].codec_type = 'audio'; + return file; + })(), + librarySettings: {}, + inputs: { + preferred_language: 'fre', + }, + otherArguments: {}, + }, + output: { + processFile: false, + preset: '', + container: '.mp4', + handBrakeMode: false, + FFmpegMode: false, + reQueueAfter: false, + infoLog: '☑ Preferred language is already first audio track! \n', + }, + }, + { + input: { + file: (() => { + const file = _.cloneDeep(require('../sampleData/media/sampleH264_2.json')); + file.ffProbeData.streams[0].codec_type = 'audio'; + return file; + })(), + librarySettings: {}, + inputs: { + preferred_language: 'eng', + }, + otherArguments: {}, + }, + output: { + processFile: true, + preset: ', -c copy -map 0:v? -map 0:a:1 -disposition:a:0 default -map 0:a:0 -disposition:a:1 0 -map 0:a:2 -disposition:a:2 0 -map 0:a:3 -disposition:a:3 0 -map 0:a:4 -disposition:a:4 0 -map 0:a:5 -disposition:a:5 0 -map 0:s? -map 0:d? ', container: '.mkv', handBrakeMode: false, FFmpegMode: true,