Add option to overwriteTrack true/false (#215)

make-only-subtitle-default
HaveAGitGat 4 years ago committed by GitHub
parent ebb022f80a
commit 5c0dd11ec5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,86 +1,119 @@
const loadDefaultValues = require('../methods/loadDefaultValues');
/* eslint-disable */
const details = () => {
return {
id: "Tdarr_Plugin_b39x_the1poet_surround_sound_to_ac3",
Stage: "Pre-processing",
Name: "the1poet Video surround sound to ac3",
Type: "Video",
Operation: 'Transcode',
Description: `[Contains built-in filter] If the file has surround sound tracks not in ac3, they will be converted to ac3. \n\n
const details = () => ({
id: 'Tdarr_Plugin_b39x_the1poet_surround_sound_to_ac3',
Stage: 'Pre-processing',
Name: 'the1poet Video surround sound to ac3',
Type: 'Video',
Operation: 'Transcode',
Description: '[Contains built-in filter] If the file has surround sound tracks not in ac3,'
+ ` they will be converted to ac3. \n\n
`,
Version: "1.00",
Tags: "pre-processing,ffmpeg,audio only,",
Inputs:[]
};
}
Version: '1.01',
Tags: 'pre-processing,ffmpeg,audio only,',
Inputs: [
{
name: 'overwriteTrack',
type: 'boolean',
defaultValue: true,
inputUI: {
type: 'dropdown',
options: [
'false',
'true',
],
},
tooltip: 'Specify if you\'d like to overwrite the existing track or keep'
+ 'it and have a new stream be created (default: true)',
},
],
});
// eslint-disable-next-line no-unused-vars
const plugin = (file, librarySettings, inputs, otherArguments) => {
// eslint-disable-next-line no-unused-vars,no-param-reassign
inputs = loadDefaultValues(inputs, details);
//Must return this object
// Must return this object
var response = {
const response = {
processFile: false,
preset: "",
container: ".mp4",
preset: '',
container: '.mp4',
handBrakeMode: false,
FFmpegMode: false,
reQueueAfter: false,
infoLog: "",
infoLog: '',
};
if (file.fileMedium !== "video") {
console.log("File is not video");
if (file.fileMedium !== 'video') {
// eslint-disable-next-line no-console
console.log('File is not video');
response.infoLog += "☒File is not video \n";
response.infoLog += '☒File is not video \n';
response.processFile = false;
return response;
} else {
var audioIdx = -1;
var ffmpegCommandInsert = "";
var hasnonAC3SurroundTrack = false;
}
let audioIdx = -1;
let ffmpegCommandInsert = '';
let hasnonAC3SurroundTrack = false;
for (var i = 0; i < file.ffProbeData.streams.length; i++) {
try {
if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio") {
audioIdx++;
}
} catch (err) {}
let shouldTranscode = true;
if (inputs.overwriteTrack === false) {
const hasAc3_6Stream = file.ffProbeData.streams.filter((row) => row.channels === 6
&& row.codec_name === 'ac3');
if (hasAc3_6Stream.length > 0) {
shouldTranscode = false;
}
}
try {
if (
file.ffProbeData.streams[i].channels == 6 &&
file.ffProbeData.streams[i].codec_name !== "ac3" &&
file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio"
) {
for (let i = 0; i < file.ffProbeData.streams.length; i += 1) {
const currStream = file.ffProbeData.streams[i];
try {
if (currStream.codec_type.toLowerCase() === 'audio') {
audioIdx += 1;
}
} catch (err) {
// eslint-disable-next-line no-console
console.log(err);
}
try {
if (
currStream.channels === 6
&& currStream.codec_name !== 'ac3'
&& currStream.codec_type.toLowerCase() === 'audio'
) {
if (inputs.overwriteTrack === true) {
ffmpegCommandInsert += ` -c:a:${audioIdx} ac3 `;
hasnonAC3SurroundTrack = true;
} else {
ffmpegCommandInsert += `-map 0:a:${audioIdx} -c:a:${audioIdx} ac3 `;
}
} catch (err) {}
hasnonAC3SurroundTrack = true;
}
} catch (err) {
// eslint-disable-next-line no-console
console.log(err);
}
}
var ffmpegCommand = `,-map 0 -c:v copy -c:a copy ${ffmpegCommandInsert} -c:s copy -c:d copy`;
if (hasnonAC3SurroundTrack == true) {
response.processFile = true;
response.preset = ffmpegCommand;
response.container = "." + file.container;
response.handBrakeMode = false;
response.FFmpegMode = true;
response.reQueueAfter = true;
response.infoLog += "☒ File has surround audio which is NOT in ac3! \n";
return response;
} else {
response.infoLog += "☑ All surround audio streams are in ac3! \n";
}
const ffmpegCommand = `,-map 0 -c:v copy -c:a copy ${ffmpegCommandInsert} -c:s copy -c:d copy`;
response.infoLog += "☑File meets conditions! \n";
if (shouldTranscode && hasnonAC3SurroundTrack === true) {
response.processFile = true;
response.preset = ffmpegCommand;
response.container = `.${file.container}`;
response.handBrakeMode = false;
response.FFmpegMode = true;
response.reQueueAfter = true;
response.infoLog += '☒ File has surround audio which is NOT in ac3! \n';
return response;
}
}
response.infoLog += '☑ All surround audio streams are in ac3! \n';
response.infoLog += '☑File meets conditions! \n';
return response;
};
module.exports.details = details;
module.exports.plugin = plugin;

Loading…
Cancel
Save