You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
2.8 KiB
83 lines
2.8 KiB
/* 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 = -1;
|
|
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') {
|
|
subtitleIdx += 1;
|
|
if ((["honorific", "weeb"].some((s) => file.ffProbeData.streams[i].tags.title.toLowerCase().includes(s)) ||
|
|
(file.ffProbeData.streams[i].title !== undefined && file.ffProbeData.streams[i].tags.language.toLowerCase() === 'enm')) && !convert
|
|
) {
|
|
response.infoLog += `☒Subtitle with id ${subtitleIdx} detected as being honorific, setting default. \n`
|
|
convert = true
|
|
ffmpegCommandInsert += `-disposition:s:${subtitleIdx} default `
|
|
honorificTrackIdx = subtitleIdx
|
|
}
|
|
}
|
|
} 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;
|