make-only-subtitle-default
HaveAGitGat 6 years ago
commit e2c9e83b57

@ -1,162 +1,178 @@
function details() { function details() {
return { return {
id: "Tdarr_Plugin_MC93_Migz1FFMPEG", id: "Tdarr_Plugin_MC93_Migz1FFMPEG",
Stage: "Pre-processing", Stage: "Pre-processing",
Name: "Migz-Transcode Using Nvidia GPU & FFMPEG", Name: "Migz-Transcode Using Nvidia GPU & FFMPEG",
Type: "Video", Type: "Video",
Operation:"Transcode", Operation: "Transcode",
Description: `Files will be transcoded using Nvidia GPU with ffmpeg, settings are dependant on file bitrate, working by the logic that H265 can support the same ammount of data at half the bitrate of H264. NVDEC & NVENC compatable GPU required. \n\n`, Description: `Files not in H265 will be transcoded into H265 using Nvidia GPU with ffmpeg, settings are dependant on file bitrate, working by the logic that H265 can support the same ammount of data at half the bitrate of H264. NVDEC & NVENC compatable GPU required. \n\n`,
Version: "2.20", Version: "2.4",
Link: "https://github.com/HaveAGitGat/Tdarr_Plugins/blob/master/Community/Tdarr_Plugin_MC93_Migz1FFMPEG.js", Link: "https://github.com/HaveAGitGat/Tdarr_Plugins/blob/master/Community/Tdarr_Plugin_MC93_Migz1FFMPEG.js",
Tags:'pre-processing,ffmpeg,video only,nvenc h265,configurable', Tags: 'pre-processing,ffmpeg,video only,nvenc h265,configurable',
Inputs: [ Inputs: [{
{ name: 'container',
name: 'container', tooltip: `Specify output container of file, ensure that all stream types you may have are supported by your chosen container. mkv is recommended.
tooltip: `Specify output container of file, ensure that all stream types you may have are supported by your chosen container. mkv is recommended. \\nExample:\\n
\\nExample:\\n mkv
mkv
\\nExample:\\n
\\nExample:\\n mp4`
mp4`
},
}, {
{ name: 'bitrate_cutoff',
name: 'bitrate_cutoff', tooltip: `Specify bitrate cutoff, files with a current bitrate lower then this will not be transcoded. Rate is in kbps. Leave empty to disable.
tooltip: `Specify bitrate cutoff, files with a current bitrate lower then this will not be transcoded. Rate is in kbps. Leave empty to disable. \\nExample:\\n
\\nExample:\\n 6000
6000
\\nExample:\\n
\\nExample:\\n 4000`
4000` },
{
name: 'enable_10bit',
}, tooltip: `Specify if output file should be 10bit. Default is false.
] \\nExample:\\n
} true
\\nExample:\\n
false`
},
]
}
} }
function plugin(file, librarySettings, inputs) { function plugin(file, librarySettings, inputs) {
var response = { var response = {
processFile: false, processFile: false,
preset: '', preset: '',
handBrakeMode: false, handBrakeMode: false,
FFmpegMode: true, FFmpegMode: true,
reQueueAfter: true, reQueueAfter: true,
infoLog: '' infoLog: ''
} }
if (inputs.container == "") { // Check if inputs.container has been configured. If it hasn't then exit plugin.
response.infoLog += "☒Container has not been configured within plugin settings, please configure required options. Skipping this plugin. \n" if (inputs.container == "") {
response.processFile = false response.infoLog += "☒Container has not been configured within plugin settings, please configure required options. Skipping this plugin. \n"
return response response.processFile = false
return response
} else { } else {
response.container = '.' + inputs.container response.container = '.' + inputs.container
} }
if (inputs.container == "mkv") { // Check if file is MKV, if so then add extra argument to drop data. MKV does not support data streams.
extraArguments += "-map -0:d " if (inputs.container == "mkv") {
} extraArguments += "-map -0:d "
}
if (file.fileMedium !== "video") { // Check if file is a video. If it isn't then exit plugin.
response.processFile = false if (file.fileMedium !== "video") {
response.infoLog += "☒File is not a video. \n" response.processFile = false
return response response.infoLog += "☒File is not a video. \n"
return response
} }
if (typeof file.meta.Duration != 'undefined') { // Check if duration info is filled, if so times it by 0.0166667 to get time in minutes. If not filled then get duration of stream 0 and do the same.
var duration = (file.meta.Duration * 0.0166667) if (typeof file.meta.Duration != 'undefined') {
} else { var duration = (file.meta.Duration * 0.0166667)
var duration = (file.ffProbeData.streams[0].duration * 0.0166667) } else {
} var duration = (file.ffProbeData.streams[0].duration * 0.0166667)
var videoIdx = 0
var extraArguments = ""
var bitrateSettings = ""
var filesize = (file.file_size / 1000)
var currentBitrate = ~~(file.file_size / (duration * 0.0075))
var targetBitrate = ~~((file.file_size / (duration * 0.0075)) / 2)
var minimumBitrate = ~~(targetBitrate * 0.7)
var maximumBitrate = ~~(targetBitrate * 1.3)
if (targetBitrate == "0") {
response.processFile = false
response.infoLog += "☒Target bitrate could not be calculated. Skipping this plugin. \n"
return response
}
if (inputs.bitrate_cutoff != "") {
if (currentBitrate <= inputs.bitrate_cutoff) {
if (file.container == inputs.container) {
response.processFile = false
response.infoLog += `☑Current bitrate is below configured bitrate cutoff of ${inputs.bitrate_cutoff} & file container is already ${inputs.container}. Nothing to do, skipping. \n`
return response
} else {
response.processFile = true
response.preset += `, -c copy ${extraArguments}`
response.infoLog += `☒Current bitrate is below configured bitrate cutoff of ${inputs.bitrate_cutoff} but is not in correct container. Remuxing to ${inputs.container} but not transcoding. \n`
return response
}
} }
}
for (var i = 0; i < file.ffProbeData.streams.length; i++) { // Set up required variables.
if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "video") { var videoIdx = 0
if (file.ffProbeData.streams[i].codec_name == 'mjpeg') { var extraArguments = ""
extraArguments += `-map -v:${videoIdx} ` var bitrateSettings = ""
} // Work out currentBitrate using "Bitrate = file size / (number of minutes * .0075)" - Used from here https://blog.frame.io/2017/03/06/calculate-video-bitrates/
if (file.ffProbeData.streams[i].codec_name == 'hevc' && file.container == inputs.container) { var currentBitrate = ~~(file.file_size / (duration * 0.0075))
response.processFile = false // Use the same calculation used for currentBitrate but divide it in half to get targetBitrate. Logic of h265 can be half the bitrate as h264 without losing quality.
response.infoLog += `☑File is already in ${inputs.container} & hevc. \n` var targetBitrate = ~~((file.file_size / (duration * 0.0075)) / 2)
return response // Allow some leeway under and over the targetBitrate.
} var minimumBitrate = ~~(targetBitrate * 0.7)
if (file.ffProbeData.streams[i].codec_name == 'hevc' && file.container != '${inputs.container}') { var maximumBitrate = ~~(targetBitrate * 1.3)
response.infoLog += `☒File is hevc but is not in ${inputs.container} container. Remuxing. \n`
response.preset = `, -map 0 -c copy ${extraArguments}` // If targetBitrate comes out as 0 then something has gone wrong and bitrates could not be calculcated. Cancel plugin completely.
response.processFile = true; if (targetBitrate == "0") {
return response response.processFile = false
} response.infoLog += "☒Target bitrate could not be calculated. Skipping this plugin. \n"
videoIdx++ return response
}
}
bitrateSettings = `-b:v ${targetBitrate}k -minrate ${minimumBitrate}k -maxrate ${maximumBitrate}k`
response.infoLog += `Container for output selected as ${inputs.container}. \n Current bitrate = ${~~(file.file_size / (duration * 0.0075))} \n Bitrate settings: \nTarget = ${targetBitrate} \nMinimum = ${minimumBitrate} \nMaximum = ${maximumBitrate} \n`
//codec will be checked so it can be transcoded correctly
if (file.video_codec_name == 'h263') {
response.preset = `-c:v h263_cuvid`
} }
else if (file.video_codec_name == 'h264') {
if (file.ffProbeData.streams[0].profile != 'High 10') { //if a h264 coded video is not HDR // Check if inputs.bitrate cutoff has something entered (Entered means user actually wants something to happen, empty would disable this).
response.preset = `-c:v h264_cuvid` if (inputs.bitrate_cutoff != "") {
// Checks if currentBitrate is below inputs.bitrate_cutoff, if so then cancel plugin without touching original files.
if (currentBitrate <= inputs.bitrate_cutoff) {
response.processFile = false
response.infoLog += `☑Current bitrate is below configured bitrate cutoff of ${inputs.bitrate_cutoff}. Nothing to do, cancelling plugin. \n`
return response
}
} }
}
else if (file.video_codec_name == 'mjpeg') {
response.preset = `c:v mjpeg_cuvid`
}
else if (file.video_codec_name == 'mpeg1') {
response.preset = `-c:v mpeg1_cuvid`
}
else if (file.video_codec_name == 'mpeg2') {
response.preset = `-c:v mpeg2_cuvid`
}
else if (file.video_codec_name == 'vc1') {
response.preset = `-c:v vc1_cuvid`
}
else if (file.video_codec_name == 'vp8') {
response.preset = `-c:v vp8_cuvid`
}
else if (file.video_codec_name == 'vp9') {
response.preset = `-c:v vp9_cuvid`
}
response.preset += `,-map 0 -c:v hevc_nvenc -rc:v vbr_hq ${bitrateSettings} -bufsize 2M -spatial_aq:v 1 -c:a copy -c:s copy -max_muxing_queue_size 4096 ${extraArguments}`
response.processFile = true
response.infoLog += `☒File is not hevc. Transcoding. \n`
return response
}
// Check if 10bit variable is true.
if (inputs.enable_10bit == "true") {
// If set to true then add 10bit argument
extraArguments += `-pix_fmt p010le `
}
// Go through each stream in the file.
for (var i = 0; i < file.ffProbeData.streams.length; i++) {
// Check if stream is a video.
if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "video") {
// Check if codec of stream is mjpeg, if so then remove this "video" stream. mjpeg are usually imbedded pictures that can cause havoc with plugins.
if (file.ffProbeData.streams[i].codec_name == 'mjpeg') {
extraArguments += `-map -v:${videoIdx} `
}
// Check if codec of stream is hevc AND check if file.container matches inputs.container. If so nothing for plugin to do.
if (file.ffProbeData.streams[i].codec_name == 'hevc' && file.container == inputs.container) {
response.processFile = false
response.infoLog += `☑File is already hevc & in ${inputs.container}. \n`
return response
}
// Check if codec of stream is hevc AND check if file.container does NOT match inputs.container. If so remux file.
if (file.ffProbeData.streams[i].codec_name == 'hevc' && file.container != '${inputs.container}') {
response.infoLog += `☒File is hevc but is not in ${inputs.container} container. Remuxing. \n`
response.preset = `, -map 0 -c copy ${extraArguments}`
response.processFile = true;
return response
}
// Increment videoIdx.
videoIdx++
}
}
// Set bitrateSettings variable using bitrate information calulcated earlier.
bitrateSettings = `-b:v ${targetBitrate}k -minrate ${minimumBitrate}k -maxrate ${maximumBitrate}k -bufsize ${currentBitrate}k`
// Print to infoLog information around file & bitrate settings.
response.infoLog += `Container for output selected as ${inputs.container}. \n Current bitrate = ${~~(file.file_size / (duration * 0.0075))} \n Bitrate settings: \nTarget = ${targetBitrate} \nMinimum = ${minimumBitrate} \nMaximum = ${maximumBitrate} \n`
// Codec will be checked so it can be transcoded correctly
if (file.video_codec_name == 'h263') {
response.preset = `-c:v h263_cuvid`
} else if (file.video_codec_name == 'h264') {
if (file.ffProbeData.streams[0].profile != 'High 10') { //if a h264 coded video is not HDR
response.preset = `-c:v h264_cuvid`
}
} else if (file.video_codec_name == 'mjpeg') {
response.preset = `c:v mjpeg_cuvid`
} else if (file.video_codec_name == 'mpeg1') {
response.preset = `-c:v mpeg1_cuvid`
} else if (file.video_codec_name == 'mpeg2') {
response.preset = `-c:v mpeg2_cuvid`
} else if (file.video_codec_name == 'vc1') {
response.preset = `-c:v vc1_cuvid`
} else if (file.video_codec_name == 'vp8') {
response.preset = `-c:v vp8_cuvid`
} else if (file.video_codec_name == 'vp9') {
response.preset = `-c:v vp9_cuvid`
}
response.preset += `,-map 0 -c:v hevc_nvenc -rc:v vbr_hq -cq:v 19 ${bitrateSettings} -spatial_aq:v 1 -rc-lookahead:v 32 -c:a copy -c:s copy -max_muxing_queue_size 4096 ${extraArguments}`
response.processFile = true
response.infoLog += `☒File is not hevc. Transcoding. \n`
return response
}
module.exports.details = details; module.exports.details = details;
module.exports.plugin = plugin; module.exports.plugin = plugin;

