forked from HaveAGitGat/Tdarr_Plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Tdarr_Plugin_00td_action_remove_audio_by_channel_count
- Loading branch information
1 parent
b13151d
commit 4190809
Showing
2 changed files
with
199 additions
and
0 deletions.
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
Community/Tdarr_Plugin_00td_action_remove_audio_by_channel_count.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
const details = () => ({ | ||
id: 'Tdarr_Plugin_00td_action_remove_audio_by_channel_count', | ||
Stage: 'Pre-processing', | ||
Name: 'Remove audio streams by channel count', | ||
Type: 'Video', | ||
Operation: 'Transcode', | ||
Description: ` | ||
This plugin removes audio streams based on channel count. The output container is the same as the original. | ||
`, | ||
Version: '1.00', | ||
Tags: 'action', | ||
Inputs: [ | ||
{ | ||
name: 'channelCounts', | ||
type: 'string', | ||
defaultValue: '', | ||
inputUI: { | ||
type: 'text', | ||
}, | ||
tooltip: | ||
'Enter the the channel counts to remove', | ||
}, | ||
], | ||
}); | ||
|
||
// eslint-disable-next-line no-unused-vars | ||
const plugin = (file, librarySettings, inputs, otherArguments) => { | ||
const lib = require('../methods/lib')(); | ||
// eslint-disable-next-line no-unused-vars,no-param-reassign | ||
inputs = lib.loadDefaultValues(inputs, details); | ||
const response = { | ||
processFile: false, | ||
preset: '', | ||
container: `.${file.container}`, | ||
handBrakeMode: false, | ||
FFmpegMode: true, | ||
reQueueAfter: false, | ||
infoLog: '', | ||
}; | ||
|
||
if (inputs.channelCounts.trim() === '') { | ||
response.infoLog += 'No input entered in plugin, skipping'; | ||
return response; | ||
} | ||
|
||
const audioStreams = file.ffProbeData.streams.filter((row) => row.codec_type === 'audio'); | ||
|
||
if (audioStreams.length === 0) { | ||
response.infoLog += 'File has no audio streams, skipping plugin'; | ||
return response; | ||
} | ||
|
||
if (audioStreams.length === 1) { | ||
response.infoLog += 'File only has 1 audio stream, skipping plugin'; | ||
return response; | ||
} | ||
|
||
response.preset += ', -map 0 -c copy -max_muxing_queue_size 9999'; | ||
|
||
const audioToRemove = []; | ||
const channelCounts = inputs.channelCounts.trim().split(','); | ||
|
||
for (let i = 0; i < channelCounts.length; i += 1) { | ||
const channelCount = parseInt(channelCounts[i], 10); | ||
for (let j = 0; j < audioStreams.length; j += 1) { | ||
if (channelCount === audioStreams[j].channels) { | ||
audioToRemove.push(audioStreams[j]); | ||
} | ||
} | ||
} | ||
|
||
if (audioToRemove.length === 0) { | ||
response.infoLog += 'No audio streams to remove!'; | ||
return response; | ||
} | ||
|
||
if (audioToRemove.length === audioStreams.length) { | ||
response.infoLog += 'The number of audio streams to remove equals ' | ||
+ 'the total number of audio streams, skipping plugin'; | ||
return response; | ||
} | ||
|
||
audioToRemove.forEach((row) => { | ||
response.preset += ` -map -0:${row.index} `; | ||
response.infoLog += ` Removing stream ${row.index} which has ${row.channels} channels.`; | ||
}); | ||
|
||
response.processFile = true; | ||
return response; | ||
}; | ||
|
||
module.exports.details = details; | ||
module.exports.plugin = plugin; |
106 changes: 106 additions & 0 deletions
106
tests/Community/Tdarr_Plugin_00td_action_remove_audio_by_channel_count.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* eslint max-len: 0 */ | ||
const _ = require('lodash'); | ||
const run = require('../helpers/run'); | ||
|
||
const tests = [ | ||
{ | ||
input: { | ||
file: _.cloneDeep(require('../sampleData/media/sampleH264_1.json')), | ||
librarySettings: {}, | ||
inputs: {}, | ||
otherArguments: {}, | ||
}, | ||
output: { | ||
processFile: false, | ||
preset: '', | ||
container: '.mp4', | ||
handBrakeMode: false, | ||
FFmpegMode: true, | ||
reQueueAfter: false, | ||
infoLog: 'No input entered in plugin, skipping', | ||
}, | ||
}, | ||
{ | ||
input: { | ||
file: _.cloneDeep(require('../sampleData/media/sampleH264_1.json')), | ||
librarySettings: {}, | ||
inputs: { | ||
channelCounts: '8', | ||
}, | ||
otherArguments: {}, | ||
}, | ||
output: { | ||
processFile: false, | ||
preset: '', | ||
container: '.mp4', | ||
handBrakeMode: false, | ||
FFmpegMode: true, | ||
reQueueAfter: false, | ||
infoLog: 'File only has 1 audio stream, skipping plugin', | ||
}, | ||
}, | ||
{ | ||
input: { | ||
file: _.cloneDeep(require('../sampleData/media/sampleH264_2.json')), | ||
librarySettings: {}, | ||
inputs: { | ||
channelCounts: '8', | ||
}, | ||
otherArguments: {}, | ||
}, | ||
output: { | ||
processFile: false, | ||
preset: ', -map 0 -c copy -max_muxing_queue_size 9999', | ||
container: '.mkv', | ||
handBrakeMode: false, | ||
FFmpegMode: true, | ||
reQueueAfter: false, | ||
infoLog: 'No audio streams to remove!', | ||
}, | ||
}, | ||
{ | ||
input: { | ||
file: _.cloneDeep(require('../sampleData/media/sampleH264_2.json')), | ||
librarySettings: {}, | ||
inputs: { | ||
channelCounts: '2', | ||
}, | ||
otherArguments: {}, | ||
}, | ||
output: { | ||
processFile: false, | ||
preset: ', -map 0 -c copy -max_muxing_queue_size 9999', | ||
container: '.mkv', | ||
handBrakeMode: false, | ||
FFmpegMode: true, | ||
reQueueAfter: false, | ||
infoLog: 'The number of audio streams to remove equals the total number of audio streams, skipping plugin', | ||
}, | ||
}, | ||
{ | ||
input: { | ||
file: (() => { | ||
const file = _.cloneDeep(require('../sampleData/media/sampleH264_2.json')); | ||
file.ffProbeData.streams[1].channels = 8; | ||
file.ffProbeData.streams[2].channels = 6; | ||
return file; | ||
})(), | ||
librarySettings: {}, | ||
inputs: { | ||
channelCounts: '8,6', | ||
}, | ||
otherArguments: {}, | ||
}, | ||
output: { | ||
processFile: true, | ||
preset: ', -map 0 -c copy -max_muxing_queue_size 9999 -map -0:1 -map -0:2 ', | ||
container: '.mkv', | ||
handBrakeMode: false, | ||
FFmpegMode: true, | ||
reQueueAfter: false, | ||
infoLog: ' Removing stream 1 which has 8 channels. Removing stream 2 which has 6 channels.', | ||
}, | ||
}, | ||
]; | ||
|
||
run(tests); |