From c81a5ce5943a4a591f5d35a394719453ac79b293 Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Sun, 6 Sep 2020 20:25:24 +0200 Subject: [PATCH] Tdarr_Plugin_078d_Output_embedded_subs_to_SRT_and_remove --- ..._Output_embedded_subs_to_SRT_and_remove.js | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 Community/Tdarr_Plugin_078d_Output_embedded_subs_to_SRT_and_remove.js diff --git a/Community/Tdarr_Plugin_078d_Output_embedded_subs_to_SRT_and_remove.js b/Community/Tdarr_Plugin_078d_Output_embedded_subs_to_SRT_and_remove.js new file mode 100644 index 0000000..12e31ad --- /dev/null +++ b/Community/Tdarr_Plugin_078d_Output_embedded_subs_to_SRT_and_remove.js @@ -0,0 +1,67 @@ +module.exports.details = function details() { + return { + id: "Tdarr_Plugin_078d_Output_embedded_subs_to_SRT_and_remove", + Stage: "Pre-processing", + Name: "Output embedded subs to SRT and remove", + Type: "Video", + Operation: "Transcode", + Description: `This plugin outputs embedded subs to SRT and then removes them \n\n`, + Version: "1.00", + Link: "", + Tags: "ffmpeg", + }; +}; + +module.exports.plugin = function plugin(file, librarySettings, inputs, otherArguments) { + //Must return this object at some point in the function else plugin will fail. + + let response = { + processFile: false, + preset: "", + container: "", + handBrakeMode: false, + FFmpegMode: false, + reQueueAfter: true, + infoLog: "", + }; + + const ffmpegPath = otherArguments.ffmpegPath + const exec = require("child_process").exec; + + let subsArr = file.ffProbeData.streams.filter(row => row.codec_name === 'subrip') + + if (subsArr.length === 0) { + response.infoLog += "No subs in file to extract!"; + return response + } + + let subStream = subsArr[0] + 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('.') + + let index = subStream.index + let command = `${ffmpegPath} -i "${file.file}" -map 0:${index} "${subsFile}"` + + exec(command); + + response = { + processFile: true, + preset: `, -map 0 -map -0:${index} -c copy`, + container: "." + file.container, + handBrakeMode: false, + FFmpegMode: true, + reQueueAfter: true, + infoLog: "Found sub to extract!", + }; + + return response; +}; \ No newline at end of file