parent
11228bd18e
commit
2c6258429e
@ -0,0 +1,86 @@
|
||||
/* eslint max-len: 0, no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||
const details = () => ({
|
||||
id: 'Tdarr_Plugin_gabehf_Prefer_Honorific_Subs',
|
||||
Stage: 'Pre-processing',
|
||||
Name: 'Prefer Honorific Subs',
|
||||
Type: 'Subtitle',
|
||||
Operation: 'Transcode',
|
||||
Description:
|
||||
'This plugin sets the disposition of honorific/weeb subtitle tracks to default based on the track title or enm language code. \n\n',
|
||||
Version: '1.0',
|
||||
Tags: 'pre-processing,ffmpeg,subtitle only',
|
||||
Inputs: [],
|
||||
});
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const plugin = (file, librarySettings, inputs, otherArguments) => {
|
||||
const lib = require('../methods/lib')();
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||
inputs = lib.loadDefaultValues(inputs, details);
|
||||
const response = {
|
||||
processFile: false,
|
||||
preset: '',
|
||||
container: `.${file.container}`,
|
||||
handBrakeMode: false,
|
||||
FFmpegMode: true,
|
||||
reQueueAfter: false,
|
||||
infoLog: '',
|
||||
};
|
||||
|
||||
// Check if file is a video. If it isn't then exit plugin.
|
||||
if (file.fileMedium !== 'video') {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('File is not video');
|
||||
response.infoLog += '☒File is not video \n';
|
||||
response.processFile = false;
|
||||
return response;
|
||||
}
|
||||
|
||||
// Set up required variables.
|
||||
let ffmpegCommandInsert = '';
|
||||
let subtitleIdx = 0;
|
||||
let convert = false;
|
||||
let honorificTrackIdx = -1;
|
||||
|
||||
for (let i = 0; i < file.ffProbeData.streams.length; i++) {
|
||||
try {
|
||||
if (file.ffProbeData.streams[i].codec_type.toLowerCase() === 'subtitle') {
|
||||
if (["honorific", "weeb"].some((s) => file.ffProbeData.streams[i].tags.title.toLowerCase().includes(s))
|
||||
|| file.ffprobeData.streams[i].tags.language.toLowerCase() === 'enm'
|
||||
) {
|
||||
if (convert) {
|
||||
// handle case where an honorific was already found
|
||||
continue
|
||||
}
|
||||
response.infoLog += `☒Subtitle with id ${subtitleIdx} detected as being honorific, setting default. \n`
|
||||
convert = true
|
||||
ffmpegCommandInsert += `-disposition:s:${subtitleIdx} default `
|
||||
honorificTrackIdx = subtitleIdx
|
||||
}
|
||||
subtitleIdx += 1;
|
||||
}
|
||||
} catch (err) {
|
||||
// Error
|
||||
}
|
||||
}
|
||||
|
||||
// Convert file if convert variable is set to true.
|
||||
if (convert === true) {
|
||||
for (let i = 0; i < subtitleIdx; i++) {
|
||||
if (i === honorificTrackIdx) {
|
||||
continue
|
||||
}
|
||||
ffmpegCommandInsert += `-disposition:s:${i} 0 `
|
||||
}
|
||||
response.processFile = true;
|
||||
response.preset = `, -map 0 ${ffmpegCommandInsert}-c copy -max_muxing_queue_size 9999`;
|
||||
response.container = `.${file.container}`;
|
||||
response.reQueueAfter = true;
|
||||
} else {
|
||||
response.processFile = false;
|
||||
response.infoLog += "☑File doesn't contain subtitle tracks that require modification.\n";
|
||||
}
|
||||
return response;
|
||||
};
|
||||
module.exports.details = details;
|
||||
module.exports.plugin = plugin;
|
||||
Loading…
Reference in new issue