Migz Plugins

1. Made changes to all plugins following lint testing. There are still various warnings/errors but my very limited knowledge of javascript means I just don't understand what the errors mean. Or in some cases I don't understand how to split the variable across several lines to confirm to the line limits.
I did manage to get it from
952 problems (943 errors, 9 warnings)
down to
37 problems (28 errors, 9 warnings)

2. Fix Flawed logic in FFMPEG plugins which would cause remux conditions to never trigger. Was checking if file was HEVC & VP9 which is impossible as they're both codecs.

3. Fixed a bug with CleanTitle where plugin would fail if a stream in the file didn't have a title.

4. Modify CleanSubtitle plugin to not remove sdh subtitles.

5. Include new plugin to just perform remuxes. Mainly aimed at remuxing to mkv or mp4.
This commit is contained in:
Migz93 2020-12-14 17:33:17 +00:00
parent e9370ffe7c
commit 864cf41f1d
10 changed files with 1136 additions and 882 deletions

View file

@ -1,185 +1,201 @@
/* eslint-disable */
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
function details() {
return {
id: "Tdarr_Plugin_MC93_Migz6OrderStreams",
Stage: "Pre-processing",
Name: "Migz-Order Streams",
Type: "Streams",
Operation: "Order",
Description: `Orders streams into Video first, then Audio (2ch, 6ch, 8ch) and finally Subtitles. \n\n`,
Version: "1.2",
id: 'Tdarr_Plugin_MC93_Migz6OrderStreams',
Stage: 'Pre-processing',
Name: 'Migz-Order Streams',
Type: 'Streams',
Operation: 'Order',
Description: 'Orders streams into Video first, then Audio (2ch, 6ch, 8ch) and finally Subtitles. \n\n',
Version: '1.3',
Link:
"https://github.com/HaveAGitGat/Tdarr_Plugins/blob/master/Community/Tdarr_Plugin_MC93_Migz6OrderStreams.js",
Tags: "pre-processing,ffmpeg,",
'https://github.com/HaveAGitGat/Tdarr_Plugins/blob/master/Community/Tdarr_Plugin_MC93_Migz6OrderStreams.js',
Tags: 'pre-processing,ffmpeg,',
};
}
function plugin(file) {
var response = {
const response = {
processFile: false,
preset: "",
container: "." + file.container,
preset: '',
container: `.${file.container}`,
handBrakeMode: false,
FFmpegMode: true,
infoLog: "",
infoLog: '',
};
// Set up required variables.
var ffmpegCommandInsert = "";
var videoIdx = 0;
var audioIdx = 0;
var audio2Idx = 0;
var audio6Idx = 0;
var audio8Idx = 0;
var subtitleIdx = 0;
var convert = false;
let ffmpegCommandInsert = '';
let audioIdx = 0;
let audio6Idx = 0;
let audio8Idx = 0;
let subtitleIdx = 0;
let convert = false;
// Go through each stream in the file.
for (var i = 0; i < file.ffProbeData.streams.length; i++) {
for (let i = 0; i < file.ffProbeData.streams.length; i++) {
try {
// Check if stream is video.
if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "video") {
// Check if audioIdx or subtitleIdx do NOT equal 0, if they do then it means a audio or subtitle track has already appeared before the video track so file needs to be organized.
if (audioIdx != "0" || subtitleIdx != "0") {
if (file.ffProbeData.streams[i].codec_type.toLowerCase() === 'video') {
// Check if audioIdx or subtitleIdx do NOT equal 0
// If so then it means a audio or subtitle track has already appeared before the video track
// So file needs to be organized.
if (audioIdx !== '0' || subtitleIdx !== '0') {
convert = true;
response.infoLog += "☒ Video not first. \n";
response.infoLog += '☒ Video not first. \n';
}
// Increment videoIdx.
videoIdx++;
}
// Check if stream is audio.
if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio") {
// Check if subtitleIdx does NOT equal 0, if it does then it means a subtitle track has already appeared before an audio track so file needs to be organized.
if (subtitleIdx != "0") {
if (file.ffProbeData.streams[i].codec_type.toLowerCase() === 'audio') {
// Check if subtitleIdx does NOT equal 0.
// If so then it means a subtitle track has already appeared before an audio track
// So file needs to be organized.
if (subtitleIdx !== '0') {
convert = true;
response.infoLog += "☒ Audio not second. \n";
response.infoLog += '☒ Audio not second. \n';
}
// Increment audioIdx.
audioIdx++;
audioIdx += 1;
// Check if audio track is 2 channel.
if (file.ffProbeData.streams[i].channels == "2") {
// Check if audio6Idx or audio8Idx do NOT equal 0, if they do then it means a 6 channel or 8 channel audio track has already appeared before the 2 channel audio track so file needs to be organized.
if (audio6Idx != "0" || audio8Idx != "0") {
if (file.ffProbeData.streams[i].channels === '2') {
// Check if audio6Idx or audio8Idx do NOT equal 0.
// If so then it means a 6 or 8 channel audio track has already appeared before the 2 channel audio track
// So file needs to be organized.
if (audio6Idx !== '0' || audio8Idx !== '0') {
convert = true;
response.infoLog += "☒ Audio 2ch not first. \n";
response.infoLog += '☒ Audio 2ch not first. \n';
}
// Increment audio2Idx.
audio2Idx++;
}
// Check if audio track is 6 channel.
if (file.ffProbeData.streams[i].channels == "6") {
// Check if audio8Idx does NOT equal 0, if it does then it means a 8 channel audio track has already appeared before the 6 channel audio track so file needs to be organized.
if (audio8Idx != "0") {
if (file.ffProbeData.streams[i].channels === '6') {
// Check if audio8Idx does NOT equal 0.
// If so then it means a 8 channel audio track has already appeared before the 6 channel audio track
// So file needs to be organized.
if (audio8Idx !== '0') {
convert = true;
response.infoLog += "☒ Audio 6ch not second. \n";
response.infoLog += '☒ Audio 6ch not second. \n';
}
// Increment audio6Idx.
audio6Idx++;
audio6Idx += 1;
}
// Check if audio track is 8 channel.
if (file.ffProbeData.streams[i].channels == "8") {
if (file.ffProbeData.streams[i].channels === '8') {
// Increment audio8Idx.
audio8Idx++;
audio8Idx += 1;
}
}
// Check if stream is subtitle.
if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "subtitle") {
if (file.ffProbeData.streams[i].codec_type.toLowerCase() === 'subtitle') {
// Increment subtitleIdx
subtitleIdx++;
subtitleIdx += 1;
}
} catch (err) {}
} catch (err) {
// Error
}
}
// Go through each stream in the file.
for (var i = 0; i < file.ffProbeData.streams.length; i++) {
for (let i = 0; i < file.ffProbeData.streams.length; i++) {
try {
// Check if stream is video AND is not a mjpeg.
if (
file.ffProbeData.streams[i].codec_type.toLowerCase() == "video" &&
file.ffProbeData.streams[i].codec_name.toLowerCase() != "mjpeg"
file.ffProbeData.streams[i].codec_type.toLowerCase() === 'video'
&& file.ffProbeData.streams[i].codec_name.toLowerCase() !== 'mjpeg'
) {
ffmpegCommandInsert += `-map 0:${i} `;
}
} catch (err) {}
} catch (err) {
// Error
}
}
// Go through each stream in the file.
for (var i = 0; i < file.ffProbeData.streams.length; i++) {
for (let i = 0; i < file.ffProbeData.streams.length; i++) {
try {
// Check if stream is audio AND 2 channel.
if (
file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio" &&
file.ffProbeData.streams[i].channels == "2"
file.ffProbeData.streams[i].codec_type.toLowerCase() === 'audio'
&& file.ffProbeData.streams[i].channels === '2'
) {
ffmpegCommandInsert += `-map 0:${i} `;
}
} catch (err) {}
} catch (err) {
// Error
}
}
// Go through each stream in the file.
for (var i = 0; i < file.ffProbeData.streams.length; i++) {
for (let i = 0; i < file.ffProbeData.streams.length; i++) {
try {
// Check if stream is audio AND 6 channel.
if (
file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio" &&
file.ffProbeData.streams[i].channels == "6"
file.ffProbeData.streams[i].codec_type.toLowerCase() === 'audio'
&& file.ffProbeData.streams[i].channels === '6'
) {
ffmpegCommandInsert += `-map 0:${i} `;
}
} catch (err) {}
} catch (err) {
// Error
}
}
// Go through each stream in the file.
for (var i = 0; i < file.ffProbeData.streams.length; i++) {
for (let i = 0; i < file.ffProbeData.streams.length; i++) {
try {
// Check if stream is audio AND 8 channel.
if (
file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio" &&
file.ffProbeData.streams[i].channels == "8"
file.ffProbeData.streams[i].codec_type.toLowerCase() === 'audio'
&& file.ffProbeData.streams[i].channels === '8'
) {
ffmpegCommandInsert += `-map 0:${i} `;
}
} catch (err) {}
} catch (err) {
// Error
}
}
// Go through each stream in the file.
for (var i = 0; i < file.ffProbeData.streams.length; i++) {
for (let i = 0; i < file.ffProbeData.streams.length; i++) {
try {
// Check if stream is audio AND not 2, 6 or 8 channel.
if (
file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio" &&
file.ffProbeData.streams[i].channels != "2" &&
file.ffProbeData.streams[i].channels != "6" &&
file.ffProbeData.streams[i].channels != "8"
file.ffProbeData.streams[i].codec_type.toLowerCase() === 'audio'
&& file.ffProbeData.streams[i].channels !== '2'
&& file.ffProbeData.streams[i].channels !== '6'
&& file.ffProbeData.streams[i].channels !== '8'
) {
ffmpegCommandInsert += `-map 0:${i} `;
}
} catch (err) {}
} catch (err) {
// Error
}
}
// Go through each stream in the file.
for (var i = 0; i < file.ffProbeData.streams.length; i++) {
for (let i = 0; i < file.ffProbeData.streams.length; i++) {
try {
// Check if stream is subtitle.
if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "subtitle") {
if (file.ffProbeData.streams[i].codec_type.toLowerCase() === 'subtitle') {
ffmpegCommandInsert += `-map 0:${i} `;
}
} catch (err) {}
} catch (err) {
// Error
}
}
// Convert file if convert variable is set to true.
if (convert == true) {
if (convert === true) {
response.processFile = true;
response.preset = `,${ffmpegCommandInsert} -c copy -max_muxing_queue_size 9999`;
response.reQueueAfter = true;
response.infoLog +=
"☒ Streams are out of order, reorganizing streams. Video, Audio, Subtitles. \n";
response.infoLog
+= '☒ Streams are out of order, reorganizing streams. Video, Audio, Subtitles. \n';
} else {
response.infoLog += "☑ Streams are in expected order. \n ";
response.infoLog += '☑ Streams are in expected order. \n ';
response.processFile = false;
}
return response;