From 2e37ed84bf0a471990cbdf88d3828dd3739b2f42 Mon Sep 17 00:00:00 2001 From: Migz93 <33037112+Migz93@users.noreply.github.com> Date: Mon, 23 Mar 2020 10:56:26 +0000 Subject: [PATCH 1/2] Update: Migz2CleanTitle Updated the way that audio/subtitles decide if the title is junk or not. Fixes issue with conversion loop when used with my CleanAudio plugin. --- .../Tdarr_Plugin_MC93_Migz2CleanTitle.js | 92 +++++++++++-------- 1 file changed, 54 insertions(+), 38 deletions(-) diff --git a/Community/Tdarr_Plugin_MC93_Migz2CleanTitle.js b/Community/Tdarr_Plugin_MC93_Migz2CleanTitle.js index 98388e7..07fc898 100644 --- a/Community/Tdarr_Plugin_MC93_Migz2CleanTitle.js +++ b/Community/Tdarr_Plugin_MC93_Migz2CleanTitle.js @@ -5,14 +5,34 @@ function details() { Name: "Migz-Clean title metadata", Type: "Video", Operation: "Clean", - Description: `This plugin removes title metadata from video/audio/subtitles, if it exists. \n\n`, - Version: "1.10", + 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", Link: "https://github.com/HaveAGitGat/Tdarr_Plugins/blob/master/Community/Tdarr_Plugin_MC93_Migz2CleanTitle.js", - Tags:'pre-processing,ffmpeg', + Tags:'pre-processing,ffmpeg,configurable', + Inputs: [ + { + name: 'clean_audio', + tooltip: `Specify if audio titles should be checked & cleaned. Optional. + \\nExample:\\n + true + + \\nExample:\\n + false` + }, + { + name: 'clean_subtitles', + tooltip: `Specify if subtitle titles should be checked & cleaned. Optional. + \\nExample:\\n + true + + \\nExample:\\n + false` + }, + ] } } -function plugin(file) { +function plugin(file, librarySettings, inputs) { var response = { processFile : false, preset : '', @@ -23,7 +43,7 @@ function plugin(file) { infoLog : '', } - + var ffmpegCommandInsert = '' var videoIdx = 0 var audioIdx = 0 @@ -36,47 +56,43 @@ function plugin(file) { response.processFile = false; return response } - - try { - if (typeof file.meta.Title != 'undefined' ){ + + if (typeof file.meta.Title != 'undefined') try { ffmpegCommandInsert += ` -metadata title="" ` - response.infoLog += "1" convert = true - } - } catch (err) { } - - for (var i = 0; i < file.ffProbeData.streams.length; i++) { + } catch (err) { } + + for (var i = 0; i < file.ffProbeData.streams.length; i++) try { if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "video") { - try { - if (typeof file.ffProbeData.streams[i].tags.title != 'undefined') { - ffmpegCommandInsert += ` -metadata:s:v:${videoIdx} title="" ` - convert = true - } - } catch (err) { } + if (typeof file.ffProbeData.streams[i].tags.title != 'undefined') { + response.infoLog += `☒Video stream title is not empty, most likely junk metadata. Removing title from stream ${i} \n` + ffmpegCommandInsert += ` -metadata:s:v:${videoIdx} title="" ` + convert = true + } videoIdx++ } - if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio") { - try { - if (typeof file.ffProbeData.streams[i].tags.title != 'undefined') { - ffmpegCommandInsert += ` -metadata:s:a:${audioIdx} title="" ` - convert = true - } - } catch (err) { } + + if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio" && inputs.clean_audio.toLowerCase() == "true") { + if (file.ffProbeData.streams[i].tags.title.split('.').length-1 > 3) { + 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:a:${audioIdx} title="" ` + convert = true + } audioIdx++ } - if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "subtitle") { - try { - if (typeof file.ffProbeData.streams[i].tags.title != 'undefined') { - ffmpegCommandInsert += ` -metadata:s:s:${subtitleIdx} title="" ` - convert = true - } - } catch (err) { } + + if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "subtitle" && inputs.clean_subtitles.toLowerCase() == "true") { + if (file.ffProbeData.streams[i].tags.title.split('.').length-1 > 3) { + 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 + } subtitleIdx++ } - } - - if (convert == true){ - response.infoLog += "☒File has title metadata \n" + } catch (err) { } + + if (convert == true) { + response.infoLog += "☒File has title metadata. Removing \n" response.preset = `,${ffmpegCommandInsert} -c copy` response.reQueueAfter = true; response.processFile = true; @@ -87,4 +103,4 @@ function plugin(file) { } module.exports.details = details; -module.exports.plugin = plugin; \ No newline at end of file +module.exports.plugin = plugin; From f9124c2368b1f1023f49b61fb38de2cdfa168677 Mon Sep 17 00:00:00 2001 From: Migz93 <33037112+Migz93@users.noreply.github.com> Date: Mon, 23 Mar 2020 12:40:16 +0000 Subject: [PATCH 2/2] Update: MigzPlugins Update to both FFMPEG plugins to fix issue with data streams not being dropped for mkv in certain circumstances. Would cause plugin to fail. --- Community/Tdarr_Plugin_MC93_Migz1FFMPEG.js | 12 +++++++----- Community/Tdarr_Plugin_MC93_Migz1FFMPEG_CPU.js | 11 ++++++----- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Community/Tdarr_Plugin_MC93_Migz1FFMPEG.js b/Community/Tdarr_Plugin_MC93_Migz1FFMPEG.js index 5f056e5..e4a24e7 100644 --- a/Community/Tdarr_Plugin_MC93_Migz1FFMPEG.js +++ b/Community/Tdarr_Plugin_MC93_Migz1FFMPEG.js @@ -53,6 +53,10 @@ function plugin(file, librarySettings, inputs) { } else { response.container = '.' + inputs.container } + + if (inputs.container == "mkv") { + extraArguments = "-map -0:d " + } if (file.fileMedium !== "video") { response.processFile = false @@ -73,6 +77,7 @@ function plugin(file, librarySettings, inputs) { 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" @@ -87,7 +92,7 @@ function plugin(file, librarySettings, inputs) { return response } else { response.processFile = true - response.preset += `, -c copy` + 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 } @@ -102,7 +107,7 @@ function plugin(file, librarySettings, inputs) { } 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' + response.preset = `, -map 0 -c copy ${extraArguments}` response.processFile = true; return response } @@ -140,9 +145,6 @@ function plugin(file, librarySettings, inputs) { response.preset = `-c:v vp9_cuvid` } - if (inputs.container == "mkv") { - extraArguments = "-map -0:d " - } 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 diff --git a/Community/Tdarr_Plugin_MC93_Migz1FFMPEG_CPU.js b/Community/Tdarr_Plugin_MC93_Migz1FFMPEG_CPU.js index c4f4fda..fad9d24 100644 --- a/Community/Tdarr_Plugin_MC93_Migz1FFMPEG_CPU.js +++ b/Community/Tdarr_Plugin_MC93_Migz1FFMPEG_CPU.js @@ -53,6 +53,10 @@ function plugin(file, librarySettings, inputs) { } else { response.container = '.' + inputs.container } + + if (inputs.container == "mkv") { + extraArguments = "-map -0:d " + } if (file.fileMedium !== "video") { response.processFile = false @@ -87,7 +91,7 @@ function plugin(file, librarySettings, inputs) { return response } else { response.processFile = true - response.preset += `, -c copy` + 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 } @@ -102,7 +106,7 @@ function plugin(file, librarySettings, inputs) { } 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' + response.preset = `, -map 0 -c copy ${extraArguments}` response.processFile = true; return response } @@ -112,9 +116,6 @@ function plugin(file, librarySettings, inputs) { 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` - if (inputs.container == "mkv") { - extraArguments = "-map -0:d " - } 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