mirror of
https://github.com/gabehf/Tdarr_Plugins.git
synced 2026-03-09 07:29:04 -07:00
Update classic plugin wrapper with scan types
This commit is contained in:
parent
0921ed23bf
commit
0e3ffd5471
6 changed files with 211 additions and 44 deletions
|
|
@ -37,6 +37,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|||
};
|
||||
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");
|
||||
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||
var details = function () { return ({
|
||||
|
|
@ -77,7 +78,7 @@ 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 path, lib, pluginSourceId, parts, pluginSource, pluginId, relativePluginPath, absolutePath, classicPlugin, res, container, cacheFilePath, otherArguments, result, outputNumber;
|
||||
var path, lib, pluginSourceId, parts, pluginSource, pluginId, relativePluginPath, absolutePath, classicPlugin, pluginSrcStr, res, container, cacheFilePath, otherArguments, scanTypes, pluginInputFileObj, result, outputNumber;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
|
|
@ -91,40 +92,45 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function
|
|||
pluginId = parts[1];
|
||||
relativePluginPath = "../../../../../".concat(pluginSource, "/").concat(pluginId, ".js");
|
||||
absolutePath = path.resolve(__dirname, relativePluginPath);
|
||||
if (!(pluginSource === 'Community')) return [3 /*break*/, 1];
|
||||
pluginSrcStr = '';
|
||||
if (!(pluginSource === 'Community')) return [3 /*break*/, 2];
|
||||
classicPlugin = args.deps.importFresh(relativePluginPath);
|
||||
return [3 /*break*/, 3];
|
||||
case 1: return [4 /*yield*/, args.deps.axiosMiddleware('api/v2/read-plugin', {
|
||||
return [4 /*yield*/, fs_1.promises.readFile(absolutePath, 'utf8')];
|
||||
case 1:
|
||||
pluginSrcStr = _a.sent();
|
||||
return [3 /*break*/, 4];
|
||||
case 2: return [4 /*yield*/, args.deps.axiosMiddleware('api/v2/read-plugin', {
|
||||
plugin: {
|
||||
id: pluginId,
|
||||
source: pluginSource,
|
||||
},
|
||||
})];
|
||||
case 2:
|
||||
case 3:
|
||||
res = _a.sent();
|
||||
classicPlugin = args.deps.requireFromString(res.pluginRaw, absolutePath);
|
||||
_a.label = 3;
|
||||
case 3:
|
||||
pluginSrcStr = res.pluginRaw;
|
||||
_a.label = 4;
|
||||
case 4:
|
||||
if (classicPlugin.details().Operation !== 'Filter') {
|
||||
throw new Error("".concat('This plugin is meant for classic plugins that have '
|
||||
+ 'Operation: Filter. This classic plugin has Operation: ').concat(classicPlugin.details().Operation)
|
||||
+ 'Please use the Run Classic Transcode Flow Plugin plugin instead.');
|
||||
}
|
||||
if (!Array.isArray(classicPlugin.dependencies)) return [3 /*break*/, 7];
|
||||
if (!args.installClassicPluginDeps) return [3 /*break*/, 5];
|
||||
if (!Array.isArray(classicPlugin.dependencies)) return [3 /*break*/, 8];
|
||||
if (!args.installClassicPluginDeps) return [3 /*break*/, 6];
|
||||
args.jobLog("Installing dependencies for ".concat(pluginSourceId));
|
||||
return [4 /*yield*/, args.installClassicPluginDeps(classicPlugin.dependencies)];
|
||||
case 4:
|
||||
_a.sent();
|
||||
return [3 /*break*/, 6];
|
||||
case 5:
|
||||
_a.sent();
|
||||
return [3 /*break*/, 7];
|
||||
case 6:
|
||||
args.jobLog("Not installing dependencies for ".concat(pluginSourceId, ", please update Tdarr"));
|
||||
_a.label = 6;
|
||||
case 6: return [3 /*break*/, 8];
|
||||
case 7:
|
||||
args.jobLog("No depedencies to install for ".concat(pluginSourceId));
|
||||
_a.label = 8;
|
||||
_a.label = 7;
|
||||
case 7: return [3 /*break*/, 9];
|
||||
case 8:
|
||||
args.jobLog("No depedencies to install for ".concat(pluginSourceId));
|
||||
_a.label = 9;
|
||||
case 9:
|
||||
container = (0, fileUtils_1.getContainer)(args.inputFileObj._id);
|
||||
cacheFilePath = "".concat((0, fileUtils_1.getPluginWorkDir)(args), "/").concat((0, fileUtils_1.getFileName)(args.inputFileObj._id), ".").concat(container);
|
||||
otherArguments = {
|
||||
|
|
@ -140,8 +146,20 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function
|
|||
cacheFilePath: cacheFilePath,
|
||||
job: args.job,
|
||||
};
|
||||
return [4 /*yield*/, classicPlugin.plugin(args.inputFileObj, args.librarySettings, args.inputs, otherArguments)];
|
||||
case 9:
|
||||
scanTypes = (0, fileUtils_1.getScanTypes)([pluginSrcStr]);
|
||||
return [4 /*yield*/, args.deps.axiosMiddleware('api/v2/scan-individual-file', {
|
||||
file: {
|
||||
_id: args.inputFileObj._id,
|
||||
file: args.inputFileObj.file,
|
||||
DB: args.inputFileObj.DB,
|
||||
footprintId: args.inputFileObj.footprintId,
|
||||
},
|
||||
scanTypes: scanTypes,
|
||||
})];
|
||||
case 10:
|
||||
pluginInputFileObj = _a.sent();
|
||||
return [4 /*yield*/, classicPlugin.plugin(pluginInputFileObj, args.librarySettings, args.inputs, otherArguments)];
|
||||
case 11:
|
||||
result = _a.sent();
|
||||
args.jobLog(JSON.stringify(result, null, 2));
|
||||
outputNumber = (result === null || result === void 0 ? void 0 : result.processFile) ? 1 : 2;
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.plugin = exports.details = void 0;
|
||||
var fs_1 = require("fs");
|
||||
var cliUtils_1 = require("../../../../FlowHelpers/1.0.0/cliUtils");
|
||||
var fileUtils_1 = require("../../../../FlowHelpers/1.0.0/fileUtils");
|
||||
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||
|
|
@ -88,7 +89,7 @@ var replaceContainer = function (filePath, container) {
|
|||
};
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function () {
|
||||
var path, lib, pluginSourceId, parts, pluginSource, pluginId, relativePluginPath, absolutePath, classicPlugin, res_1, container, cacheFilePath, otherArguments, result, cliPath_1, customArgs, isCustomConfig, presetSplit, workerCommand, cliPath, cli, res;
|
||||
var path, lib, pluginSourceId, parts, pluginSource, pluginId, relativePluginPath, absolutePath, classicPlugin, pluginSrcStr, res_1, container, cacheFilePath, otherArguments, scanTypes, pluginInputFileObj, result, cliPath_1, customArgs, isCustomConfig, presetSplit, workerCommand, cliPath, cli, res;
|
||||
var _a, _b, _c;
|
||||
return __generator(this, function (_d) {
|
||||
switch (_d.label) {
|
||||
|
|
@ -103,40 +104,45 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function
|
|||
pluginId = parts[1];
|
||||
relativePluginPath = "../../../../../".concat(pluginSource, "/").concat(pluginId, ".js");
|
||||
absolutePath = path.resolve(__dirname, relativePluginPath);
|
||||
if (!(pluginSource === 'Community')) return [3 /*break*/, 1];
|
||||
pluginSrcStr = '';
|
||||
if (!(pluginSource === 'Community')) return [3 /*break*/, 2];
|
||||
classicPlugin = args.deps.importFresh(relativePluginPath);
|
||||
return [3 /*break*/, 3];
|
||||
case 1: return [4 /*yield*/, args.deps.axiosMiddleware('api/v2/read-plugin', {
|
||||
return [4 /*yield*/, fs_1.promises.readFile(absolutePath, 'utf8')];
|
||||
case 1:
|
||||
pluginSrcStr = _d.sent();
|
||||
return [3 /*break*/, 4];
|
||||
case 2: return [4 /*yield*/, args.deps.axiosMiddleware('api/v2/read-plugin', {
|
||||
plugin: {
|
||||
id: pluginId,
|
||||
source: pluginSource,
|
||||
},
|
||||
})];
|
||||
case 2:
|
||||
case 3:
|
||||
res_1 = _d.sent();
|
||||
classicPlugin = args.deps.requireFromString(res_1.pluginRaw, absolutePath);
|
||||
_d.label = 3;
|
||||
case 3:
|
||||
pluginSrcStr = res_1.pluginRaw;
|
||||
_d.label = 4;
|
||||
case 4:
|
||||
if (classicPlugin.details().Operation === 'Filter') {
|
||||
throw new Error("".concat('This plugin is meant for classic plugins that have '
|
||||
+ 'Operation: Transcode. This classic plugin has Operation: ').concat(classicPlugin.details().Operation)
|
||||
+ 'Please use the Run Classic Filter Flow Plugin plugin instead.');
|
||||
}
|
||||
if (!Array.isArray(classicPlugin.dependencies)) return [3 /*break*/, 7];
|
||||
if (!args.installClassicPluginDeps) return [3 /*break*/, 5];
|
||||
if (!Array.isArray(classicPlugin.dependencies)) return [3 /*break*/, 8];
|
||||
if (!args.installClassicPluginDeps) return [3 /*break*/, 6];
|
||||
args.jobLog("Installing dependencies for ".concat(pluginSourceId));
|
||||
return [4 /*yield*/, args.installClassicPluginDeps(classicPlugin.dependencies)];
|
||||
case 4:
|
||||
_d.sent();
|
||||
return [3 /*break*/, 6];
|
||||
case 5:
|
||||
_d.sent();
|
||||
return [3 /*break*/, 7];
|
||||
case 6:
|
||||
args.jobLog("Not installing dependencies for ".concat(pluginSourceId, ", please update Tdarr"));
|
||||
_d.label = 6;
|
||||
case 6: return [3 /*break*/, 8];
|
||||
case 7:
|
||||
args.jobLog("No depedencies to install for ".concat(pluginSourceId));
|
||||
_d.label = 8;
|
||||
_d.label = 7;
|
||||
case 7: return [3 /*break*/, 9];
|
||||
case 8:
|
||||
args.jobLog("No depedencies to install for ".concat(pluginSourceId));
|
||||
_d.label = 9;
|
||||
case 9:
|
||||
container = (0, fileUtils_1.getContainer)(args.inputFileObj._id);
|
||||
cacheFilePath = "".concat((0, fileUtils_1.getPluginWorkDir)(args), "/").concat((0, fileUtils_1.getFileName)(args.inputFileObj._id), ".").concat(container);
|
||||
otherArguments = {
|
||||
|
|
@ -152,8 +158,20 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function
|
|||
cacheFilePath: cacheFilePath,
|
||||
job: args.job,
|
||||
};
|
||||
return [4 /*yield*/, classicPlugin.plugin(args.inputFileObj, args.librarySettings, args.inputs, otherArguments)];
|
||||
case 9:
|
||||
scanTypes = (0, fileUtils_1.getScanTypes)([pluginSrcStr]);
|
||||
return [4 /*yield*/, args.deps.axiosMiddleware('api/v2/scan-individual-file', {
|
||||
file: {
|
||||
_id: args.inputFileObj._id,
|
||||
file: args.inputFileObj.file,
|
||||
DB: args.inputFileObj.DB,
|
||||
footprintId: args.inputFileObj.footprintId,
|
||||
},
|
||||
scanTypes: scanTypes,
|
||||
})];
|
||||
case 10:
|
||||
pluginInputFileObj = _d.sent();
|
||||
return [4 /*yield*/, classicPlugin.plugin(pluginInputFileObj, args.librarySettings, args.inputs, otherArguments)];
|
||||
case 11:
|
||||
result = _d.sent();
|
||||
args.jobLog(JSON.stringify(result, null, 2));
|
||||
if (!result) {
|
||||
|
|
@ -267,7 +285,7 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function
|
|||
updateWorker: args.updateWorker,
|
||||
});
|
||||
return [4 /*yield*/, cli.runCli()];
|
||||
case 10:
|
||||
case 12:
|
||||
res = _d.sent();
|
||||
if (res.cliExitCode !== 0) {
|
||||
args.jobLog("Running ".concat(cliPath, " failed"));
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|||
}
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getPluginWorkDir = exports.moveFileAndValidate = exports.getSubStem = exports.getFfType = exports.getFileAbosluteDir = exports.getFileName = exports.getContainer = void 0;
|
||||
exports.getScanTypes = exports.getPluginWorkDir = exports.moveFileAndValidate = exports.getSubStem = exports.getFfType = exports.getFileAbosluteDir = exports.getFileName = exports.getContainer = void 0;
|
||||
var fs_1 = require("fs");
|
||||
var getContainer = function (filePath) {
|
||||
var parts = filePath.split('.');
|
||||
|
|
@ -152,3 +152,41 @@ var getPluginWorkDir = function (args) {
|
|||
return pluginWorkDir;
|
||||
};
|
||||
exports.getPluginWorkDir = getPluginWorkDir;
|
||||
var getScanTypes = function (pluginsTextRaw) {
|
||||
var scanTypes = {
|
||||
exifToolScan: true,
|
||||
mediaInfoScan: false,
|
||||
closedCaptionScan: false,
|
||||
};
|
||||
var scannerTypes = [
|
||||
// needed for frame and duration data for ffmpeg
|
||||
// {
|
||||
// type: 'exifToolScan',
|
||||
// terms: [
|
||||
// 'meta',
|
||||
// ],
|
||||
// },
|
||||
{
|
||||
type: 'mediaInfoScan',
|
||||
terms: [
|
||||
'mediaInfo',
|
||||
],
|
||||
},
|
||||
{
|
||||
type: 'closedCaptionScan',
|
||||
terms: [
|
||||
'hasClosedCaptions',
|
||||
],
|
||||
},
|
||||
];
|
||||
var text = pluginsTextRaw.join('');
|
||||
scannerTypes.forEach(function (scanner) {
|
||||
scanner.terms.forEach(function (term) {
|
||||
if (text.includes(term)) {
|
||||
scanTypes[scanner.type] = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
return scanTypes;
|
||||
};
|
||||
exports.getScanTypes = getScanTypes;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
import { getContainer, getFileName, getPluginWorkDir } from '../../../../FlowHelpers/1.0.0/fileUtils';
|
||||
import { promises as fs } from 'fs';
|
||||
import {
|
||||
getContainer, getFileName, getPluginWorkDir, getScanTypes,
|
||||
} from '../../../../FlowHelpers/1.0.0/fileUtils';
|
||||
import {
|
||||
IpluginDetails,
|
||||
IpluginInputArgs,
|
||||
|
|
@ -58,8 +61,10 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
|||
const absolutePath = path.resolve(__dirname, relativePluginPath);
|
||||
|
||||
let classicPlugin;
|
||||
let pluginSrcStr = '';
|
||||
if (pluginSource === 'Community') {
|
||||
classicPlugin = args.deps.importFresh(relativePluginPath);
|
||||
pluginSrcStr = await fs.readFile(absolutePath, 'utf8');
|
||||
} else {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
const res = await args.deps.axiosMiddleware('api/v2/read-plugin', {
|
||||
|
|
@ -70,6 +75,7 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
|||
});
|
||||
|
||||
classicPlugin = args.deps.requireFromString(res.pluginRaw, absolutePath);
|
||||
pluginSrcStr = res.pluginRaw;
|
||||
}
|
||||
|
||||
if (classicPlugin.details().Operation !== 'Filter') {
|
||||
|
|
@ -109,7 +115,24 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
|||
job: args.job,
|
||||
};
|
||||
|
||||
const result = await classicPlugin.plugin(args.inputFileObj, args.librarySettings, args.inputs, otherArguments);
|
||||
const scanTypes = getScanTypes([pluginSrcStr]);
|
||||
|
||||
const pluginInputFileObj = await args.deps.axiosMiddleware('api/v2/scan-individual-file', {
|
||||
file: {
|
||||
_id: args.inputFileObj._id,
|
||||
file: args.inputFileObj.file,
|
||||
DB: args.inputFileObj.DB,
|
||||
footprintId: args.inputFileObj.footprintId,
|
||||
},
|
||||
scanTypes,
|
||||
});
|
||||
|
||||
const result = await classicPlugin.plugin(
|
||||
pluginInputFileObj,
|
||||
args.librarySettings,
|
||||
args.inputs,
|
||||
otherArguments,
|
||||
);
|
||||
|
||||
args.jobLog(JSON.stringify(result, null, 2));
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
import { promises as fs } from 'fs';
|
||||
import { CLI } from '../../../../FlowHelpers/1.0.0/cliUtils';
|
||||
import { getContainer, getFileName, getPluginWorkDir } from '../../../../FlowHelpers/1.0.0/fileUtils';
|
||||
import {
|
||||
getContainer, getFileName, getPluginWorkDir, getScanTypes,
|
||||
} from '../../../../FlowHelpers/1.0.0/fileUtils';
|
||||
import {
|
||||
IpluginDetails,
|
||||
IpluginInputArgs,
|
||||
|
|
@ -61,8 +64,10 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
|||
const absolutePath = path.resolve(__dirname, relativePluginPath);
|
||||
|
||||
let classicPlugin;
|
||||
let pluginSrcStr = '';
|
||||
if (pluginSource === 'Community') {
|
||||
classicPlugin = args.deps.importFresh(relativePluginPath);
|
||||
pluginSrcStr = await fs.readFile(absolutePath, 'utf8');
|
||||
} else {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
const res = await args.deps.axiosMiddleware('api/v2/read-plugin', {
|
||||
|
|
@ -73,6 +78,7 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
|||
});
|
||||
|
||||
classicPlugin = args.deps.requireFromString(res.pluginRaw, absolutePath);
|
||||
pluginSrcStr = res.pluginRaw;
|
||||
}
|
||||
|
||||
if (classicPlugin.details().Operation === 'Filter') {
|
||||
|
|
@ -112,7 +118,24 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
|||
job: args.job,
|
||||
};
|
||||
|
||||
const result = await classicPlugin.plugin(args.inputFileObj, args.librarySettings, args.inputs, otherArguments);
|
||||
const scanTypes = getScanTypes([pluginSrcStr]);
|
||||
|
||||
const pluginInputFileObj = await args.deps.axiosMiddleware('api/v2/scan-individual-file', {
|
||||
file: {
|
||||
_id: args.inputFileObj._id,
|
||||
file: args.inputFileObj.file,
|
||||
DB: args.inputFileObj.DB,
|
||||
footprintId: args.inputFileObj.footprintId,
|
||||
},
|
||||
scanTypes,
|
||||
});
|
||||
|
||||
const result = await classicPlugin.plugin(
|
||||
pluginInputFileObj,
|
||||
args.librarySettings,
|
||||
args.inputs,
|
||||
otherArguments,
|
||||
);
|
||||
|
||||
args.jobLog(JSON.stringify(result, null, 2));
|
||||
|
||||
|
|
|
|||
|
|
@ -104,3 +104,50 @@ export const getPluginWorkDir = (args: IpluginInputArgs):string => {
|
|||
args.deps.fsextra.ensureDirSync(pluginWorkDir);
|
||||
return pluginWorkDir;
|
||||
};
|
||||
|
||||
export interface IscanTypes {
|
||||
mediaInfoScan: boolean,
|
||||
exifToolScan: boolean,
|
||||
closedCaptionScan: boolean,
|
||||
[index: string]: boolean,
|
||||
}
|
||||
|
||||
export const getScanTypes = (pluginsTextRaw: string[]): IscanTypes => {
|
||||
const scanTypes: IscanTypes = {
|
||||
exifToolScan: true,
|
||||
mediaInfoScan: false,
|
||||
closedCaptionScan: false,
|
||||
};
|
||||
const scannerTypes = [
|
||||
// needed for frame and duration data for ffmpeg
|
||||
// {
|
||||
// type: 'exifToolScan',
|
||||
// terms: [
|
||||
// 'meta',
|
||||
// ],
|
||||
// },
|
||||
{
|
||||
type: 'mediaInfoScan',
|
||||
terms: [
|
||||
'mediaInfo',
|
||||
],
|
||||
},
|
||||
{
|
||||
type: 'closedCaptionScan',
|
||||
terms: [
|
||||
'hasClosedCaptions',
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const text = pluginsTextRaw.join('');
|
||||
|
||||
scannerTypes.forEach((scanner) => {
|
||||
scanner.terms.forEach((term) => {
|
||||
if (text.includes(term)) {
|
||||
scanTypes[scanner.type] = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
return scanTypes;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue