mirror of
https://github.com/gabehf/Tdarr_Plugins.git
synced 2026-03-11 00:10:29 -07:00
Update file operation plugins
This commit is contained in:
parent
579aab99e9
commit
80f02bf810
22 changed files with 692 additions and 47 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import { CLI } from '../../../../FlowHelpers/1.0.0/cliUtils';
|
||||
import { getContainer } from '../../../../FlowHelpers/1.0.0/fileUtils';
|
||||
import { getContainer, getFileName, getPluginWorkDir } from '../../../../FlowHelpers/1.0.0/fileUtils';
|
||||
import {
|
||||
IpluginDetails,
|
||||
IpluginInputArgs,
|
||||
|
|
@ -69,7 +69,7 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
|||
const { tp } = args.inputs;
|
||||
|
||||
const container = getContainer(args.inputFileObj._id);
|
||||
const outputFilePath = `${args.workDir}/tempFile_${new Date().getTime()}.${container}`;
|
||||
const outputFilePath = `${getPluginWorkDir(args)}/${getFileName(args.inputFileObj._id)}.${container}`;
|
||||
|
||||
const normArgs1: string[] = [
|
||||
'-i',
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { getContainer } from '../../../../FlowHelpers/1.0.0/fileUtils';
|
||||
import { getContainer, getFileName, getPluginWorkDir } from '../../../../FlowHelpers/1.0.0/fileUtils';
|
||||
import {
|
||||
IpluginDetails,
|
||||
IpluginInputArgs,
|
||||
|
|
@ -80,7 +80,7 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
|||
}
|
||||
|
||||
const container = getContainer(args.inputFileObj._id);
|
||||
const cacheFilePath = `${args.workDir}/tempFile_${new Date().getTime()}.${container}`;
|
||||
const cacheFilePath = `${getPluginWorkDir(args)}/${getFileName(args.inputFileObj._id)}.${container}`;
|
||||
|
||||
const otherArguments = {
|
||||
handbrakePath: args.handbrakePath,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { CLI } from '../../../../FlowHelpers/1.0.0/cliUtils';
|
||||
import { getContainer } from '../../../../FlowHelpers/1.0.0/fileUtils';
|
||||
import { getContainer, getFileName, getPluginWorkDir } from '../../../../FlowHelpers/1.0.0/fileUtils';
|
||||
import {
|
||||
IpluginDetails,
|
||||
IpluginInputArgs,
|
||||
|
|
@ -83,7 +83,7 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
|||
}
|
||||
|
||||
const container = getContainer(args.inputFileObj._id);
|
||||
let cacheFilePath = `${args.workDir}/tempFile_${new Date().getTime()}.${container}`;
|
||||
let cacheFilePath = `${getPluginWorkDir(args)}/${getFileName(args.inputFileObj._id)}.${container}`;
|
||||
|
||||
const otherArguments = {
|
||||
handbrakePath: args.handbrakePath,
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import {
|
|||
IpluginOutputArgs,
|
||||
} from '../../../../FlowHelpers/1.0.0/interfaces/interfaces';
|
||||
import { CLI } from '../../../../FlowHelpers/1.0.0/cliUtils';
|
||||
import { getFileName, getPluginWorkDir } from '../../../../FlowHelpers/1.0.0/fileUtils';
|
||||
|
||||
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||
const details = (): IpluginDetails => ({
|
||||
|
|
@ -121,7 +122,9 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
|||
const idx = cliArgs.indexOf('-i');
|
||||
cliArgs.splice(idx, 0, ...inputArgs);
|
||||
|
||||
const outputFilePath = `${args.workDir}/tempFile_${new Date().getTime()}.${args.variables.ffmpegCommand.container}`;
|
||||
const outputFilePath = `${getPluginWorkDir(args)}/${getFileName(args.inputFileObj._id)}`
|
||||
+ `.${args.variables.ffmpegCommand.container}`;
|
||||
|
||||
cliArgs.push(outputFilePath);
|
||||
|
||||
args.jobLog('Processing file');
|
||||
|
|
|
|||
|
|
@ -0,0 +1,86 @@
|
|||
import fs from 'fs';
|
||||
import { getContainer, getFileAbosluteDir, getFileName } from '../../../../FlowHelpers/1.0.0/fileUtils';
|
||||
import {
|
||||
IpluginDetails,
|
||||
IpluginInputArgs,
|
||||
IpluginOutputArgs,
|
||||
} from '../../../../FlowHelpers/1.0.0/interfaces/interfaces';
|
||||
|
||||
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||
const details = (): IpluginDetails => ({
|
||||
name: 'Check File Exists',
|
||||
description: 'Check file Exists',
|
||||
style: {
|
||||
borderColor: 'orange',
|
||||
},
|
||||
tags: 'video',
|
||||
isStartPlugin: false,
|
||||
sidebarPosition: -1,
|
||||
icon: 'faQuestion',
|
||||
inputs: [
|
||||
{
|
||||
name: 'fileToCheck',
|
||||
type: 'string',
|
||||
// eslint-disable-next-line no-template-curly-in-string
|
||||
defaultValue: '${fileName}_720p.${container}',
|
||||
inputUI: {
|
||||
type: 'text',
|
||||
},
|
||||
// eslint-disable-next-line no-template-curly-in-string
|
||||
tooltip: 'Specify file to check using templating e.g. ${fileName}_720p.${container}',
|
||||
},
|
||||
{
|
||||
name: 'directory',
|
||||
type: 'string',
|
||||
defaultValue: '',
|
||||
inputUI: {
|
||||
type: 'directory',
|
||||
},
|
||||
tooltip: 'Specify directory to check. Leave blank to use working directory. Put below input plugin to check original file directory.',
|
||||
},
|
||||
],
|
||||
outputs: [
|
||||
{
|
||||
number: 1,
|
||||
tooltip: 'File exists',
|
||||
},
|
||||
{
|
||||
number: 2,
|
||||
tooltip: 'File does not exist',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const plugin = (args: IpluginInputArgs): 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 directory = String(args.inputs.directory).trim() || getFileAbosluteDir(args.inputFileObj._id);
|
||||
|
||||
const fileName = getFileName(args.inputFileObj._id);
|
||||
|
||||
let fileToCheck = String(args.inputs.fileToCheck).trim();
|
||||
fileToCheck = fileToCheck.replace(/\${fileName}/g, fileName);
|
||||
fileToCheck = fileToCheck.replace(/\${container}/g, getContainer(args.inputFileObj._id));
|
||||
fileToCheck = `${directory}/${fileToCheck}`;
|
||||
|
||||
let fileExists = false;
|
||||
if (fs.existsSync(fileToCheck)) {
|
||||
fileExists = true;
|
||||
args.jobLog(`File exists: ${fileToCheck}`);
|
||||
} else {
|
||||
args.jobLog(`File does not exist: ${fileToCheck}`);
|
||||
}
|
||||
|
||||
return {
|
||||
outputFileObj: args.inputFileObj,
|
||||
outputNumber: fileExists ? 1 : 2,
|
||||
variables: args.variables,
|
||||
};
|
||||
};
|
||||
export {
|
||||
details,
|
||||
plugin,
|
||||
};
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
import { getContainer, getFileName } from '../../../../FlowHelpers/1.0.0/fileUtils';
|
||||
import {
|
||||
IpluginDetails,
|
||||
IpluginInputArgs,
|
||||
IpluginOutputArgs,
|
||||
} from '../../../../FlowHelpers/1.0.0/interfaces/interfaces';
|
||||
|
||||
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||
const details = (): IpluginDetails => ({
|
||||
name: 'Check File Name Includes',
|
||||
description: 'Check if a file name includes specific terms. Only needs to match one term',
|
||||
style: {
|
||||
borderColor: 'orange',
|
||||
},
|
||||
tags: 'video',
|
||||
isStartPlugin: false,
|
||||
sidebarPosition: -1,
|
||||
icon: 'faQuestion',
|
||||
inputs: [
|
||||
{
|
||||
name: 'terms',
|
||||
type: 'string',
|
||||
// eslint-disable-next-line no-template-curly-in-string
|
||||
defaultValue: '_720p,_1080p',
|
||||
inputUI: {
|
||||
type: 'text',
|
||||
},
|
||||
// eslint-disable-next-line no-template-curly-in-string
|
||||
tooltip: 'Specify terms to check for in file name using comma seperated list e.g. _720p,_1080p',
|
||||
},
|
||||
],
|
||||
outputs: [
|
||||
{
|
||||
number: 1,
|
||||
tooltip: 'File name contains terms',
|
||||
},
|
||||
{
|
||||
number: 2,
|
||||
tooltip: 'File name does not contains terms',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const plugin = (args: IpluginInputArgs): 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 fileName = `${getFileName(args.inputFileObj._id)}.${getContainer(args.inputFileObj._id)}`;
|
||||
const terms = String(args.inputs.terms).trim().split(',');
|
||||
let containsTerms = false;
|
||||
|
||||
for (let i = 0; i < terms.length; i++) {
|
||||
if (fileName.includes(terms[i])) {
|
||||
containsTerms = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
outputFileObj: args.inputFileObj,
|
||||
outputNumber: containsTerms ? 1 : 2,
|
||||
variables: args.variables,
|
||||
};
|
||||
};
|
||||
export {
|
||||
details,
|
||||
plugin,
|
||||
};
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
import {
|
||||
getContainer, getFileAbosluteDir, getFileName, getSubStem, moveFileAndValidate,
|
||||
} from '../../../../FlowHelpers/1.0.0/fileUtils';
|
||||
import {
|
||||
IpluginDetails,
|
||||
IpluginInputArgs,
|
||||
IpluginOutputArgs,
|
||||
} from '../../../../FlowHelpers/1.0.0/interfaces/interfaces';
|
||||
import normJoinPath from '../../../../FlowHelpers/1.0.0/normJoinPath';
|
||||
|
||||
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||
const details = ():IpluginDetails => ({
|
||||
name: 'Move To Original Directory',
|
||||
description: 'Move working file original directory.',
|
||||
style: {
|
||||
borderColor: 'green',
|
||||
},
|
||||
tags: '',
|
||||
|
||||
isStartPlugin: false,
|
||||
sidebarPosition: -1,
|
||||
icon: 'faArrowRight',
|
||||
inputs: [],
|
||||
outputs: [
|
||||
{
|
||||
number: 1,
|
||||
tooltip: 'Continue to next plugin',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
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 fileName = getFileName(args.inputFileObj._id);
|
||||
const container = getContainer(args.inputFileObj._id);
|
||||
const outputDir = getFileAbosluteDir(args.originalLibraryFile._id);
|
||||
|
||||
const ouputFilePath = `${outputDir}/${fileName}.${container}`;
|
||||
|
||||
await moveFileAndValidate({
|
||||
inputPath: args.inputFileObj._id,
|
||||
outputPath: ouputFilePath,
|
||||
args,
|
||||
});
|
||||
|
||||
return {
|
||||
outputFileObj: {
|
||||
_id: ouputFilePath,
|
||||
},
|
||||
outputNumber: 1,
|
||||
variables: args.variables,
|
||||
};
|
||||
};
|
||||
export {
|
||||
details,
|
||||
plugin,
|
||||
};
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
import {
|
||||
getContainer, getFileAbosluteDir, getFileName, moveFileAndValidate,
|
||||
} from '../../../../FlowHelpers/1.0.0/fileUtils';
|
||||
import {
|
||||
IpluginDetails,
|
||||
IpluginInputArgs,
|
||||
IpluginOutputArgs,
|
||||
} from '../../../../FlowHelpers/1.0.0/interfaces/interfaces';
|
||||
|
||||
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||
const details = (): IpluginDetails => ({
|
||||
name: 'Rename File',
|
||||
description: 'Rename a file',
|
||||
style: {
|
||||
borderColor: 'green',
|
||||
},
|
||||
tags: 'video',
|
||||
isStartPlugin: false,
|
||||
sidebarPosition: -1,
|
||||
icon: '',
|
||||
inputs: [
|
||||
{
|
||||
name: 'fileRename',
|
||||
type: 'string',
|
||||
// eslint-disable-next-line no-template-curly-in-string
|
||||
defaultValue: '${fileName}_720p.${container}',
|
||||
inputUI: {
|
||||
type: 'text',
|
||||
},
|
||||
// eslint-disable-next-line no-template-curly-in-string
|
||||
tooltip: 'Specify file to check using templating e.g. ${fileName}_720p.${container}',
|
||||
},
|
||||
],
|
||||
outputs: [
|
||||
{
|
||||
number: 1,
|
||||
tooltip: 'Continue to next plugin',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
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 fileName = getFileName(args.inputFileObj._id);
|
||||
|
||||
let newName = String(args.inputs.fileRename).trim();
|
||||
newName = newName.replace(/\${fileName}/g, fileName);
|
||||
newName = newName.replace(/\${container}/g, getContainer(args.inputFileObj._id));
|
||||
|
||||
const fileDir = getFileAbosluteDir(args.inputFileObj._id);
|
||||
const newPath = `${fileDir}/${newName}`;
|
||||
|
||||
await moveFileAndValidate({
|
||||
inputPath: args.inputFileObj._id,
|
||||
outputPath: newPath,
|
||||
args,
|
||||
});
|
||||
|
||||
return {
|
||||
outputFileObj: {
|
||||
_id: newPath,
|
||||
},
|
||||
outputNumber: 1,
|
||||
variables: args.variables,
|
||||
};
|
||||
};
|
||||
export {
|
||||
details,
|
||||
plugin,
|
||||
};
|
||||
|
|
@ -1,4 +1,6 @@
|
|||
import { moveFileAndValidate } from '../../../../FlowHelpers/1.0.0/fileUtils';
|
||||
import {
|
||||
getContainer, getFileAbosluteDir, getFileName, moveFileAndValidate,
|
||||
} from '../../../../FlowHelpers/1.0.0/fileUtils';
|
||||
import {
|
||||
IpluginDetails,
|
||||
IpluginInputArgs,
|
||||
|
|
@ -25,16 +27,6 @@ const details = (): IpluginDetails => ({
|
|||
],
|
||||
});
|
||||
|
||||
const getNewPath = (originalPath: string, tempPath: string) => {
|
||||
const tempPathParts = tempPath.split('.');
|
||||
const container = tempPathParts[tempPathParts.length - 1];
|
||||
|
||||
const originalPathParts = originalPath.split('.');
|
||||
|
||||
originalPathParts[originalPathParts.length - 1] = container;
|
||||
return originalPathParts.join('.');
|
||||
};
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
||||
const fs = require('fs');
|
||||
|
|
@ -57,7 +49,11 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
|||
args.jobLog('File has changed, replacing original file');
|
||||
|
||||
const currentPath = args.inputFileObj._id;
|
||||
const newPath = getNewPath(args.originalLibraryFile._id, currentPath);
|
||||
const orignalFolder = getFileAbosluteDir(args.originalLibraryFile._id);
|
||||
const fileName = getFileName(args.inputFileObj._id);
|
||||
const container = getContainer(args.inputFileObj._id);
|
||||
|
||||
const newPath = `${orignalFolder}/${fileName}.${container}`;
|
||||
const newPathTmp = `${newPath}.tmp`;
|
||||
|
||||
args.jobLog(JSON.stringify({
|
||||
|
|
@ -68,11 +64,6 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
|||
|
||||
await new Promise((resolve) => setTimeout(resolve, 2000));
|
||||
|
||||
// delete temp file
|
||||
if (fs.existsSync(newPath)) {
|
||||
fs.unlinkSync(newPath);
|
||||
}
|
||||
|
||||
await moveFileAndValidate({
|
||||
inputPath: currentPath,
|
||||
outputPath: newPathTmp,
|
||||
|
|
@ -80,7 +71,11 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
|||
});
|
||||
|
||||
// delete original file
|
||||
if (fs.existsSync(args.originalLibraryFile._id)) {
|
||||
if (
|
||||
fs.existsSync(args.originalLibraryFile._id)
|
||||
&& args.originalLibraryFile._id !== currentPath
|
||||
) {
|
||||
args.jobLog(`Deleting original file:${args.originalLibraryFile._id}`);
|
||||
fs.unlinkSync(args.originalLibraryFile._id);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import {
|
|||
IpluginInputArgs,
|
||||
IpluginOutputArgs,
|
||||
} from '../../../../FlowHelpers/1.0.0/interfaces/interfaces';
|
||||
import { getContainer } from '../../../../FlowHelpers/1.0.0/fileUtils';
|
||||
import { getContainer, getFileName, getPluginWorkDir } from '../../../../FlowHelpers/1.0.0/fileUtils';
|
||||
|
||||
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||
const details = ():IpluginDetails => ({
|
||||
|
|
@ -79,7 +79,7 @@ const plugin = async (args:IpluginInputArgs):Promise<IpluginOutputArgs> => {
|
|||
container = getContainer(args.inputFileObj._id);
|
||||
}
|
||||
|
||||
const outputFilePath = `${args.workDir}/tempFile_${new Date().getTime()}.${container}`;
|
||||
const outputFilePath = `${getPluginWorkDir(args)}/${getFileName(args.inputFileObj._id)}.${container}`;
|
||||
|
||||
const presetString = String(args.inputs.jsonPreset);
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,12 @@ export const getFileName = (filePath: string): string => {
|
|||
return parts2.join('.');
|
||||
};
|
||||
|
||||
export const getFileAbosluteDir = (filePath: string):string => {
|
||||
const parts = filePath.split('/');
|
||||
parts.pop();
|
||||
return parts.join('/');
|
||||
};
|
||||
|
||||
export const getFfType = (codecType: string): string => (codecType === 'video' ? 'v' : 'a');
|
||||
|
||||
export const getSubStem = ({
|
||||
|
|
@ -92,3 +98,9 @@ export const moveFileAndValidate = async ({
|
|||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const getPluginWorkDir = (args: IpluginInputArgs):string => {
|
||||
const pluginWorkDir = `${args.workDir}/${new Date().getTime()}`;
|
||||
args.deps.fsextra.ensureDirSync(pluginWorkDir);
|
||||
return pluginWorkDir;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue