From 07784116535cd44be102e9e5b03becfa59bd3fbb Mon Sep 17 00:00:00 2001 From: controlol <46456214+controlol@users.noreply.github.com> Date: Thu, 6 Feb 2020 22:54:37 +0100 Subject: [PATCH 1/4] Tdarr_Plugin_e5c3_CnT_Keep_Preferred_Audio Plugin that checks for unwanted audio, per 1.104 beta you can change the languages yourself from within Tdarr! Untill you enter a value it keep english tracks by default. Undefined languages are kept to prevent videos without sound. If you would like to keep track of the languages you have for each file you can use the 'special' option. --- ...Tdarr_Plugin_e5c3_CnT_Keep_Preferred_Audio | 119 ++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 Community/Tdarr_Plugin_e5c3_CnT_Keep_Preferred_Audio diff --git a/Community/Tdarr_Plugin_e5c3_CnT_Keep_Preferred_Audio b/Community/Tdarr_Plugin_e5c3_CnT_Keep_Preferred_Audio new file mode 100644 index 0000000..f9869be --- /dev/null +++ b/Community/Tdarr_Plugin_e5c3_CnT_Keep_Preferred_Audio @@ -0,0 +1,119 @@ +const exec = require('child_process').exec; +const fs = require('fs'); + +function details() { + return { + id: "Tdarr_Plugin_e5c3_CnT_Keep_Preferred_Audio", + Name: "Remove non-English audio", + Type: "Audio", + Operation:"Remove Audio", + 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.1", + Link: "https://github.com/HaveAGitGat/Tdarr_Plugins/blob/master/Community/Tdarr_Plugin_e5c3_CnT_Remove_non_English_Audio.js", + Inputs: [ + { + name: 'languages', + tooltip: `Desired Languages you would like to keep, language format has to be according to the iso-639-2 standard: https://en.wikipedia.org/wiki/List_of_ISO_639-2_codes\nIt could look like: "eng","dut"` + }, + { + name: 'special', + tooltip: `This is if you want a specific language to be logged to a file in your Tdarr documents folder.\nIt will add the name of the file that is being processed if this language(s) has been found.\nThe file is created the first time it finds a file with the language.\nIt could look like: "eng","dut"\nThe languages don't have to be in "languages".` + } + ] + } +} + +function plugin(file, librarySettings, inputs, otherArguments) { + if (inputs.languages == null) { + var languages = ["eng", "en"]; //these languages should be kept, named according to ISO 639-2 language scheme + } else { + var languages = inputs.languages.split(','); //these languages should be kept, named according to ISO 639-2 language scheme + } + if (inputs.special !== null) { + var special = inputs.special.split(','); + } + if (languages.length >= special.length) { + var length = languages.length; + } else { + var length = special.length; + } + var transcode = 0; //if this becomes '1' it will be transcoded + var sourcename = file.meta.FileName.substring(0, file.meta.FileName.lastIndexOf(".")); //filename without extension + var specialcheck = ``; //contains the txt string if special language was found + var wanted = 0; + var audio = 0; + + //default response + var response = { + processFile: false, + preset: `, -map 0:v`, + container: '.mkv', + handBrakeMode: false, + FFmpegMode: false, + reQueueAfter: false, + infoLog: 'Removing unwanted audio...\n', + }; + + for (i = 0; i < file.ffProbeData.streams.length; i++) { + if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio") { + //check for non-english tracks + if (file.ffProbeData.streams[i].tags.language) { + if (typeof file.ffProbeData.streams[i].tags.language !== 'undefined') { + for (l = 0; l < length; 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 + exec(`echo "${sourcename}" >> ${otherArguments.homePath}/Tdarr/special_audio_${special[l]}.txt`); //first file will be added and file is created + console.log(`added to txt: ` + sourcename); + } else { + specialcheck = fs.readFileSync(otherArguments.homePath + `/Tdarr/special_audio_${special[l]}.txt`).toString(); //create string from existing file + if (!specialcheck.includes(sourcename)) { //only add the filename if it wasn't added already + exec(`echo "${sourcename}" >> ${otherArguments.homePath}/Tdarr/special_audio_${special[l]}.txt`); + console.log(`added to txt: ` + sourcename); + } + } + + response.preset += ` -map 0:${i}`; + response.infoLog += `Found special ${special[l]}: ${i}\n`; + wanted++; + break; + } else if (file.ffProbeData.streams[i].tags.language == languages[l]) { + response.preset += ` -map 0:${i}`; + response.infoLog += `Found wanted ${languages[l]}: ${i}\n`; + wanted++; + break; + } + } + } else { + response.preset += ` -map 0:${i}`; + response.infoLog += `Added undefined: ${i}\n`; + wanted++; + } + } else { + response.preset += ` -map 0:${i}`; + response.infoLog += `Added undefined: ${i}\n`; + wanted++; + } + + audio++; + } + } + + if (audio > wanted && wanted > 1) { + transcode = 1; + } + + if (transcode == 1) { + response.infoLog += `Found unwanted audio\nIt will be removed\n`; + response.processFile = true; + response.FFmpegMode = true; + response.preset += ` -map 0:s? -c copy`; + response.reQueueAfter = true; + } else { + response.infoLog += `No unwanted audio found!\n`; + } + + return response +} + +module.exports.details = details; +module.exports.plugin = plugin; From f61b225095d7c4c88488a0e608145d154191d158 Mon Sep 17 00:00:00 2001 From: controlol <46456214+controlol@users.noreply.github.com> Date: Thu, 6 Feb 2020 23:08:29 +0100 Subject: [PATCH 2/4] Update Tdarr_Plugin_e5c3_CnT_Keep_Preferred_Audio --- Community/Tdarr_Plugin_e5c3_CnT_Keep_Preferred_Audio | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Community/Tdarr_Plugin_e5c3_CnT_Keep_Preferred_Audio b/Community/Tdarr_Plugin_e5c3_CnT_Keep_Preferred_Audio index f9869be..033e5cb 100644 --- a/Community/Tdarr_Plugin_e5c3_CnT_Keep_Preferred_Audio +++ b/Community/Tdarr_Plugin_e5c3_CnT_Keep_Preferred_Audio @@ -4,7 +4,7 @@ const fs = require('fs'); function details() { return { id: "Tdarr_Plugin_e5c3_CnT_Keep_Preferred_Audio", - Name: "Remove non-English audio", + Name: "Keep Preffered Audio", Type: "Audio", Operation:"Remove Audio", 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", @@ -24,7 +24,7 @@ function details() { } function plugin(file, librarySettings, inputs, otherArguments) { - if (inputs.languages == null) { + if (inputs.languages == "") { var languages = ["eng", "en"]; //these languages should be kept, named according to ISO 639-2 language scheme } else { var languages = inputs.languages.split(','); //these languages should be kept, named according to ISO 639-2 language scheme @@ -37,6 +37,7 @@ function plugin(file, librarySettings, inputs, otherArguments) { } else { var length = special.length; } + console.log(languages); var transcode = 0; //if this becomes '1' it will be transcoded var sourcename = file.meta.FileName.substring(0, file.meta.FileName.lastIndexOf(".")); //filename without extension var specialcheck = ``; //contains the txt string if special language was found From 3286e34d87217e3074b0342e88ea6517604e7d66 Mon Sep 17 00:00:00 2001 From: controlol <46456214+controlol@users.noreply.github.com> Date: Thu, 6 Feb 2020 23:10:04 +0100 Subject: [PATCH 3/4] Update Tdarr_Plugin_e5c3_CnT_Keep_Preferred_Audio --- Community/Tdarr_Plugin_e5c3_CnT_Keep_Preferred_Audio | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Community/Tdarr_Plugin_e5c3_CnT_Keep_Preferred_Audio b/Community/Tdarr_Plugin_e5c3_CnT_Keep_Preferred_Audio index 033e5cb..2c80b8c 100644 --- a/Community/Tdarr_Plugin_e5c3_CnT_Keep_Preferred_Audio +++ b/Community/Tdarr_Plugin_e5c3_CnT_Keep_Preferred_Audio @@ -5,7 +5,7 @@ function details() { return { id: "Tdarr_Plugin_e5c3_CnT_Keep_Preferred_Audio", Name: "Keep Preffered Audio", - Type: "Audio", + Type: "Video", Operation:"Remove Audio", 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.1", From 1abb17d809cb608133b073b0db628c6341179b14 Mon Sep 17 00:00:00 2001 From: controlol <46456214+controlol@users.noreply.github.com> Date: Thu, 6 Feb 2020 23:29:43 +0100 Subject: [PATCH 4/4] forgot .js extension --- ...ferred_Audio => Tdarr_Plugin_e5c3_CnT_Keep_Preferred_Audio.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Community/{Tdarr_Plugin_e5c3_CnT_Keep_Preferred_Audio => Tdarr_Plugin_e5c3_CnT_Keep_Preferred_Audio.js} (100%) diff --git a/Community/Tdarr_Plugin_e5c3_CnT_Keep_Preferred_Audio b/Community/Tdarr_Plugin_e5c3_CnT_Keep_Preferred_Audio.js similarity index 100% rename from Community/Tdarr_Plugin_e5c3_CnT_Keep_Preferred_Audio rename to Community/Tdarr_Plugin_e5c3_CnT_Keep_Preferred_Audio.js