mirror of
https://github.com/gabehf/Tdarr_Plugins.git
synced 2026-03-14 09:45:55 -07:00
Merge pull request #612 from Marnalas/flowPluginCheckFileNameIncludes
Extend Check File Name Includes plugin to allow regex pattern
This commit is contained in:
commit
aaa02e8431
5 changed files with 210 additions and 8 deletions
16
.github/workflows/lint_and_test.yml
vendored
16
.github/workflows/lint_and_test.yml
vendored
|
|
@ -23,7 +23,10 @@ jobs:
|
||||||
git config --global core.autocrlf false
|
git config --global core.autocrlf false
|
||||||
git config --global core.eol lf
|
git config --global core.eol lf
|
||||||
|
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
ref: ${{ github.event.pull_request.head.sha }}
|
||||||
|
|
||||||
- name: Use Node.js ${{ matrix.node-version }}
|
- name: Use Node.js ${{ matrix.node-version }}
|
||||||
uses: actions/setup-node@v1
|
uses: actions/setup-node@v1
|
||||||
with:
|
with:
|
||||||
|
|
@ -46,9 +49,9 @@ jobs:
|
||||||
contents: write
|
contents: write
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
ref: ${{ github.head_ref }}
|
ref: ${{ github.event.pull_request.head.sha }}
|
||||||
|
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
|
|
@ -57,5 +60,10 @@ jobs:
|
||||||
- run: npm i && npm i -g typescript && rm -rdf ./FlowPlugins && tsc -v && tsc
|
- run: npm i && npm i -g typescript && rm -rdf ./FlowPlugins && tsc -v && tsc
|
||||||
|
|
||||||
- uses: stefanzweifel/git-auto-commit-action@v5
|
- uses: stefanzweifel/git-auto-commit-action@v5
|
||||||
|
if: ${{ github.event.pull_request.head.repo.full_name == 'org/repo' }}
|
||||||
with:
|
with:
|
||||||
commit_message: Apply auto-build changes
|
commit_message: Apply auto-build changes
|
||||||
|
|
||||||
|
- run: |
|
||||||
|
(git diff --quiet HEAD -- 2>/dev/null && echo "No uncommitted changes" \
|
||||||
|
|| (echo "Error - Uncommitted changes found." && git --no-pager diff HEAD && exit 1))
|
||||||
|
|
@ -20,12 +20,10 @@ var details = function () { return ({
|
||||||
label: 'Terms',
|
label: 'Terms',
|
||||||
name: 'terms',
|
name: 'terms',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
// eslint-disable-next-line no-template-curly-in-string
|
|
||||||
defaultValue: '_720p,_1080p',
|
defaultValue: '_720p,_1080p',
|
||||||
inputUI: {
|
inputUI: {
|
||||||
type: 'text',
|
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',
|
tooltip: 'Specify terms to check for in file name using comma seperated list e.g. _720p,_1080p',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,93 @@
|
||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.plugin = exports.details = void 0;
|
||||||
|
var fileUtils_1 = require("../../../../FlowHelpers/1.0.0/fileUtils");
|
||||||
|
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||||
|
var details = function () { return ({
|
||||||
|
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,
|
||||||
|
pType: '',
|
||||||
|
requiresVersion: '2.11.01',
|
||||||
|
sidebarPosition: -1,
|
||||||
|
icon: 'faQuestion',
|
||||||
|
inputs: [
|
||||||
|
{
|
||||||
|
label: 'Terms',
|
||||||
|
name: 'terms',
|
||||||
|
type: 'string',
|
||||||
|
defaultValue: '_720p,_1080p',
|
||||||
|
inputUI: {
|
||||||
|
type: 'text',
|
||||||
|
},
|
||||||
|
tooltip: 'Specify terms to check for in file name using comma seperated list e.g. _720p,_1080p',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Pattern (regular expression)',
|
||||||
|
name: 'pattern',
|
||||||
|
type: 'string',
|
||||||
|
defaultValue: '',
|
||||||
|
inputUI: {
|
||||||
|
type: 'text',
|
||||||
|
},
|
||||||
|
tooltip: 'Specify the pattern (regex) to check for in file name e.g. ^Pattern.*mkv$',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Include file directory in check',
|
||||||
|
name: 'includeFileDirectory',
|
||||||
|
type: 'boolean',
|
||||||
|
defaultValue: 'false',
|
||||||
|
inputUI: {
|
||||||
|
type: 'switch',
|
||||||
|
},
|
||||||
|
tooltip: 'Should the terms and patterns be evaluated against the file directory e.g. false, true',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
outputs: [
|
||||||
|
{
|
||||||
|
number: 1,
|
||||||
|
tooltip: 'File name contains terms or patterns',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
number: 2,
|
||||||
|
tooltip: 'File name does not contain any of the terms or patterns',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}); };
|
||||||
|
exports.details = details;
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
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 terms = String(args.inputs.terms);
|
||||||
|
var pattern = String(args.inputs.pattern);
|
||||||
|
var includeFileDirectory = args.inputs.includeFileDirectory;
|
||||||
|
var fileName = includeFileDirectory
|
||||||
|
? args.inputFileObj._id
|
||||||
|
: "".concat((0, fileUtils_1.getFileName)(args.inputFileObj._id), ".").concat((0, fileUtils_1.getContainer)(args.inputFileObj._id));
|
||||||
|
var searchCriteriasArray = terms.trim().split(',')
|
||||||
|
.map(function (term) { return term.replace(/[\\^$*+?.()|[\]{}]/g, '\\$&'); }); // https://github.com/tc39/proposal-regex-escaping
|
||||||
|
if (pattern) {
|
||||||
|
searchCriteriasArray.push(pattern);
|
||||||
|
}
|
||||||
|
var searchCriteriaMatched = searchCriteriasArray
|
||||||
|
.find(function (searchCriteria) { return new RegExp(searchCriteria).test(fileName); });
|
||||||
|
var isAMatch = searchCriteriaMatched !== undefined;
|
||||||
|
if (isAMatch) {
|
||||||
|
args.jobLog("'".concat(fileName, "' includes '").concat(searchCriteriaMatched, "'"));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
args.jobLog("'".concat(fileName, "' does not include any of the terms or patterns"));
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
outputFileObj: args.inputFileObj,
|
||||||
|
outputNumber: isAMatch ? 1 : 2,
|
||||||
|
variables: args.variables,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
exports.plugin = plugin;
|
||||||
|
|
@ -23,12 +23,10 @@ const details = (): IpluginDetails => ({
|
||||||
label: 'Terms',
|
label: 'Terms',
|
||||||
name: 'terms',
|
name: 'terms',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
// eslint-disable-next-line no-template-curly-in-string
|
|
||||||
defaultValue: '_720p,_1080p',
|
defaultValue: '_720p,_1080p',
|
||||||
inputUI: {
|
inputUI: {
|
||||||
type: 'text',
|
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',
|
tooltip: 'Specify terms to check for in file name using comma seperated list e.g. _720p,_1080p',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,105 @@
|
||||||
|
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,
|
||||||
|
pType: '',
|
||||||
|
requiresVersion: '2.11.01',
|
||||||
|
sidebarPosition: -1,
|
||||||
|
icon: 'faQuestion',
|
||||||
|
inputs: [
|
||||||
|
{
|
||||||
|
label: 'Terms',
|
||||||
|
name: 'terms',
|
||||||
|
type: 'string',
|
||||||
|
defaultValue: '_720p,_1080p',
|
||||||
|
inputUI: {
|
||||||
|
type: 'text',
|
||||||
|
},
|
||||||
|
tooltip: 'Specify terms to check for in file name using comma seperated list e.g. _720p,_1080p',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Pattern (regular expression)',
|
||||||
|
name: 'pattern',
|
||||||
|
type: 'string',
|
||||||
|
defaultValue: '',
|
||||||
|
inputUI: {
|
||||||
|
type: 'text',
|
||||||
|
},
|
||||||
|
tooltip: 'Specify the pattern (regex) to check for in file name e.g. ^Pattern.*mkv$',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Include file directory in check',
|
||||||
|
name: 'includeFileDirectory',
|
||||||
|
type: 'boolean',
|
||||||
|
defaultValue: 'false',
|
||||||
|
inputUI: {
|
||||||
|
type: 'switch',
|
||||||
|
},
|
||||||
|
tooltip: 'Should the terms and patterns be evaluated against the file directory e.g. false, true',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
outputs: [
|
||||||
|
{
|
||||||
|
number: 1,
|
||||||
|
tooltip: 'File name contains terms or patterns',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
number: 2,
|
||||||
|
tooltip: 'File name does not contain any of the terms or patterns',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
// 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 terms = String(args.inputs.terms);
|
||||||
|
const pattern = String(args.inputs.pattern);
|
||||||
|
const { includeFileDirectory } = args.inputs;
|
||||||
|
|
||||||
|
const fileName = includeFileDirectory
|
||||||
|
? args.inputFileObj._id
|
||||||
|
: `${getFileName(args.inputFileObj._id)}.${getContainer(args.inputFileObj._id)}`;
|
||||||
|
|
||||||
|
const searchCriteriasArray = terms.trim().split(',')
|
||||||
|
.map((term) => term.replace(/[\\^$*+?.()|[\]{}]/g, '\\$&')); // https://github.com/tc39/proposal-regex-escaping
|
||||||
|
|
||||||
|
if (pattern) {
|
||||||
|
searchCriteriasArray.push(pattern);
|
||||||
|
}
|
||||||
|
|
||||||
|
const searchCriteriaMatched = searchCriteriasArray
|
||||||
|
.find((searchCriteria) => new RegExp(searchCriteria).test(fileName));
|
||||||
|
const isAMatch = searchCriteriaMatched !== undefined;
|
||||||
|
|
||||||
|
if (isAMatch) {
|
||||||
|
args.jobLog(`'${fileName}' includes '${searchCriteriaMatched}'`);
|
||||||
|
} else {
|
||||||
|
args.jobLog(`'${fileName}' does not include any of the terms or patterns`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
outputFileObj: args.inputFileObj,
|
||||||
|
outputNumber: isAMatch ? 1 : 2,
|
||||||
|
variables: args.variables,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
export {
|
||||||
|
details,
|
||||||
|
plugin,
|
||||||
|
};
|
||||||
Loading…
Add table
Add a link
Reference in a new issue