@ -1,133 +1,157 @@
function details() { function details() {
return { return {
id: "Tdarr_Plugin_MC93_Migz1FFMPEG_CPU", id: "Tdarr_Plugin_MC93_Migz1FFMPEG_CPU",
Stage: "Pre-processing", Stage: "Pre-processing",
Name: "Migz-Transcode Using CPU & FFMPEG", Name: "Migz-Transcode Using CPU & FFMPEG",
Type: "Video", Type: "Video",
Operation:"Transcode", Operation: "Transcode",
Description: `Files will be transcoded using CPU with ffmpeg, settings are dependant on file bitrate, working by the logic that H265 can support the same ammount of data at half the bitrate of H264. \n\n`, Description: `Files not in H265 will be transcoded into H265 using CPU with ffmpeg, settings are dependant on file bitrate, working by the logic that H265 can support the same ammount of data at half the bitrate of H264. \n\n`,
Version: "1.1", Version: "1.3",
Link: "https://github.com/HaveAGitGat/Tdarr_Plugins/blob/master/Community/Tdarr_Plugin_MC93_Migz1FFMPEG_CPU.js", Link: "https://github.com/HaveAGitGat/Tdarr_Plugins/blob/master/Community/Tdarr_Plugin_MC93_Migz1FFMPEG_CPU.js",
Tags:'pre-processing,ffmpeg,video only,configurable,h265', Tags: 'pre-processing,ffmpeg,video only,configurable,h265',
Inputs: [ Inputs: [{
{ name: 'container',
name: 'container', tooltip: `Specify output container of file, ensure that all stream types you may have are supported by your chosen container. mkv is recommended.
tooltip: `Specify output container of file, ensure that all stream types you may have are supported by your chosen container. mkv is recommended. \\nExample:\\n
\\nExample:\\n mkv
mkv
\\nExample:\\n
\\nExample:\\n mp4`
mp4`
},
}, {
{ name: 'bitrate_cutoff',
name: 'bitrate_cutoff', tooltip: `Specify bitrate cutoff, files with a current bitrate lower then this will not be transcoded. Rate is in kbps. Leave empty to disable.
tooltip: `Specify bitrate cutoff, files with a current bitrate lower then this will not be transcoded. Rate is in kbps. Leave empty to disable. \\nExample:\\n
\\nExample:\\n 6000
6000
\\nExample:\\n
\\nExample:\\n 4000`
4000` },
{
name: 'enable_10bit',
}, tooltip: `Specify if output file should be 10bit. Default is false.
] \\nExample:\\n
} true
\\nExample:\\n
false`
},
]
}
} }
function plugin(file, librarySettings, inputs) { function plugin(file, librarySettings, inputs) {
var response = { var response = {
processFile: false, processFile: false,
preset: '', preset: '',
handBrakeMode: false, handBrakeMode: false,
FFmpegMode: true, FFmpegMode: true,
reQueueAfter: true, reQueueAfter: true,
infoLog: '' infoLog: ''
} }
if (inputs.container == "") { // Check if inputs.container has been configured. If it hasn't then exit plugin.
response.infoLog += "☒Container has not been configured within plugin settings, please configure required options. Skipping this plugin. \n" if (inputs.container == "") {
response.processFile = false response.infoLog += "☒Container has not been configured within plugin settings, please configure required options. Skipping this plugin. \n"
return response response.processFile = false
return response
} else { } else {
response.container = '.' + inputs.container response.container = '.' + inputs.container
} }
if (inputs.container == "mkv") { // Check if file is MKV, if so then add extra argument to drop data. MKV does not support data streams.
extraArguments += "-map -0:d " if (inputs.container == "mkv") {
} extraArguments += "-map -0:d "
}
if (file.fileMedium !== "video") { // Check if file is a video. If it isn't then exit plugin.
response.processFile = false if (file.fileMedium !== "video") {
response.infoLog += "☒File is not a video. \n" response.processFile = false
return response response.infoLog += "☒File is not a video. \n"
return response
} }
if (typeof file.meta.Duration != 'undefined') { // Check if duration info is filled, if so times it by 0.0166667 to get time in minutes. If not filled then get duration of stream 0 and do the same.
var duration = (file.meta.Duration * 0.0166667) if (typeof file.meta.Duration != 'undefined') {
} else { var duration = (file.meta.Duration * 0.0166667)
var duration = (file.ffProbeData.streams[0].duration * 0.0166667) } else {
} var duration = (file.ffProbeData.streams[0].duration * 0.0166667)
}
var videoIdx = 0
var extraArguments = "" // Set up required variables.
var bitrateSettings = "" var videoIdx = -1
var filesize = (file.file_size / 1000) var extraArguments = ""
var currentBitrate = ~~(file.file_size / (duration * 0.0075)) var bitrateSettings = ""
var targetBitrate = ~~((file.file_size / (duration * 0.0075)) / 2) // Work out currentBitrate using "Bitrate = file size / (number of minutes * .0075)" - Used from here https://blog.frame.io/2017/03/06/calculate-video-bitrates/
var minimumBitrate = ~~(targetBitrate * 0.7) var currentBitrate = ~~(file.file_size / (duration * 0.0075))
var maximumBitrate = ~~(targetBitrate * 1.3) // Use the same calculation used for currentBitrate but divide it in half to get targetBitrate. Logic of h265 can be half the bitrate as h264 without losing quality.
var targetBitrate = ~~((file.file_size / (duration * 0.0075)) / 2)
if (targetBitrate == "0") { // Allow some leeway under and over the targetBitrate.
response.processFile = false var minimumBitrate = ~~(targetBitrate * 0.7)
response.infoLog += "☒Target bitrate could not be calculated. Skipping this plugin. \n" var maximumBitrate = ~~(targetBitrate * 1.3)
return response
} // If targetBitrate comes out as 0 then something has gone wrong and bitrates could not be calculcated. Cancel plugin completely.
if (targetBitrate == "0") {
if (inputs.bitrate_cutoff != "") { response.processFile = false
if (currentBitrate <= inputs.bitrate_cutoff) { response.infoLog += "☒Target bitrate could not be calculated. Skipping this plugin. \n"
if (file.container == inputs.container) { return response
response.processFile = false
response.infoLog += `☑Current bitrate is below configured bitrate cutoff of ${inputs.bitrate_cutoff} & file container is already ${inputs.container}. Nothing to do, skipping. \n`
return response
} else {
response.processFile = true
response.preset += `, -c copy ${extraArguments}`
response.infoLog += `☒Current bitrate is below configured bitrate cutoff of ${inputs.bitrate_cutoff} but is not in correct container. Remuxing to ${inputs.container} but not transcoding. \n`
return response
}
} }
}
for (var i = 0; i < file.ffProbeData.streams.length; i++) {
if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "video") {
if (file.ffProbeData.streams[i].codec_name == 'mjpeg') {
extraArguments += `-map -v:${videoIdx} `
}
if (file.ffProbeData.streams[i].codec_name == 'hevc' && file.container == inputs.container) {
response.processFile = false
response.infoLog += `☑File is already in ${inputs.container} & hevc. \n`
return response
}
if (file.ffProbeData.streams[i].codec_name == 'hevc' && file.container != '${inputs.container}') {
response.infoLog += `☒File is hevc but is not in ${inputs.container} container. Remuxing. \n`
response.preset = `, -map 0 -c copy ${extraArguments}`
response.processFile = true;
return response
}
videoIdx++
}
}
bitrateSettings = `-b:v ${targetBitrate}k -minrate ${minimumBitrate}k -maxrate ${maximumBitrate}k`
response.infoLog += `Container for output selected as ${inputs.container}. \n Current bitrate = ${~~(file.file_size / (duration * 0.0075))} \n Bitrate settings: \nTarget = ${targetBitrate} \nMinimum = ${minimumBitrate} \nMaximum = ${maximumBitrate} \n`
response.preset += `,-map 0 -c:v libx265 ${bitrateSettings} -bufsize 2M -spatial_aq:v 1 -c:a copy -c:s copy -max_muxing_queue_size 4096 ${extraArguments}`
response.processFile = true
response.infoLog += `☒File is not hevc. Transcoding. \n`
return response
}
// Check if inputs.bitrate cutoff has something entered (Entered means user actually wants something to happen, empty would disable this).
if (inputs.bitrate_cutoff != "") {
// Checks if currentBitrate is below inputs.bitrate_cutoff, if so then cancel plugin without touching original files.
if (currentBitrate <= inputs.bitrate_cutoff) {
response.processFile = false
response.infoLog += `☑Current bitrate is below configured bitrate cutoff of ${inputs.bitrate_cutoff}. Nothing to do, cancelling plugin. \n`
return response
}
}
// Check if 10bit variable is true.
if (inputs.enable_10bit == "true") {
// If set to true then add 10bit argument
extraArguments += `-pix_fmt p010le `
}
// Go through each stream in the file.
for (var i = 0; i < file.ffProbeData.streams.length; i++) {
// Check if stream is a video.
if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "video") {
// Check if codec of stream is mjpeg, if so then remove this "video" stream. mjpeg are usually imbedded pictures that can cause havoc with plugins.
if (file.ffProbeData.streams[i].codec_name == 'mjpeg') {
extraArguments += `-map -v:${videoIdx} `
}
// Check if codec of stream is hevc AND check if file.container matches inputs.container. If so nothing for plugin to do.
if (file.ffProbeData.streams[i].codec_name == 'hevc' && file.container == inputs.container) {
response.processFile = false
response.infoLog += `☑File is already hevc & in ${inputs.container}. \n`
return response
}
// Check if codec of stream is hevc AND check if file.container does NOT match inputs.container. If so remux file.
if (file.ffProbeData.streams[i].codec_name == 'hevc' && file.container != '${inputs.container}') {
response.infoLog += `☒File is hevc but is not in ${inputs.container} container. Remuxing. \n`
response.preset = `, -map 0 -c copy ${extraArguments}`
response.processFile = true;
return response
}
// Increment videoIdx.
videoIdx++
}
}
// Set bitrateSettings variable using bitrate information calulcated earlier.
bitrateSettings = `-b:v ${targetBitrate}k -minrate ${minimumBitrate}k -maxrate ${maximumBitrate}k -bufsize ${currentBitrate}k`
// Print to infoLog information around file & bitrate settings.
response.infoLog += `Container for output selected as ${inputs.container}. \n Current bitrate = ${~~(file.file_size / (duration * 0.0075))} \n Bitrate settings: \nTarget = ${targetBitrate} \nMinimum = ${minimumBitrate} \nMaximum = ${maximumBitrate} \n`
response.preset += `,-map 0 -c:v libx265 ${bitrateSettings} -c:a copy -c:s copy -max_muxing_queue_size 4096 ${extraArguments}`
response.processFile = true
response.infoLog += `☒File is not hevc. Transcoding. \n`
return response
}
module.exports.details = details; module.exports.details = details;
module.exports.plugin = plugin; module.exports.plugin = plugin;

