Added support for autoscan authentication support

make-only-subtitle-default
Mike R 4 years ago
parent 005eabf826
commit 9074a2d4e4

@ -1,24 +1,25 @@
module.exports.dependencies = ['request']; module.exports.dependencies = [
'request',
];
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */ /* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
module.exports.details = function details() { module.exports.details = function details() {
return { return {
id: 'Tdarr_Plugin_TD01_TOAD_Autoscan', id: 'Tdarr_Plugin_TD01_TOAD_Plex_Autoscan',
Stage: 'Post-processing', Stage: 'Post-processing',
Name: 'Trigger Autoscan.', Name: 'Trigger Plex_Autoscan.',
Type: 'Video', Type: 'Video',
Operation: '', Operation: '',
Description: `Connects to autoscan and triggers a manual search within the files directory.\n\n Description: `Connects to plex_autoscan and triggers a manual search within the files directory.\n\n
Works with the hotio autoscan docker that can be found here https://hotio.dev/containers/autoscan/ which \n\n Works with the hotio autoscan docker that can be found here https://hotio.dev/containers/autoscan/ which \n\n
is based on https://github.com/cloudbox/autoscan`, is based on https://github.com/cloudbox/autoscan`,
Version: '1.0', Version: '1.0',
Link: 'https://github.com/HaveAGitGat/Tdarr_Plugins/blob/master/Community/Tdarr_Plugin_TD01_TOAD_Autoscan.js', Link: '',
Tags: '3rd party,post-processing,configurable', Tags: '3rd party,post-processing,configurable',
Inputs: [ Inputs: [{
{ name: 'autoscan_address',
name: 'autoscan_address', tooltip: `
tooltip: `
Enter the IP address/URL for autoscan. Must include http(s):// Enter the IP address/URL for autoscan. Must include http(s)://
\\nExample:\\n \\nExample:\\n
@ -26,15 +27,31 @@ module.exports.details = function details() {
\\nExample:\\n \\nExample:\\n
https://subdomain.domain.tld`, https://subdomain.domain.tld`,
}, },
{ {
name: 'autoscan_port', name: 'autoscan_port',
tooltip: ` tooltip: `
Enter the port Autoscan is using, default is 3468 Enter the port Autoscan is using, default is 3468
\\nExample:\\n \\nExample:\\n
3468`, 3468`,
}, },
{
name: 'autoscan_username',
tooltip: `
If authentication is configured, specify the username
\\nExample:\\n
Batman`,
},
{
name: 'autoscan_password',
tooltip: `
If authentication is configured, specify the password
\\nExample:\\n
SecretPassword`,
},
], ],
}; };
}; };
@ -45,46 +62,51 @@ module.exports.plugin = function plugin(file, librarySettings, inputs) {
// Set up required variables. // Set up required variables.
const ADDRESS = inputs.autoscan_address; const ADDRESS = inputs.autoscan_address;
const PORT = inputs.autoscan_port; const PORT = inputs.autoscan_port;
let file2 = '';
if(inputs.autoscan_username) {
auth = "Basic " + Buffer.from(inputs.autoscan_username + ":" + inputs.autoscan_password).toString('base64');
}
let filepath = ''; let filepath = '';
const response = {}; const response = {};
filepath = `${file.file}`; filepath = `${file.file.split('/').slice(0, -1).join('/')}/`;
filepath = `${filepath filepath = encodeURI(filepath);
.split('/')
.slice(0, -1)
.join('/')}/`;
// Check if all inputs have been configured. If they haven't then exit plugin. // Check if all inputs have been configured. If they haven't then exit plugin.
if (!inputs.autoscan_address || !inputs.autoscan_port) { if (
inputs
&& inputs.autoscan_address === ''
&& inputs.autoscan_port === ''
) {
response.infoLog += '☒Plugin options have not been configured, please configure options. Skipping this plugin. \n'; response.infoLog += '☒Plugin options have not been configured, please configure options. Skipping this plugin. \n';
response.processFile = false; response.processFile = false;
return response; return response;
} }
// Set content of request/post. // Set content of request/post.
request.post( request.post({
{ headers: {
headers: { 'content-type': 'application/json',
'content-type': 'application/json', 'Authorization' : auth
},
url: `${ADDRESS}:${PORT}/triggers/manual?dir=${filepath}`,
}, },
(error, res, body) => { url: `${ADDRESS}:${PORT}/triggers/manual?dir=${filepath}`,
if (error) { },
// eslint-disable-next-line no-console (error, res, body) => {
console.error(error); if (error) {
}
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.log(`statusCode: ${res.statusCode}`); console.error(error);
// eslint-disable-next-line no-console }
console.log(body); // eslint-disable-next-line no-console
}, // console.log(`statusCode: ${res.statusCode}`);
); // eslint-disable-next-line no-console
// console.log(body);
});
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.log('request next'); // console.log('request next');
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.log(request.post); // console.log(request.post);
return undefined; return undefined;
}; };

Loading…
Cancel
Save