Run lint fix

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

View file

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