mirror of
https://github.com/gabehf/Tdarr_Plugins.git
synced 2026-03-09 15:38:19 -07:00
commit
e53ece1c70
19 changed files with 519 additions and 51 deletions
|
|
@ -47,7 +47,6 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.plugin = exports.details = void 0;
|
||||
var cliUtils_1 = require("../../../../FlowHelpers/1.0.0/cliUtils");
|
||||
var fileUtils_1 = require("../../../../FlowHelpers/1.0.0/fileUtils");
|
||||
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||
var details = function () { return ({
|
||||
name: 'Execute',
|
||||
|
|
@ -113,9 +112,6 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function
|
|||
}
|
||||
return !stream.removed;
|
||||
});
|
||||
if ((0, fileUtils_1.getContainer)(args.inputFileObj._id) !== args.variables.ffmpegCommand.container) {
|
||||
shouldProcess = true;
|
||||
}
|
||||
_loop_1 = function (i) {
|
||||
var stream = streams[i];
|
||||
stream.outputArgs = stream.outputArgs.map(function (arg) {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.plugin = exports.details = void 0;
|
||||
var fileUtils_1 = require("../../../../FlowHelpers/1.0.0/fileUtils");
|
||||
/* eslint-disable no-param-reassign */
|
||||
var details = function () { return ({
|
||||
name: 'Set Container',
|
||||
|
|
@ -41,7 +42,11 @@ var plugin = function (args) {
|
|||
var lib = require('../../../../../methods/lib')();
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||
args.variables.ffmpegCommand.container = String(args.inputs.container);
|
||||
var newContainer = String(args.inputs.container);
|
||||
if ((0, fileUtils_1.getContainer)(args.inputFileObj._id) !== args.inputs.container) {
|
||||
args.variables.ffmpegCommand.container = newContainer;
|
||||
args.variables.ffmpegCommand.shouldProcess = true;
|
||||
}
|
||||
return {
|
||||
outputFileObj: args.inputFileObj,
|
||||
outputNumber: 1,
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ var __assign = (this && this.__assign) || function () {
|
|||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.plugin = exports.details = void 0;
|
||||
var fileUtils_1 = require("../../../../FlowHelpers/1.0.0/fileUtils");
|
||||
/* eslint-disable no-param-reassign */
|
||||
var details = function () { return ({
|
||||
name: 'Begin Command',
|
||||
|
|
@ -39,8 +40,7 @@ var plugin = function (args) {
|
|||
var lib = require('../../../../../methods/lib')();
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||
var containerParts = args.inputFileObj._id.split('.');
|
||||
var container = containerParts[containerParts.length - 1];
|
||||
var container = (0, fileUtils_1.getContainer)(args.inputFileObj._id);
|
||||
var ffmpegCommand = {
|
||||
inputFiles: [],
|
||||
streams: JSON.parse(JSON.stringify(args.inputFileObj.ffProbeData.streams)).map(function (stream) { return (__assign(__assign({}, stream), { removed: false, mapArgs: [
|
||||
|
|
|
|||
|
|
@ -35,10 +35,14 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.plugin = exports.details = void 0;
|
||||
var fs_1 = require("fs");
|
||||
var fileUtils_1 = require("../../../../FlowHelpers/1.0.0/fileUtils");
|
||||
var normJoinPath_1 = __importDefault(require("../../../../FlowHelpers/1.0.0/normJoinPath"));
|
||||
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||
var details = function () { return ({
|
||||
name: 'Copy to Directory',
|
||||
|
|
@ -56,16 +60,29 @@ var details = function () { return ({
|
|||
type: 'string',
|
||||
defaultValue: '',
|
||||
inputUI: {
|
||||
type: 'text',
|
||||
type: 'directory',
|
||||
},
|
||||
tooltip: 'Specify ouput directory',
|
||||
},
|
||||
{
|
||||
name: 'keepRelativePath',
|
||||
type: 'boolean',
|
||||
defaultValue: 'false',
|
||||
inputUI: {
|
||||
type: 'text',
|
||||
options: [
|
||||
'false',
|
||||
'true',
|
||||
],
|
||||
},
|
||||
tooltip: 'Specify whether to keep the relative path',
|
||||
},
|
||||
{
|
||||
name: 'makeWorkingFile',
|
||||
type: 'boolean',
|
||||
defaultValue: 'false',
|
||||
inputUI: {
|
||||
type: 'text',
|
||||
type: 'dropdown',
|
||||
options: [
|
||||
'false',
|
||||
'true',
|
||||
|
|
@ -84,23 +101,51 @@ var details = function () { return ({
|
|||
exports.details = details;
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function () {
|
||||
var lib, originalFileName, newContainer, outputPath, workingFile;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
var lib, _a, keepRelativePath, makeWorkingFile, outputDirectory, originalFileName, newContainer, outputPath, subStem, ouputFilePath, workingFile;
|
||||
return __generator(this, function (_b) {
|
||||
switch (_b.label) {
|
||||
case 0:
|
||||
lib = require('../../../../../methods/lib')();
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||
_a = args.inputs, keepRelativePath = _a.keepRelativePath, makeWorkingFile = _a.makeWorkingFile;
|
||||
outputDirectory = String(args.inputs.outputDirectory);
|
||||
originalFileName = (0, fileUtils_1.getFileName)(args.originalLibraryFile._id);
|
||||
newContainer = (0, fileUtils_1.getContainer)(args.inputFileObj._id);
|
||||
outputPath = "".concat(args.inputs.outputDirectory, "/").concat(originalFileName, ".").concat(newContainer);
|
||||
return [4 /*yield*/, fs_1.promises.copyFile(args.inputFileObj._id, outputPath)];
|
||||
case 1:
|
||||
_a.sent();
|
||||
workingFile = args.inputFileObj._id;
|
||||
if (args.inputs.makeWorkingFile) {
|
||||
workingFile = outputPath;
|
||||
outputPath = '';
|
||||
if (keepRelativePath) {
|
||||
subStem = (0, fileUtils_1.getSubStem)({
|
||||
inputPathStem: args.librarySettings.folder,
|
||||
inputPath: args.originalLibraryFile._id,
|
||||
});
|
||||
outputPath = (0, normJoinPath_1.default)({
|
||||
upath: args.deps.upath,
|
||||
paths: [
|
||||
outputDirectory,
|
||||
subStem,
|
||||
],
|
||||
});
|
||||
}
|
||||
else {
|
||||
outputPath = outputDirectory;
|
||||
}
|
||||
ouputFilePath = (0, normJoinPath_1.default)({
|
||||
upath: args.deps.upath,
|
||||
paths: [
|
||||
outputPath,
|
||||
"".concat(originalFileName, ".").concat(newContainer),
|
||||
],
|
||||
});
|
||||
workingFile = args.inputFileObj._id;
|
||||
if (makeWorkingFile) {
|
||||
workingFile = ouputFilePath;
|
||||
}
|
||||
args.jobLog("Input path: ".concat(args.inputFileObj._id));
|
||||
args.jobLog("Output path: ".concat(outputPath));
|
||||
args.deps.fsextra.ensureDirSync(outputPath);
|
||||
return [4 /*yield*/, fs_1.promises.copyFile(args.inputFileObj._id, ouputFilePath)];
|
||||
case 1:
|
||||
_b.sent();
|
||||
return [2 /*return*/, {
|
||||
outputFileObj: {
|
||||
_id: workingFile,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,102 @@
|
|||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.plugin = exports.details = void 0;
|
||||
var fs_1 = require("fs");
|
||||
var fileUtils_1 = require("../../../../FlowHelpers/1.0.0/fileUtils");
|
||||
var normJoinPath_1 = __importDefault(require("../../../../FlowHelpers/1.0.0/normJoinPath"));
|
||||
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||
var details = function () { return ({
|
||||
name: 'Copy to Working Directory',
|
||||
description: 'Copy the working file to the working directory of the Tdarr worker. '
|
||||
+ 'Useful if you want to copy the file to the library cache before transcoding begins',
|
||||
style: {
|
||||
borderColor: 'green',
|
||||
},
|
||||
tags: '',
|
||||
isStartPlugin: false,
|
||||
sidebarPosition: -1,
|
||||
icon: 'faArrowRight',
|
||||
inputs: [],
|
||||
outputs: [
|
||||
{
|
||||
number: 1,
|
||||
tooltip: 'Continue to next plugin',
|
||||
},
|
||||
],
|
||||
}); };
|
||||
exports.details = details;
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function () {
|
||||
var lib, originalFileName, newContainer, outputPath, ouputFilePath;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
lib = require('../../../../../methods/lib')();
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||
originalFileName = (0, fileUtils_1.getFileName)(args.originalLibraryFile._id);
|
||||
newContainer = (0, fileUtils_1.getContainer)(args.inputFileObj._id);
|
||||
outputPath = args.workDir;
|
||||
ouputFilePath = (0, normJoinPath_1.default)({
|
||||
upath: args.deps.upath,
|
||||
paths: [
|
||||
outputPath,
|
||||
"".concat(originalFileName, ".").concat(newContainer),
|
||||
],
|
||||
});
|
||||
args.jobLog("Input path: ".concat(args.inputFileObj._id));
|
||||
args.jobLog("Output path: ".concat(outputPath));
|
||||
args.deps.fsextra.ensureDirSync(outputPath);
|
||||
return [4 /*yield*/, fs_1.promises.copyFile(args.inputFileObj._id, ouputFilePath)];
|
||||
case 1:
|
||||
_a.sent();
|
||||
return [2 /*return*/, {
|
||||
outputFileObj: {
|
||||
_id: ouputFilePath,
|
||||
},
|
||||
outputNumber: 1,
|
||||
variables: args.variables,
|
||||
}];
|
||||
}
|
||||
});
|
||||
}); };
|
||||
exports.plugin = plugin;
|
||||
|
|
@ -35,10 +35,14 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.plugin = exports.details = void 0;
|
||||
var fs_1 = require("fs");
|
||||
var fileUtils_1 = require("../../../../FlowHelpers/1.0.0/fileUtils");
|
||||
var normJoinPath_1 = __importDefault(require("../../../../FlowHelpers/1.0.0/normJoinPath"));
|
||||
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||
var details = function () { return ({
|
||||
name: 'Move To Directory',
|
||||
|
|
@ -56,10 +60,23 @@ var details = function () { return ({
|
|||
type: 'string',
|
||||
defaultValue: '',
|
||||
inputUI: {
|
||||
type: 'text',
|
||||
type: 'directory',
|
||||
},
|
||||
tooltip: 'Specify ouput directory',
|
||||
},
|
||||
{
|
||||
name: 'keepRelativePath',
|
||||
type: 'boolean',
|
||||
defaultValue: 'false',
|
||||
inputUI: {
|
||||
type: 'text',
|
||||
options: [
|
||||
'false',
|
||||
'true',
|
||||
],
|
||||
},
|
||||
tooltip: 'Specify whether to keep the relative path',
|
||||
},
|
||||
],
|
||||
outputs: [
|
||||
{
|
||||
|
|
@ -71,22 +88,50 @@ var details = function () { return ({
|
|||
exports.details = details;
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function () {
|
||||
var lib, originalFileName, newContainer, outputPath;
|
||||
var lib, keepRelativePath, outputDirectory, originalFileName, newContainer, outputPath, subStem, ouputFilePath;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
lib = require('../../../../../methods/lib')();
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||
keepRelativePath = args.inputs.keepRelativePath;
|
||||
outputDirectory = String(args.inputs.outputDirectory);
|
||||
originalFileName = (0, fileUtils_1.getFileName)(args.originalLibraryFile._id);
|
||||
newContainer = (0, fileUtils_1.getContainer)(args.inputFileObj._id);
|
||||
outputPath = "".concat(args.inputs.outputDirectory, "/").concat(originalFileName, ".").concat(newContainer);
|
||||
return [4 /*yield*/, fs_1.promises.rename(args.inputFileObj._id, outputPath)];
|
||||
outputPath = '';
|
||||
if (keepRelativePath) {
|
||||
subStem = (0, fileUtils_1.getSubStem)({
|
||||
inputPathStem: args.librarySettings.folder,
|
||||
inputPath: args.originalLibraryFile._id,
|
||||
});
|
||||
outputPath = (0, normJoinPath_1.default)({
|
||||
upath: args.deps.upath,
|
||||
paths: [
|
||||
outputDirectory,
|
||||
subStem,
|
||||
],
|
||||
});
|
||||
}
|
||||
else {
|
||||
outputPath = outputDirectory;
|
||||
}
|
||||
ouputFilePath = (0, normJoinPath_1.default)({
|
||||
upath: args.deps.upath,
|
||||
paths: [
|
||||
outputPath,
|
||||
"".concat(originalFileName, ".").concat(newContainer),
|
||||
],
|
||||
});
|
||||
args.jobLog("Input path: ".concat(args.inputFileObj._id));
|
||||
args.jobLog("Output path: ".concat(ouputFilePath));
|
||||
args.deps.fsextra.ensureDirSync(outputPath);
|
||||
return [4 /*yield*/, fs_1.promises.rename(args.inputFileObj._id, ouputFilePath)];
|
||||
case 1:
|
||||
_a.sent();
|
||||
return [2 /*return*/, {
|
||||
outputFileObj: {
|
||||
_id: outputPath,
|
||||
_id: ouputFilePath,
|
||||
},
|
||||
outputNumber: 1,
|
||||
variables: args.variables,
|
||||
|
|
|
|||
|
|
@ -74,6 +74,16 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function
|
|||
lib = require('../../../../../methods/lib')();
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||
if (args.inputFileObj._id === args.originalLibraryFile._id
|
||||
&& args.inputFileObj.file_size === args.originalLibraryFile.file_size) {
|
||||
args.jobLog('File has not changed, no need to replace file');
|
||||
return [2 /*return*/, {
|
||||
outputFileObj: args.inputFileObj,
|
||||
outputNumber: 1,
|
||||
variables: args.variables,
|
||||
}];
|
||||
}
|
||||
args.jobLog('File has changed, replacing original file');
|
||||
currentPath = args.inputFileObj._id;
|
||||
newPath = getNewPath(args.originalLibraryFile._id, currentPath);
|
||||
newPathTmp = "".concat(newPath, ".tmp");
|
||||
|
|
@ -85,10 +95,15 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function
|
|||
return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 2000); })];
|
||||
case 1:
|
||||
_a.sent();
|
||||
fs.renameSync(currentPath, newPathTmp);
|
||||
// delete original file
|
||||
if (fs.existsSync(args.originalLibraryFile._id)) {
|
||||
fs.unlinkSync(args.originalLibraryFile._id);
|
||||
}
|
||||
// delete temp file
|
||||
if (fs.existsSync(newPath)) {
|
||||
fs.unlinkSync(newPath);
|
||||
}
|
||||
fs.renameSync(currentPath, newPathTmp);
|
||||
return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 2000); })];
|
||||
case 2:
|
||||
_a.sent();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getFfType = exports.getFileName = exports.getContainer = void 0;
|
||||
exports.getSubStem = exports.getFfType = exports.getFileName = exports.getContainer = void 0;
|
||||
var getContainer = function (filePath) {
|
||||
var parts = filePath.split('.');
|
||||
return parts[parts.length - 1];
|
||||
|
|
@ -10,8 +10,17 @@ var getFileName = function (filePath) {
|
|||
var parts = filePath.split('/');
|
||||
var fileNameAndContainer = parts[parts.length - 1];
|
||||
var parts2 = fileNameAndContainer.split('.');
|
||||
return parts2[0];
|
||||
parts2.pop();
|
||||
return parts2.join('.');
|
||||
};
|
||||
exports.getFileName = getFileName;
|
||||
var getFfType = function (codecType) { return (codecType === 'video' ? 'v' : 'a'); };
|
||||
exports.getFfType = getFfType;
|
||||
var getSubStem = function (_a) {
|
||||
var inputPathStem = _a.inputPathStem, inputPath = _a.inputPath;
|
||||
var subStem = inputPath.substring(inputPathStem.length);
|
||||
var parts = subStem.split('/');
|
||||
parts.pop();
|
||||
return parts.join('/');
|
||||
};
|
||||
exports.getSubStem = getSubStem;
|
||||
|
|
|
|||
19
FlowPlugins/FlowHelpers/1.0.0/normJoinPath.js
Normal file
19
FlowPlugins/FlowHelpers/1.0.0/normJoinPath.js
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var formatWindowsRootFolder = function (path) {
|
||||
// Remove '.' from end of Windows root folder mapping e.g. 'E:.'
|
||||
if (path.length === 3
|
||||
&& path.charAt(1) === ':'
|
||||
&& path.charAt(2) === '.') {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
path = path.slice(0, -1);
|
||||
}
|
||||
return path;
|
||||
};
|
||||
var normJoinPath = function (_a) {
|
||||
var upath = _a.upath, paths = _a.paths;
|
||||
var path = upath.joinSafe.apply(upath, paths);
|
||||
path = formatWindowsRootFolder(path);
|
||||
return path;
|
||||
};
|
||||
exports.default = normJoinPath;
|
||||
|
|
@ -82,10 +82,6 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
|||
return !stream.removed;
|
||||
});
|
||||
|
||||
if (getContainer(args.inputFileObj._id) !== args.variables.ffmpegCommand.container) {
|
||||
shouldProcess = true;
|
||||
}
|
||||
|
||||
for (let i = 0; i < streams.length; i += 1) {
|
||||
const stream = streams[i];
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||
|
||||
import { getContainer } from '../../../../FlowHelpers/1.0.0/fileUtils';
|
||||
import {
|
||||
IpluginDetails,
|
||||
IpluginInputArgs,
|
||||
|
|
@ -46,7 +47,12 @@ const plugin = (args:IpluginInputArgs):IpluginOutputArgs => {
|
|||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||
|
||||
args.variables.ffmpegCommand.container = String(args.inputs.container);
|
||||
const newContainer = String(args.inputs.container);
|
||||
|
||||
if (getContainer(args.inputFileObj._id) !== args.inputs.container) {
|
||||
args.variables.ffmpegCommand.container = newContainer;
|
||||
args.variables.ffmpegCommand.shouldProcess = true;
|
||||
}
|
||||
|
||||
return {
|
||||
outputFileObj: args.inputFileObj,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||
|
||||
import { getContainer } from '../../../../FlowHelpers/1.0.0/fileUtils';
|
||||
import {
|
||||
IpluginDetails,
|
||||
IpluginInputArgs,
|
||||
|
|
@ -16,7 +17,6 @@ const details = () :IpluginDetails => ({
|
|||
borderColor: 'green',
|
||||
},
|
||||
tags: 'video',
|
||||
|
||||
isStartPlugin: false,
|
||||
sidebarPosition: 1,
|
||||
icon: '',
|
||||
|
|
@ -35,8 +35,7 @@ const plugin = (args:IpluginInputArgs):IpluginOutputArgs => {
|
|||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||
|
||||
const containerParts = args.inputFileObj._id.split('.');
|
||||
const container = containerParts[containerParts.length - 1];
|
||||
const container = getContainer(args.inputFileObj._id);
|
||||
|
||||
const ffmpegCommand = {
|
||||
inputFiles: [],
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
import { promises as fs } from 'fs';
|
||||
import { getContainer, getFileName } from '../../../../FlowHelpers/1.0.0/fileUtils';
|
||||
import { getContainer, getFileName, getSubStem } 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 => ({
|
||||
|
|
@ -24,16 +25,29 @@ const details = (): IpluginDetails => ({
|
|||
type: 'string',
|
||||
defaultValue: '',
|
||||
inputUI: {
|
||||
type: 'text',
|
||||
type: 'directory',
|
||||
},
|
||||
tooltip: 'Specify ouput directory',
|
||||
},
|
||||
{
|
||||
name: 'keepRelativePath',
|
||||
type: 'boolean',
|
||||
defaultValue: 'false',
|
||||
inputUI: {
|
||||
type: 'text',
|
||||
options: [
|
||||
'false',
|
||||
'true',
|
||||
],
|
||||
},
|
||||
tooltip: 'Specify whether to keep the relative path',
|
||||
},
|
||||
{
|
||||
name: 'makeWorkingFile',
|
||||
type: 'boolean',
|
||||
defaultValue: 'false',
|
||||
inputUI: {
|
||||
type: 'text',
|
||||
type: 'dropdown',
|
||||
options: [
|
||||
'false',
|
||||
'true',
|
||||
|
|
@ -56,19 +70,55 @@ 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 {
|
||||
keepRelativePath, makeWorkingFile,
|
||||
} = args.inputs;
|
||||
|
||||
const outputDirectory = String(args.inputs.outputDirectory);
|
||||
|
||||
const originalFileName = getFileName(args.originalLibraryFile._id);
|
||||
const newContainer = getContainer(args.inputFileObj._id);
|
||||
|
||||
const outputPath = `${args.inputs.outputDirectory}/${originalFileName}.${newContainer}`;
|
||||
let outputPath = '';
|
||||
|
||||
await fs.copyFile(args.inputFileObj._id, outputPath);
|
||||
if (keepRelativePath) {
|
||||
const subStem = getSubStem({
|
||||
inputPathStem: args.librarySettings.folder,
|
||||
inputPath: args.originalLibraryFile._id,
|
||||
});
|
||||
|
||||
outputPath = normJoinPath({
|
||||
upath: args.deps.upath,
|
||||
paths: [
|
||||
outputDirectory,
|
||||
subStem,
|
||||
],
|
||||
});
|
||||
} else {
|
||||
outputPath = outputDirectory;
|
||||
}
|
||||
|
||||
const ouputFilePath = normJoinPath({
|
||||
upath: args.deps.upath,
|
||||
paths: [
|
||||
outputPath,
|
||||
`${originalFileName}.${newContainer}`,
|
||||
],
|
||||
});
|
||||
|
||||
let workingFile = args.inputFileObj._id;
|
||||
|
||||
if (args.inputs.makeWorkingFile) {
|
||||
workingFile = outputPath;
|
||||
if (makeWorkingFile) {
|
||||
workingFile = ouputFilePath;
|
||||
}
|
||||
|
||||
args.jobLog(`Input path: ${args.inputFileObj._id}`);
|
||||
args.jobLog(`Output path: ${outputPath}`);
|
||||
|
||||
args.deps.fsextra.ensureDirSync(outputPath);
|
||||
|
||||
await fs.copyFile(args.inputFileObj._id, ouputFilePath);
|
||||
|
||||
return {
|
||||
outputFileObj: {
|
||||
_id: workingFile,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,69 @@
|
|||
import { promises as fs } from 'fs';
|
||||
import { getContainer, getFileName } 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: 'Copy to Working Directory',
|
||||
description: 'Copy the working file to the working directory of the Tdarr worker. '
|
||||
+ 'Useful if you want to copy the file to the library cache before transcoding begins',
|
||||
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 originalFileName = getFileName(args.originalLibraryFile._id);
|
||||
const newContainer = getContainer(args.inputFileObj._id);
|
||||
|
||||
const outputPath = args.workDir;
|
||||
|
||||
const ouputFilePath = normJoinPath({
|
||||
upath: args.deps.upath,
|
||||
paths: [
|
||||
outputPath,
|
||||
`${originalFileName}.${newContainer}`,
|
||||
],
|
||||
});
|
||||
|
||||
args.jobLog(`Input path: ${args.inputFileObj._id}`);
|
||||
args.jobLog(`Output path: ${outputPath}`);
|
||||
|
||||
args.deps.fsextra.ensureDirSync(outputPath);
|
||||
|
||||
await fs.copyFile(args.inputFileObj._id, ouputFilePath);
|
||||
|
||||
return {
|
||||
outputFileObj: {
|
||||
_id: ouputFilePath,
|
||||
},
|
||||
outputNumber: 1,
|
||||
variables: args.variables,
|
||||
};
|
||||
};
|
||||
export {
|
||||
details,
|
||||
plugin,
|
||||
};
|
||||
|
|
@ -1,10 +1,11 @@
|
|||
import { promises as fs } from 'fs';
|
||||
import { getContainer, getFileName } from '../../../../FlowHelpers/1.0.0/fileUtils';
|
||||
import { getContainer, getFileName, getSubStem } 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 => ({
|
||||
|
|
@ -24,10 +25,23 @@ const details = ():IpluginDetails => ({
|
|||
type: 'string',
|
||||
defaultValue: '',
|
||||
inputUI: {
|
||||
type: 'text',
|
||||
type: 'directory',
|
||||
},
|
||||
tooltip: 'Specify ouput directory',
|
||||
},
|
||||
{
|
||||
name: 'keepRelativePath',
|
||||
type: 'boolean',
|
||||
defaultValue: 'false',
|
||||
inputUI: {
|
||||
type: 'text',
|
||||
options: [
|
||||
'false',
|
||||
'true',
|
||||
],
|
||||
},
|
||||
tooltip: 'Specify whether to keep the relative path',
|
||||
},
|
||||
],
|
||||
outputs: [
|
||||
{
|
||||
|
|
@ -43,16 +57,51 @@ 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 {
|
||||
keepRelativePath,
|
||||
} = args.inputs;
|
||||
|
||||
const outputDirectory = String(args.inputs.outputDirectory);
|
||||
|
||||
const originalFileName = getFileName(args.originalLibraryFile._id);
|
||||
const newContainer = getContainer(args.inputFileObj._id);
|
||||
|
||||
const outputPath = `${args.inputs.outputDirectory}/${originalFileName}.${newContainer}`;
|
||||
let outputPath = '';
|
||||
|
||||
await fs.rename(args.inputFileObj._id, outputPath);
|
||||
if (keepRelativePath) {
|
||||
const subStem = getSubStem({
|
||||
inputPathStem: args.librarySettings.folder,
|
||||
inputPath: args.originalLibraryFile._id,
|
||||
});
|
||||
|
||||
outputPath = normJoinPath({
|
||||
upath: args.deps.upath,
|
||||
paths: [
|
||||
outputDirectory,
|
||||
subStem,
|
||||
],
|
||||
});
|
||||
} else {
|
||||
outputPath = outputDirectory;
|
||||
}
|
||||
|
||||
const ouputFilePath = normJoinPath({
|
||||
upath: args.deps.upath,
|
||||
paths: [
|
||||
outputPath,
|
||||
`${originalFileName}.${newContainer}`,
|
||||
],
|
||||
});
|
||||
|
||||
args.jobLog(`Input path: ${args.inputFileObj._id}`);
|
||||
args.jobLog(`Output path: ${ouputFilePath}`);
|
||||
|
||||
args.deps.fsextra.ensureDirSync(outputPath);
|
||||
await fs.rename(args.inputFileObj._id, ouputFilePath);
|
||||
|
||||
return {
|
||||
outputFileObj: {
|
||||
_id: outputPath,
|
||||
_id: ouputFilePath,
|
||||
},
|
||||
outputNumber: 1,
|
||||
variables: args.variables,
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@ const getNewPath = (originalPath:string, tempPath:string) => {
|
|||
const originalPathParts = originalPath.split('.');
|
||||
|
||||
originalPathParts[originalPathParts.length - 1] = container;
|
||||
|
||||
return originalPathParts.join('.');
|
||||
};
|
||||
|
||||
|
|
@ -42,6 +41,20 @@ 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);
|
||||
|
||||
if (
|
||||
args.inputFileObj._id === args.originalLibraryFile._id
|
||||
&& args.inputFileObj.file_size === args.originalLibraryFile.file_size
|
||||
) {
|
||||
args.jobLog('File has not changed, no need to replace file');
|
||||
return {
|
||||
outputFileObj: args.inputFileObj,
|
||||
outputNumber: 1,
|
||||
variables: args.variables,
|
||||
};
|
||||
}
|
||||
|
||||
args.jobLog('File has changed, replacing original file');
|
||||
|
||||
const currentPath = args.inputFileObj._id;
|
||||
const newPath = getNewPath(args.originalLibraryFile._id, currentPath);
|
||||
const newPathTmp = `${newPath}.tmp`;
|
||||
|
|
@ -54,12 +67,17 @@ const plugin = async (args:IpluginInputArgs):Promise<IpluginOutputArgs> => {
|
|||
|
||||
await new Promise((resolve) => setTimeout(resolve, 2000));
|
||||
|
||||
fs.renameSync(currentPath, newPathTmp);
|
||||
// delete original file
|
||||
if (fs.existsSync(args.originalLibraryFile._id)) {
|
||||
fs.unlinkSync(args.originalLibraryFile._id);
|
||||
}
|
||||
|
||||
// delete temp file
|
||||
if (fs.existsSync(newPath)) {
|
||||
fs.unlinkSync(newPath);
|
||||
}
|
||||
|
||||
fs.renameSync(currentPath, newPathTmp);
|
||||
await new Promise((resolve) => setTimeout(resolve, 2000));
|
||||
fs.renameSync(newPathTmp, newPath);
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,22 @@ export const getFileName = (filePath: string):string => {
|
|||
const parts = filePath.split('/');
|
||||
const fileNameAndContainer = parts[parts.length - 1];
|
||||
const parts2 = fileNameAndContainer.split('.');
|
||||
return parts2[0];
|
||||
parts2.pop();
|
||||
return parts2.join('.');
|
||||
};
|
||||
|
||||
export const getFfType = (codecType:string):string => (codecType === 'video' ? 'v' : 'a');
|
||||
|
||||
export const getSubStem = ({
|
||||
inputPathStem,
|
||||
inputPath,
|
||||
}: {
|
||||
inputPathStem: string,
|
||||
inputPath: string,
|
||||
}):string => {
|
||||
const subStem = inputPath.substring(inputPathStem.length);
|
||||
const parts = subStem.split('/');
|
||||
parts.pop();
|
||||
|
||||
return parts.join('/');
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { IFileObject, Istreams } from './synced/IFileObject';
|
|||
import Ijob from './synced/jobInterface';
|
||||
|
||||
export interface IpluginInputUi {
|
||||
type: 'dropdown' | 'text' | 'textarea',
|
||||
type: 'dropdown' | 'text' | 'textarea' | 'directory',
|
||||
options?: string[],
|
||||
style?:Record<string, unknown>,
|
||||
onSelect?: {
|
||||
|
|
@ -115,5 +115,7 @@ export interface IpluginInputArgs {
|
|||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
axiosMiddleware: (endpoint: string, data: Record<string, unknown>) => Promise<any>,
|
||||
requireFromString: (pluginText: string, relativePath:string) => Record<string, unknown>,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
upath:any,
|
||||
},
|
||||
}
|
||||
|
|
|
|||
28
FlowPluginsTs/FlowHelpers/1.0.0/normJoinPath.ts
Normal file
28
FlowPluginsTs/FlowHelpers/1.0.0/normJoinPath.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
const formatWindowsRootFolder = (path: string): string => {
|
||||
// Remove '.' from end of Windows root folder mapping e.g. 'E:.'
|
||||
if (
|
||||
path.length === 3
|
||||
&& path.charAt(1) === ':'
|
||||
&& path.charAt(2) === '.'
|
||||
) {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
path = path.slice(0, -1);
|
||||
}
|
||||
|
||||
return path;
|
||||
};
|
||||
|
||||
const normJoinPath = ({
|
||||
upath,
|
||||
paths,
|
||||
}:{
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
upath: any,
|
||||
paths: string[]
|
||||
}):string => {
|
||||
let path = upath.joinSafe(...paths);
|
||||
path = formatWindowsRootFolder(path);
|
||||
return path;
|
||||
};
|
||||
|
||||
export default normJoinPath;
|
||||
Loading…
Add table
Add a link
Reference in a new issue