Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- **BETA PLUGIN SRT (da provare)**
- Cosa fa? Il plugin analizza ogni file .mkv, estrae i sottotitoli in formato SRT se già presenti o li converte da formati compatibili come ASS o SSA. Qualsiasi sottotitolo non compatibile viene ignorato e rimosso. Alla fine, tutti i sottotitoli interni vengono cancellati dal file video e quelli validi vengono salvati esternamente con una nomenclatura compatibile con Plex e Bazarr. Il file .mkv viene rimuxato mantenendo solo audio e video, senza modifiche al contenuto principale.
- const details = () => ({
- id: 'Tdarr_Plugin_ExtractSubs_Plex',
- Stage: 'Pre-processing',
- Name: 'Extract/Convert subtitles to external SRT and remove all internal subs (Plex/Bazarr)',
- Type: 'Subtitle',
- Operation: 'Transcode',
- Description:
- 'Extracts all SRT/ASS/SSA subtitles as external SRT files and removes all subtitle tracks from container. Keeps video/audio unchanged. Naming follows Plex/Bazarr standards.',
- Version: '1.0',
- Tags: 'subtitles,external,srt,plex,bazarr,ffmpeg,remove subs'
- });
- const plugin = (file, librarySettings, inputs, otherArguments) => {
- const lib = require('../methods/lib')();
- inputs = lib.loadDefaultValues(inputs, details);
- const response = {
- processFile: false,
- container: `.${file.container}`,
- handBrakeMode: false,
- FFmpegMode: true,
- reQueueAfter: false,
- infoLog: '',
- };
- const filePath = file.file;
- const fileName = filePath.split('/').pop().replace(/\.[^/.]+$/, '');
- const fileDir = filePath.replace(/\/[^/]+$/, '');
- let hasSubtitle = false;
- let mapVideo = false;
- let mapAudio = false;
- let streams = file.ffProbeData.streams;
- const subsToExtract = [];
- const subsToConvert = [];
- streams.forEach((stream, index) => {
- if (stream.codec_type === 'video') mapVideo = true;
- if (stream.codec_type === 'audio') mapAudio = true;
- if (stream.codec_type === 'subtitle') {
- hasSubtitle = true;
- const codec = (stream.codec_name || '').toLowerCase();
- const lang = (stream.tags && stream.tags.language) || 'und';
- const title = (stream.tags && stream.tags.title) ? stream.tags.title.toLowerCase() : '';
- const isForced = (stream.disposition && stream.disposition.forced === 1) || title.includes('forced');
- const isSDH = title.includes('sdh');
- let suffix = '';
- if (isForced) suffix = '.forced';
- else if (isSDH) suffix = '.sdh';
- const srtName = `${fileDir}/${fileName}.${lang}${suffix}.srt`;
- if (codec === 'srt') {
- subsToExtract.push({ index, path: srtName });
- } else if (codec === 'ass' || codec === 'ssa') {
- subsToConvert.push({ index, path: srtName });
- }
- }
- });
- if (!hasSubtitle) {
- response.infoLog = 'No subtitles found. Skipping.';
- return response;
- }
- let ffmpegCommandInsert = '';
- if (mapVideo) ffmpegCommandInsert += '-map 0:v -c:v copy ';
- if (mapAudio) ffmpegCommandInsert += '-map 0:a -c:a copy ';
- ffmpegCommandInsert += '-map -0:s? ';
- response.extraShellCommands = [];
- subsToExtract.forEach(sub => {
- response.extraShellCommands.push(`ffmpeg -y -i \"${filePath}\" -map 0:${sub.index} -c:s srt \"${sub.path}\"`);
- response.infoLog += `Extracted SRT → ${sub.path}\n`;
- });
- subsToConvert.forEach(sub => {
- response.extraShellCommands.push(`ffmpeg -y -i \"${filePath}\" -map 0:${sub.index} -c:s srt \"${sub.path}\"`);
- response.infoLog += `Converted to SRT → ${sub.path}\n`;
- });
- response.processFile = true;
- response.preset = `, ${ffmpegCommandInsert} -strict -2 -max_muxing_queue_size 9999`;
- response.infoLog += 'All internal subtitles removed. File remuxed.\n';
- return response;
- };
- module.exports.details = details;
- module.exports.plugin = plugin;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement