-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilter_by_filename.js
86 lines (79 loc) · 2.52 KB
/
filter_by_filename.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
const details = () => ({
id: 'Tdarr_Plugin_00uw_filter_by_filename',
Stage: 'Pre-processing',
Name: 'Filter - Filter by filename',
Type: 'Video',
Operation: 'Filter',
Description: `This plugin allows you to filter by filename.`,
Version: '1.00',
Tags: 'filter',
Inputs: [{
name: 'filter_tag',
type: 'string',
defaultValue: '',
inputUI: {
type: 'text',
},
tooltip: `Enter a comma separated list of words to be processed.\n
\nExample\n
trailer, featurette, short\n
\nExample\n
-trailer, -featurette, -short\n
\nExample\n
KRaLiMaRKo,EPSiLON,CtrlHD\n
\nExample\n
AC3 5.1,DTS-HD MA 7.1,AC3 2.0\n`,
},{
name: 'filter_skip',
type: 'boolean',
defaultValue: 'true',
inputUI: {
type: 'dropdown',
options: [
'true',
'false',
],
},
tooltip: `Choose whether to skip or process files with these words.`
}],
});
// eslint-disable-next-line no-unused-vars
const plugin = (file, librarySettings, inputs, otherArguments) => {
const lib = require('../methods/lib')();
// eslint-disable-next-line no-unused-vars,no-param-reassign
inputs = lib.loadDefaultValues(inputs, details);
const response = {
processFile: false,
infoLog: '',
};
if(inputs.filter_tag === "") {
response.infoLog += "No tags found for filter, skipping."
return response;
}
var filename = otherArguments.originalLibraryFile.file.toLowerCase();
var filter_tag = inputs.filter_tag.toLowerCase().split(",");
for (let i = 0; i < filter_tag.length; i++) {
let tag = filter_tag[i].trim();
if(filename.includes(tag)){
response.infoLog += `Filename matches tag ${tag}`;
if(inputs.filter_skip) {
response.infoLog += `, Skipping.\n`;
return response;
}
response.infoLog += `, Processing.\n`;
response.processFile = true;
return response;
}
}
response.infoLog += `Filename does not match tag ${tag}`;
if(inputs.filter_skip) {
response.infoLog += `, Skipping.\n`;
return response;
}
response.infoLog += `, Processing.\n`;
response.processFile = true;
return response;
};
module.exports.details = details;
module.exports.plugin = plugin;