mirror of
https://github.com/gabehf/Tdarr_Plugins.git
synced 2026-03-14 17:55:55 -07:00
Merge pull request #38 from controlol/patch-5
Updated inputs, iso-639-2 auto install on any OS
This commit is contained in:
commit
3cd62c2237
1 changed files with 77 additions and 45 deletions
|
|
@ -1,23 +1,54 @@
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
const execSync = require('child_process').execSync;
|
||||||
|
|
||||||
function details() {
|
function details() {
|
||||||
return {
|
return {
|
||||||
id: "Tdarr_Plugin_e5c3_CnT_Add_Subtitles",
|
id: "Tdarr_Plugin_e5c3_CnT_Add_Subtitles",
|
||||||
Stage: "Pre-processing",
|
|
||||||
Name: "Add subtitles to MKV files",
|
Name: "Add subtitles to MKV files",
|
||||||
Type: "Video",
|
Type: "Video",
|
||||||
Operation:"Remux",
|
Operation:"Remux",
|
||||||
Description: `Add subtitles. READ THIS!! You must run "npm install iso-639-2" in the folder "/home/Tdarr/Documents" for this plugin to work. This is a plugin that will check for subtitles, they should be named according to the ISO 639-2 language code.`,
|
Description: `This plugin will check for subtitles, they should be named according to the ISO 639-2 language code.\nA subtitle could look like this: eng.srt\n If there are subtitles found they will be added with FFMPEG, if there are no subs of that language found.\n On first run node module iso-639-2 will be installed in the documents folder.\n Created by @control#0405`,
|
||||||
Version: "1.00",
|
Version: "1.3",
|
||||||
Link: "https://github.com/HaveAGitGat/Tdarr_Plugins/blob/master/Community/Tdarr_Plugin_e5c3_CnT_Add_Subtitles.js",
|
Link: "https://github.com/HaveAGitGat/Tdarr_Plugins/blob/master/Community/Tdarr_Plugin_e5c3_CnT_Add_Subtitles.js",
|
||||||
|
Inputs: [
|
||||||
|
{
|
||||||
|
name: 'install_packages',
|
||||||
|
tooltip: `Please change this to "yes", it allows the plugin to install the required nodemodule. (iso-639-2)`
|
||||||
|
},
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function plugin(file) {
|
function plugin(file, librarySettings, inputs, otherArguments) {
|
||||||
//Additional packages used here so details function above will still work if packages aren't installed
|
//default response
|
||||||
const iso6392 = require('/home/Tdarr/Documents/node_modules/iso-639-2');
|
var response = {
|
||||||
|
processFile: false,
|
||||||
|
preset: `,`,
|
||||||
|
container: '.mkv',
|
||||||
|
handBrakeMode: false,
|
||||||
|
FFmpegMode: false,
|
||||||
|
reQueueAfter: false,
|
||||||
|
infoLog: `Searching new subtitles...\n`,
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inputs.install_packages == "yes") {
|
||||||
|
if (!fs.existsSync(`${otherArguments.homePath}/Tdarr/node_modules/iso-639-2`)) {
|
||||||
|
execSync(`cd ${otherArguments.homePath}/Tdarr \n npm install iso-639-2`);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
response.infoLog = `Please take a look at the input options\n A extra nodemodule is required.`
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fs.existsSync(`/home/Tdarr/Documents/Tdarr/node_modules/iso-639-2`)) {
|
||||||
|
var iso6392 = require('/home/Tdarr/Documents/Tdarr/node_modules/iso-639-2');
|
||||||
|
} else {
|
||||||
|
response.infoLog += `Nodemodule iso-639-2 isn't installed!\nTry Again`
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
var i = 0; //int for counting lang[position]
|
var i = 0; //int for counting lang[position]
|
||||||
|
var found_subtitle_stream = 0;
|
||||||
var sub = 0; //becomes first subtitle stream
|
var sub = 0; //becomes first subtitle stream
|
||||||
var lang = iso6392; //languages to check against
|
var lang = iso6392; //languages to check against
|
||||||
var path = file.meta.Directory; //path of media folder
|
var path = file.meta.Directory; //path of media folder
|
||||||
|
|
@ -27,59 +58,56 @@ function plugin(file) {
|
||||||
var preset_import = '';
|
var preset_import = '';
|
||||||
var preset_meta = '';
|
var preset_meta = '';
|
||||||
|
|
||||||
|
|
||||||
//default response
|
|
||||||
var response = {
|
|
||||||
processFile: false,
|
|
||||||
preset: `,`,
|
|
||||||
container: '.mkv',
|
|
||||||
handBrakeMode: false,
|
|
||||||
FFmpegMode: false,
|
|
||||||
reQueueAfter: false,
|
|
||||||
infoLog: `Testing for subtitles...\nPath: ${path}\n`,
|
|
||||||
}
|
|
||||||
|
|
||||||
//find first subtitle stream
|
//find first subtitle stream
|
||||||
while (file.ffProbeData.streams[sub].codec_type.toLowerCase() != "subtitle") {
|
while (found_subtitle_stream == 0 && sub < file.ffProbeData.streams.length) {
|
||||||
sub++
|
if (file.ffProbeData.streams[sub].codec_type.toLowerCase() == "subtitle") {
|
||||||
|
found_subtitle_stream = 1;
|
||||||
|
} else {
|
||||||
|
sub++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
response.infoLog += `The first subtitle stream is ${sub}\n`
|
|
||||||
|
response.infoLog += `Path: ${path}\n`;
|
||||||
for (i = 0; i < lang.length; i++) {
|
for (i = 0; i < lang.length; i++) {
|
||||||
//check if srt exists in folder
|
//check if srt file exists in folder
|
||||||
if (fs.existsSync(`${path}/${lang[i].iso6392B}.srt`)) {
|
if (fs.existsSync(`${path}/${lang[i].iso6392B}.srt`)) {
|
||||||
response.infoLog += `Found subtitle ${lang[i].name}\n`
|
response.infoLog += `Found subtitle ${lang[i].name}.srt\n`;
|
||||||
|
|
||||||
//check if language already exists
|
if (found_subtitle_stream == 1) {
|
||||||
for (sub_stream = sub; sub_stream < file.ffProbeData.streams.length; sub_stream++) {
|
//check if language already exists
|
||||||
response.infoLog += `does ${lang[i].name} exist in stream ${sub_stream}?\n`
|
for (sub_stream = sub; sub_stream < file.ffProbeData.streams.length; sub_stream++) {
|
||||||
if (file.ffProbeData.streams[sub_stream].tags.language.toLowerCase() == lang[i].iso6392B) {
|
//response.infoLog += `does ${lang[i].name} exist in stream ${sub_stream}?\n`
|
||||||
response.infoLog += `YES\n`
|
if (file.ffProbeData.streams[sub_stream].tags.language) {
|
||||||
exist = 1;
|
if (file.ffProbeData.streams[sub_stream].tags.language.toLowerCase() == lang[i].iso6392B) {
|
||||||
} else {
|
//response.infoLog += `YES\n`
|
||||||
response.infoLog += `NO\n`
|
exist = 1;
|
||||||
|
response.infoLog += `Language already exists in stream ${sub_stream}\n It will not be added\n`;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
exist = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//add if it hasn't found the language
|
//add if it hasn't found the language
|
||||||
if (exist != 1) {
|
if (exist != 1) {
|
||||||
preset_import += ` -sub_charenc "UTF-8" -f srt -i "${path}/${lang[i].iso6392B}.srt"`
|
preset_import += ` -sub_charenc "UTF-8" -f srt -i "${path}/${lang[i].iso6392B}.srt"`;
|
||||||
preset_meta += ` -metadata:s:s:${new_subs} language=${lang[i].iso6392B}`
|
preset_meta += ` -metadata:s:s:${new_subs} language=${lang[i].iso6392B}`;
|
||||||
new_subs++
|
new_subs++;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
response.infoLog += `did not find sub ${lang[i].iso6392B}.srt\n`
|
//else {
|
||||||
}
|
// response.infoLog += `did not find sub ${lang[i].iso6392B}.srt\n`
|
||||||
|
//}
|
||||||
exist = 0;
|
exist = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
response.infoLog += `${new_subs} new subs will be added\n`
|
|
||||||
response.preset += ` ${preset_import}${preset_meta} -map 0:v -map 0:a`
|
response.preset += ` ${preset_import}${preset_meta} -map 0:v -map 0:a`
|
||||||
|
|
||||||
//map new subs
|
//map new subs
|
||||||
while (added_subs < new_subs) {
|
while (added_subs < new_subs) {
|
||||||
added_subs++
|
added_subs++;
|
||||||
response.preset += ` -map ${added_subs}:s`
|
response.preset += ` -map ${added_subs}:s`;
|
||||||
}
|
}
|
||||||
|
|
||||||
//if new subs have been found they will be added
|
//if new subs have been found they will be added
|
||||||
|
|
@ -87,12 +115,16 @@ function plugin(file) {
|
||||||
response.FFmpegMode = true;
|
response.FFmpegMode = true;
|
||||||
response.processFile = true;
|
response.processFile = true;
|
||||||
response.reQueueAfter = true;
|
response.reQueueAfter = true;
|
||||||
response.preset += ` -map 0:s -c copy`
|
if (found_subtitle_stream == 1) {
|
||||||
|
response.preset += ` -map 0:s `;
|
||||||
|
}
|
||||||
|
response.preset += ` -c copy`;
|
||||||
|
response.infoLog += `${new_subs} new subs will be added\n`;
|
||||||
} else {
|
} else {
|
||||||
response.infoLog += `No new subtitle languages were found\n`
|
response.infoLog += `No new subtitle languages were found\n`;
|
||||||
}
|
}
|
||||||
|
|
||||||
response.infoLog += `The ffmpeg string is: ${response.preset}\n`
|
//response.infoLog += `The ffmpeg string is: ${response.preset}\n`
|
||||||
|
|
||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue