mirror of
https://github.com/gabehf/Tdarr_Plugins.git
synced 2026-03-15 10:15:54 -07:00
Run lint fix
This commit is contained in:
parent
a0273d3417
commit
73482c5a10
1 changed files with 196 additions and 204 deletions
|
|
@ -1,204 +1,196 @@
|
||||||
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',
|
defaultValue: false,
|
||||||
defaultValue: false,
|
inputUI: {
|
||||||
inputUI: {
|
type: 'dropdown',
|
||||||
type: 'dropdown',
|
options: [
|
||||||
options: [
|
'false',
|
||||||
'false',
|
'true',
|
||||||
'true',
|
],
|
||||||
],
|
},
|
||||||
},
|
tooltip: `Will Rename According to Audio Codec after x264 or x265.
|
||||||
tooltip: `Will Rename According to Audio Codec after x264 or x265.
|
\\nExample:\\n
|
||||||
\\nExample:\\n
|
true
|
||||||
true
|
\\nExample:\\n
|
||||||
\\nExample:\\n
|
false`,
|
||||||
false`,
|
},
|
||||||
},
|
{
|
||||||
{
|
name: 'rename_video',
|
||||||
name: 'rename_video',
|
type: 'boolean',
|
||||||
type: 'boolean',
|
defaultValue: false,
|
||||||
defaultValue: false,
|
inputUI: {
|
||||||
inputUI: {
|
type: 'dropdown',
|
||||||
type: 'dropdown',
|
options: [
|
||||||
options: [
|
'false',
|
||||||
'false',
|
'true',
|
||||||
'true',
|
],
|
||||||
],
|
},
|
||||||
},
|
tooltip: `Will Rename According to Video Codec after x264 or x265.
|
||||||
tooltip: `Will Rename According to Video Codec after x264 or x265.
|
\\nExample:\\n
|
||||||
\\nExample:\\n
|
true
|
||||||
true
|
\\nExample:\\n
|
||||||
\\nExample:\\n
|
false`,
|
||||||
false`,
|
},
|
||||||
},
|
{
|
||||||
{
|
name: 'additional_extensions',
|
||||||
name: 'additional_extensions',
|
type: 'text',
|
||||||
type: 'text',
|
defaultValue: '.nfo,.srt',
|
||||||
defaultValue: '.nfo,.srt',
|
inputUI: {
|
||||||
inputUI: {
|
type: 'text',
|
||||||
type: 'text',
|
},
|
||||||
},
|
tooltip: `Additional file extensions to rename (comma-separated).
|
||||||
tooltip: `Additional file extensions to rename (comma-separated).
|
\\nExample:\\n
|
||||||
\\nExample:\\n
|
.nfo,.srt`,
|
||||||
.nfo,.srt`,
|
},
|
||||||
},
|
],
|
||||||
],
|
});
|
||||||
};
|
|
||||||
};
|
const plugin = (file, librarySettings, inputs, otherArguments) => {
|
||||||
|
inputs = loadDefaultValues(inputs, details);
|
||||||
const plugin = (file, librarySettings, inputs, otherArguments) => {
|
const fileNameOld = file._id;
|
||||||
inputs = loadDefaultValues(inputs, details);
|
|
||||||
const fileNameOld = file._id;
|
const response = {
|
||||||
|
file,
|
||||||
|
removeFromDB: false,
|
||||||
var response = {
|
updateDB: true,
|
||||||
file,
|
infoLog: '',
|
||||||
removeFromDB: false,
|
processFile: false,
|
||||||
updateDB: true,
|
};
|
||||||
infoLog: "",
|
|
||||||
processFile: false,
|
const codecMap = {
|
||||||
};
|
aac: 'AAC',
|
||||||
|
ac3: 'AC3',
|
||||||
|
av1: 'AV1',
|
||||||
const codecMap = {
|
avc: 'h264',
|
||||||
'aac': 'AAC',
|
dts: 'DTS',
|
||||||
'ac3': 'AC3',
|
eac3: 'EAC3',
|
||||||
'av1': 'AV1',
|
flac: 'FLAC',
|
||||||
'avc': 'h264',
|
hevc: 'h265',
|
||||||
'dts': 'DTS',
|
mp2: 'MP2',
|
||||||
'eac3': 'EAC3',
|
mp3: 'MP3',
|
||||||
'flac': 'FLAC',
|
mpeg2: 'MPEG2',
|
||||||
'hevc': 'h265',
|
truehd: 'TrueHD',
|
||||||
'mp2': 'MP2',
|
x264: 'h264',
|
||||||
'mp3': 'MP3',
|
x265: 'h265',
|
||||||
'mpeg2': 'MPEG2',
|
h264: 'h264',
|
||||||
'truehd': 'TrueHD',
|
h265: 'h265',
|
||||||
'x264': 'h264',
|
dts: 'DTS-X',
|
||||||
'x265': 'h265',
|
'dts-hd ma': 'DTS-HD MA',
|
||||||
'h264': 'h264',
|
'dts-es': 'DTS-HD ES',
|
||||||
'h265': 'h265',
|
'dts-hd hra': 'DTS-HD HRA',
|
||||||
'dts': 'DTS-X',
|
'dts express ': 'DTS Express',
|
||||||
'dts-hd ma': 'DTS-HD MA',
|
'dts 96/24': 'DTS',
|
||||||
'dts-es': 'DTS-HD ES',
|
};
|
||||||
'dts-hd hra': 'DTS-HD HRA',
|
|
||||||
'dts express ': 'DTS Express',
|
let firstVideoStreamCodec;
|
||||||
'dts 96/24': 'DTS',
|
let firstAudioStreamCodec;
|
||||||
};
|
|
||||||
|
const videoCodecRegex = /(h264|h265|x264|x265|avc|hevc|mpeg2|av1)/gi;
|
||||||
var firstVideoStreamCodec;
|
const audioCodecRegex = /(aac|ac3|eac3|flac|mp2|mp3|truehd|dts[-. ]hd[-. ]ma|dts[-. ]hd[-. ]es|dts[-. ]hd[-. ]hra|dts[-. ]express|dts)/gi;
|
||||||
var firstAudioStreamCodec;
|
|
||||||
|
const videoStream = file.ffProbeData.streams.find((stream) => stream.codec_type === 'video');
|
||||||
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;
|
if (videoStream && inputs.rename_video) {
|
||||||
|
const videoCodec = videoStream.codec_name.toLowerCase();
|
||||||
const videoStream = file.ffProbeData.streams.find((stream) => stream.codec_type === 'video');
|
firstVideoStreamCodec = videoCodec;
|
||||||
|
|
||||||
if (videoStream && inputs.rename_video) {
|
if (videoCodec in codecMap) {
|
||||||
const videoCodec = videoStream.codec_name.toLowerCase();
|
const renamedCodec = codecMap[videoCodec];
|
||||||
firstVideoStreamCodec = videoCodec;
|
file._id = file._id.replace(videoCodecRegex, renamedCodec);
|
||||||
|
file.file = file.file.replace(videoCodecRegex, renamedCodec);
|
||||||
if (videoCodec in codecMap) {
|
}
|
||||||
const renamedCodec = codecMap[videoCodec];
|
}
|
||||||
file._id = file._id.replace(videoCodecRegex, renamedCodec);
|
|
||||||
file.file = file.file.replace(videoCodecRegex, renamedCodec);
|
const audioStream = file.ffProbeData.streams.find((stream) => stream.codec_type === 'audio');
|
||||||
}
|
|
||||||
}
|
if (audioStream && inputs.rename_audio) {
|
||||||
|
const audioCodec = audioStream.codec_name.toLowerCase();
|
||||||
const audioStream = file.ffProbeData.streams.find((stream) => stream.codec_type === 'audio');
|
firstAudioStreamCodec = audioCodec;
|
||||||
|
|
||||||
if (audioStream && inputs.rename_audio) {
|
if (audioCodec in codecMap) {
|
||||||
const audioCodec = audioStream.codec_name.toLowerCase();
|
const renamedCodec = codecMap[audioCodec];
|
||||||
firstAudioStreamCodec = audioCodec;
|
file._id = file._id.replace(audioCodecRegex, renamedCodec);
|
||||||
|
file.file = file.file.replace(audioCodecRegex, renamedCodec);
|
||||||
if (audioCodec in codecMap) {
|
}
|
||||||
const renamedCodec = codecMap[audioCodec];
|
}
|
||||||
file._id = file._id.replace(audioCodecRegex, renamedCodec);
|
|
||||||
file.file = file.file.replace(audioCodecRegex, renamedCodec);
|
let additionalFilesCount = 0; // Counter for additional files found
|
||||||
}
|
|
||||||
}
|
if ((audioStream && inputs.rename_audio) || (videoStream && inputs.rename_video)) {
|
||||||
|
const filename = path.basename(fileNameOld);
|
||||||
let additionalFilesCount = 0; // Counter for additional files found
|
const JustName = path.parse(filename).name;
|
||||||
|
const popJustnamen = JustName.split('.');
|
||||||
if ((audioStream && inputs.rename_audio) || (videoStream && inputs.rename_video)) {
|
popJustnamen.splice(popJustnamen.length - 5);
|
||||||
const filename = path.basename(fileNameOld);
|
const modJustname = popJustnamen.join('.');
|
||||||
const JustName = path.parse(filename).name;
|
|
||||||
const popJustnamen = JustName.split('.');
|
const fileDir = path.dirname(fileNameOld);
|
||||||
popJustnamen.splice(popJustnamen.length - 5);
|
const directoryPath = fileDir;
|
||||||
const modJustname = popJustnamen.join('.');
|
|
||||||
|
const additionalExtensions = inputs.additional_extensions.split(',');
|
||||||
const fileDir = path.dirname(fileNameOld);
|
|
||||||
const directoryPath = fileDir;
|
const fileList = []; // Array to store the file names
|
||||||
|
const files = fs.readdirSync(directoryPath);
|
||||||
const additionalExtensions = inputs.additional_extensions.split(',');
|
|
||||||
|
files.forEach((supportFile) => {
|
||||||
let fileList = []; // Array to store the file names
|
fileList.push(supportFile); // Add all files to the fileList array
|
||||||
const files = fs.readdirSync(directoryPath);
|
});
|
||||||
|
|
||||||
files.forEach((supportFile) => {
|
const extensionList = additionalExtensions.map((extension) => extension.trim()); // Remove leading/trailing spaces from extensions
|
||||||
fileList.push(supportFile); // Add all files to the fileList array
|
const regex = new RegExp(`(${extensionList.join('|')})$`, 'i');
|
||||||
});
|
|
||||||
|
files.forEach((supportFile) => {
|
||||||
const extensionList = additionalExtensions.map(extension => extension.trim()); // Remove leading/trailing spaces from extensions
|
if (supportFile.startsWith(modJustname) && regex.test(supportFile)) {
|
||||||
const regex = new RegExp(`(${extensionList.join('|')})$`, 'i');
|
const renamedFileWithVideoCodec = supportFile.replace(videoCodecRegex, codecMap[firstVideoStreamCodec]);
|
||||||
|
const renamedFileWithBothCodecs = renamedFileWithVideoCodec.replace(audioCodecRegex, codecMap[firstAudioStreamCodec]);
|
||||||
files.forEach((supportFile) => {
|
|
||||||
if (supportFile.startsWith(modJustname) && regex.test(supportFile)) {
|
fs.renameSync(`${directoryPath}/${supportFile}`, `${directoryPath}/${renamedFileWithBothCodecs}`, {
|
||||||
const renamedFileWithVideoCodec = supportFile.replace(videoCodecRegex, codecMap[firstVideoStreamCodec]);
|
overwrite: true,
|
||||||
const renamedFileWithBothCodecs = renamedFileWithVideoCodec.replace(audioCodecRegex, codecMap[firstAudioStreamCodec]);
|
});
|
||||||
|
|
||||||
fs.renameSync(`${directoryPath}/${supportFile}`, `${directoryPath}/${renamedFileWithBothCodecs}`, {
|
response.infoLog += `${directoryPath}/${supportFile} renamed to ${directoryPath}/${renamedFileWithBothCodecs}\n`;
|
||||||
overwrite: true,
|
additionalFilesCount++; // Increment the count for each additional file found
|
||||||
});
|
}
|
||||||
|
});
|
||||||
response.infoLog += `${directoryPath}/${supportFile} renamed to ${directoryPath}/${renamedFileWithBothCodecs}\n`;
|
|
||||||
additionalFilesCount++; // Increment the count for each additional file found
|
// const textFilePath = path.join(directoryPath, `${modJustname}.txt`);
|
||||||
}
|
// fs.writeFileSync(textFilePath, fileList.filter(file => file.startsWith(modJustname) && regex.test(file)).join('\n'), 'utf-8');
|
||||||
});
|
}
|
||||||
|
|
||||||
//const textFilePath = path.join(directoryPath, `${modJustname}.txt`);
|
if (fileNameOld !== file._id) {
|
||||||
//fs.writeFileSync(textFilePath, fileList.filter(file => file.startsWith(modJustname) && regex.test(file)).join('\n'), 'utf-8');
|
fs.renameSync(fileNameOld, file._id, {
|
||||||
}
|
overwrite: true,
|
||||||
|
});
|
||||||
|
response.infoLog += `Renamed file to: ${file._id}\n`;
|
||||||
|
if (additionalFilesCount > 0) {
|
||||||
if (fileNameOld !== file._id) {
|
response.infoLog += `and: ${additionalFilesCount} additional Files!\n`;
|
||||||
fs.renameSync(fileNameOld, file._id, {
|
}
|
||||||
overwrite: true,
|
return response;
|
||||||
});
|
}
|
||||||
response.infoLog += `Renamed file to: ${file._id}\n`
|
|
||||||
if (additionalFilesCount > 0) {
|
response.infoLog += 'Video File not renamed!\n';
|
||||||
response.infoLog += `and: ${additionalFilesCount} additional Files!\n`;
|
if (additionalFilesCount > 0) {
|
||||||
}
|
response.infoLog += `But: ${additionalFilesCount} additional Files!\n`;
|
||||||
return response;
|
}
|
||||||
}
|
return response;
|
||||||
else {
|
};
|
||||||
response.infoLog += `Video File not renamed!\n`
|
|
||||||
if (additionalFilesCount > 0) {
|
module.exports.details = details;
|
||||||
response.infoLog += `But: ${additionalFilesCount} additional Files!\n`;
|
module.exports.plugin = plugin;
|
||||||
}
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.details = details;
|
|
||||||
module.exports.plugin = plugin;
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue