From 4ba83c804b175fe09e62eb3f7b34a7c522b4dccc Mon Sep 17 00:00:00 2001 From: Migz93 <33037112+Migz93@users.noreply.github.com> Date: Mon, 19 Oct 2020 19:48:04 +0100 Subject: [PATCH] Migz Plugin Updates 1) Update to CleanTitle plugin to allow user input custom matching title, allows to remove more then just the default of something with 3 full stops. 2) Update to both FFMPEG plugins to fix a bug where if the force_conform option was enabled and a stream had no codec_name it would cause the plugin to error out. --- Community/Tdarr_Plugin_MC93_Migz1FFMPEG.js | 56 ++++++++++--------- .../Tdarr_Plugin_MC93_Migz1FFMPEG_CPU.js | 56 ++++++++++--------- .../Tdarr_Plugin_MC93_Migz2CleanTitle.js | 31 +++++++++- 3 files changed, 86 insertions(+), 57 deletions(-) diff --git a/Community/Tdarr_Plugin_MC93_Migz1FFMPEG.js b/Community/Tdarr_Plugin_MC93_Migz1FFMPEG.js index 98e25b7..d5e0172 100644 --- a/Community/Tdarr_Plugin_MC93_Migz1FFMPEG.js +++ b/Community/Tdarr_Plugin_MC93_Migz1FFMPEG.js @@ -6,7 +6,7 @@ function details() { Type: "Video", Operation: "Transcode", 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.6", + Version: "2.7", Link: "https://github.com/HaveAGitGat/Tdarr_Plugins/blob/master/Community/Tdarr_Plugin_MC93_Migz1FFMPEG.js", Tags: "pre-processing,ffmpeg,video only,nvenc h265,configurable", @@ -132,34 +132,36 @@ function plugin(file, librarySettings, inputs) { if (inputs.force_conform == "true") { if (inputs.container.toLowerCase() == "mkv") { extraArguments += `-map -0:d `; - for (var i = 0; i < file.ffProbeData.streams.length; i++) { - if ( - file.ffProbeData.streams[i].codec_name - .toLowerCase() == "mov_text" || - file.ffProbeData.streams[i].codec_name - .toLowerCase() == "eia_608" || - file.ffProbeData.streams[i].codec_name - .toLowerCase() == "timed_id3" - ) { - extraArguments += `-map -0:${i} `; - } - } + for (var i = 0; i < file.ffProbeData.streams.length; i++) + try { + if ( + file.ffProbeData.streams[i].codec_name + .toLowerCase() == "mov_text" || + file.ffProbeData.streams[i].codec_name + .toLowerCase() == "eia_608" || + file.ffProbeData.streams[i].codec_name + .toLowerCase() == "timed_id3" + ) { + extraArguments += `-map -0:${i} `; + } + } catch (err) {} } if (inputs.container.toLowerCase() == "mp4") { - for (var i = 0; i < file.ffProbeData.streams.length; i++) { - if ( - file.ffProbeData.streams[i].codec_name - .toLowerCase() == "hdmv_pgs_subtitle" || - file.ffProbeData.streams[i].codec_name - .toLowerCase() == "eia_608" || - file.ffProbeData.streams[i].codec_name - .toLowerCase() == "subrip" || - file.ffProbeData.streams[i].codec_name - .toLowerCase() == "timed_id3" - ) { - extraArguments += `-map -0:${i} `; - } - } + for (var i = 0; i < file.ffProbeData.streams.length; i++) + try { + if ( + file.ffProbeData.streams[i].codec_name + .toLowerCase() == "hdmv_pgs_subtitle" || + file.ffProbeData.streams[i].codec_name + .toLowerCase() == "eia_608" || + file.ffProbeData.streams[i].codec_name + .toLowerCase() == "subrip" || + file.ffProbeData.streams[i].codec_name + .toLowerCase() == "timed_id3" + ) { + extraArguments += `-map -0:${i} `; + } + } catch (err) {} } } diff --git a/Community/Tdarr_Plugin_MC93_Migz1FFMPEG_CPU.js b/Community/Tdarr_Plugin_MC93_Migz1FFMPEG_CPU.js index 10f61d1..53b4dd2 100644 --- a/Community/Tdarr_Plugin_MC93_Migz1FFMPEG_CPU.js +++ b/Community/Tdarr_Plugin_MC93_Migz1FFMPEG_CPU.js @@ -6,7 +6,7 @@ function details() { Type: "Video", Operation: "Transcode", 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.5", + Version: "1.6", Link: "https://github.com/HaveAGitGat/Tdarr_Plugins/blob/master/Community/Tdarr_Plugin_MC93_Migz1FFMPEG_CPU.js", Tags: "pre-processing,ffmpeg,video only,configurable,h265", @@ -122,34 +122,36 @@ function plugin(file, librarySettings, inputs) { if (inputs.force_conform == "true") { if (inputs.container.toLowerCase() == "mkv") { extraArguments += `-map -0:d `; - for (var i = 0; i < file.ffProbeData.streams.length; i++) { - if ( - file.ffProbeData.streams[i].codec_name - .toLowerCase() == "mov_text" || - file.ffProbeData.streams[i].codec_name - .toLowerCase() == "eia_608" || - file.ffProbeData.streams[i].codec_name - .toLowerCase() == "timed_id3" - ) { - extraArguments += `-map -0:${i} `; - } - } + for (var i = 0; i < file.ffProbeData.streams.length; i++) + try { + if ( + file.ffProbeData.streams[i].codec_name + .toLowerCase() == "mov_text" || + file.ffProbeData.streams[i].codec_name + .toLowerCase() == "eia_608" || + file.ffProbeData.streams[i].codec_name + .toLowerCase() == "timed_id3" + ) { + extraArguments += `-map -0:${i} `; + } + } catch (err) {} } if (inputs.container.toLowerCase() == "mp4") { - for (var i = 0; i < file.ffProbeData.streams.length; i++) { - if ( - file.ffProbeData.streams[i].codec_name - .toLowerCase() == "hdmv_pgs_subtitle" || - file.ffProbeData.streams[i].codec_name - .toLowerCase() == "eia_608" || - file.ffProbeData.streams[i].codec_name - .toLowerCase() == "subrip" || - file.ffProbeData.streams[i].codec_name - .toLowerCase() == "timed_id3" - ) { - extraArguments += `-map -0:${i} `; - } - } + for (var i = 0; i < file.ffProbeData.streams.length; i++) + try { + if ( + file.ffProbeData.streams[i].codec_name + .toLowerCase() == "hdmv_pgs_subtitle" || + file.ffProbeData.streams[i].codec_name + .toLowerCase() == "eia_608" || + file.ffProbeData.streams[i].codec_name + .toLowerCase() == "subrip" || + file.ffProbeData.streams[i].codec_name + .toLowerCase() == "timed_id3" + ) { + extraArguments += `-map -0:${i} `; + } + } catch (err) {} } } diff --git a/Community/Tdarr_Plugin_MC93_Migz2CleanTitle.js b/Community/Tdarr_Plugin_MC93_Migz2CleanTitle.js index 8233088..993ef94 100644 --- a/Community/Tdarr_Plugin_MC93_Migz2CleanTitle.js +++ b/Community/Tdarr_Plugin_MC93_Migz2CleanTitle.js @@ -6,7 +6,7 @@ function details() { Type: "Video", 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`, - Version: "1.3", + Version: "1.4", Link: "https://github.com/HaveAGitGat/Tdarr_Plugins/blob/master/Community/Tdarr_Plugin_MC93_Migz2CleanTitle.js", Tags: "pre-processing,ffmpeg,configurable", @@ -28,6 +28,15 @@ function details() { \\nExample:\\n false`, + }, + { + name: "custom_title_matching", + tooltip: `By default if you enable audio or subtitle cleaning the plugin only looks for titles with more then 3 full stops, this is what i think is the safest way to identify junk metadata without removing real metadata that you might want to keep. Here you can specify your own text for it to also search for to match and remove. Comma separated. Optional. + \\nExample:\\n + MiNX - Small HD episodes + + \\nExample:\\n + MiNX - Small HD episodes,GalaxyTV - small excellence!`, }, ], }; @@ -45,11 +54,17 @@ function plugin(file, librarySettings, inputs) { }; // Set up required variables. + var ffmpegCommandInsert = ""; var videoIdx = 0; var audioIdx = 0; var subtitleIdx = 0; var convert = false; + + // Check if inputs.custom_title_matching has been configured. If it has then set variable + if (inputs.custom_title_matching != "") { + var custom_title_matching = inputs.custom_title_matching.toLowerCase().split(","); + } // Check if file is a video. If it isn't then exit plugin. if (file.fileMedium !== "video") { @@ -81,7 +96,7 @@ function plugin(file, librarySettings, inputs) { videoIdx++; } - // 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. + // 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. Then check if any audio streams match with user input custom_title_matching variable, if so then remove. if ( file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio" && inputs.clean_audio.toLowerCase() == "true" @@ -90,12 +105,17 @@ function plugin(file, librarySettings, inputs) { response.infoLog += `☒More then 3 full stops detected in audio title, likely to be junk metadata. Removing title from stream ${i} \n`; ffmpegCommandInsert += ` -metadata:s:a:${audioIdx} title="" `; convert = true; + } + if (custom_title_matching.indexOf(file.ffProbeData.streams[i].tags.title.toLowerCase()) !== -1) { + response.infoLog += `☒Audio matched custom input. Removing title from stream ${i} \n`; + ffmpegCommandInsert += ` -metadata:s:a:${audioIdx} title="" `; + convert = true; } // Increment audioIdx. audioIdx++; } - // 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. + // 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. Then check if any audio streams match with user input custom_title_matching variable, if so then remove. if ( file.ffProbeData.streams[i].codec_type.toLowerCase() == "subtitle" && inputs.clean_subtitles.toLowerCase() == "true" @@ -104,6 +124,11 @@ function plugin(file, librarySettings, inputs) { response.infoLog += `☒More then 3 full stops detected in subtitle title, likely to be junk metadata. Removing title from stream ${i} \n`; ffmpegCommandInsert += ` -metadata:s:s:${subtitleIdx} title="" `; convert = true; + } + if (custom_title_matching.indexOf(file.ffProbeData.streams[i].tags.title.toLowerCase()) !== -1) { + response.infoLog += `☒Subtitle matched custom input. Removing title from stream ${i} \n`; + ffmpegCommandInsert += ` -metadata:s:s:${subtitleIdx} title="" `; + convert = true; } // Increment subtitleIdx. subtitleIdx++;