@ -1,106 +1,116 @@
function details() { function details() {
return { return {
id: "Tdarr_Plugin_MC93_Migz2CleanTitle", id: "Tdarr_Plugin_MC93_Migz2CleanTitle",
Stage: "Pre-processing", Stage: "Pre-processing",
Name: "Migz-Clean title metadata", Name: "Migz-Clean title metadata",
Type: "Video", Type: "Video",
Operation: "Clean", Operation: "Clean",
Description: `This plugin removes title metadata from video/audio/subtitles, if it exists. Video checking is mandatory, audio and subtitles are optional.\n\n`, Description: `This plugin removes title metadata from video/audio/subtitles, if it exists. Video checking is mandatory, audio and subtitles are optional.\n\n`,
Version: "1.20", Version: "1.2",
Link: "https://github.com/HaveAGitGat/Tdarr_Plugins/blob/master/Community/Tdarr_Plugin_MC93_Migz2CleanTitle.js", Link: "https://github.com/HaveAGitGat/Tdarr_Plugins/blob/master/Community/Tdarr_Plugin_MC93_Migz2CleanTitle.js",
Tags:'pre-processing,ffmpeg,configurable', Tags: 'pre-processing,ffmpeg,configurable',
Inputs: [ Inputs: [{
{ name: 'clean_audio',
name: 'clean_audio', tooltip: `Specify if audio titles should be checked & cleaned. Optional.
tooltip: `Specify if audio titles should be checked & cleaned. Optional. \\nExample:\\n
\\nExample:\\n true
true
\\nExample:\\n \\nExample:\\n
false` false`
}, },
{ {
name: 'clean_subtitles', name: 'clean_subtitles',
tooltip: `Specify if subtitle titles should be checked & cleaned. Optional. tooltip: `Specify if subtitle titles should be checked & cleaned. Optional.
\\nExample:\\n \\nExample:\\n
true true
\\nExample:\\n \\nExample:\\n
false` false`
}, },
] ]
} }
} }
function plugin(file, librarySettings, inputs) { function plugin(file, librarySettings, inputs) {
var response = { var response = {
processFile : false, processFile: false,
preset : '', preset: '',
container: '.' + file.container, container: '.' + file.container,
handBrakeMode : false, handBrakeMode: false,
FFmpegMode : true, FFmpegMode: true,
reQueueAfter : false, reQueueAfter: false,
infoLog : '', infoLog: '',
} }
var ffmpegCommandInsert = '' // Set up required variables.
var videoIdx = 0 var ffmpegCommandInsert = ''
var audioIdx = 0 var videoIdx = 0
var subtitleIdx = 0 var audioIdx = 0
var convert = false var subtitleIdx = 0
var convert = false
if (file.fileMedium !== "video") { // Check if file is a video. If it isn't then exit plugin.
console.log("File is not video") if (file.fileMedium !== "video") {
response.infoLog += "☒File is not video \n" console.log("File is not video")
response.processFile = false; response.infoLog += "☒File is not video \n"
return response response.processFile = false;
} return response
}
// Check if overall file metadata title is not empty, if it's not empty set to "".
if (typeof file.meta.Title != 'undefined') try { if (typeof file.meta.Title != 'undefined') try {
ffmpegCommandInsert += ` -metadata title="" ` ffmpegCommandInsert += ` -metadata title="" `
convert = true convert = true
} catch (err) { } } catch (err) {}
for (var i = 0; i < file.ffProbeData.streams.length; i++) try { // Go through each stream in the file.
for (var i = 0; i < file.ffProbeData.streams.length; i++) try {
// Check if stream is a video.
if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "video") { if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "video") {
if (typeof file.ffProbeData.streams[i].tags.title != 'undefined') { // Check if stream title is not empty, if it's nto empty set to "".
response.infoLog += `☒Video stream title is not empty, most likely junk metadata. Removing title from stream ${i} \n` if (typeof file.ffProbeData.streams[i].tags.title != 'undefined') {
ffmpegCommandInsert += ` -metadata:s:v:${videoIdx} title="" ` response.infoLog += `☒Video stream title is not empty, most likely junk metadata. Removing title from stream ${i} \n`
convert = true ffmpegCommandInsert += ` -metadata:s:v:${videoIdx} title="" `
convert = true
} }
videoIdx++ // Increment videoIdx.
} videoIdx++
}
if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio" && inputs.clean_audio.toLowerCase() == "true") { // Check if title metadata of audio stream has more then 3 full stops. If so then it's likely to be junk metadata so remove.
if (file.ffProbeData.streams[i].tags.title.split('.').length-1 > 3) { if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio" && inputs.clean_audio.toLowerCase() == "true") {
response.infoLog += `☒More then 3 full stops detected in subtitle title, likely to be junk metadata. Removing title from stream ${i} \n` if (file.ffProbeData.streams[i].tags.title.split('.').length - 1 > 3) {
ffmpegCommandInsert += ` -metadata:s:a:${audioIdx} title="" ` response.infoLog += `☒More then 3 full stops detected in audio title, likely to be junk metadata. Removing title from stream ${i} \n`
convert = true ffmpegCommandInsert += ` -metadata:s:a:${audioIdx} title="" `
} convert = true
audioIdx++ }
} // Increment audioIdx.
audioIdx++
}
if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "subtitle" && inputs.clean_subtitles.toLowerCase() == "true") { // Check if title metadata of subtitle stream has more then 3 full stops. If so then it's likely to be junk metadata so remove.
if (file.ffProbeData.streams[i].tags.title.split('.').length-1 > 3) { if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "subtitle" && inputs.clean_subtitles.toLowerCase() == "true") {
response.infoLog += `☒More then 3 full stops detected in subtitle title, likely to be junk metadata. Removing title from stream ${i} \n` if (file.ffProbeData.streams[i].tags.title.split('.').length - 1 > 3) {
ffmpegCommandInsert += ` -metadata:s:s:${subtitleIdx} title="" ` response.infoLog += `☒More then 3 full stops detected in subtitle title, likely to be junk metadata. Removing title from stream ${i} \n`
convert = true ffmpegCommandInsert += ` -metadata:s:s:${subtitleIdx} title="" `
} convert = true
subtitleIdx++ }
} // Increment subtitleIdx.
} catch (err) { } subtitleIdx++
}
} catch (err) {}
if (convert == true) { // Convert file if convert variable is set to true.
response.infoLog += "☒File has title metadata. Removing \n" if (convert == true) {
response.preset = `,${ffmpegCommandInsert} -c copy -map 0 -max_muxing_queue_size 4096` response.infoLog += "☒File has title metadata. Removing \n"
response.reQueueAfter = true; response.preset = `,${ffmpegCommandInsert} -c copy -map 0 -max_muxing_queue_size 4096`
response.processFile = true; response.reQueueAfter = true;
response.processFile = true;
} else { } else {
response.infoLog += "☑File has no title metadata \n" response.infoLog += "☑File has no title metadata \n"
} }
return response return response
} }
module.exports.details = details; module.exports.details = details;
module.exports.plugin = plugin; module.exports.plugin = plugin;

