Advertisement
Harakiri88

**BETA** SRT Plugin Tdarr

Apr 8th, 2025
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.75 KB | None | 0 0
  1. **BETA PLUGIN SRT (da provare)**
  2.  
  3. 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.
  4.  
  5. const details = () => ({
  6. id: 'Tdarr_Plugin_ExtractSubs_Plex',
  7. Stage: 'Pre-processing',
  8. Name: 'Extract/Convert subtitles to external SRT and remove all internal subs (Plex/Bazarr)',
  9. Type: 'Subtitle',
  10. Operation: 'Transcode',
  11. Description:
  12. '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.',
  13. Version: '1.0',
  14. Tags: 'subtitles,external,srt,plex,bazarr,ffmpeg,remove subs'
  15. });
  16.  
  17. const plugin = (file, librarySettings, inputs, otherArguments) => {
  18. const lib = require('../methods/lib')();
  19. inputs = lib.loadDefaultValues(inputs, details);
  20.  
  21. const response = {
  22. processFile: false,
  23. container: `.${file.container}`,
  24. handBrakeMode: false,
  25. FFmpegMode: true,
  26. reQueueAfter: false,
  27. infoLog: '',
  28. };
  29.  
  30. const filePath = file.file;
  31. const fileName = filePath.split('/').pop().replace(/\.[^/.]+$/, '');
  32. const fileDir = filePath.replace(/\/[^/]+$/, '');
  33.  
  34. let hasSubtitle = false;
  35. let mapVideo = false;
  36. let mapAudio = false;
  37. let streams = file.ffProbeData.streams;
  38.  
  39. const subsToExtract = [];
  40. const subsToConvert = [];
  41.  
  42. streams.forEach((stream, index) => {
  43. if (stream.codec_type === 'video') mapVideo = true;
  44. if (stream.codec_type === 'audio') mapAudio = true;
  45.  
  46. if (stream.codec_type === 'subtitle') {
  47. hasSubtitle = true;
  48. const codec = (stream.codec_name || '').toLowerCase();
  49. const lang = (stream.tags && stream.tags.language) || 'und';
  50. const title = (stream.tags && stream.tags.title) ? stream.tags.title.toLowerCase() : '';
  51. const isForced = (stream.disposition && stream.disposition.forced === 1) || title.includes('forced');
  52. const isSDH = title.includes('sdh');
  53.  
  54. let suffix = '';
  55. if (isForced) suffix = '.forced';
  56. else if (isSDH) suffix = '.sdh';
  57.  
  58. const srtName = `${fileDir}/${fileName}.${lang}${suffix}.srt`;
  59.  
  60. if (codec === 'srt') {
  61. subsToExtract.push({ index, path: srtName });
  62. } else if (codec === 'ass' || codec === 'ssa') {
  63. subsToConvert.push({ index, path: srtName });
  64. }
  65. }
  66. });
  67.  
  68. if (!hasSubtitle) {
  69. response.infoLog = 'No subtitles found. Skipping.';
  70. return response;
  71. }
  72.  
  73. let ffmpegCommandInsert = '';
  74. if (mapVideo) ffmpegCommandInsert += '-map 0:v -c:v copy ';
  75. if (mapAudio) ffmpegCommandInsert += '-map 0:a -c:a copy ';
  76. ffmpegCommandInsert += '-map -0:s? ';
  77.  
  78. response.extraShellCommands = [];
  79.  
  80. subsToExtract.forEach(sub => {
  81. response.extraShellCommands.push(`ffmpeg -y -i \"${filePath}\" -map 0:${sub.index} -c:s srt \"${sub.path}\"`);
  82. response.infoLog += `Extracted SRT → ${sub.path}\n`;
  83. });
  84.  
  85. subsToConvert.forEach(sub => {
  86. response.extraShellCommands.push(`ffmpeg -y -i \"${filePath}\" -map 0:${sub.index} -c:s srt \"${sub.path}\"`);
  87. response.infoLog += `Converted to SRT → ${sub.path}\n`;
  88. });
  89.  
  90. response.processFile = true;
  91. response.preset = `, ${ffmpegCommandInsert} -strict -2 -max_muxing_queue_size 9999`;
  92. response.infoLog += 'All internal subtitles removed. File remuxed.\n';
  93.  
  94. return response;
  95. };
  96.  
  97. module.exports.details = details;
  98. module.exports.plugin = plugin;
  99.  
  100.  
  101.  
  102.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement