Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // tdarrSkipTest
- const details = () => ({
- id: 'Tdarr_Plugin_0000_Extract_Subtitles',
- Stage: 'Pre-processing',
- Name: 'Extract Subtitles',
- Type: 'Video',
- Operation: 'Transcode',
- Description: 'This plugin extracts embedded english, spanish and SDH subs in one pass and optionally removes them. \n\n '
- + 'Based on rr01_drpeppershaker_extract_subs_to_SRT ',
- Version: '1.05',
- Tags: 'pre-processing,subtitle only,ffmpeg,configurable',
- Inputs: [
- {
- name: 'remove_subs',
- type: 'string',
- defaultValue: 'no',
- inputUI: {
- type: 'text',
- },
- tooltip: `Do you want to remove subtitles after they are extracted?
- \\nExample:\\n
- yes
- \\nExample:\\n
- no
- `,
- },
- ],
- });
- // eslint-disable-next-line no-unused-vars
- const plugin = (file, librarySettings, inputs, otherArguments) => {
- const lib = require('../methods/lib')(); const fs = require('fs');
- // eslint-disable-next-line no-unused-vars,no-param-reassign
- inputs = lib.loadDefaultValues(inputs, details);
- // 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: '',
- };
- 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 <io>';
- for (let i = 0; i < subsArr.length; i += 1) {
- const subStream = subsArr[i];
- let lang = '';
- let title = 'none';
- if (subStream && subStream.tags && subStream.tags.language) {
- lang = subStream.tags.language;
- }
- if (subStream && subStream.tags && subStream.tags.title) {
- title = subStream.tags.title;
- }
- // Filter for English, Spanish, and SDH subtitles
- if (!['eng', 'spa'].includes(lang) && !(title.toLowerCase().includes('sdh') && lang === 'eng')) {
- continue; // Skip if the subtitle isn't English, Spanish, or SDH
- }
- const { originalLibraryFile } = otherArguments;
- let subsFile = '';
- // for Tdarr V2 (2.00.05+)
- if (originalLibraryFile && originalLibraryFile.file) {
- subsFile = originalLibraryFile.file;
- } else {
- // for Tdarr V1
- subsFile = file.file;
- }
- subsFile = subsFile.split('.');
- if (title.toLowerCase().includes('sdh') && lang === 'eng') {
- subsFile[subsFile.length - 2] += `.eng.sdh`;
- } else {
- 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 if (typeof title === 'string'
- && (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}"`;
- }
- }
- if (command === '-y <io>') {
- 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;
- };
- module.exports.details = details;
- module.exports.plugin = plugin;
Advertisement
Add Comment
Please, Sign In to add comment