@ -1,172 +1,180 @@
function details() { function details() {
return { return {
id: "Tdarr_Plugin_MC93_Migz3CleanAudio", id: "Tdarr_Plugin_MC93_Migz3CleanAudio",
Stage: "Pre-processing", Stage: "Pre-processing",
Name: "Migz-Clean audio streams", Name: "Migz-Clean audio streams",
Type: "Audio", Type: "Audio",
Operation: "Clean", Operation: "Clean",
Description: `This plugin keeps only specified language audio tracks & can tags those that have an unknown language. \n\n`, Description: `This plugin keeps only specified language audio tracks & can tags those that have an unknown language. \n\n`,
Version: "2.00", Version: "2.1",
Link: "https://github.com/HaveAGitGat/Tdarr_Plugins/blob/master/Community/Tdarr_Plugin_MC93_Migz3CleanAudio.js", Link: "https://github.com/HaveAGitGat/Tdarr_Plugins/blob/master/Community/Tdarr_Plugin_MC93_Migz3CleanAudio.js",
Tags:'pre-processing,ffmpeg,audio only,configurable', Tags: 'pre-processing,ffmpeg,audio only,configurable',
Inputs: [ Inputs: [{
{ name: 'language',
name: 'language', tooltip: `Specify language tag/s here for the audio tracks you'd like to keep, recommended to keep "und" as this stands for undertermined, some files may not have the language specified. Must follow ISO-639-2 3 letter format. https://en.wikipedia.org/wiki/List_of_ISO_639-2_codes
tooltip: `Specify language tag/s here for the audio tracks you'd like to keep, recommended to keep "und" as this stands for undertermined, some files may not have the language specified. Must follow ISO-639-2 3 letter format. https://en.wikipedia.org/wiki/List_of_ISO_639-2_codes \\nExample:\\n
\\nExample:\\n eng
eng
\\nExample:\\n
\\nExample:\\n eng,und
eng,und
\\nExample:\\n
\\nExample:\\n eng,und,jap`
eng,und,jap` },
}, {
{ name: 'commentary',
name: 'commentary', tooltip: `Specify if audio tracks that contain commentary/description should be removed.
tooltip: `Specify if audio tracks that contain commentary/description should be removed. \\nExample:\\n
\\nExample:\\n true
true
\\nExample:\\n
\\nExample:\\n false`
false` },
}, {
{ name: 'tag_language',
name: 'tag_language', tooltip: `Specify a single language for audio tracks with no language or unknown language to be tagged with, leave empty to disable, you must have "und" in your list of languages to keep for this to function. Must follow ISO-639-2 3 letter format. https://en.wikipedia.org/wiki/List_of_ISO_639-2_codes
tooltip: `Specify a single language for audio tracks with no language or unknown language to be tagged with, leave empty to disable, you must have "und" in your list of languages to keep for this to function. Must follow ISO-639-2 3 letter format. https://en.wikipedia.org/wiki/List_of_ISO_639-2_codes \\nExample:\\n
\\nExample:\\n eng
eng
\\nExample:\\n
\\nExample:\\n por`
por },
` {
}, name: 'tag_title',
{ tooltip: `Specify audio tracks with no title to be tagged with the number of channels they contain. Do NOT use this with mp4, as mp4 does not support title tags.
name: 'tag_title',
tooltip: `Specify audio tracks with no title to be tagged with the number of channels they contain. Do NOT use this with mp4, as mp4 does not support title tags.
\\nExample:\\n \\nExample:\\n
true true
\\nExample:\\n \\nExample:\\n
false` false`
}, },
] ]
} }
} }
function plugin(file, librarySettings, inputs) { function plugin(file, librarySettings, inputs) {
var response = { var response = {
processFile: false, processFile: false,
preset: '', preset: '',
container: '.' + file.container, container: '.' + file.container,
handBrakeMode: false, handBrakeMode: false,
FFmpegMode: true, FFmpegMode: true,
reQueueAfter: false, reQueueAfter: false,
infoLog: '', infoLog: '',
} }
if (file.fileMedium !== "video") {
console.log("File is not video")
response.infoLog += "☒File is not video \n"
response.processFile = false;
return response
}
if (inputs.language == "") { // Check if file is a video. If it isn't then exit plugin.
response.infoLog += "☒Language/s keep have not been configured within plugin settings, please configure required options. Skipping this plugin. \n" if (file.fileMedium !== "video") {
response.processFile = false; console.log("File is not video")
return response response.infoLog += "☒File is not video \n"
} response.processFile = false;
return response
}
// Check if inputs.language has been configured. If it hasn't then exit plugin.
if (inputs.language == "") {
response.infoLog += "☒Language/s keep have not been configured within plugin settings, please configure required options. Skipping this plugin. \n"
response.processFile = false;
return response
}
// Set up required variables.
var language = inputs.language.split(",") var language = inputs.language.split(",")
var ffmpegCommandInsert = '' var ffmpegCommandInsert = ''
var convert = false var convert = false
var audioIdx = -1 var audioIdx = 0
var audioStreamsRemoved = 0 var audioStreamsRemoved = 0
var audioStreamCount = file.ffProbeData.streams.filter(row => (row.codec_type.toLowerCase() == "audio")).length; var audioStreamCount = file.ffProbeData.streams.filter(row => (row.codec_type.toLowerCase() == "audio")).length;
console.log("audioStreamCount:" + audioStreamCount) for (var i = 0; i < file.ffProbeData.streams.length; i++) {
response.infoLog += `Languages to keep are ${language} \n`
// Catch error here incase the language metadata is completely missing.
for (var i = 0; i < file.ffProbeData.streams.length; i++) { try {
try { // Check if stream is audio AND checks if the tracks language code does not match any of the languages entered in inputs.language.
if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio") { if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio" && language.indexOf(file.ffProbeData.streams[i].tags.language.toLowerCase()) === -1) {
audioIdx++ audioStreamsRemoved++
} ffmpegCommandInsert += `-map -0:a:${audioIdx} `
} catch (err) { } response.infoLog += `☒Audio stream detected as being an unwanted language, removing. Audio stream 0:a:${audioIdx} - ${file.ffProbeData.streams[i].tags.language.toLowerCase()} \n`
convert = true
try { }
if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio" && language.indexOf(file.ffProbeData.streams[i].tags.language.toLowerCase()) === -1) { } catch (err) {}
audioStreamsRemoved++
ffmpegCommandInsert += `-map -0:a:${audioIdx} ` // Catch error here incase the title metadata is completely missing.
response.infoLog += `☒Audio stream detected as being an unwanted language, removing. Audio stream 0:a:${audioIdx} - ${file.ffProbeData.streams[i].tags.language.toLowerCase()} \n` try {
convert = true // Check if inputs.commentary is set to true AND if stream is audio AND then checks for stream titles with the following "commentary, description, sdh". Removing any streams that are applicable.
} if (inputs.commentary.toLowerCase() == "true" && file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio" && (file.ffProbeData.streams[i].tags.title.toLowerCase().includes('commentary') || file.ffProbeData.streams[i].tags.title.toLowerCase().includes('description') || file.ffProbeData.streams[i].tags.title.toLowerCase().includes('sdh'))) {
} catch (err) { } audioStreamsRemoved++
ffmpegCommandInsert += `-map -0:a:${audioIdx} `
try { response.infoLog += `☒Audio stream detected as being Commentary or Description, removing. Audio stream 0:a:${audioIdx} - ${file.ffProbeData.streams[i].tags.title}. \n`
if (inputs.commentary.toLowerCase() == "true" && file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio" && (file.ffProbeData.streams[i].tags.title.toLowerCase().includes('commentary') || file.ffProbeData.streams[i].tags.title.toLowerCase().includes('description') || file.ffProbeData.streams[i].tags.title.toLowerCase().includes('sdh'))) { convert = true
audioStreamsRemoved++ }
ffmpegCommandInsert += `-map -0:a:${audioIdx} ` } catch (err) {}
response.infoLog += `☒Audio stream detected as being Commentary or Description, removing. Audio stream 0:a:${audioIdx} - ${file.ffProbeData.streams[i].tags.title}. \n`
convert = true // Check if inputs.tag_language has something entered (Entered means user actually wants something to happen, empty would disable this) AND checks that stream is audio.
} if (inputs.tag_language != "" && file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio") {
} catch (err) { } // Catch error here incase the metadata is completely missing.
try {
try { // Look for audio with "und" as metadata language.
if (inputs.tag_language != "") { if (file.ffProbeData.streams[i].tags.language.toLowerCase().includes('und')) {
if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio" && file.ffProbeData.streams[i].tags.language.toLowerCase().includes('und') && language.indexOf('und') !== -1) { response.infoLog += `first`
ffmpegCommandInsert += `-metadata:s:a:${audioIdx} language=${inputs.tag_language} ` ffmpegCommandInsert += `-metadata:s:a:${audioIdx} language=${inputs.tag_language} `
response.infoLog += `☒Audio stream detected as having unknown language tagged, tagging as ${inputs.tag_language}. \n` response.infoLog += `☒Audio stream detected as having unknown language tagged, tagging as ${inputs.tag_language}. \n`
convert = true convert = true
} }
} catch (err) {}
if (typeof file.ffProbeData.streams[i].tags.language === 'undefined' && file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio") {
ffmpegCommandInsert += `-metadata:s:a:${audioIdx} language=${inputs.tag_language} ` // Checks if the tags.language metadata is completely missing, if so this would cause playback to show language as "undefined". No catch error here otherwise it would never detect the metadata as missing.
response.infoLog += `☒Audio stream detected as having no language tagged, tagging as ${inputs.tag_language}. \n` if (typeof file.ffProbeData.streams[i].tags.language == 'undefined') {
convert = true ffmpegCommandInsert += `-metadata:s:a:${audioIdx} language=${inputs.tag_language} `
response.infoLog += `☒Audio stream detected as having no language tagged, tagging as ${inputs.tag_language}. \n`
convert = true
}
} }
try {
// Check if title metadata is missing from any streams AND inputs.tag_title set to true AND if stream type is audio. Add title to any applicable streams.
if (typeof file.ffProbeData.streams[i].tags.title == 'undefined' && inputs.tag_title.toLowerCase() == "true" && file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio") {
if (file.ffProbeData.streams[i].channels == "8") {
ffmpegCommandInsert += `-metadata:s:a:${audioIdx} title="7.1" `
response.infoLog += `☒Audio stream detected as 8 channel audio track with no title, tagging title. Audio stream 0:a:${audioIdx} tagged as "7.1" \n`
convert = true
}
if (file.ffProbeData.streams[i].channels == "6") {
ffmpegCommandInsert += `-metadata:s:a:${audioIdx} title="5.1" `
response.infoLog += `☒Audio stream detected as 6 channel audio track with no title, tagging title. Audio stream 0:a:${audioIdx} tagged as "5.1" \n`
convert = true
}
if (file.ffProbeData.streams[i].channels == "2") {
ffmpegCommandInsert += `-metadata:s:a:${audioIdx} title="2.0" `
response.infoLog += `☒Audio stream detected as 2 channel audio track with no title, tagging title. Audio stream 0:a:${audioIdx} tagged as "2.0" \n`
convert = true
}
}
} catch (err) {}
// Check if stream type is audio and increment audioIdx if true.
if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio") {
audioIdx++
}
}
// Failsafe to cancel processing if all streams would be removed following this plugin. We don't want no audio.
if (audioStreamsRemoved == audioStreamCount) {
response.infoLog += "☒Cancelling plugin otherwise all audio tracks would be removed. \n"
response.processFile = false
return response
} }
} catch (err) { }
// Convert file if convert variable is set to true.
try { if (convert === true) {
if (typeof file.ffProbeData.streams[i].tags.title == 'undefined' && inputs.tag_title.toLowerCase() == "true" && file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio") {
if (file.ffProbeData.streams[i].channels == "8") {
ffmpegCommandInsert += `-metadata:s:a:${audioIdx} title="7.1" `
response.infoLog += `☒Audio stream detected as 8 channel audio track with no title, tagging title. Audio stream 0:a:${audioIdx} tagged as "7.1" \n`
convert = true
}
if (file.ffProbeData.streams[i].channels == "6") {
ffmpegCommandInsert += `-metadata:s:a:${audioIdx} title="5.1" `
response.infoLog += `☒Audio stream detected as 6 channel audio track with no title, tagging title. Audio stream 0:a:${audioIdx} tagged as "5.1" \n`
convert = true
}
if (file.ffProbeData.streams[i].channels == "2") {
ffmpegCommandInsert += `-metadata:s:a:${audioIdx} title="2.0" `
response.infoLog += `☒Audio stream detected as 2 channel audio track with no title, tagging title. Audio stream 0:a:${audioIdx} tagged as "2.0" \n`
convert = true
}
}
} catch (err) { }
}
if (audioStreamsRemoved == audioStreamCount) {
response.infoLog += "☒Cancelling plugin otherwise all audio tracks would be removed. \n"
response.processFile = false
return response
}
if (convert === true && (audioStreamsRemoved != audioStreamCount)) {
response.processFile = true response.processFile = true
response.preset = `, -map 0 ${ffmpegCommandInsert} -c copy -max_muxing_queue_size 4096` response.preset = `, -map 0 ${ffmpegCommandInsert} -c copy -max_muxing_queue_size 4096`
response.container = '.' + file.container response.container = '.' + file.container
response.reQueueAfter = true response.reQueueAfter = true
} else { } else {
response.processFile = false response.processFile = false
response.infoLog += "☑File doesn't contain audio tracks which are unwanted or that require tagging.\n" response.infoLog += "☑File doesn't contain audio tracks which are unwanted or that require tagging.\n"
} }
return response return response
} }
module.exports.details = details; module.exports.details = details;
module.exports.plugin = plugin; module.exports.plugin = plugin;

@ -1,126 +1,137 @@
function details() { function details() {
return { return {
id: "Tdarr_Plugin_MC93_Migz4CleanSubs", id: "Tdarr_Plugin_MC93_Migz4CleanSubs",
Stage: "Pre-processing", Stage: "Pre-processing",
Name: "Migz-Clean subtitle streams", Name: "Migz-Clean subtitle streams",
Type: "subtitless", Type: "subtitles",
Operation: "Clean", Operation: "Clean",
Description: `This plugin keeps only specified language subtitle tracks & can tag those that have an unknown language. \n\n`, Description: `This plugin keeps only specified language subtitle tracks & can tag those that have an unknown language. \n\n`,
Version: "2.00", Version: "2.1",
Link: "https://github.com/HaveAGitGat/Tdarr_Plugins/blob/master/Community/Tdarr_Plugin_MC93_Migz4CleanSubs.js", Link: "https://github.com/HaveAGitGat/Tdarr_Plugins/blob/master/Community/Tdarr_Plugin_MC93_Migz4CleanSubs.js",
Tags:'pre-processing,ffmpeg,subtitle only,configurable', Tags: 'pre-processing,ffmpeg,subtitle only,configurable',
Inputs: [ Inputs: [{
{ name: 'language',
name: 'language', tooltip: `Specify language tag/s here for the subtitle tracks you'd like to keep. Must follow ISO-639-2 3 letter format. https://en.wikipedia.org/wiki/List_of_ISO_639-2_codes
tooltip: `Specify language tag/s here for the subtitle tracks you'd like to keep. Must follow ISO-639-2 3 letter format. https://en.wikipedia.org/wiki/List_of_ISO_639-2_codes \\nExample:\\n
\\nExample:\\n eng
eng
\\nExample:\\n \\nExample:\\n
eng,jap` eng,jap`
}, },
{ {
name: 'commentary', name: 'commentary',
tooltip: `Specify if subtitle tracks that contain commentary/description should be removed. tooltip: `Specify if subtitle tracks that contain commentary/description should be removed.
\\nExample:\\n \\nExample:\\n
true true
\\nExample:\\n \\nExample:\\n
false` false`
}, },
{ {
name: 'tag_title', name: 'tag_language',
tooltip: `Specify a single language for subtitle tracks with no language or unknown language to be tagged with, leave empty to disable. Must follow ISO-639-2 3 letter format. https://en.wikipedia.org/wiki/List_of_ISO_639-2_codes tooltip: `Specify a single language for subtitle tracks with no language or unknown language to be tagged with, leave empty to disable. Must follow ISO-639-2 3 letter format. https://en.wikipedia.org/wiki/List_of_ISO_639-2_codes
\\nExample:\\n \\nExample:\\n
eng eng
\\nExample:\\n \\nExample:\\n
por` por`
}, },
] ]
} }
} }
function plugin(file, librarySettings, inputs) { function plugin(file, librarySettings, inputs) {
var response = { var response = {
processFile: false, processFile: false,
preset: '', preset: '',
container: '.' + file.container, container: '.' + file.container,
handBrakeMode: false, handBrakeMode: false,
FFmpegMode: true, FFmpegMode: true,
reQueueAfter: false, reQueueAfter: false,
infoLog: '', infoLog: '',
} }
if (file.fileMedium !== "video") { // Check if file is a video. If it isn't then exit plugin.
console.log("File is not video") if (file.fileMedium !== "video") {
response.infoLog += "☒File is not video \n" console.log("File is not video")
response.processFile = false; response.infoLog += "☒File is not video \n"
return response response.processFile = false;
return response
} }
if (inputs.language == "") { // Check if inputs.language has been configured. If it hasn't then exit plugin.
response.infoLog += "☒Language/s keep have not been configured within plugin settings, please configure required options. Skipping this plugin. \n" if (inputs.language == "") {
response.processFile = false; response.infoLog += "☒Language/s keep have not been configured within plugin settings, please configure required options. Skipping this plugin. \n"
return response response.processFile = false;
return response
} }
var language = inputs.language.split(",") // Set up required variables.
var ffmpegCommandInsert = '' var language = inputs.language.split(",")
var subtitleIdx = -1 var ffmpegCommandInsert = ''
var convert = false var subtitleIdx = 0
var convert = false
for (var i = 0; i < file.ffProbeData.streams.length; i++) { // Go through each stream in the file.
try { for (var i = 0; i < file.ffProbeData.streams.length; i++) {
if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "subtitle") {
subtitleIdx++
}
} catch (err) { }
try { // Catch error here incase the language metadata is completely missing.
if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "subtitle" && language.indexOf(file.ffProbeData.streams[i].tags.language.toLowerCase()) === -1) { try {
// Check if stream is subtitle AND checks if the tracks language code does not match any of the languages entered in inputs.language.
if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "subtitle" && language.indexOf(file.ffProbeData.streams[i].tags.language.toLowerCase()) === -1) {
ffmpegCommandInsert += `-map -0:s:${subtitleIdx} ` ffmpegCommandInsert += `-map -0:s:${subtitleIdx} `
response.infoLog += `☒Subtitle stream detected as being an unwanted language, removing. Subtitle stream 0:s:${subtitleIdx} - ${file.ffProbeData.streams[i].tags.language.toLowerCase()} \n` response.infoLog += `☒Subtitle stream detected as being an unwanted language, removing. Subtitle stream 0:s:${subtitleIdx} - ${file.ffProbeData.streams[i].tags.language.toLowerCase()} \n`
convert = true convert = true
} }
} catch (err) { } } catch (err) {}
try { // Catch error here incase the title metadata is completely missing.
try {
// Check if inputs.commentary is set to true AND if stream is subtitle AND then checks for stream titles with the following "commentary, description, sdh". Removing any streams that are applicable.
if (inputs.commentary.toLowerCase() == "true" && file.ffProbeData.streams[i].codec_type.toLowerCase() == "subtitle" && (file.ffProbeData.streams[i].tags.title.toLowerCase().includes('commentary') || file.ffProbeData.streams[i].tags.title.toLowerCase().includes('description') || file.ffProbeData.streams[i].tags.title.toLowerCase().includes('sdh'))) { if (inputs.commentary.toLowerCase() == "true" && file.ffProbeData.streams[i].codec_type.toLowerCase() == "subtitle" && (file.ffProbeData.streams[i].tags.title.toLowerCase().includes('commentary') || file.ffProbeData.streams[i].tags.title.toLowerCase().includes('description') || file.ffProbeData.streams[i].tags.title.toLowerCase().includes('sdh'))) {
ffmpegCommandInsert += `-map -0:s:${subtitleIdx} ` ffmpegCommandInsert += `-map -0:s:${subtitleIdx} `
response.infoLog += `☒Subtitle stream detected as being Commentary or Description, removing. Subtitle stream 0:s:${SubtitleIdx} - ${file.ffProbeData.streams[i].tags.title}. \n` response.infoLog += `☒Subtitle stream detected as being Commentary or Description, removing. Subtitle stream 0:s:${SubtitleIdx} - ${file.ffProbeData.streams[i].tags.title}. \n`
convert = true convert = true
} }
} catch (err) { } } catch (err) {}
try { // Check if inputs.tag_language has something entered (Entered means user actually wants something to happen, empty would disable this) AND checks that stream is audio.
if (inputs.tag_title != "") { if (inputs.tag_language != "" && file.ffProbeData.streams[i].codec_type.toLowerCase() == "subtitle") {
if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "subtitle" && file.ffProbeData.streams[i].tags.language.toLowerCase().includes('und')) { // Catch error here incase the metadata is completely missing.
ffmpegCommandInsert += `-metadata:s:s:${subtitleIdx} language=${inputs.tag_title} ` try {
response.infoLog += `☒Subtitle stream detected as having unknown language tagged, tagging as ${inputs.tag_title}. \n` // Look for subtitle with "und" as metadata language.
if (file.ffProbeData.streams[i].tags.language.toLowerCase().includes('und')) {
ffmpegCommandInsert += `-metadata:s:s:${subtitleIdx} language=${inputs.tag_language} `
response.infoLog += `☒Subtitle stream detected as having unknown language tagged, tagging as ${inputs.tag_language}. \n`
convert = true convert = true
}
}
} catch (err) { }
try {
if (typeof file.ffProbeData.streams[i].tags.language == 'undefined' && file.ffProbeData.streams[i].codec_type.toLowerCase() == "subtitle") {
ffmpegCommandInsert += `-metadata:s:s:${subtitleIdx} language=${inputs.tag_title} `
response.infoLog += `☒Subtitle stream detected as having no language tagged, tagging as ${inputs.tag_title}. \n`
convert = true
} }
} catch (err) { } } catch (err) {}
// Checks if the tags.language metadata is completely missing, if so this would cause playback to show language as "undefined". No catch error here otherwise it would never detect the metadata as missing.
if (typeof file.ffProbeData.streams[i].tags.language == 'undefined' && file.ffProbeData.streams[i].codec_type.toLowerCase() == "subtitle") {
ffmpegCommandInsert += `-metadata:s:s:${subtitleIdx} language=${inputs.tag_language} `
response.infoLog += `☒Subtitle stream detected as having no language tagged, tagging as ${inputs.tag_language}. \n`
convert = true
}
}
// Check if stream type is subtitle and increment subtitleIdx if true.
if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "subtitle") {
subtitleIdx++
}
} }
if (convert === true ) {
response.processFile = true; // Convert file if convert variable is set to true.
response.preset = `, -map 0 ${ffmpegCommandInsert} -c copy -max_muxing_queue_size 4096` if (convert === true) {
response.container = '.' + file.container response.processFile = true;
response.reQueueAfter = true; response.preset = `, -map 0 ${ffmpegCommandInsert} -c copy -max_muxing_queue_size 4096`
response.container = '.' + file.container
response.reQueueAfter = true;
} else { } else {
response.processFile = false; response.processFile = false;
response.infoLog += "☑File doesn't contain subtitle tracks which are unwanted or that require tagging.\n" response.infoLog += "☑File doesn't contain subtitle tracks which are unwanted or that require tagging.\n"
} }
return response return response
} }
module.exports.details = details; module.exports.details = details;
module.exports.plugin = plugin; module.exports.plugin = plugin;

