mirror of
https://github.com/gabehf/Tdarr_Plugins.git
synced 2026-03-14 17:55:55 -07:00
Merge pull request #65 from controlol/master
fix errors that came with the version of 4/4/2020
This commit is contained in:
commit
77a7c3f220
2 changed files with 55 additions and 42 deletions
|
|
@ -11,6 +11,7 @@ function details() {
|
||||||
Description: "Plugin that checks for unwanted audio, per 1.104 beta you can change the languages yourself from within Tdarr!\nUntill you enter a value it keep english tracks by default.\nUndefined languages are kept to prevent videos without sound.\nIf you would like to keep track of the languages you have for each file you can use the 'special' option.\nCreated by @control#0405",
|
Description: "Plugin that checks for unwanted audio, per 1.104 beta you can change the languages yourself from within Tdarr!\nUntill you enter a value it keep english tracks by default.\nUndefined languages are kept to prevent videos without sound.\nIf you would like to keep track of the languages you have for each file you can use the 'special' option.\nCreated by @control#0405",
|
||||||
Version: "1.2",
|
Version: "1.2",
|
||||||
Link: "https://github.com/HaveAGitGat/Tdarr_Plugins/blob/master/Community/Tdarr_Plugin_e5c3_CnT_Keep_Preferred_Audio.js",
|
Link: "https://github.com/HaveAGitGat/Tdarr_Plugins/blob/master/Community/Tdarr_Plugin_e5c3_CnT_Keep_Preferred_Audio.js",
|
||||||
|
Tags: 'pre-processing,ffmpeg,configurable,audio only',
|
||||||
Inputs: [
|
Inputs: [
|
||||||
{
|
{
|
||||||
name: 'languages',
|
name: 'languages',
|
||||||
|
|
@ -23,18 +24,18 @@ function details() {
|
||||||
{
|
{
|
||||||
name: 'container',
|
name: 'container',
|
||||||
tooltip: `Enter the output container of the new file.\\n Default: .mkv\\nExample:\\n.mkv`
|
tooltip: `Enter the output container of the new file.\\n Default: .mkv\\nExample:\\n.mkv`
|
||||||
}
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function plugin(file, librarySettings, inputs, otherArguments) {
|
function plugin(file, librarySettings, inputs, otherArguments) {
|
||||||
if (inputs.languages == "" || inputs.special == 'undefined') {
|
if (inputs.languages == "" || typeof inputs.special == 'undefined') {
|
||||||
var languages = ["eng", "en"]; //these languages should be kept, named according to ISO 639-2 language scheme
|
var languages = ["eng", "en"]; //these languages should be kept, named according to ISO 639-2 language scheme
|
||||||
} else {
|
} else {
|
||||||
var languages = inputs.languages.toLowerCase().split(','); //these languages should be kept, named according to ISO 639-2 language scheme
|
var languages = inputs.languages.toLowerCase().split(','); //these languages should be kept, named according to ISO 639-2 language scheme
|
||||||
}
|
}
|
||||||
if (inputs.special == "" || inputs.special == 'undefined') {
|
if (inputs.special == "" || typeof inputs.special == 'undefined') {
|
||||||
var special = ``;
|
var special = ``;
|
||||||
} else {
|
} else {
|
||||||
var special = inputs.special.toLowerCase().split(',');
|
var special = inputs.special.toLowerCase().split(',');
|
||||||
|
|
@ -64,14 +65,17 @@ function plugin(file, librarySettings, inputs, otherArguments) {
|
||||||
|
|
||||||
if (inputs.container !== undefined) {
|
if (inputs.container !== undefined) {
|
||||||
response.container = inputs.container;
|
response.container = inputs.container;
|
||||||
console.log(`Changed container to: ` + inputs.container);
|
console.log(`Container was set to: ` + inputs.container);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < file.ffProbeData.streams.length; i++) {
|
for (i = 0; i < file.ffProbeData.streams.length; i++) {
|
||||||
if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio") {
|
if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio") {
|
||||||
//check for non-english tracks
|
//check for non-english tracks
|
||||||
if (file.ffProbeData.streams[i].tags.language) {
|
console.log(`Audio track ${i}`);
|
||||||
if (typeof file.ffProbeData.streams[i].tags.language !== 'undefined') {
|
console.log("type: " + typeof file.ffProbeData.streams[i].tags);
|
||||||
|
if (typeof file.ffProbeData.streams[i].tags !== 'undefined' || file.ffProbeData.streams[i].tags) {
|
||||||
|
console.log("Type: " + typeof file.ffProbeData.streams[i].tags.language)
|
||||||
|
if (typeof file.ffProbeData.streams[i].tags.language !== 'undefined' || file.ffProbeData.streams[i].tags.language) {
|
||||||
for (l = 0; l < length; l++) {
|
for (l = 0; l < length; l++) {
|
||||||
if (file.ffProbeData.streams[i].tags.language == special[l]) {
|
if (file.ffProbeData.streams[i].tags.language == special[l]) {
|
||||||
if (!fs.existsSync(otherArguments.homePath + `/Tdarr/special_audio_${special[l]}.txt`)) { //create txt file if it doesn't exist yet
|
if (!fs.existsSync(otherArguments.homePath + `/Tdarr/special_audio_${special[l]}.txt`)) { //create txt file if it doesn't exist yet
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,9 @@ function details() {
|
||||||
Type: "Video",
|
Type: "Video",
|
||||||
Operation:"Transcode",
|
Operation:"Transcode",
|
||||||
Description: `Uses iiDrakeii's filter, and crops video files when letterboxing is detected.\nThis uses the FFMPEG NVENC transcoding(hw).\nIf a file is 4K it will be scaled down to 1080p.\nNow with user definable bitrates!(since 1.104 beta)\nCreated by @control#0405`,
|
Description: `Uses iiDrakeii's filter, and crops video files when letterboxing is detected.\nThis uses the FFMPEG NVENC transcoding(hw).\nIf a file is 4K it will be scaled down to 1080p.\nNow with user definable bitrates!(since 1.104 beta)\nCreated by @control#0405`,
|
||||||
Version: "1.4",
|
Version: "1.3",
|
||||||
Link: "https://github.com/HaveAGitGat/Tdarr_Plugins/blob/master/Community/Tdarr_Plugin_e5c3_CnT_Remove_Letterbox.js",
|
Link: "https://github.com/HaveAGitGat/Tdarr_Plugins/blob/master/Community/Tdarr_Plugin_e5c3_CnT_Remove_Letterbox.js",
|
||||||
|
Tags: 'pre-processing,ffmpeg,nvenc h265,configurable,h265,video only',
|
||||||
Inputs: [
|
Inputs: [
|
||||||
{
|
{
|
||||||
name: 'bitrate',
|
name: 'bitrate',
|
||||||
|
|
@ -20,13 +21,12 @@ function details() {
|
||||||
name: 'container',
|
name: 'container',
|
||||||
tooltip: `Enter the output container of the new file.\\n Default: .mkv\\nExample:\\n.mkv`
|
tooltip: `Enter the output container of the new file.\\n Default: .mkv\\nExample:\\n.mkv`
|
||||||
},
|
},
|
||||||
],
|
]
|
||||||
Tags:'pre-processing,video only,ffmpeg,configurable',
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function plugin(file, librarySettings, inputs, otherArguments) {
|
function plugin(file, librarySettings, inputs, otherArguments) {
|
||||||
if (inputs.bitrate == "" || inputs.special == 'undefined') {
|
if (inputs.bitrate == "" || inputs.bitrate == 'undefined') {
|
||||||
var min_bitrate = 6600;
|
var min_bitrate = 6600;
|
||||||
var avg_rate = 3000;
|
var avg_rate = 3000;
|
||||||
var max_rate = 6000;
|
var max_rate = 6000;
|
||||||
|
|
@ -36,14 +36,6 @@ function plugin(file, librarySettings, inputs, otherArguments) {
|
||||||
var max_rate = inputs.bitrate*2;
|
var max_rate = inputs.bitrate*2;
|
||||||
}
|
}
|
||||||
|
|
||||||
var source = file.meta.SourceFile; //source file
|
|
||||||
var stats = fs.statSync(source);
|
|
||||||
var size = stats["size"]/1000000000;
|
|
||||||
size = size.toFixed(2);
|
|
||||||
var decoder = decoder_string(file); //decoder, before the input
|
|
||||||
var encoder = encoder_string_full(file, highres(file), crop_decider(file, create_crop_values(file).crop_height).crop, avg_rate, max_rate); //encoder
|
|
||||||
var process = 0; //decides if it should be processed
|
|
||||||
|
|
||||||
//default values that will be returned
|
//default values that will be returned
|
||||||
var response = {
|
var response = {
|
||||||
processFile: false,
|
processFile: false,
|
||||||
|
|
@ -57,12 +49,20 @@ function plugin(file, librarySettings, inputs, otherArguments) {
|
||||||
|
|
||||||
if (inputs.container !== undefined) {
|
if (inputs.container !== undefined) {
|
||||||
response.container = inputs.container;
|
response.container = inputs.container;
|
||||||
console.log(`Changed container to: ` + inputs.container);
|
console.log(`Container was set to: ` + inputs.container);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var source = file.meta.SourceFile; //source file
|
||||||
|
var stats = fs.statSync(source);
|
||||||
|
var size = stats["size"]/1000000000;
|
||||||
|
size = size.toFixed(2);
|
||||||
|
var decoder = decoder_string(file); //decoder, before the input
|
||||||
|
var encoder = encoder_string_full(highres(file), crop_decider(file, generate_crop_values(file, otherArguments).crop_height).crop, encoder_string(file, avg_rate, max_rate, response.container)); //encoder
|
||||||
|
var process = 0; //decides if it should be processed
|
||||||
|
|
||||||
var returns = {
|
var returns = {
|
||||||
create_crop: create_crop_values(file),
|
create_crop: generate_crop_values(file, otherArguments),
|
||||||
crop: crop_decider(file, create_crop_values(file).crop_height),
|
crop: crop_decider(file, generate_crop_values(file, otherArguments).crop_height),
|
||||||
size: size_check(file, min_bitrate)
|
size: size_check(file, min_bitrate)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -90,7 +90,7 @@ function plugin(file, librarySettings, inputs, otherArguments) {
|
||||||
log.resolution += `☒ - Resolution <= 1080p \n`;
|
log.resolution += `☒ - Resolution <= 1080p \n`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (crop_decider(file, create_crop_values(file).crop_height).crop != "0") {
|
if (crop_decider(file, generate_crop_values(file, otherArguments).crop_height).crop != "0") {
|
||||||
process = 1;
|
process = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -109,10 +109,6 @@ function plugin(file, librarySettings, inputs, otherArguments) {
|
||||||
} else if (file.forceProcessing === true) {
|
} else if (file.forceProcessing === true) {
|
||||||
response.processFile = true;
|
response.processFile = true;
|
||||||
response.infoLog += `Force processing!\n`;
|
response.infoLog += `Force processing!\n`;
|
||||||
} else if (response.container !== `.` + file.container) {
|
|
||||||
response.infoLog += `Container is not correct\nMuxing to ${response.container}!\n`;
|
|
||||||
response.preset = `${decoder}, -c copy`;
|
|
||||||
response.processFile = true;
|
|
||||||
} else {
|
} else {
|
||||||
response.infoLog += `Processing not necessary\n`;
|
response.infoLog += `Processing not necessary\n`;
|
||||||
}
|
}
|
||||||
|
|
@ -129,7 +125,7 @@ function highres(file) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function create_crop_values(file) {
|
function generate_crop_values(file, otherArguments) {
|
||||||
var source = file.meta.SourceFile; //source file
|
var source = file.meta.SourceFile; //source file
|
||||||
var dir = file.meta.Directory; //source directory
|
var dir = file.meta.Directory; //source directory
|
||||||
var sourcename = file.meta.FileName.substring(0, file.meta.FileName.lastIndexOf(".")); //filename without extension
|
var sourcename = file.meta.FileName.substring(0, file.meta.FileName.lastIndexOf(".")); //filename without extension
|
||||||
|
|
@ -142,8 +138,8 @@ function create_crop_values(file) {
|
||||||
//create crop value
|
//create crop value
|
||||||
if (!fs.existsSync(`${cropfile}`)) {
|
if (!fs.existsSync(`${cropfile}`)) {
|
||||||
returns.log += `Creating crop values...\n`;
|
returns.log += `Creating crop values...\n`;
|
||||||
execSync(otherArguments.ffmpegPath + ` -ss 300 -i \"${source}\" -frames:v 240 -vf cropdetect -f null - 2>&1 | awk \'/crop/ { print $NF }\' | tail -240 > \"${cropfile}\"`);
|
execSync(`${otherArguments.ffmpegPath} -ss 300 -i \"${source}\" -frames:v 240 -vf cropdetect -f null - 2>&1 | awk \'/crop/ { print $NF }\' | tail -240 > \"${cropfile}\"`);
|
||||||
execSync(otherArguments.ffmpegPath + ` -ss 1200 -i \"${source}\" -frames:v 240 -vf cropdetect -f null - 2>&1 | awk \'/crop/ { print $NF }\' | tail -240 >> \"${cropfile}\"`);
|
execSync(`${otherArguments.ffmpegPath} -ss 1200 -i \"${source}\" -frames:v 240 -vf cropdetect -f null - 2>&1 | awk \'/crop/ { print $NF }\' | tail -240 >> \"${cropfile}\"`);
|
||||||
} else {
|
} else {
|
||||||
returns.log += `Crop values already exist\n`;
|
returns.log += `Crop values already exist\n`;
|
||||||
}
|
}
|
||||||
|
|
@ -154,9 +150,11 @@ function create_crop_values(file) {
|
||||||
//get height of the supposed cropped video
|
//get height of the supposed cropped video
|
||||||
//var crop_height = parseInt(data[0].substring(10, 14));
|
//var crop_height = parseInt(data[0].substring(10, 14));
|
||||||
for (var c = 0; c < data.length; c++) {
|
for (var c = 0; c < data.length; c++) {
|
||||||
if (parseInt(data[c].substring(10, 14)) > returns.crop_height) {
|
crop = data[c].split(":");
|
||||||
returns.crop_height = parseInt(data[c].substring(10, 14));
|
crop_height = Math.abs(parseInt(crop[1]));
|
||||||
returns.log += `New cropheight: ${parseInt(data[c].substring(10, 14))}\n`;
|
if (crop_height > returns.crop_height) {
|
||||||
|
returns.crop_height = crop_height;
|
||||||
|
returns.log += `New cropheight: ${crop_height}\n`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return returns;
|
return returns;
|
||||||
|
|
@ -303,7 +301,7 @@ function size_check(file, min_bitrate) {
|
||||||
return returns;
|
return returns;
|
||||||
}
|
}
|
||||||
|
|
||||||
function error_fix(file) {
|
function error_fix(file, container) {
|
||||||
var fix = {
|
var fix = {
|
||||||
sub_codec: 0, //changes to 1 if unwanted codec is found
|
sub_codec: 0, //changes to 1 if unwanted codec is found
|
||||||
muxing: 0
|
muxing: 0
|
||||||
|
|
@ -313,7 +311,7 @@ function error_fix(file) {
|
||||||
|
|
||||||
//these subtitle codecs don't fit in a mkv container
|
//these subtitle codecs don't fit in a mkv container
|
||||||
if (file.ffProbeData.streams[i].codec_name && file.ffProbeData.streams[i].codec_type) {
|
if (file.ffProbeData.streams[i].codec_name && file.ffProbeData.streams[i].codec_type) {
|
||||||
if (file.ffProbeData.streams[i].codec_name.toLowerCase() == "eia_608" || file.ffProbeData.streams[i].codec_name.toLowerCase() == "mov_text" && file.ffProbeData.streams[i].codec_type.toLowerCase.includes("sub") && response.container == '.mkv') {
|
if (file.ffProbeData.streams[i].codec_name.toLowerCase() == "eia_608" || file.ffProbeData.streams[i].codec_name.toLowerCase() == "mov_text" && file.ffProbeData.streams[i].codec_type.toLowerCase().includes("sub") && container == '.mkv') {
|
||||||
fix.sub_codec = 1;
|
fix.sub_codec = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -327,9 +325,9 @@ function error_fix(file) {
|
||||||
return fix;
|
return fix;
|
||||||
}
|
}
|
||||||
|
|
||||||
function encoder_string(file, avg_rate, max_rate) {
|
function encoder_string(file, avg_rate, max_rate, container) {
|
||||||
var encoder = ``; //encoder
|
var encoder = ``; //encoder
|
||||||
var fix = error_fix(file);
|
var fix = error_fix(file, container);
|
||||||
var sub = ``;
|
var sub = ``;
|
||||||
|
|
||||||
//tree for resolution : quality
|
//tree for resolution : quality
|
||||||
|
|
@ -339,6 +337,8 @@ function encoder_string(file, avg_rate, max_rate) {
|
||||||
encoder += ` -pix_fmt p010le -rc:v vbr_hq -qmin 0 -cq:v 26 -b:v ${avg_rate/2}k -maxrate:v ${max_rate/2}k`; //-qp 28
|
encoder += ` -pix_fmt p010le -rc:v vbr_hq -qmin 0 -cq:v 26 -b:v ${avg_rate/2}k -maxrate:v ${max_rate/2}k`; //-qp 28
|
||||||
} else if(file.video_resolution === "480p" || file.video_resolution === "576p") { //file will be encoded if the resolution is 480p or 576p
|
} else if(file.video_resolution === "480p" || file.video_resolution === "576p") { //file will be encoded if the resolution is 480p or 576p
|
||||||
encoder += ` -pix_fmt p010le -rc:v vbr_hq -qmin 0 -cq:v 26 -b:v ${avg_rate/4}k -maxrate:v ${max_rate/4}k`; //-qp 30
|
encoder += ` -pix_fmt p010le -rc:v vbr_hq -qmin 0 -cq:v 26 -b:v ${avg_rate/4}k -maxrate:v ${max_rate/4}k`; //-qp 30
|
||||||
|
} else { //fallback option to 1080p quality
|
||||||
|
encoder += ` -pix_fmt p010le -rc:v vbr_hq -qmin 0 -cq:v 26 -b:v ${avg_rate}k -maxrate:v ${max_rate}k`; //-qp 26
|
||||||
}
|
}
|
||||||
encoder += ` -c:v hevc_nvenc -preset slow -rc-lookahead 32 -spatial_aq:v 1 -aq-strength:v 8 -a53cc 0 -dn`;
|
encoder += ` -c:v hevc_nvenc -preset slow -rc-lookahead 32 -spatial_aq:v 1 -aq-strength:v 8 -a53cc 0 -dn`;
|
||||||
|
|
||||||
|
|
@ -363,14 +363,11 @@ function encoder_string(file, avg_rate, max_rate) {
|
||||||
if (fix.muxing == 1) {
|
if (fix.muxing == 1) {
|
||||||
encoder += ` -max_muxing_queue_size 2048`;
|
encoder += ` -max_muxing_queue_size 2048`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return encoder + ` -c:a copy` + sub;
|
return encoder + ` -c:a copy` + sub;
|
||||||
}
|
}
|
||||||
|
|
||||||
function encoder_string_full(file, highres, crop, avg_rate, max_rate) {
|
function encoder_string_full(highres, crop, encoder) {
|
||||||
var encoder = encoder_string(file, avg_rate, max_rate);
|
console.log(`crop filter: ` + crop);
|
||||||
|
|
||||||
console.log(`crop filter: ` + crop)
|
|
||||||
|
|
||||||
if (highres == 1 && crop != "0") {
|
if (highres == 1 && crop != "0") {
|
||||||
return crop + `,scale=-1:1920 ` + encoder;
|
return crop + `,scale=-1:1920 ` + encoder;
|
||||||
|
|
@ -383,5 +380,17 @@ function encoder_string_full(file, highres, crop, avg_rate, max_rate) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function execCommand(cmd) {
|
||||||
|
const exec = require('child_process').exec;
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
exec(cmd, (error, stdout, stderr) => {
|
||||||
|
if (error) {
|
||||||
|
console.warn(error);
|
||||||
|
}
|
||||||
|
resolve(stdout? stdout : stderr);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
module.exports.details = details;
|
module.exports.details = details;
|
||||||
module.exports.plugin = plugin;
|
module.exports.plugin = plugin;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue