From bfef01f41d549f719092e13929fb26c8cddb06a4 Mon Sep 17 00:00:00 2001 From: drpeppershaker <67330126+drpeppershaker@users.noreply.github.com> Date: Tue, 22 Dec 2020 16:36:39 -0500 Subject: [PATCH 01/10] Add files via upload --- ...rr01_drpeppershaker_extract_subs_to_SRT.js | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 Community/Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js diff --git a/Community/Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js b/Community/Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js new file mode 100644 index 0000000..b50d4da --- /dev/null +++ b/Community/Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js @@ -0,0 +1,109 @@ +const fs = require('fs'); + +module.exports.details = function details() { + return { + id: 'Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT', + Stage: 'Pre-processing', + Name: 'drpeppershaker Extract embedded subtitles and optionally remove them', + Type: 'Video', + Operation: 'Transcode', + Description: 'This plugin extracts embedded subs in one pass inside Tdarr and will optionally remove them. \n\n ' + + 'All processes happen within Tdarr without the use of any exec() functions, which lets the progress bar ' + + 'report the status correctly. AND all subtitles are extracted in one pass, which is much faster than ' + + 'other options.\n\nCreated by drpeppershaker with help from reddit user /u/jakejones48, lots of ' + + 'improvements made after looking at "Tdarr_Plugin_078d" by HaveAGitGat.', + Version: '1.00', + Link: '', + Tags: "pre-processing,subtitle only,ffmpeg,configurable", + Inputs: [ + { + name: 'remove_subs', + tooltip: `Do you want to remove subtitles after they are extracted? + + \\nExample:\\n + + yes + + \\nExample:\\n + + no + `, + }, + ], + }; +}; + +module.exports.plugin = function plugin(file, librarySettings, inputs) { + // Must return this object at some point in the function else plugin will fail. + + const response = { + processFile: true, + preset: '', + container: `.${file.container}`, + handBrakeMode: false, + FFmpegMode: true, + reQueueAfter: false, + infoLog: '', + }; + + console.log(inputs.remove_subs); + + if (inputs.remove_subs === undefined) { + response.processFile = false; + response.infoLog += '☒ Inputs not entered! \n'; + return response; + } + + const subsArr = file.ffProbeData.streams.filter((row) => row.codec_name === 'subrip'); + + if (subsArr.length === 0) { + response.infoLog += 'No subs in file to extract!\n'; + response.processFile = false; + return response; + } + response.infoLog += 'Found subs to extract!\n'; + + let command = '-y,'; + for (let i = 0; i < subsArr.length; i += 1) { + const subStream = subsArr[i]; + let lang = ''; + + if (subStream.tags) { + lang = subStream.tags.language; + } + + let subsFile = file.file; + subsFile = subsFile.split('.'); + subsFile[subsFile.length - 2] += `.${lang}`; + subsFile[subsFile.length - 1] = 'srt'; + subsFile = subsFile.join('.'); + + const { index } = subStream; + if (fs.existsSync(`${subsFile}`)) { + response.infoLog += `${lang}.srt already exists. Skipping!\n`; + } else { + response.infoLog += `Extracting ${lang}.srt\n`; + command += ` -map 0:${index} "${subsFile}"`; + } + } + + if (command === '-y,') { + response.infoLog += 'All subs already extracted!\n'; + if (inputs.remove_subs === 'no') { + response.processFile = false; + return response; + } + } + + response.preset = command; + + if (inputs.remove_subs === 'yes') { + response.preset += ' -map 0 -map -0:s -c copy'; + } + + if (inputs.remove_subs === 'no') { + response.preset += ' -map 0 -c copy'; + } + + return response; +}; From d922df54ee4b2a36b8267969d824d20a65ab14f9 Mon Sep 17 00:00:00 2001 From: drpeppershaker <67330126+drpeppershaker@users.noreply.github.com> Date: Tue, 22 Dec 2020 16:44:09 -0500 Subject: [PATCH 02/10] Update Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js --- .../Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/Community/Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js b/Community/Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js index b50d4da..e9f66e3 100644 --- a/Community/Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js +++ b/Community/Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js @@ -46,8 +46,6 @@ module.exports.plugin = function plugin(file, librarySettings, inputs) { infoLog: '', }; - console.log(inputs.remove_subs); - if (inputs.remove_subs === undefined) { response.processFile = false; response.infoLog += '☒ Inputs not entered! \n'; From b24c44992dd5372a024c0986760b460ce291bf20 Mon Sep 17 00:00:00 2001 From: drpeppershaker <67330126+drpeppershaker@users.noreply.github.com> Date: Tue, 22 Dec 2020 16:47:01 -0500 Subject: [PATCH 03/10] Update Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js --- .../Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Community/Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js b/Community/Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js index e9f66e3..8ce18f6 100644 --- a/Community/Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js +++ b/Community/Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js @@ -14,7 +14,7 @@ module.exports.details = function details() { + 'improvements made after looking at "Tdarr_Plugin_078d" by HaveAGitGat.', Version: '1.00', Link: '', - Tags: "pre-processing,subtitle only,ffmpeg,configurable", + Tags: 'pre-processing,subtitle only,ffmpeg,configurable', Inputs: [ { name: 'remove_subs', From a4bbfb2ddfb3cc41172e1e9d01c6276530a04db6 Mon Sep 17 00:00:00 2001 From: drpeppershaker <67330126+drpeppershaker@users.noreply.github.com> Date: Wed, 23 Dec 2020 11:20:17 -0500 Subject: [PATCH 04/10] Update Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js --- ...arr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Community/Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js b/Community/Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js index 8ce18f6..5b229ef 100644 --- a/Community/Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js +++ b/Community/Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js @@ -8,10 +8,11 @@ module.exports.details = function details() { Type: 'Video', Operation: 'Transcode', Description: 'This plugin extracts embedded subs in one pass inside Tdarr and will optionally remove them. \n\n ' - + 'All processes happen within Tdarr without the use of any exec() functions, which lets the progress bar ' - + 'report the status correctly. AND all subtitles are extracted in one pass, which is much faster than ' - + 'other options.\n\nCreated by drpeppershaker with help from reddit user /u/jakejones48, lots of ' - + 'improvements made after looking at "Tdarr_Plugin_078d" by HaveAGitGat.', + + 'All processes happen within Tdarr without the use of any exec() functions, which lets the progress bar ' + + 'report the status correctly. AND all subtitles are extracted in one pass, which is much faster than ' + + 'other options.', + // Created by drpeppershaker with help from reddit user /u/jakejones48, lots of + // improvements made after looking at "Tdarr_Plugin_078d" by HaveAGitGat. Version: '1.00', Link: '', Tags: 'pre-processing,subtitle only,ffmpeg,configurable', From c67334ee73eb103e7b3e821264926be0370fba06 Mon Sep 17 00:00:00 2001 From: drpeppershaker <67330126+drpeppershaker@users.noreply.github.com> Date: Wed, 23 Dec 2020 16:34:10 -0500 Subject: [PATCH 05/10] Update Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js --- ..._Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Community/Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js b/Community/Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js index 5b229ef..f5788f7 100644 --- a/Community/Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js +++ b/Community/Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js @@ -13,7 +13,7 @@ module.exports.details = function details() { + 'other options.', // Created by drpeppershaker with help from reddit user /u/jakejones48, lots of // improvements made after looking at "Tdarr_Plugin_078d" by HaveAGitGat. - Version: '1.00', + Version: '1.04', Link: '', Tags: 'pre-processing,subtitle only,ffmpeg,configurable', Inputs: [ @@ -66,9 +66,14 @@ module.exports.plugin = function plugin(file, librarySettings, inputs) { for (let i = 0; i < subsArr.length; i += 1) { const subStream = subsArr[i]; let lang = ''; + let title = 'none'; if (subStream.tags) { - lang = subStream.tags.language; + lang = subStream.tags.language.toLowerCase(); + } + + if (subStream.tags.title) { + title = subStream.tags.title; } let subsFile = file.file; @@ -80,6 +85,8 @@ module.exports.plugin = function plugin(file, librarySettings, inputs) { const { index } = subStream; if (fs.existsSync(`${subsFile}`)) { response.infoLog += `${lang}.srt already exists. Skipping!\n`; + } else if (title.toLowerCase().includes('commentary') || title.toLowerCase().includes('description')) { + response.infoLog += `Stream ${i} ${lang}.srt is a ${title} track. Skipping!\n`; } else { response.infoLog += `Extracting ${lang}.srt\n`; command += ` -map 0:${index} "${subsFile}"`; From 3cb7fe8d0385adaa618227680684a8d0c755f3f5 Mon Sep 17 00:00:00 2001 From: drpeppershaker <67330126+drpeppershaker@users.noreply.github.com> Date: Wed, 23 Dec 2020 16:36:30 -0500 Subject: [PATCH 06/10] Update Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js --- .../Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Community/Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js b/Community/Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js index f5788f7..4876261 100644 --- a/Community/Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js +++ b/Community/Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js @@ -69,9 +69,9 @@ module.exports.plugin = function plugin(file, librarySettings, inputs) { let title = 'none'; if (subStream.tags) { - lang = subStream.tags.language.toLowerCase(); + lang = subStream.tags } - + if (subStream.tags.title) { title = subStream.tags.title; } From 31f90319b2827c88f645dda2410b8f165160a34e Mon Sep 17 00:00:00 2001 From: drpeppershaker <67330126+drpeppershaker@users.noreply.github.com> Date: Wed, 23 Dec 2020 16:39:22 -0500 Subject: [PATCH 07/10] Update Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js --- .../Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Community/Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js b/Community/Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js index 4876261..7de46f5 100644 --- a/Community/Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js +++ b/Community/Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js @@ -69,9 +69,9 @@ module.exports.plugin = function plugin(file, librarySettings, inputs) { let title = 'none'; if (subStream.tags) { - lang = subStream.tags + lang = subStream.tags; } - + if (subStream.tags.title) { title = subStream.tags.title; } From 4726f6bf91e39973abce442e748cb33aa9876c7b Mon Sep 17 00:00:00 2001 From: drpeppershaker <67330126+drpeppershaker@users.noreply.github.com> Date: Wed, 23 Dec 2020 16:42:43 -0500 Subject: [PATCH 08/10] Update Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js --- .../Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Community/Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js b/Community/Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js index 7de46f5..88eced3 100644 --- a/Community/Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js +++ b/Community/Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js @@ -69,7 +69,7 @@ module.exports.plugin = function plugin(file, librarySettings, inputs) { let title = 'none'; if (subStream.tags) { - lang = subStream.tags; + lang = subStream.tags.language; } if (subStream.tags.title) { From ef74d9039a8e6531dda4dbf77bc6ae39ce00b72b Mon Sep 17 00:00:00 2001 From: drpeppershaker <67330126+drpeppershaker@users.noreply.github.com> Date: Wed, 23 Dec 2020 16:50:35 -0500 Subject: [PATCH 09/10] Update Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js --- .../Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Community/Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js b/Community/Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js index 88eced3..7de46f5 100644 --- a/Community/Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js +++ b/Community/Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js @@ -69,7 +69,7 @@ module.exports.plugin = function plugin(file, librarySettings, inputs) { let title = 'none'; if (subStream.tags) { - lang = subStream.tags.language; + lang = subStream.tags; } if (subStream.tags.title) { From e7fbbcdf2ed7a0afc4f6d6a2d8a4a343c7fa1208 Mon Sep 17 00:00:00 2001 From: drpeppershaker <67330126+drpeppershaker@users.noreply.github.com> Date: Wed, 23 Dec 2020 16:57:02 -0500 Subject: [PATCH 10/10] Update Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js fixed missing .language tag --- .../Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Community/Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js b/Community/Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js index 7de46f5..88eced3 100644 --- a/Community/Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js +++ b/Community/Tdarr_Plugin_rr01_drpeppershaker_extract_subs_to_SRT.js @@ -69,7 +69,7 @@ module.exports.plugin = function plugin(file, librarySettings, inputs) { let title = 'none'; if (subStream.tags) { - lang = subStream.tags; + lang = subStream.tags.language; } if (subStream.tags.title) {