@ -1,120 +1,137 @@
function details() { function details() {
return { return {
id: "Tdarr_Plugin_MC93_Migz5ConvertAudio", id: "Tdarr_Plugin_MC93_Migz5ConvertAudio",
Stage: "Pre-processing", Stage: "Pre-processing",
Name: "Migz-Convert audio streams", Name: "Migz-Convert audio streams",
Type: "Audio", Type: "Audio",
Operation: "Transcode", Operation: "Transcode",
Description: `This plugin can convert any 2.0 audio track/s to AAC and can create downmixed audio tracks. \n\n`, Description: `This plugin can convert any 2.0 audio track/s to AAC and can create downmixed audio tracks. \n\n`,
Version: "2.00", Version: "2.1",
Link: "", Link: "",
Tags:'pre-processing,ffmpeg,audio only,configurable', Tags: 'pre-processing,ffmpeg,audio only,configurable',
Inputs: [ Inputs: [{
{ name: 'aac_stereo',
name: 'aac_stereo', tooltip: `Specify if any 2.0 audio tracks should be converted to aac for maximum compatability with devices. Optional.
tooltip: `Specify if any 2.0 audio tracks should be converted to aac for maximum compatability with devices. \\nExample:\\n
\\nExample:\\n true
true
\\nExample:\\n \\nExample:\\n
false` false`
}, },
{ {
name: 'downmix', name: 'downmix',
tooltip: `Specify if downmixing should be used to create extra audio tracks. I.e if you have an 8ch but no 2ch or 6ch, create the missing audio tracks from the 8 ch. Likewise if you only have 6ch, create the missing 2ch from it. tooltip: `Specify if downmixing should be used to create extra audio tracks. I.e if you have an 8ch but no 2ch or 6ch, create the missing audio tracks from the 8 ch. Likewise if you only have 6ch, create the missing 2ch from it. Optional.
\\nExample:\\n \\nExample:\\n
true true
\\nExample:\\n \\nExample:\\n
false` false`
}, },
] ]
} }
} }
function plugin(file, librarySettings, inputs) { function plugin(file, librarySettings, inputs) {
var response = { var response = {
processFile: false, processFile: false,
container: '.' + file.container, container: '.' + file.container,
handBrakeMode: false, handBrakeMode: false,
FFmpegMode: true, FFmpegMode: true,
reQueueAfter: true, reQueueAfter: true,
infoLog: '', infoLog: '',
} }
if (file.fileMedium !== "video") { // Check if both inputs.aac_stereo AND inputs.downmix have been left empty. If they have then exit plugin.
console.log("File is not video") if (inputs && inputs.aac_stereo == "" && inputs.downmix == "") {
response.infoLog += "☒File is not video. \n" response.infoLog += "☒Neither aac_stereo or downmix options have been configured within plugin settings, please configure required options. Skipping this plugin. \n"
response.processFile = false; response.processFile = false
return response return response
} }
if (inputs.aac_stereo == "" && inputs.downmix == "") { // Check if file is a video. If it isn't then exit plugin.
response.infoLog += "☒Neither aac_stereo or downmix options have been configured within plugin settings, please configure required options. Skipping this plugin. \n" if (file.fileMedium !== "video") {
response.processFile = false console.log("File is not video")
return response response.infoLog += "☒File is not video. \n"
response.processFile = false;
return response
} }
// Set up required variables.
var ffmpegCommandInsert = '' var ffmpegCommandInsert = ''
var audioIdx = 0 var audioIdx = 0
var has2Channel = false var has2Channel = false
var has6Channel = false var has6Channel = false
var has8Channel = false var has8Channel = false
var convert = false var convert = false
for (var i = 0; i < file.ffProbeData.streams.length; i++) {
try {
if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio") {
if (file.ffProbeData.streams[i].channels == "2") {
has2Channel = true
}
if (file.ffProbeData.streams[i].channels == "6") {
has6Channel = true
}
if (file.ffProbeData.streams[i].channels == "8") {
has8Channel = true
}
}
} catch (err) { }
}
for (var i = 0; i < file.ffProbeData.streams.length; i++) { // Go through each stream in the file.
if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio") { for (var i = 0; i < file.ffProbeData.streams.length; i++) {
if (inputs.downmix.toLowerCase() == "true") { try {
if (has8Channel == true && has6Channel == false && file.ffProbeData.streams[i].channels == "8") { // Go through all audio streams and check if 2,6 & 8 channel tracks exist or not.
ffmpegCommandInsert += `-map 0:${i} -c:a:${audioIdx} ac3 -ac 6 -metadata:s:a:${audioIdx} title="5.1 " ` if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio") {
response.infoLog += "☒Audio track is 8 channel, no 6 channel exists. Creating 2 channel from 6 channel. \n" if (file.ffProbeData.streams[i].channels == "2") {
convert = true has2Channel = true
} }
if (has6Channel == true && has2Channel == false && file.ffProbeData.streams[i].channels == "6") { if (file.ffProbeData.streams[i].channels == "6") {
ffmpegCommandInsert += `-map 0:${i} -c:a:${audioIdx} aac -ac 2 -metadata:s:a:${audioIdx} title="2.0 " ` has6Channel = true
response.infoLog += "☒Audio track is 6 channel, no 2 channel exists. Creating 2 channel from 6 channel. \n" }
convert = true if (file.ffProbeData.streams[i].channels == "8") {
} has8Channel = true
} }
if (inputs.aac_stereo.toLowerCase() == "true") {
if (file.ffProbeData.streams[i].codec_name != "aac" && file.ffProbeData.streams[i].channels == "2" ) {
ffmpegCommandInsert += `-c:a:${audioIdx} aac `
response.infoLog += "☒Audio track is 2 channel but is not AAC. Converting. \n"
convert = true
} }
} } catch (err) {}
audioIdx++ }
}
} // Go through each stream in the file.
for (var i = 0; i < file.ffProbeData.streams.length; i++) {
// Check if stream is audio.
if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio") {
// Catch error here incase user left inputs.downmix empty.
try {
// Check if inputs.downmix is set to true.
if (inputs.downmix.toLowerCase() == "true") {
// Check if file has 8 channel audio but no 6 channel, if so then create extra downmix from the 8 channel.
if (has8Channel == true && has6Channel == false && file.ffProbeData.streams[i].channels == "8") {
ffmpegCommandInsert += `-map 0:${i} -c:a:${audioIdx} ac3 -ac 6 -metadata:s:a:${audioIdx} title="5.1 " `
response.infoLog += "☒Audio track is 8 channel, no 6 channel exists. Creating 6 channel from 8 channel. \n"
convert = true
}
// Check if file has 6 channel audio but no 2 channel, if so then create extra downmix from the 6 channel.
if (has6Channel == true && has2Channel == false && file.ffProbeData.streams[i].channels == "6") {
ffmpegCommandInsert += `-map 0:${i} -c:a:${audioIdx} aac -ac 2 -metadata:s:a:${audioIdx} title="2.0 " `
response.infoLog += "☒Audio track is 6 channel, no 2 channel exists. Creating 2 channel from 6 channel. \n"
convert = true
}
}
} catch (err) {}
if (convert == true) { // Catch error here incase user left inputs.downmix empty.
try {
// Check if inputs.aac_stereo is set to true.
if (inputs.aac_stereo.toLowerCase() == "true") {
// Check if codec_name for stream is NOT aac AND check if channel ammount is 2.
if (file.ffProbeData.streams[i].codec_name != "aac" && file.ffProbeData.streams[i].channels == "2") {
ffmpegCommandInsert += `-c:a:${audioIdx} aac `
response.infoLog += "☒Audio track is 2 channel but is not AAC. Converting. \n"
convert = true
}
}
} catch (err) {}
audioIdx++
}
}
// Convert file if convert variable is set to true.
if (convert == true) {
response.processFile = true; response.processFile = true;
response.preset = `, -map 0 -c:v copy -c:a copy ${ffmpegCommandInsert} -strict -2 -c:s copy -max_muxing_queue_size 4096 ` response.preset = `, -map 0 -c:v copy -c:a copy ${ffmpegCommandInsert} -strict -2 -c:s copy -max_muxing_queue_size 4096 `
} else { } else {
response.infoLog += "☑File contains all required audio formats. \n" response.infoLog += "☑File contains all required audio formats. \n"
response.processFile = false; response.processFile = false;
} }
return response return response
} }
module.exports.details = details; module.exports.details = details;
module.exports.plugin = plugin; module.exports.plugin = plugin;

@ -1,136 +1,168 @@
function details() { function details() {
return { return {
id: "Tdarr_Plugin_MC93_Migz6OrderStreams", id: "Tdarr_Plugin_MC93_Migz6OrderStreams",
Stage: "Pre-processing", Stage: "Pre-processing",
Name: "Migz-Organize Streams", Name: "Migz-Order Streams",
Type: "Streams", Type: "Streams",
Operation: "Organize", Operation: "Order",
Description: `Organizes streams into Video first, then Audio (2ch, 6ch, 8ch) and finally Subtitles. \n\n`, Description: `Orders streams into Video first, then Audio (2ch, 6ch, 8ch) and finally Subtitles. \n\n`,
Version: "1.00", Version: "1.1",
Link: "https://github.com/HaveAGitGat/Tdarr_Plugins/blob/master/Community/Tdarr_Plugin_MC93_Migz6OrderStreams.js", Link: "https://github.com/HaveAGitGat/Tdarr_Plugins/blob/master/Community/Tdarr_Plugin_MC93_Migz6OrderStreams.js",
Tags:'pre-processing,ffmpeg,' Tags: 'pre-processing,ffmpeg,'
} }
} }
function plugin(file) { function plugin(file) {
var response = { var response = {
processFile: false, processFile: false,
preset: '', preset: '',
container: '.' + file.container, container: '.' + file.container,
handBrakeMode: false, handBrakeMode: false,
FFmpegMode: true, FFmpegMode: true,
infoLog: '', infoLog: '',
} }
// Set up required variables.
var ffmpegCommandInsert = '' var ffmpegCommandInsert = ''
var videoIdx = 0 var videoIdx = 0
var audioIdx = 0 var audioIdx = 0
var audio2Idx = 0 var audio2Idx = 0
var audio6Idx = 0 var audio6Idx = 0
var audio8Idx = 0 var audio8Idx = 0
var subtitleIdx = 0 var subtitleIdx = 0
var convert = false var convert = false
// Go through each stream in the file.
for (var i = 0; i < file.ffProbeData.streams.length; i++) { for (var i = 0; i < file.ffProbeData.streams.length; i++) {
try { try {
if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "video") { // Check if stream is video.
if (audioIdx != "0" || subtitleIdx != "0") { if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "video") {
convert = true // 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.
response.infoLog += "☒ Video not first. \n" if (audioIdx != "0" || subtitleIdx != "0") {
} convert = true
videoIdx++ 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") {
convert = true
response.infoLog += "☒ Audio not second. \n"
}
// Increment audioIdx.
audioIdx++
if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio") { // Check if audio track is 2 channel.
if (subtitleIdx != "0") { if (file.ffProbeData.streams[i].channels == "2") {
convert = true // 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.
response.infoLog += "☒ Audio not second. \n" if (audio6Idx != "0" || audio8Idx != "0") {
} convert = true
audioIdx++ response.infoLog += "☒ Audio 2ch not first. \n"
if (file.ffProbeData.streams[i].channels == "2") { }
if (audio6Idx != "0" || audio8Idx != "0") { // Increment audio2Idx.
convert = true audio2Idx++
response.infoLog += "☒ Audio 2ch not first. \n" }
} // Check if audio track is 6 channel.
audio2Idx++ 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 (file.ffProbeData.streams[i].channels == "6") { if (audio8Idx != "0") {
if (audio8Idx != "0") { convert = true
convert = true response.infoLog += "☒ Audio 6ch not second. \n"
response.infoLog += "☒ Audio 6ch not second. \n" }
} // Increment audio6Idx.
audio6Idx++ audio6Idx++
} }
if (file.ffProbeData.streams[i].channels == "8") {
audio8Idx++
response.infoLog += "☒ Audio 8ch not last. \n"
}
}
if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "subtitle") { // Check if audio track is 8 channel.
subtitleIdx++ if (file.ffProbeData.streams[i].channels == "8") {
} // Increment audio8Idx.
} catch (err) { } audio8Idx++
}
}
// Check if stream is subtitle.
if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "subtitle") {
// Increment subtitleIdx
subtitleIdx++
}
} catch (err) {}
} }
// Go through each stream in the file.
for (var i = 0; i < file.ffProbeData.streams.length; i++) { for (var i = 0; i < file.ffProbeData.streams.length; i++) {
try { try {
if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "video" && file.ffProbeData.streams[i].codec_name.toLowerCase() != "mjpeg") { // Check if stream is video AND is not a mjpeg.
ffmpegCommandInsert += `-map 0:${i} ` if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "video" && file.ffProbeData.streams[i].codec_name.toLowerCase() != "mjpeg") {
} ffmpegCommandInsert += `-map 0:${i} `
} catch (err) { } }
} } catch (err) {}
}
// Go through each stream in the file.
for (var i = 0; i < file.ffProbeData.streams.length; i++) { for (var i = 0; i < file.ffProbeData.streams.length; i++) {
try { try {
if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio" && file.ffProbeData.streams[i].channels == "2") { // Check if stream is audio AND 2 channel.
ffmpegCommandInsert += `-map 0:${i} ` if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio" && file.ffProbeData.streams[i].channels == "2") {
} ffmpegCommandInsert += `-map 0:${i} `
} catch (err) { } }
} } catch (err) {}
}
// Go through each stream in the file.
for (var i = 0; i < file.ffProbeData.streams.length; i++) { for (var i = 0; i < file.ffProbeData.streams.length; i++) {
try { try {
if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio" && file.ffProbeData.streams[i].channels == "6") { // Check if stream is audio AND 6 channel.
ffmpegCommandInsert += `-map 0:${i} ` if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio" && file.ffProbeData.streams[i].channels == "6") {
} ffmpegCommandInsert += `-map 0:${i} `
} catch (err) { } }
} } catch (err) {}
}
// Go through each stream in the file.
for (var i = 0; i < file.ffProbeData.streams.length; i++) { for (var i = 0; i < file.ffProbeData.streams.length; i++) {
try { try {
if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio" && file.ffProbeData.streams[i].channels == "8") { // Check if stream is audio AND 8 channel.
ffmpegCommandInsert += `-map 0:${i} ` if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio" && file.ffProbeData.streams[i].channels == "8") {
} ffmpegCommandInsert += `-map 0:${i} `
} catch (err) { } }
} } catch (err) {}
}
// Go through each stream in the file.
for (var i = 0; i < file.ffProbeData.streams.length; i++) { for (var i = 0; i < file.ffProbeData.streams.length; i++) {
try { try {
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") { // Check if stream is audio AND not 2, 6 or 8 channel.
ffmpegCommandInsert += `-map 0:${i} ` 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") {
} ffmpegCommandInsert += `-map 0:${i} `
} catch (err) { } }
} } catch (err) {}
}
// Go through each stream in the file.
for (var i = 0; i < file.ffProbeData.streams.length; i++) { for (var i = 0; i < file.ffProbeData.streams.length; i++) {
try { try {
if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "subtitle") { // Check if stream is subtitle.
ffmpegCommandInsert += `-map 0:${i} ` if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "subtitle") {
} ffmpegCommandInsert += `-map 0:${i} `
} catch (err) { } }
} } catch (err) {}
}
if (convert == true) { // Convert file if convert variable is set to true.
if (convert == true) {
response.processFile = true; response.processFile = true;
response.preset = `,${ffmpegCommandInsert} -c copy -max_muxing_queue_size 4096` response.preset = `,${ffmpegCommandInsert} -c copy -max_muxing_queue_size 4096`
response.reQueueAfter = true; 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 { } else {
response.infoLog += "☑ Streams are in expected order. \n " response.infoLog += "☑ Streams are in expected order. \n "
response.processFile = false; response.processFile = false;
} }
return response return response
} }
module.exports.details = details; module.exports.details = details;

