mirror of
https://github.com/gabehf/Tdarr_Plugins.git
synced 2026-03-10 16:00:28 -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
|
|
@ -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