mirror of
https://github.com/gabehf/Tdarr_Plugins.git
synced 2026-03-13 09:20:27 -07:00
Merge branch 'master' into pr/650
This commit is contained in:
commit
7767f05c9a
25 changed files with 341 additions and 159 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import fs from 'fs';
|
||||
import { getContainer, getFileAbosluteDir, getFileName } from '../../../../FlowHelpers/1.0.0/fileUtils';
|
||||
import {
|
||||
fileExists, getContainer, getFileAbosluteDir, getFileName,
|
||||
} from '../../../../FlowHelpers/1.0.0/fileUtils';
|
||||
import {
|
||||
IpluginDetails,
|
||||
IpluginInputArgs,
|
||||
|
|
@ -57,7 +58,7 @@ const details = (): IpluginDetails => ({
|
|||
});
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const plugin = (args: IpluginInputArgs): IpluginOutputArgs => {
|
||||
const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
||||
const lib = require('../../../../../methods/lib')();
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||
|
|
@ -71,9 +72,9 @@ const plugin = (args: IpluginInputArgs): IpluginOutputArgs => {
|
|||
fileToCheck = fileToCheck.replace(/\${container}/g, getContainer(args.inputFileObj._id));
|
||||
fileToCheck = `${directory}/${fileToCheck}`;
|
||||
|
||||
let fileExists = false;
|
||||
if (fs.existsSync(fileToCheck)) {
|
||||
fileExists = true;
|
||||
let fileDoesExist = false;
|
||||
if (await fileExists(fileToCheck)) {
|
||||
fileDoesExist = true;
|
||||
args.jobLog(`File exists: ${fileToCheck}`);
|
||||
} else {
|
||||
args.jobLog(`File does not exist: ${fileToCheck}`);
|
||||
|
|
@ -81,7 +82,7 @@ const plugin = (args: IpluginInputArgs): IpluginOutputArgs => {
|
|||
|
||||
return {
|
||||
outputFileObj: args.inputFileObj,
|
||||
outputNumber: fileExists ? 1 : 2,
|
||||
outputNumber: fileDoesExist ? 1 : 2,
|
||||
variables: args.variables,
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { promises as fs } from 'fs';
|
||||
import { promises as fsp } from 'fs';
|
||||
import {
|
||||
getContainer, getFileAbosluteDir, getSubStem,
|
||||
} from '../../../../FlowHelpers/1.0.0/fileUtils';
|
||||
|
|
@ -188,7 +188,7 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
|||
sourceDir = getFileAbosluteDir(args.inputFileObj._id);
|
||||
}
|
||||
|
||||
let filesInDir = (await fs.readdir(sourceDir))
|
||||
let filesInDir = (await fsp.readdir(sourceDir))
|
||||
.map((row) => ({
|
||||
source: `${sourceDir}/${row}`,
|
||||
destination: normJoinPath({
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { promises as fs } from 'fs';
|
||||
import { promises as fsp } from 'fs';
|
||||
import { getContainer, getFileName, getSubStem } from '../../../../FlowHelpers/1.0.0/fileUtils';
|
||||
import {
|
||||
IpluginDetails,
|
||||
|
|
@ -73,7 +73,7 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
|||
|
||||
const outputDirectory = String(args.inputs.outputDirectory);
|
||||
|
||||
const originalFileName = getFileName(args.originalLibraryFile._id);
|
||||
const originalFileName = getFileName(args.inputFileObj._id);
|
||||
const newContainer = getContainer(args.inputFileObj._id);
|
||||
|
||||
let outputPath = '';
|
||||
|
|
@ -126,7 +126,7 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
|||
|
||||
args.deps.fsextra.ensureDirSync(outputPath);
|
||||
|
||||
await fs.copyFile(args.inputFileObj._id, ouputFilePath);
|
||||
await fsp.copyFile(args.inputFileObj._id, ouputFilePath);
|
||||
|
||||
return {
|
||||
outputFileObj: {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { promises as fs } from 'fs';
|
||||
import { promises as fsp } from 'fs';
|
||||
import { getContainer, getFileName } from '../../../../FlowHelpers/1.0.0/fileUtils';
|
||||
import {
|
||||
IpluginDetails,
|
||||
|
|
@ -37,7 +37,7 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
|||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||
|
||||
const originalFileName = getFileName(args.originalLibraryFile._id);
|
||||
const originalFileName = getFileName(args.inputFileObj._id);
|
||||
const newContainer = getContainer(args.inputFileObj._id);
|
||||
|
||||
const outputPath = args.workDir;
|
||||
|
|
@ -67,7 +67,7 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
|||
|
||||
args.deps.fsextra.ensureDirSync(outputPath);
|
||||
|
||||
await fs.copyFile(args.inputFileObj._id, ouputFilePath);
|
||||
await fsp.copyFile(args.inputFileObj._id, ouputFilePath);
|
||||
|
||||
return {
|
||||
outputFileObj: {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { promises as fs } from 'fs';
|
||||
import { promises as fsp } from 'fs';
|
||||
|
||||
import {
|
||||
IpluginDetails,
|
||||
IpluginInputArgs,
|
||||
|
|
@ -64,21 +65,21 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
|||
|
||||
if (fileToDelete === 'workingFile') {
|
||||
args.jobLog(`Deleting working file ${args.inputFileObj._id}`);
|
||||
await fs.unlink(args.inputFileObj._id);
|
||||
await fsp.unlink(args.inputFileObj._id);
|
||||
} else if (fileToDelete === 'originalFile') {
|
||||
args.jobLog(`Deleting original file ${args.originalLibraryFile._id}`);
|
||||
await fs.unlink(args.originalLibraryFile._id);
|
||||
await fsp.unlink(args.originalLibraryFile._id);
|
||||
}
|
||||
|
||||
const fileDir = getFileAbosluteDir(args.originalLibraryFile._id);
|
||||
|
||||
if (deleteParentFolderIfEmpty) {
|
||||
args.jobLog(`Checking if folder ${fileDir} is empty`);
|
||||
const files = await fs.readdir(fileDir);
|
||||
const files = await fsp.readdir(fileDir);
|
||||
|
||||
if (files.length === 0) {
|
||||
args.jobLog(`Deleting empty folder ${fileDir}`);
|
||||
await fs.rmdir(fileDir);
|
||||
await fsp.rmdir(fileDir);
|
||||
} else {
|
||||
args.jobLog(`Folder ${fileDir} is not empty, skipping delete`);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ const plugin = async (args:IpluginInputArgs):Promise<IpluginOutputArgs> => {
|
|||
|
||||
const outputDirectory = String(args.inputs.outputDirectory);
|
||||
|
||||
const originalFileName = getFileName(args.originalLibraryFile._id);
|
||||
const originalFileName = getFileName(args.inputFileObj._id);
|
||||
const newContainer = getContainer(args.inputFileObj._id);
|
||||
|
||||
let outputPath = '';
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
import { promises as fsp } from 'fs';
|
||||
import fileMoveOrCopy from '../../../../FlowHelpers/1.0.0/fileMoveOrCopy';
|
||||
import {
|
||||
fileExists,
|
||||
getContainer, getFileAbosluteDir, getFileName,
|
||||
} from '../../../../FlowHelpers/1.0.0/fileUtils';
|
||||
import {
|
||||
|
|
@ -32,7 +34,6 @@ const details = (): IpluginDetails => ({
|
|||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
||||
const fs = require('fs');
|
||||
const lib = require('../../../../../methods/lib')();
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||
|
|
@ -76,11 +77,11 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
|||
|
||||
// delete original file
|
||||
if (
|
||||
fs.existsSync(args.originalLibraryFile._id)
|
||||
await fileExists(args.originalLibraryFile._id)
|
||||
&& args.originalLibraryFile._id !== currentPath
|
||||
) {
|
||||
args.jobLog(`Deleting original file:${args.originalLibraryFile._id}`);
|
||||
fs.unlinkSync(args.originalLibraryFile._id);
|
||||
await fsp.unlink(args.originalLibraryFile._id);
|
||||
}
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 2000));
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { promises as fs } from 'fs';
|
||||
import { promises as fsp } from 'fs';
|
||||
import { CLI } from '../../../../FlowHelpers/1.0.0/cliUtils';
|
||||
import {
|
||||
IpluginDetails,
|
||||
|
|
@ -99,7 +99,7 @@ const plugin = async (args:IpluginInputArgs):Promise<IpluginOutputArgs> => {
|
|||
|
||||
if (presetString.trim() !== '') {
|
||||
const preset = JSON.parse(presetString);
|
||||
await fs.writeFile(presetPath, JSON.stringify(preset, null, 2));
|
||||
await fsp.writeFile(presetPath, JSON.stringify(preset, null, 2));
|
||||
cliArgs.push('--preset-import-file');
|
||||
cliArgs.push(presetPath);
|
||||
cliArgs.push('-Z');
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { promises as fs } from 'fs';
|
||||
import { promises as fsp } from 'fs';
|
||||
import { CLI } from '../../../../FlowHelpers/1.0.0/cliUtils';
|
||||
import {
|
||||
IpluginDetails,
|
||||
|
|
@ -142,7 +142,7 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
|||
|
||||
if (useJsonPreset) {
|
||||
const preset = JSON.parse(presetString);
|
||||
await fs.writeFile(presetPath, JSON.stringify(preset, null, 2));
|
||||
await fsp.writeFile(presetPath, JSON.stringify(preset, null, 2));
|
||||
cliArgs.push('--preset-import-file');
|
||||
cliArgs.push(presetPath);
|
||||
cliArgs.push('-Z');
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { promises as fs } from 'fs';
|
||||
import { promises as fsp } from 'fs';
|
||||
|
||||
import {
|
||||
IpluginDetails,
|
||||
|
|
@ -86,7 +86,7 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
|||
|
||||
const checkReadWrite = async (location: string) => {
|
||||
try {
|
||||
await fs.access(location, fs.constants.R_OK);
|
||||
await fsp.access(location, fsp.constants.R_OK);
|
||||
} catch (err) {
|
||||
args.jobLog(JSON.stringify(err));
|
||||
if (pauseNodeIfAccessChecksFail) {
|
||||
|
|
@ -97,7 +97,7 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
|||
}
|
||||
|
||||
try {
|
||||
await fs.access(location, fs.constants.W_OK);
|
||||
await fsp.access(location, fsp.constants.W_OK);
|
||||
} catch (err) {
|
||||
args.jobLog(JSON.stringify(err));
|
||||
if (pauseNodeIfAccessChecksFail) {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
import { promises as fsp } from 'fs';
|
||||
import {
|
||||
IpluginDetails,
|
||||
IpluginInputArgs,
|
||||
IpluginOutputArgs,
|
||||
} from '../../../../FlowHelpers/1.0.0/interfaces/interfaces';
|
||||
import { fileExists } from '../../../../FlowHelpers/1.0.0/fileUtils';
|
||||
|
||||
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||
const details = ():IpluginDetails => ({
|
||||
|
|
@ -46,21 +48,19 @@ const details = ():IpluginDetails => ({
|
|||
});
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const plugin = (args:IpluginInputArgs):IpluginOutputArgs => {
|
||||
const plugin = async (args:IpluginInputArgs):Promise<IpluginOutputArgs> => {
|
||||
const lib = require('../../../../../methods/lib')();
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
const oldFile = args.inputFileObj._id;
|
||||
const newFile = `${args.inputFileObj._id}.tmp`;
|
||||
|
||||
if (fs.existsSync(newFile)) {
|
||||
fs.unlinkSync(newFile);
|
||||
if (await fileExists(newFile)) {
|
||||
await fsp.unlink(newFile);
|
||||
}
|
||||
|
||||
fs.copyFileSync(oldFile, newFile);
|
||||
await fsp.copyFile(oldFile, newFile);
|
||||
|
||||
return {
|
||||
outputFileObj: { _id: newFile },
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { promises as fs } from 'fs';
|
||||
import { promises as fsp } from 'fs';
|
||||
import {
|
||||
getContainer, getFileName, getPluginWorkDir, getScanTypes,
|
||||
} from './fileUtils';
|
||||
|
|
@ -43,7 +43,7 @@ export const runClassicPlugin = async (args:IpluginInputArgs, type:'filter'|'tra
|
|||
let pluginSrcStr = '';
|
||||
if (pluginSource === 'Community') {
|
||||
classicPlugin = args.deps.importFresh(relativePluginPath);
|
||||
pluginSrcStr = await fs.readFile(absolutePath, 'utf8');
|
||||
pluginSrcStr = await fsp.readFile(absolutePath, 'utf8');
|
||||
} else {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
const res = await args.deps.axiosMiddleware('api/v2/read-plugin', {
|
||||
|
|
|
|||
|
|
@ -39,6 +39,28 @@ const handbrakeParser = ({
|
|||
return percentage;
|
||||
};
|
||||
|
||||
const getHandBrakeFps = ({
|
||||
str,
|
||||
}: {
|
||||
str: string,
|
||||
}): number => {
|
||||
try {
|
||||
if (typeof str !== 'string' || !(str.includes('(') && str.includes('fps'))) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const out = parseInt(str.split('(')[1].split('fps')[0].trim(), 10);
|
||||
|
||||
// eslint-disable-next-line no-restricted-globals
|
||||
if (!isNaN(out)) {
|
||||
return out;
|
||||
}
|
||||
} catch (err) {
|
||||
// err
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
|
||||
// frame= 889 fps=106 q=26.0 Lsize= 25526kB time=00:00:35.69 bitrate=5858.3kbits/s speed=4.25x
|
||||
const getFFmpegVar = ({
|
||||
str,
|
||||
|
|
@ -227,5 +249,6 @@ export {
|
|||
ffmpegParser,
|
||||
getFFmpegPercentage,
|
||||
getFFmpegVar,
|
||||
getHandBrakeFps,
|
||||
editreadyParser,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
import { editreadyParser, ffmpegParser, handbrakeParser } from './cliParsers';
|
||||
import fs from 'fs';
|
||||
import {
|
||||
editreadyParser, ffmpegParser, getHandBrakeFps, handbrakeParser,
|
||||
} from './cliParsers';
|
||||
import { Ilog, IupdateWorker } from './interfaces/interfaces';
|
||||
import { IFileObject, Istreams } from './interfaces/synced/IFileObject';
|
||||
|
||||
const fs = require('fs');
|
||||
import { fileExists } from './fileUtils';
|
||||
|
||||
const fancyTimeFormat = (time: number) => {
|
||||
// Hours, minutes and seconds
|
||||
|
|
@ -91,7 +93,7 @@ class CLI {
|
|||
this.config = config;
|
||||
}
|
||||
|
||||
updateETA = (perc: number): void => {
|
||||
updateETA = async (perc: number): Promise<void> => {
|
||||
if (perc > 0) {
|
||||
if (this.lastProgCheck === 0) {
|
||||
this.lastProgCheck = new Date().getTime();
|
||||
|
|
@ -123,9 +125,11 @@ class CLI {
|
|||
let outputFileSizeInGbytes;
|
||||
|
||||
try {
|
||||
if (fs.existsSync(this.config.outputFilePath)) {
|
||||
if (await fileExists(this.config.outputFilePath)) {
|
||||
let singleFileSize = fs.statSync(this.config.outputFilePath);
|
||||
// @ts-expect-error type
|
||||
singleFileSize = singleFileSize.size;
|
||||
// @ts-expect-error type
|
||||
outputFileSizeInGbytes = singleFileSize / (1024 * 1024 * 1024);
|
||||
|
||||
if (outputFileSizeInGbytes !== this.oldOutSize) {
|
||||
|
|
@ -177,11 +181,21 @@ class CLI {
|
|||
});
|
||||
|
||||
if (percentage > 0) {
|
||||
this.updateETA(percentage);
|
||||
void this.updateETA(percentage);
|
||||
this.config.updateWorker({
|
||||
percentage,
|
||||
});
|
||||
}
|
||||
|
||||
const fps = getHandBrakeFps({
|
||||
str,
|
||||
});
|
||||
|
||||
if (fps > 0) {
|
||||
this.config.updateWorker({
|
||||
fps,
|
||||
});
|
||||
}
|
||||
} else if (this.config.cli.toLowerCase().includes('ffmpeg')) {
|
||||
const n = str.indexOf('fps');
|
||||
const shouldUpdate = str.length >= 6 && n >= 6;
|
||||
|
|
@ -223,7 +237,7 @@ class CLI {
|
|||
}
|
||||
|
||||
if (percentage > 0) {
|
||||
this.updateETA(percentage);
|
||||
void this.updateETA(percentage);
|
||||
this.config.updateWorker({
|
||||
percentage,
|
||||
});
|
||||
|
|
@ -233,7 +247,7 @@ class CLI {
|
|||
str,
|
||||
});
|
||||
if (percentage > 0) {
|
||||
this.updateETA(percentage);
|
||||
void this.updateETA(percentage);
|
||||
this.config.updateWorker({
|
||||
percentage,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { promises as fs } from 'fs';
|
||||
import { promises as fsp } from 'fs';
|
||||
|
||||
import { getFileSize } from './fileUtils';
|
||||
import { IpluginInputArgs } from './interfaces/interfaces';
|
||||
|
|
@ -48,7 +48,7 @@ const tryMove = async ({
|
|||
|
||||
let error = false;
|
||||
try {
|
||||
await fs.rename(sourcePath, destinationPath);
|
||||
await fsp.rename(sourcePath, destinationPath);
|
||||
} catch (err) {
|
||||
error = true;
|
||||
args.jobLog(`File move error: ${JSON.stringify(err)}`);
|
||||
|
|
@ -157,7 +157,7 @@ const tryNormalCopy = async ({
|
|||
|
||||
let error = false;
|
||||
try {
|
||||
await fs.copyFile(sourcePath, destinationPath);
|
||||
await fsp.copyFile(sourcePath, destinationPath);
|
||||
} catch (err) {
|
||||
error = true;
|
||||
args.jobLog(`File copy error: ${JSON.stringify(err)}`);
|
||||
|
|
@ -186,7 +186,7 @@ const cleanSourceFile = async ({
|
|||
}) => {
|
||||
try {
|
||||
args.jobLog(`Deleting source file ${sourcePath}`);
|
||||
await fs.unlink(sourcePath);
|
||||
await fsp.unlink(sourcePath);
|
||||
} catch (err) {
|
||||
args.jobLog(`Failed to delete source file ${sourcePath}: ${JSON.stringify(err)}`);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
import { promises as fs } from 'fs';
|
||||
import { promises as fsp } from 'fs';
|
||||
import { IpluginInputArgs } from './interfaces/interfaces';
|
||||
|
||||
export const fileExists = async (path:string): Promise<boolean> => !!(await fsp.stat(path).catch(() => false));
|
||||
|
||||
export const getContainer = (filePath: string): string => {
|
||||
const parts = filePath.split('.');
|
||||
return parts[parts.length - 1];
|
||||
|
|
@ -37,7 +39,7 @@ export const getSubStem = ({
|
|||
};
|
||||
|
||||
export const getFileSize = async (file:string):Promise<number> => {
|
||||
const stats = await fs.stat(file);
|
||||
const stats = await fsp.stat(file);
|
||||
const { size } = stats;
|
||||
return size;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue