Run lint fix

This commit is contained in:
HaveAGitGat 2023-09-25 08:25:25 +01:00
parent a0273d3417
commit 73482c5a10

View file

@ -1,20 +1,19 @@
const loadDefaultValues = require('../methods/loadDefaultValues');
const fs = require('fs');
const path = require('path');
const loadDefaultValues = require('../methods/loadDefaultValues');
const details = () => {
return {
id: "Tdarr_Plugin_rename_based_on_codec_schadi",
Stage: "Post-processing",
Name: "Rename based on codec Video and Audio",
Type: "Video_Audio",
Operation: "Transcode",
const details = () => ({
id: 'Tdarr_Plugin_rename_based_on_codec_schadi',
Stage: 'Post-processing',
Name: 'Rename based on codec Video and Audio',
Type: 'Video_Audio',
Operation: 'Transcode',
Description: `
If the filename contains a codec information like h264, av1 or similar for video and AC3, AAC or trueHD \n\n
the plugin will read the codec info from the file and rename it accordingly. \n\n
It also takes care off addiotnal files deffined in the input Option. \n\n`,
Version: "1.00",
Tags: "post-processing",
Version: '1.00',
Tags: 'post-processing',
Inputs: [
{
name: 'rename_audio',
@ -62,41 +61,38 @@ const details = () => {
.nfo,.srt`,
},
],
};
};
});
const plugin = (file, librarySettings, inputs, otherArguments) => {
inputs = loadDefaultValues(inputs, details);
const fileNameOld = file._id;
var response = {
const response = {
file,
removeFromDB: false,
updateDB: true,
infoLog: "",
infoLog: '',
processFile: false,
};
const codecMap = {
'aac': 'AAC',
'ac3': 'AC3',
'av1': 'AV1',
'avc': 'h264',
'dts': 'DTS',
'eac3': 'EAC3',
'flac': 'FLAC',
'hevc': 'h265',
'mp2': 'MP2',
'mp3': 'MP3',
'mpeg2': 'MPEG2',
'truehd': 'TrueHD',
'x264': 'h264',
'x265': 'h265',
'h264': 'h264',
'h265': 'h265',
'dts': 'DTS-X',
aac: 'AAC',
ac3: 'AC3',
av1: 'AV1',
avc: 'h264',
dts: 'DTS',
eac3: 'EAC3',
flac: 'FLAC',
hevc: 'h265',
mp2: 'MP2',
mp3: 'MP3',
mpeg2: 'MPEG2',
truehd: 'TrueHD',
x264: 'h264',
x265: 'h265',
h264: 'h264',
h265: 'h265',
dts: 'DTS-X',
'dts-hd ma': 'DTS-HD MA',
'dts-es': 'DTS-HD ES',
'dts-hd hra': 'DTS-HD HRA',
@ -104,8 +100,8 @@ const plugin = (file, librarySettings, inputs, otherArguments) => {
'dts 96/24': 'DTS',
};
var firstVideoStreamCodec;
var firstAudioStreamCodec;
let firstVideoStreamCodec;
let firstAudioStreamCodec;
const videoCodecRegex = /(h264|h265|x264|x265|avc|hevc|mpeg2|av1)/gi;
const audioCodecRegex = /(aac|ac3|eac3|flac|mp2|mp3|truehd|dts[-. ]hd[-. ]ma|dts[-. ]hd[-. ]es|dts[-. ]hd[-. ]hra|dts[-. ]express|dts)/gi;
@ -150,14 +146,14 @@ if ((audioStream && inputs.rename_audio) || (videoStream && inputs.rename_video)
const additionalExtensions = inputs.additional_extensions.split(',');
let fileList = []; // Array to store the file names
const fileList = []; // Array to store the file names
const files = fs.readdirSync(directoryPath);
files.forEach((supportFile) => {
fileList.push(supportFile); // Add all files to the fileList array
});
const extensionList = additionalExtensions.map(extension => extension.trim()); // Remove leading/trailing spaces from extensions
const extensionList = additionalExtensions.map((extension) => extension.trim()); // Remove leading/trailing spaces from extensions
const regex = new RegExp(`(${extensionList.join('|')})$`, 'i');
files.forEach((supportFile) => {
@ -178,26 +174,22 @@ if ((audioStream && inputs.rename_audio) || (videoStream && inputs.rename_video)
// fs.writeFileSync(textFilePath, fileList.filter(file => file.startsWith(modJustname) && regex.test(file)).join('\n'), 'utf-8');
}
if (fileNameOld !== file._id) {
fs.renameSync(fileNameOld, file._id, {
overwrite: true,
});
response.infoLog += `Renamed file to: ${file._id}\n`
response.infoLog += `Renamed file to: ${file._id}\n`;
if (additionalFilesCount > 0) {
response.infoLog += `and: ${additionalFilesCount} additional Files!\n`;
}
return response;
}
else {
response.infoLog += `Video File not renamed!\n`
response.infoLog += 'Video File not renamed!\n';
if (additionalFilesCount > 0) {
response.infoLog += `But: ${additionalFilesCount} additional Files!\n`;
}
return response;
}
};
module.exports.details = details;