Add option to overwriteTrack true/false (#215)
parent
ebb022f80a
commit
5c0dd11ec5
@ -1,86 +1,119 @@
|
|||||||
const loadDefaultValues = require('../methods/loadDefaultValues');
|
const loadDefaultValues = require('../methods/loadDefaultValues');
|
||||||
/* eslint-disable */
|
|
||||||
const details = () => {
|
const details = () => ({
|
||||||
return {
|
id: 'Tdarr_Plugin_b39x_the1poet_surround_sound_to_ac3',
|
||||||
id: "Tdarr_Plugin_b39x_the1poet_surround_sound_to_ac3",
|
Stage: 'Pre-processing',
|
||||||
Stage: "Pre-processing",
|
Name: 'the1poet Video surround sound to ac3',
|
||||||
Name: "the1poet Video surround sound to ac3",
|
Type: 'Video',
|
||||||
Type: "Video",
|
Operation: 'Transcode',
|
||||||
Operation: 'Transcode',
|
Description: '[Contains built-in filter] If the file has surround sound tracks not in ac3,'
|
||||||
Description: `[Contains built-in filter] If the file has surround sound tracks not in ac3, they will be converted to ac3. \n\n
|
+ ` they will be converted to ac3. \n\n
|
||||||
`,
|
`,
|
||||||
Version: "1.00",
|
Version: '1.01',
|
||||||
Tags: "pre-processing,ffmpeg,audio only,",
|
Tags: 'pre-processing,ffmpeg,audio only,',
|
||||||
Inputs:[]
|
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
|
// eslint-disable-next-line no-unused-vars
|
||||||
const plugin = (file, librarySettings, inputs, otherArguments) => {
|
const plugin = (file, librarySettings, inputs, otherArguments) => {
|
||||||
// eslint-disable-next-line no-unused-vars,no-param-reassign
|
// eslint-disable-next-line no-unused-vars,no-param-reassign
|
||||||
inputs = loadDefaultValues(inputs, details);
|
inputs = loadDefaultValues(inputs, details);
|
||||||
//Must return this object
|
// Must return this object
|
||||||
|
|
||||||
var response = {
|
const response = {
|
||||||
processFile: false,
|
processFile: false,
|
||||||
preset: "",
|
preset: '',
|
||||||
container: ".mp4",
|
container: '.mp4',
|
||||||
handBrakeMode: false,
|
handBrakeMode: false,
|
||||||
FFmpegMode: false,
|
FFmpegMode: false,
|
||||||
reQueueAfter: false,
|
reQueueAfter: false,
|
||||||
infoLog: "",
|
infoLog: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
if (file.fileMedium !== "video") {
|
if (file.fileMedium !== 'video') {
|
||||||
console.log("File is not 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;
|
response.processFile = false;
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
} else {
|
}
|
||||||
var audioIdx = -1;
|
let audioIdx = -1;
|
||||||
var ffmpegCommandInsert = "";
|
let ffmpegCommandInsert = '';
|
||||||
var hasnonAC3SurroundTrack = false;
|
let hasnonAC3SurroundTrack = false;
|
||||||
|
|
||||||
for (var i = 0; i < file.ffProbeData.streams.length; i++) {
|
let shouldTranscode = true;
|
||||||
try {
|
if (inputs.overwriteTrack === false) {
|
||||||
if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio") {
|
const hasAc3_6Stream = file.ffProbeData.streams.filter((row) => row.channels === 6
|
||||||
audioIdx++;
|
&& row.codec_name === 'ac3');
|
||||||
}
|
if (hasAc3_6Stream.length > 0) {
|
||||||
} catch (err) {}
|
shouldTranscode = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
for (let i = 0; i < file.ffProbeData.streams.length; i += 1) {
|
||||||
if (
|
const currStream = file.ffProbeData.streams[i];
|
||||||
file.ffProbeData.streams[i].channels == 6 &&
|
try {
|
||||||
file.ffProbeData.streams[i].codec_name !== "ac3" &&
|
if (currStream.codec_type.toLowerCase() === 'audio') {
|
||||||
file.ffProbeData.streams[i].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 `;
|
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`;
|
const 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";
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
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.details = details;
|
||||||
module.exports.plugin = plugin;
|
module.exports.plugin = plugin;
|
||||||
|
|||||||
Loading…
Reference in new issue