@ -1,60 +1,64 @@
function details() { function details() {
return { return {
id: "Tdarr_Plugin_MC93_MigzImageRemoval", id: "Tdarr_Plugin_MC93_MigzImageRemoval",
Stage: "Pre-processing", Stage: "Pre-processing",
Name: "Migz-Remove image formats from file", Name: "Migz-Remove image formats from file",
Type: "Video", Type: "Video",
Operation:"Clean", Operation: "Clean",
Description: `Identify any unwanted image formats in the file and remove those streams. MJPEG & PNG \n\n`, Description: `Identify any unwanted image formats in the file and remove those streams. MJPEG & PNG \n\n`,
Version: "1.0", Version: "1.1",
Link: "https://github.com/HaveAGitGat/Tdarr_Plugins/blob/master/Community/Tdarr_Plugin_MC93_MigzImageRemoval.js", Link: "https://github.com/HaveAGitGat/Tdarr_Plugins/blob/master/Community/Tdarr_Plugin_MC93_MigzImageRemoval.js",
Tags:'pre-processing,ffmpeg,video only' Tags: 'pre-processing,ffmpeg,video only'
} }
} }
function plugin(file, librarySettings, inputs) { function plugin(file, librarySettings, inputs) {
var response = { var response = {
processFile: false, processFile: false,
preset: '', preset: '',
handBrakeMode: false, handBrakeMode: false,
container: '.' + file.container, container: '.' + file.container,
FFmpegMode: true, FFmpegMode: true,
reQueueAfter: true, reQueueAfter: true,
infoLog: '' infoLog: ''
} }
if (file.fileMedium !== "video") { // Check if file is a video. If it isn't then exit plugin.
response.processFile = false if (file.fileMedium !== "video") {
response.infoLog += "☒File is not a video. \n" response.processFile = false
return response response.infoLog += "☒File is not a video. \n"
return response
} }
var videoIdx = 0 // Set up required variables.
var extraArguments = "" var videoIdx = 0
var convert = false var extraArguments = ""
var convert = false
for (var i = 0; i < file.ffProbeData.streams.length; i++) { // Go through each stream in the file.
if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "video") { for (var i = 0; i < file.ffProbeData.streams.length; i++) {
if (file.ffProbeData.streams[i].codec_name == 'mjpeg' || file.ffProbeData.streams[i].codec_name == 'png') { // Check if stream is video.
convert = true if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "video") {
extraArguments += `-map -v:${videoIdx} ` // Check if stream codec is mjpeg or png. Remove if so.
} if (file.ffProbeData.streams[i].codec_name == 'mjpeg' || file.ffProbeData.streams[i].codec_name == 'png') {
videoIdx++ convert = true
} extraArguments += `-map -v:${videoIdx} `
} }
// Increment videoIdx.
videoIdx++
}
}
if (convert === true ) { // Convert file if convert variable is set to true.
response.preset += `,-map 0 -c copy -max_muxing_queue_size 4096 ${extraArguments}` if (convert === true) {
response.infoLog += `☒File has image format stream, removing. \n` response.preset += `,-map 0 -c copy -max_muxing_queue_size 4096 ${extraArguments}`
response.processFile = true; response.infoLog += `☒File has image format stream, removing. \n`
response.processFile = true;
} else { } else {
response.processFile = false; response.processFile = false;
response.infoLog += "☑File doesn't contain any unwanted image format streams.\n" response.infoLog += "☑File doesn't contain any unwanted image format streams.\n"
} }
return response return response
} }
module.exports.details = details; module.exports.details = details;
module.exports.plugin = plugin; module.exports.plugin = plugin;

@ -1,77 +1,84 @@
module.exports.details = function details() { module.exports.details = function details() {
return {
id: "Tdarr_Plugin_MC93_MigzPlex_Autoscan",
Stage: "Post-processing",
Name: "Send request for file to be scanned by plex_autoscan.",
Type: "Video",
Operation: "",
Description: `Send request for file to be scanned by plex_autoscan. https://github.com/l3uddz/plex_autoscan \n\n`,
Version: "1.1",
Link: "https://github.com/HaveAGitGat/Tdarr_Plugins/blob/master/Community/Tdarr_Plugin_MC93_MigzPlex_Autoscan.js",
Tags: "3rd party,post-processing,configurable",
return { Inputs: [{
id: "Tdarr_Plugin_MC93_MigzPlex_Autoscan", name: 'autoscan_address',
Stage: "Post-processing", tooltip: `
Name: "Send request for file to be scanned by plex_autoscan.", Enter the IP address/URL for autoscan. Must include http(s)://
Type: "Video",
Operation: "",
Description: `Send request for file to be scanned by plex_autoscan. https://github.com/l3uddz/plex_autoscan \n\n`,
Version: "1.00",
Link: "https://github.com/HaveAGitGat/Tdarr_Plugins/blob/master/Community/Tdarr_Plugin_MC93_MigzPlex_Autoscan.js",
Tags:"3rd party,post-processing,configurable",
Inputs: [ \\nExample:\\n
{ http://192.168.0.10
name: 'autoscan_address',
tooltip: `
Enter the IP address/URL for autoscan. Must include http(s)://
\\nExample:\\n \\nExample:\\n
http://192.168.0.10 https://subdomain.domain.tld`
},
{
name: 'autoscan_port',
tooltip: `
Enter the port Autoscan is using, default is 3468
\\nExample:\\n \\nExample:\\n
https://subdomain.domain.tld 3468`
` },
}, {
{ name: 'autoscan_passkey',
name: 'autoscan_port', tooltip: `
tooltip: `
Enter the port Autoscan is using, default is 3468
\\nExample:\\n Enter the autoscan passkey.
3468
`
},
{
name: 'autoscan_passkey',
tooltip: `
Enter the autoscan passkey. \\nExample:\\n
9c4b81fe234e4d6eb9011cefe514d915`
\\nExample:\\n },
9c4b81fe234e4d6eb9011cefe514d915 ]
` }
},
]
}
} }
module.exports.plugin = function plugin(file, librarySettings, inputs) { module.exports.plugin = function plugin(file, librarySettings, inputs) {
const request = require('request') // Check if all inputs have been configured. If they haven't then exit plugin.
const ADDRESS = inputs.autoscan_address if (inputs && inputs.autoscan_address == "" && inputs.autoscan_port == "" && inputs.autoscan_passkey == "") {
const PORT = inputs.autoscan_port response.infoLog += "☒Autoscan options have not been configured, please configure all options. Skipping this plugin. \n"
const PASSKEY = inputs.autoscan_passkey response.processFile = false;
return response
}
var response = "" // Take variable inputs and turn them into read only variable
filepath = `${file.file}` const request = require('request')
const ADDRESS = inputs.autoscan_address
const PORT = inputs.autoscan_port
const PASSKEY = inputs.autoscan_passkey
// Set up required variables.
var response = ""
filepath = `${file.file}`
// Set content of request/post.
request.post({ request.post({
headers: {'content-type': 'application/json'}, headers: {
url: `${ADDRESS}:${PORT}/${PASSKEY}`, 'content-type': 'application/json'
form: { "eventType" : "Manual", "filepath" : `${filepath}` } },
url: `${ADDRESS}:${PORT}/${PASSKEY}`,
form: {
"eventType": "Manual",
"filepath": `${filepath}`
}
}, (error, res, body) => { }, (error, res, body) => {
if (error) { if (error) {
console.error(error) console.error(error)
} }
console.log(`statusCode: ${res.statusCode}`) console.log(`statusCode: ${res.statusCode}`)
console.log(body) console.log(body)
}) })
console.log("request next") console.log("request next")
console.log(request.post) console.log(request.post)
} }

Loading…
Cancel
Save