From bc51790930aeb568a45192c12c6665b206551eb4 Mon Sep 17 00:00:00 2001 From: aunefyren Date: Mon, 6 Mar 2023 17:42:59 +0100 Subject: [PATCH 1/9] Two new plugins --- ...arr_Plugin_f4k2_refresh_files_in_sonarr.js | 235 +++++++++++++++ ...darr_Plugin_f4k3_rename_files_in_sonarr.js | 285 ++++++++++++++++++ 2 files changed, 520 insertions(+) create mode 100644 Community/Tdarr_Plugin_f4k2_refresh_files_in_sonarr.js create mode 100644 Community/Tdarr_Plugin_f4k3_rename_files_in_sonarr.js diff --git a/Community/Tdarr_Plugin_f4k2_refresh_files_in_sonarr.js b/Community/Tdarr_Plugin_f4k2_refresh_files_in_sonarr.js new file mode 100644 index 000000000..47ea00025 --- /dev/null +++ b/Community/Tdarr_Plugin_f4k2_refresh_files_in_sonarr.js @@ -0,0 +1,235 @@ +module.exports.dependencies = [ + 'axios', + 'http', + 'https', +]; + +// tdarrSkipTest +const details = () => ({ + id: 'Tdarr_Plugin_f4k2_refresh_files_in_sonarr', + Stage: 'Post-processing', + Name: 'Refresh files in Sonarr', + Type: 'Video', + Operation: 'Transcode', + Description: `Refreshes folder containing the current show in Sonarr so files are mapped properly. It retrieves the showID by using the folder name of the series.`, + Version: '1.0', + Tags: '3rd party,post-processing,configurable', + + Inputs: [ + { + name: 'Url_Protocol', + type: 'string', + defaultValue: 'http', + inputUI: { + type: 'dropdown', + options: [ + 'http', + 'https', + ], + }, + tooltip: ` + Specified the type of request to make, http:// or https:// + \\nExample:\\n + http + \\nExample:\\n + https`, + }, + { + name: 'Url_Sonarr', + type: 'string', + defaultValue: 'localhost', + inputUI: { + type: 'text', + }, + tooltip: ` + Enter the IP address/URL Tdarr uses to reach Sonarr. + \\nExample:\\n + 192.168.0.10 + \\nExample:\\n + subdomain.domain.tld`, + }, + { + name: 'Sonarr_Port', + type: 'number', + defaultValue: 8989, + inputUI: { + type: 'text', + }, + tooltip: ` + The port required to access Sonarr + \\nExample:\\n + 8989`, + }, + { + name: 'Sonarr_APIKey', + type: 'string', + defaultValue: '', + inputUI: { + type: 'text', + }, + tooltip: ` + Enter the Sonarr API key. \\n + You can find it within Sonarr at /settings/general. \\n\\n + \\nExample:\\n + 3ff1ae1c39a2a2a397315e15266dea48`, + }, + { + name: 'After_Sleep', + type: 'number', + defaultValue: 0, + inputUI: { + type: 'text', + }, + tooltip: ` + How many ms should Tdarr sleep to wait for Sonarr to finish afterward? \\n + \\nExample:\\n + 1000`, + }, + ], +}); + +function sleep(ms) { + return new Promise((resolve) => { + setTimeout(resolve, ms); + }); +} + +// eslint-disable-next-line no-unused-vars +const plugin = async (file, librarySettings, inputs, otherArguments) => { + + const response = { + file, + removeFromDB: false, + updateDB: false, + processFile: false, + infoLog: 'Refresh Sonarr files starting.', + }; + + console.log("Refresh Sonarr files starting.") + + const lib = require('../methods/lib')(); + // eslint-disable-next-line no-unused-vars,no-param-reassign + inputs = lib.loadDefaultValues(inputs, details); + const http = require('http'); + const https = require('https'); + const axios = require('axios'); + + console.log("Loaded required packages.") + + const SSL = inputs.Url_Protocol; + const IP = inputs.Url_Sonarr; + const port = inputs.Sonarr_Port; + const APIKey = inputs.Sonarr_APIKey; + const sleepInterval = inputs.After_Sleep; + var term = ""; + var termUri = ""; + const APIPathLookup = '/api/v3/series/lookup'; + const APIPathCommand = '/api/v3/command'; + const APICommand = 'RefreshSeries'; + + if (!SSL || !IP || !APIKey || !port) { + throw new Error('All fields are required.'); + } + + var connection_type = null; + try { + if(SSL == "http") { + connection_type = http + } else { + connection_type = https + } + } catch(e) { + console.log(`Failed to compare SSL string. Error: ${e}`); + connection_type = http + } + + try { + term = file.file.split('/'); + term = term[term.length - 3]; + termUri = encodeURI(term); + } catch(e){ + console.log(`Failed to split file name. Error: '${e}'.\n`) + response.infoLog += `\nFailed to split file name. Error: '${e}'.`; + return response + } + + console.log(`Searching for series '${term}'.`) + response.infoLog += `\nSearching for series '${term}'.`; + + const url1 = `${SSL}://${IP}:${port}${APIPathLookup}?term=${termUri}&apikey=${APIKey}`; + var url1_body = ""; + var url2 = ``; + var SeriesID = 0; + + try { + await new Promise((resolve) => { + connection_type.get(url1, (res) => { + + console.log(`Got status code '${res.statusCode}'.`) + response.infoLog += `\nGot status code '${res.statusCode}'.`; + + res.on("data", function(chunk) { + url1_body += chunk; + }); + + res.on('end', function() { + resolve(); + }); + + }).on('error', (e) => { + console.log(`Failed to search for series. Error: '${e}'.`) + response.infoLog += `\nFailed to search for series. Error: '${e}'.`; + resolve(); + }); + }); + } catch(e) { + console.log(`Failed API call. Error: '${e}'.`); + response.infoLog += `\nFailed API call. Error: '${e}'.`; + return response; + } + + try { + const APIresponse = JSON.parse(url1_body); + SeriesID = APIresponse[0].id; + url2 = `${SSL}://${IP}:${port}${APIPathCommand}?apikey=${APIKey}`; + } catch(e) { + console.log(`Failed make JSON payload. Error: '${e}'.`); + response.infoLog += `\nFailed make JSON payload. Error: '${e}'.`; + return response; + } + + console.log(`Refreshing series '${SeriesID}'.`); + response.infoLog += `\nRefreshing series '${SeriesID}'.`; + + try { + await new Promise((resolve) => { + axios.post(url2, { + name: APICommand, + seriesId: SeriesID + }) + .then(function (res) { + console.log(`Got status code '${res.status}'.`) + response.infoLog += `\n☑ Got status code '${res.status}'.`; + resolve(); + }) + .catch(function (error) { + console.log(`Got error: ${error}`) + response.infoLog += `\nGot error: ${error}`; + resolve(); + }); + }); + } catch(e) { + console.log(`Failed API call. Error: '${e}'.`); + response.infoLog += `\nFailed API call. Error: '${e}'.`; + return response; + } + + console.log(`Sleeping '${sleepInterval}' ms.`); + response.infoLog += `\nSleeping '${sleepInterval}' ms.`; + await sleep(sleepInterval); + + return response; +}; + +module.exports.details = details; +module.exports.plugin = plugin; diff --git a/Community/Tdarr_Plugin_f4k3_rename_files_in_sonarr.js b/Community/Tdarr_Plugin_f4k3_rename_files_in_sonarr.js new file mode 100644 index 000000000..6749ee047 --- /dev/null +++ b/Community/Tdarr_Plugin_f4k3_rename_files_in_sonarr.js @@ -0,0 +1,285 @@ +module.exports.dependencies = [ + 'axios', + 'http', + 'https', +]; + +// tdarrSkipTest +const details = () => ({ + id: 'Tdarr_Plugin_f4k3_rename_files_in_sonarr', + Stage: 'Post-processing', + Name: 'Rename files in Sonarr', + Type: 'Video', + Operation: 'Transcode', + Description: `Renames the files in the current show in Sonarr. It retrieves the showID by using the folder name of the series.`, + Version: '1.0', + Tags: '3rd party,post-processing,configurable', + + Inputs: [ + { + name: 'Url_Protocol', + type: 'string', + defaultValue: 'http', + inputUI: { + type: 'dropdown', + options: [ + 'http', + 'https', + ], + }, + tooltip: ` + Specified the type of request to make, http:// or https:// + \\nExample:\\n + http + \\nExample:\\n + https`, + }, + { + name: 'Url_Sonarr', + type: 'string', + defaultValue: 'localhost', + inputUI: { + type: 'text', + }, + tooltip: ` + Enter the IP address/URL Tdarr uses to reach Sonarr. + \\nExample:\\n + 192.168.0.10 + \\nExample:\\n + subdomain.domain.tld`, + }, + { + name: 'Sonarr_Port', + type: 'number', + defaultValue: 8989, + inputUI: { + type: 'text', + }, + tooltip: ` + The port required to access Sonarr + \\nExample:\\n + 8989`, + }, + { + name: 'Sonarr_APIKey', + type: 'string', + defaultValue: '', + inputUI: { + type: 'text', + }, + tooltip: ` + Enter the Sonarr API key. \\n + You can find it within Sonarr at /settings/general. \\n\\n + \\nExample:\\n + 3ff1ae1c39a2a2a397315e15266dea48`, + }, + { + name: 'After_Sleep', + type: 'number', + defaultValue: 0, + inputUI: { + type: 'text', + }, + tooltip: ` + How many ms should Tdarr sleep to wait for Sonarr to finish afterward? \\n + \\nExample:\\n + 1000`, + }, + ], +}); + +function sleep(ms) { + return new Promise((resolve) => { + setTimeout(resolve, ms); + }); +} + +// eslint-disable-next-line no-unused-vars +const plugin = async (file, librarySettings, inputs, otherArguments) => { + + const response = { + file, + removeFromDB: false, + updateDB: false, + processFile: false, + infoLog: 'Rename Sonarr files starting.', + }; + + console.log("Rename Sonarr files starting.") + + const lib = require('../methods/lib')(); + // eslint-disable-next-line no-unused-vars,no-param-reassign + inputs = lib.loadDefaultValues(inputs, details); + const http = require('http'); + const https = require('https'); + const axios = require('axios'); + + console.log("Loaded required packages.") + + const SSL = inputs.Url_Protocol; + const IP = inputs.Url_Sonarr; + const port = inputs.Sonarr_Port; + const APIKey = inputs.Sonarr_APIKey; + const sleepInterval = inputs.After_Sleep; + var term = ""; + var termUri = ""; + const APIPathLookup = '/api/v3/series/lookup'; + const APIPathEpisodefile = '/api/v3/episodefile'; + const APIPathCommand = '/api/v3/command'; + const APICommand = 'RenameFiles'; + + if (!SSL || !IP || !APIKey || !port) { + throw new Error('All fields are required.'); + } + + var connection_type = null; + try { + if(SSL == "http") { + connection_type = http + } else { + connection_type = https + } + } catch(e) { + console.log(`Failed to compare SSL string. Error: ${e}`); + connection_type = http + } + + try { + term = file.file.split('/'); + term = term[term.length - 3]; + termUri = encodeURI(term); + } catch(e){ + console.log(`Failed to split file name. Error: '${e}'.\n`) + response.infoLog += `\nFailed to split file name. Error: '${e}'.`; + return response + } + + console.log(`Searching for series '${term}'.`) + response.infoLog += `\nSearching for series '${term}'.`; + + const url1 = `${SSL}://${IP}:${port}${APIPathLookup}?term=${termUri}&apikey=${APIKey}`; + var url2 = ``; + var url3 = ``; + var SeriesID = 0; + var url1_body = ""; + var url2_body = ""; + + try { + await new Promise((resolve) => { + connection_type.get(url1, (res) => { + + console.log(`Got status code '${res.statusCode}'.`) + response.infoLog += `\nGot status code '${res.statusCode}'.`; + + res.on("data", function(chunk) { + url1_body += chunk; + }); + + res.on('end', function() { + resolve(); + }); + + }).on('error', (e) => { + console.log(`Failed to search for series. Error: '${e}'.`) + response.infoLog += `\nFailed to search for series. Error: '${e}'.`; + resolve(); + }); + }); + } catch(e) { + console.log(`Failed API call. Error: '${e}'.`); + response.infoLog += `\nFailed API call. Error: '${e}'.`; + return response; + } + + try { + const APIresponse = JSON.parse(url1_body); + SeriesID = APIresponse[0].id; + url2 = `${SSL}://${IP}:${port}${APIPathEpisodefile}?seriesId=${SeriesID}&includeImages=false&apikey=${APIKey}`; + url3 = `${SSL}://${IP}:${port}${APIPathCommand}?apikey=${APIKey}`; + } catch(e) { + console.log(`Failed make JSON payload. Error: '${e}'.`); + response.infoLog += `\nFailed make JSON payload. Error: '${e}'.`; + return response; + } + + var fileArray = []; + + console.log(`Searching for episode files for show '${SeriesID}'.`) + response.infoLog += `\nSearching for episode files for show '${SeriesID}'.`; + + try { + await new Promise((resolve) => { + connection_type.get(url2, (res) => { + + console.log(`Got status code '${res.statusCode}'.`) + response.infoLog += `\nGot status code '${res.statusCode}'.`; + + res.on("data", function(chunk) { + url2_body += chunk; + }); + + res.on('end', function() { + resolve(); + }); + + }).on('error', (e) => { + console.log(`Failed to search for files for series. Error: '${e}'.`) + response.infoLog += `\nFailed to search for files for series. Error: '${e}'.`; + resolve(); + }); + }); + } catch(e) { + console.log(`Failed API call. Error: '${e}'.`); + response.infoLog += `\nFailed API call. Error: '${e}'.`; + return response; + } + + try { + const APIresponse2 = JSON.parse(url2_body); + for(var i = 0; i < APIresponse2.length; i++) { + fileArray.push(APIresponse2[i].id) + } + console.log(`Found '${fileArray.length}' files for series.`); + response.infoLog += `\nFound '${fileArray.length}' files for series.`; + } catch(e) { + console.log(`Failed process episodes. Error: '${e}'.`); + response.infoLog += `\nFailed process episodes. Error: '${e}'.`; + return response; + } + + console.log(`Renaming files for series '${SeriesID}'.`); + response.infoLog += `\nRenaming files for series '${SeriesID}'.`; + + try { + await new Promise((resolve) => { + axios.post(url3, { + name: APICommand, + seriesId: SeriesID, + files: fileArray + }) + .then(function (res) { + console.log(`Got status code '${res.status}'.`) + response.infoLog += `\n☑ Got status code '${res.status}'.`; + resolve(); + }) + .catch(function (error) { + console.log(`Got error: ${error}`) + response.infoLog += `\nGot error: ${error}`; + resolve(); + }); + }); + } catch(e) { + console.log(`Failed API call. Error: '${e}'.`); + response.infoLog += `\nFailed API call. Error: '${e}'.`; + return response; + } + + console.log(`Sleeping '${sleepInterval}' ms.`); + response.infoLog += `\nSleeping '${sleepInterval}' ms.`; + await sleep(sleepInterval); + + return response; +}; + +module.exports.details = details; +module.exports.plugin = plugin; From 8ca78a5d8cd505589fa4ef84eda2121ef1c17259 Mon Sep 17 00:00:00 2001 From: aunefyren Date: Wed, 4 Oct 2023 12:34:50 +0200 Subject: [PATCH 2/9] Finalized versions --- ...ion_remove_stream_by_specified_property.js | 73 ++++- ...ugin_f4k2_aune_refresh_files_in_sonarr.js} | 13 +- ...lugin_f4k3_aune_rename_files_in_sonarr.js} | 45 ++- ...lugin_f4k4_aune_refresh_files_in_radarr.js | 242 ++++++++++++++ ...Plugin_f4k5_aune_rename_files_in_radarr.js | 300 ++++++++++++++++++ 5 files changed, 662 insertions(+), 11 deletions(-) rename Community/{Tdarr_Plugin_f4k2_refresh_files_in_sonarr.js => Tdarr_Plugin_f4k2_aune_refresh_files_in_sonarr.js} (90%) rename Community/{Tdarr_Plugin_f4k3_rename_files_in_sonarr.js => Tdarr_Plugin_f4k3_aune_rename_files_in_sonarr.js} (78%) create mode 100644 Community/Tdarr_Plugin_f4k4_aune_refresh_files_in_radarr.js create mode 100644 Community/Tdarr_Plugin_f4k5_aune_rename_files_in_radarr.js diff --git a/Community/Tdarr_Plugin_00td_action_remove_stream_by_specified_property.js b/Community/Tdarr_Plugin_00td_action_remove_stream_by_specified_property.js index 4c8068990..0ef970a1f 100644 --- a/Community/Tdarr_Plugin_00td_action_remove_stream_by_specified_property.js +++ b/Community/Tdarr_Plugin_00td_action_remove_stream_by_specified_property.js @@ -10,6 +10,20 @@ const details = () => ({ Version: '1.00', Tags: 'action', Inputs: [ + { + name: 'codecTypeFilter', + type: 'string', + defaultValue: 'subtitle', + inputUI: { + type: 'text', + }, + tooltip: + `Enter values of the stream codec type to process. Nothing/empty input means all types of streams will be inspected for processing. For example, if removing by codec_name on video streams, enter video: + + \\nExample:\\n + video,subtitle,audio + `, + }, { name: 'propertyToCheck', type: 'string', @@ -18,7 +32,7 @@ const details = () => ({ type: 'text', }, tooltip: - `Enter one stream property to check. + `Enter one stream property to check for values. \\nExample:\\n codec_name @@ -38,6 +52,20 @@ const details = () => ({ ac3,aac `, }, + { + name: 'removeIfPropertyMissing', + type: 'string', + defaultValue: '', + inputUI: { + type: 'text', + }, + tooltip: + `Enter one or more properties to check for its existance. If the property is missing or null, the stream will be removed. Useful for fixing corrupt streams. For example, if codec_name is missing, the stream will be removed: + + \\nExample:\\n + codec_name + `, + } ], }); @@ -70,17 +98,54 @@ const plugin = (file, librarySettings, inputs, otherArguments) => { const valuesToRemove = inputs.valuesToRemove.trim().split(','); + const codecTypeFilter = inputs.codecTypeFilter.trim().split(','); + + const removeIfPropertyMissing = inputs.removeIfPropertyMissing.trim().split(','); + + // Debug lines + // response.infoLog += `codecTypeFilter is ${codecTypeFilter} \n`; + // response.infoLog += `removeIfPropertyMissing is ${removeIfPropertyMissing} \n`; + response.preset += ', -map 0 -c copy -max_muxing_queue_size 9999'; try { let streamToRemove = false; for (let i = 0; i < file.ffProbeData.streams.length; i += 1) { try { - if (valuesToRemove.includes(String(file.ffProbeData.streams[i][propertyToCheck]))) { + + // Skip if the codec_type is filtered out + if(codecTypeFilter.length != 0 && !codecTypeFilter.includes(String(file.ffProbeData.streams[i]["codec_type"]))) { + continue; + } + + // Check if chosen non-empty properties are empty + // If they are empty, set emptyValue to true + var emptyValue = false; + for (let j = 0; j < removeIfPropertyMissing.length; j += 1) { + + response.infoLog += `DEBUG: stream ${i} property for ${removeIfPropertyMissing[j]} is ${file.ffProbeData.streams[i][removeIfPropertyMissing[j]]} \n`; + + if(file.ffProbeData.streams[i][removeIfPropertyMissing[j]] == 'undefined' || file.ffProbeData.streams[i][removeIfPropertyMissing[j]] == null) { + emptyValue = true; + response.infoLog += ` Removing stream ${i} which is has ${removeIfPropertyMissing[j]} missing` + break + } + } + + // If the value to remove is present OR an empty value is found, remove the stream + if ((valuesToRemove.includes(String(file.ffProbeData.streams[i][propertyToCheck]))) || emptyValue) { + + // Add to preset response.preset += ` -map -0:${i} `; - response.infoLog += ` Removing stream ${i} which is has ${propertyToCheck}` - + ` of ${file.ffProbeData.streams[i][propertyToCheck]} \n`; + + // Log the old message if the reason is not empty values + if(!emptyValue) { + response.infoLog += ` Removing stream ${i} which is has ${propertyToCheck} or` + + ` of ${file.ffProbeData.streams[i][propertyToCheck]} \n`; + } + streamToRemove = true; + } } catch (err) { response.infoLog += ` Error reading stream ${i} ${propertyToCheck} \n`; diff --git a/Community/Tdarr_Plugin_f4k2_refresh_files_in_sonarr.js b/Community/Tdarr_Plugin_f4k2_aune_refresh_files_in_sonarr.js similarity index 90% rename from Community/Tdarr_Plugin_f4k2_refresh_files_in_sonarr.js rename to Community/Tdarr_Plugin_f4k2_aune_refresh_files_in_sonarr.js index 47ea00025..3459d18d2 100644 --- a/Community/Tdarr_Plugin_f4k2_refresh_files_in_sonarr.js +++ b/Community/Tdarr_Plugin_f4k2_aune_refresh_files_in_sonarr.js @@ -6,12 +6,12 @@ module.exports.dependencies = [ // tdarrSkipTest const details = () => ({ - id: 'Tdarr_Plugin_f4k2_refresh_files_in_sonarr', + id: 'Tdarr_Plugin_f4k2_aune_refresh_files_in_sonarr', Stage: 'Post-processing', Name: 'Refresh files in Sonarr', Type: 'Video', Operation: 'Transcode', - Description: `Refreshes folder containing the current show in Sonarr so files are mapped properly. It retrieves the showID by using the folder name of the series.`, + Description: `Refreshes folder containing the current show in Sonarr so files are mapped properly. This is done using the Sonarr API. To do this action it needs the Show ID. This code attempts to retrieve the Show ID by using the folder name of the series.`, Version: '1.0', Tags: '3rd party,post-processing,configurable', @@ -116,6 +116,7 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { console.log("Loaded required packages.") + // Create variables const SSL = inputs.Url_Protocol; const IP = inputs.Url_Sonarr; const port = inputs.Sonarr_Port; @@ -127,10 +128,12 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { const APIPathCommand = '/api/v3/command'; const APICommand = 'RefreshSeries'; + // Check variables are given if (!SSL || !IP || !APIKey || !port) { throw new Error('All fields are required.'); } + // Select connection type var connection_type = null; try { if(SSL == "http") { @@ -143,6 +146,7 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { connection_type = http } + // Try to split file path to retrieve series folder name try { term = file.file.split('/'); term = term[term.length - 3]; @@ -156,11 +160,13 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { console.log(`Searching for series '${term}'.`) response.infoLog += `\nSearching for series '${term}'.`; + // Create variables for API call const url1 = `${SSL}://${IP}:${port}${APIPathLookup}?term=${termUri}&apikey=${APIKey}`; var url1_body = ""; var url2 = ``; var SeriesID = 0; + // API call to search for Series ID using the folder name try { await new Promise((resolve) => { connection_type.get(url1, (res) => { @@ -188,6 +194,7 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { return response; } + // Parse API response and save the Series ID try { const APIresponse = JSON.parse(url1_body); SeriesID = APIresponse[0].id; @@ -201,6 +208,7 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { console.log(`Refreshing series '${SeriesID}'.`); response.infoLog += `\nRefreshing series '${SeriesID}'.`; + // API request to send a command to refresh the files for the found Series ID try { await new Promise((resolve) => { axios.post(url2, { @@ -224,6 +232,7 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { return response; } + // Sleep for set amount of time console.log(`Sleeping '${sleepInterval}' ms.`); response.infoLog += `\nSleeping '${sleepInterval}' ms.`; await sleep(sleepInterval); diff --git a/Community/Tdarr_Plugin_f4k3_rename_files_in_sonarr.js b/Community/Tdarr_Plugin_f4k3_aune_rename_files_in_sonarr.js similarity index 78% rename from Community/Tdarr_Plugin_f4k3_rename_files_in_sonarr.js rename to Community/Tdarr_Plugin_f4k3_aune_rename_files_in_sonarr.js index 6749ee047..aecf4fb28 100644 --- a/Community/Tdarr_Plugin_f4k3_rename_files_in_sonarr.js +++ b/Community/Tdarr_Plugin_f4k3_aune_rename_files_in_sonarr.js @@ -6,12 +6,12 @@ module.exports.dependencies = [ // tdarrSkipTest const details = () => ({ - id: 'Tdarr_Plugin_f4k3_rename_files_in_sonarr', + id: 'Tdarr_Plugin_f4k3_aune_rename_files_in_sonarr', Stage: 'Post-processing', Name: 'Rename files in Sonarr', Type: 'Video', Operation: 'Transcode', - Description: `Renames the files in the current show in Sonarr. It retrieves the showID by using the folder name of the series.`, + Description: `Renames the files in the current show in Sonarr according to naming format. This is done using the Sonarr API. To do this action it needs the Show ID. This code attempts to retrieve the Show ID by using the folder name of the series. To rename the correct file we need the season and episode number. To find this SXXEXX needs to be present in the file name.`, Version: '1.0', Tags: '3rd party,post-processing,configurable', @@ -116,11 +116,14 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { console.log("Loaded required packages.") + // Defines variables const SSL = inputs.Url_Protocol; const IP = inputs.Url_Sonarr; const port = inputs.Sonarr_Port; const APIKey = inputs.Sonarr_APIKey; const sleepInterval = inputs.After_Sleep; + const regex = '(S[0-9]{1,4}E[0-9]{1,2})'; + var seasonEpisodeMatch = ""; var term = ""; var termUri = ""; const APIPathLookup = '/api/v3/series/lookup'; @@ -128,10 +131,12 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { const APIPathCommand = '/api/v3/command'; const APICommand = 'RenameFiles'; + // Check variables are given if (!SSL || !IP || !APIKey || !port) { throw new Error('All fields are required.'); } + // Select connection type var connection_type = null; try { if(SSL == "http") { @@ -144,19 +149,34 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { connection_type = http } + // Try to split file path to retrieve series folder name and season-episode number try { term = file.file.split('/'); term = term[term.length - 3]; termUri = encodeURI(term); + + // Use Regex to find SXXXXEXX part of file name and save it + var seasonEpisodeMatch_tmp = file.file.toString().match(regex) + if(seasonEpisodeMatch_tmp == null) { + console.log(`Failed to find SXXEXX in filename.`) + response.infoLog += `\nFailed to find SXXEXX in filename.`; + return response + } else { + seasonEpisodeMatch = seasonEpisodeMatch_tmp[0]; + } } catch(e){ - console.log(`Failed to split file name. Error: '${e}'.\n`) - response.infoLog += `\nFailed to split file name. Error: '${e}'.`; + console.log(`Failed to split file name or find episode nr. Error: '${e}'.`) + response.infoLog += `\nFailed to split file name or find episode nr. Error: '${e}'.`; return response } + console.log(`Landed on '${seasonEpisodeMatch}'.`) + response.infoLog += `\nLanded on '${seasonEpisodeMatch}'.`; + console.log(`Searching for series '${term}'.`) response.infoLog += `\nSearching for series '${term}'.`; + // Define variables to look for Series ID const url1 = `${SSL}://${IP}:${port}${APIPathLookup}?term=${termUri}&apikey=${APIKey}`; var url2 = ``; var url3 = ``; @@ -164,6 +184,7 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { var url1_body = ""; var url2_body = ""; + // API call to search for folder name to get Series ID try { await new Promise((resolve) => { connection_type.get(url1, (res) => { @@ -191,6 +212,7 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { return response; } + // Create variables, parse API response to search for episode IDs of the Series ID try { const APIresponse = JSON.parse(url1_body); SeriesID = APIresponse[0].id; @@ -202,11 +224,13 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { return response; } + // Create array variable for Episode IDs var fileArray = []; console.log(`Searching for episode files for show '${SeriesID}'.`) response.infoLog += `\nSearching for episode files for show '${SeriesID}'.`; + // API call to find Episode IDs for Series ID try { await new Promise((resolve) => { connection_type.get(url2, (res) => { @@ -234,10 +258,19 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { return response; } + // Parse API response of episode files. Find the episode ID which matches the episode name of the file try { const APIresponse2 = JSON.parse(url2_body); for(var i = 0; i < APIresponse2.length; i++) { - fileArray.push(APIresponse2[i].id) + try { + var tmp_match = APIresponse2[i].path.toString().match(regex) + var tmp_match2 = tmp_match[0] + if(tmp_match2 == seasonEpisodeMatch) { + fileArray.push(APIresponse2[i].id) + } + } catch { + continue; + } } console.log(`Found '${fileArray.length}' files for series.`); response.infoLog += `\nFound '${fileArray.length}' files for series.`; @@ -250,6 +283,7 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { console.log(`Renaming files for series '${SeriesID}'.`); response.infoLog += `\nRenaming files for series '${SeriesID}'.`; + // API call to rename the found Episode IDs for the Series ID try { await new Promise((resolve) => { axios.post(url3, { @@ -274,6 +308,7 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { return response; } + // Sleep for set amount of time console.log(`Sleeping '${sleepInterval}' ms.`); response.infoLog += `\nSleeping '${sleepInterval}' ms.`; await sleep(sleepInterval); diff --git a/Community/Tdarr_Plugin_f4k4_aune_refresh_files_in_radarr.js b/Community/Tdarr_Plugin_f4k4_aune_refresh_files_in_radarr.js new file mode 100644 index 000000000..699a63395 --- /dev/null +++ b/Community/Tdarr_Plugin_f4k4_aune_refresh_files_in_radarr.js @@ -0,0 +1,242 @@ +module.exports.dependencies = [ + 'axios', + 'http', + 'https', +]; + +// tdarrSkipTest +const details = () => ({ + id: 'Tdarr_Plugin_f4k4_aune_refresh_files_in_radarr', + Stage: 'Post-processing', + Name: 'Refresh files in Radarr', + Type: 'Video', + Operation: 'Transcode', + Description: `Refreshes folder containing the current movie in Radarr so files are mapped properly. This is done using the Radarr API. To do this action it needs the Movie ID. This code attempts to retrieve the Movie ID by using the folder name of the movie.`, + Version: '1.0', + Tags: '3rd party,post-processing,configurable', + + Inputs: [ + { + name: 'Url_Protocol', + type: 'string', + defaultValue: 'http', + inputUI: { + type: 'dropdown', + options: [ + 'http', + 'https', + ], + }, + tooltip: ` + Specified the type of request to make, http:// or https:// + \\nExample:\\n + http + \\nExample:\\n + https`, + }, + { + name: 'Url_Radarr', + type: 'string', + defaultValue: 'localhost', + inputUI: { + type: 'text', + }, + tooltip: ` + Enter the IP address/URL Tdarr uses to reach Radarr. + \\nExample:\\n + 192.168.0.10 + \\nExample:\\n + subdomain.domain.tld`, + }, + { + name: 'Radarr_Port', + type: 'number', + defaultValue: 7878, + inputUI: { + type: 'text', + }, + tooltip: ` + The port required to access Radarr + \\nExample:\\n + 7878`, + }, + { + name: 'Radarr_APIKey', + type: 'string', + defaultValue: '', + inputUI: { + type: 'text', + }, + tooltip: ` + Enter the Radarr API key. \\n + You can find it within Radarr at /settings/general. \\n\\n + \\nExample:\\n + 3ff1ae1c39a2a2a397315e15266dea48`, + }, + { + name: 'After_Sleep', + type: 'number', + defaultValue: 0, + inputUI: { + type: 'text', + }, + tooltip: ` + How many ms should Tdarr sleep to wait for Radarr to finish afterward? \\n + \\nExample:\\n + 1000`, + }, + ], +}); + +// eslint-disable-next-line no-unused-vars +const plugin = async (file, librarySettings, inputs, otherArguments) => { + + const response = { + file, + removeFromDB: false, + updateDB: false, + processFile: false, + infoLog: 'Refresh Radarr files starting.', + }; + + console.log("Refresh Radarr files starting.") + + const lib = require('../methods/lib')(); + // eslint-disable-next-line no-unused-vars,no-param-reassign + inputs = lib.loadDefaultValues(inputs, details); + const http = require('http'); + const https = require('https'); + const axios = require('axios'); + + console.log("Loaded required packages.") + + // Create variables + const SSL = inputs.Url_Protocol; + const IP = inputs.Url_Radarr; + const port = inputs.Radarr_Port; + const APIKey = inputs.Radarr_APIKey; + const sleepInterval = inputs.After_Sleep; + var term = ""; + var termUri = ""; + const APIPathLookup = '/api/v3/movie/lookup'; + const APIPathCommand = '/api/v3/command'; + const APICommand = 'RefreshMovie'; + + // Check variables are given + if (!SSL || !IP || !APIKey || !port) { + throw new Error('All fields are required.'); + } + + // Select connection type + var connection_type = null; + try { + if(SSL == "http") { + connection_type = http + } else { + connection_type = https + } + } catch(e) { + console.log(`Failed to compare SSL string. Error: ${e}`); + connection_type = http + } + + // Try to split file path to retrieve movie folder name + try { + term = file.file.split('/'); + term = term[term.length - 2]; + termUri = encodeURI(term); + } catch(e){ + console.log(`Failed to split file name. Error: '${e}'.\n`) + response.infoLog += `\nFailed to split file name. Error: '${e}'.`; + return response + } + + console.log(`Searching for movie '${term}'.`) + response.infoLog += `\nSearching for movie '${term}'.`; + + // Create variables for API call + const url1 = `${SSL}://${IP}:${port}${APIPathLookup}?term=${termUri}&apikey=${APIKey}`; + var url1_body = ""; + var url2 = ``; + var MovieID = 0; + + // API call to search for Movie ID using the folder name + try { + await new Promise((resolve) => { + connection_type.get(url1, (res) => { + + console.log(`Got status code '${res.statusCode}'.`) + response.infoLog += `\nGot status code '${res.statusCode}'.`; + + res.on("data", function(chunk) { + url1_body += chunk; + }); + + res.on('end', function() { + resolve(); + }); + + }).on('error', (e) => { + console.log(`Failed to search for movie. Error: '${e}'.`) + response.infoLog += `\nFailed to search for movie. Error: '${e}'.`; + resolve(); + }); + }); + } catch(e) { + console.log(`Failed API call. Error: '${e}'.`); + response.infoLog += `\nFailed API call. Error: '${e}'.`; + return response; + } + + // Parse API response and save the Movie ID + try { + const APIresponse = JSON.parse(url1_body); + MovieID = APIresponse[0].id; + url2 = `${SSL}://${IP}:${port}${APIPathCommand}?apikey=${APIKey}`; + } catch(e) { + console.log(`Failed make JSON payload. Error: '${e}'.`); + response.infoLog += `\nFailed make JSON payload. Error: '${e}'.`; + return response; + } + + console.log(`Refreshing movie '${MovieID}'.`); + response.infoLog += `\nRefreshing movie '${MovieID}'.`; + + // API request to send a command to refresh the files for the found Movie ID + try { + await new Promise((resolve) => { + axios.post(url2, { + name: APICommand, + movieIds: [MovieID] + }) + .then(function (res) { + console.log(`Got status code '${res.status}'.`) + response.infoLog += `\n☑ Got status code '${res.status}'.`; + resolve(); + }) + .catch(function (error) { + console.log(`Got error: ${error}`) + response.infoLog += `\nGot error: ${error}`; + resolve(); + }); + }); + } catch(e) { + console.log(`Failed API call. Error: '${e}'.`); + response.infoLog += `\nFailed API call. Error: '${e}'.`; + return response; + } + + // Sleep for set amount of time + console.log(`Sleeping '${sleepInterval}' ms.`); + response.infoLog += `\nSleeping '${sleepInterval}' ms.`; + await new Promise((resolve) => { + setTimeout(() => { + resolve(); + }, sleepInterval); + }); + + return response; +}; + +module.exports.details = details; +module.exports.plugin = plugin; diff --git a/Community/Tdarr_Plugin_f4k5_aune_rename_files_in_radarr.js b/Community/Tdarr_Plugin_f4k5_aune_rename_files_in_radarr.js new file mode 100644 index 000000000..c88f8a025 --- /dev/null +++ b/Community/Tdarr_Plugin_f4k5_aune_rename_files_in_radarr.js @@ -0,0 +1,300 @@ +module.exports.dependencies = [ + 'axios', + 'http', + 'https', +]; + +// tdarrSkipTest +const details = () => ({ + id: 'Tdarr_Plugin_f4k5_aune_rename_files_in_radarr', + Stage: 'Post-processing', + Name: 'Rename files in Radarr', + Type: 'Video', + Operation: 'Transcode', + Description: `Renames the files in the current movie in Radarr according to naming format. This is done using the Radarr API. To do this action it needs the Movie ID. This code attempts to retrieve the Movie ID by using the folder name of the movie.`, + Version: '1.0', + Tags: '3rd party,post-processing,configurable', + + Inputs: [ + { + name: 'Url_Protocol', + type: 'string', + defaultValue: 'http', + inputUI: { + type: 'dropdown', + options: [ + 'http', + 'https', + ], + }, + tooltip: ` + Specified the type of request to make, http:// or https:// + \\nExample:\\n + http + \\nExample:\\n + https`, + }, + { + name: 'Url_Radarr', + type: 'string', + defaultValue: 'localhost', + inputUI: { + type: 'text', + }, + tooltip: ` + Enter the IP address/URL Tdarr uses to reach Radarr. + \\nExample:\\n + 192.168.0.10 + \\nExample:\\n + subdomain.domain.tld`, + }, + { + name: 'Radarr_Port', + type: 'number', + defaultValue: 7878, + inputUI: { + type: 'text', + }, + tooltip: ` + The port required to access Radarr + \\nExample:\\n + 7878`, + }, + { + name: 'Radarr_APIKey', + type: 'string', + defaultValue: '', + inputUI: { + type: 'text', + }, + tooltip: ` + Enter the Radarr API key. \\n + You can find it within Radarr at /settings/general. \\n\\n + \\nExample:\\n + 3ff1ae1c39a2a2a397315e15266dea48`, + }, + { + name: 'After_Sleep', + type: 'number', + defaultValue: 0, + inputUI: { + type: 'text', + }, + tooltip: ` + How many ms should Tdarr sleep to wait for Radarr to finish afterward? \\n + \\nExample:\\n + 1000`, + }, + ], +}); + +// eslint-disable-next-line no-unused-vars +const plugin = async (file, librarySettings, inputs, otherArguments) => { + + const response = { + file, + removeFromDB: false, + updateDB: false, + processFile: false, + infoLog: 'Rename Radarr files starting.', + }; + + console.log("Rename Radarr files starting.") + + const lib = require('../methods/lib')(); + // eslint-disable-next-line no-unused-vars,no-param-reassign + inputs = lib.loadDefaultValues(inputs, details); + const http = require('http'); + const https = require('https'); + const axios = require('axios'); + + console.log("Loaded required packages.") + + // Defines variables + const SSL = inputs.Url_Protocol; + const IP = inputs.Url_Radarr; + const port = inputs.Radarr_Port; + const APIKey = inputs.Radarr_APIKey; + const sleepInterval = inputs.After_Sleep; + const regex = '(S[0-9]{1,4}E[0-9]{1,2})'; + var term = ""; + var termUri = ""; + const APIPathLookup = '/api/v3/movie/lookup'; + const APIPathMoviefile = '/api/v3/moviefile'; + const APIPathCommand = '/api/v3/command'; + const APICommand = 'RenameFiles'; + + // Check variables are given + if (!SSL || !IP || !APIKey || !port) { + throw new Error('All fields are required.'); + } + + // Select connection type + var connection_type = null; + try { + if(SSL == "http") { + connection_type = http + } else { + connection_type = https + } + } catch(e) { + console.log(`Failed to compare SSL string. Error: ${e}`); + connection_type = http + } + + // Try to split file path to retrieve movie folder name + try { + term = file.file.split('/'); + term = term[term.length - 2]; + termUri = encodeURI(term); + } catch(e){ + console.log(`Failed to split file name. Error: '${e}'.`) + response.infoLog += `\nFailed to split file name. Error: '${e}'.`; + return response + } + + console.log(`Searching for movie '${term}'.`) + response.infoLog += `\nSearching for movie '${term}'.`; + + // Define variables to look for Movie ID + const url1 = `${SSL}://${IP}:${port}${APIPathLookup}?term=${termUri}&apikey=${APIKey}`; + var url2 = ``; + var url3 = ``; + var MovieID = 0; + var url1_body = ""; + var url2_body = ""; + + // API call to search for folder name to get Movie ID + try { + await new Promise((resolve) => { + connection_type.get(url1, (res) => { + + console.log(`Got status code '${res.statusCode}'.`) + response.infoLog += `\nGot status code '${res.statusCode}'.`; + + res.on("data", function(chunk) { + url1_body += chunk; + }); + + res.on('end', function() { + resolve(); + }); + + }).on('error', (e) => { + console.log(`Failed to search for movie. Error: '${e}'.`) + response.infoLog += `\nFailed to search for movie. Error: '${e}'.`; + resolve(); + }); + }); + } catch(e) { + console.log(`Failed API call. Error: '${e}'.`); + response.infoLog += `\nFailed API call. Error: '${e}'.`; + return response; + } + + // Create variables, parse API response to search for Movie file IDs of the Movie ID + try { + const APIresponse = JSON.parse(url1_body); + MovieID = APIresponse[0].id; + url2 = `${SSL}://${IP}:${port}${APIPathMoviefile}?movieId=${MovieID}&includeImages=false&apikey=${APIKey}`; + url3 = `${SSL}://${IP}:${port}${APIPathCommand}?apikey=${APIKey}`; + } catch(e) { + console.log(`Failed make JSON payload. Error: '${e}'.`); + response.infoLog += `\nFailed make JSON payload. Error: '${e}'.`; + return response; + } + + // Create array variable for Movie file IDs + var fileArray = []; + + console.log(`Searching for Movie file IDs for movie '${MovieID}'.`) + response.infoLog += `\nSearching for Movie file IDs for movie '${MovieID}'.`; + + // API call to find Movie file IDs for Movie ID + try { + await new Promise((resolve) => { + connection_type.get(url2, (res) => { + + console.log(`Got status code '${res.statusCode}'.`) + response.infoLog += `\nGot status code '${res.statusCode}'.`; + + res.on("data", function(chunk) { + url2_body += chunk; + }); + + res.on('end', function() { + resolve(); + }); + + }).on('error', (e) => { + console.log(`Failed to search for files for movie. Error: '${e}'.`) + response.infoLog += `\nFailed to search for files for movie. Error: '${e}'.`; + resolve(); + }); + }); + } catch(e) { + console.log(`Failed API call. Error: '${e}'.`); + response.infoLog += `\nFailed API call. Error: '${e}'.`; + return response; + } + + // Parse API response of movie files IDs. Find the movie file ID + try { + const APIresponse2 = JSON.parse(url2_body); + for(var i = 0; i < APIresponse2.length; i++) { + try { + fileArray.push(APIresponse2[i].id) + } catch { + continue; + } + } + console.log(`Found '${fileArray.length}' files for movie.`); + response.infoLog += `\nFound '${fileArray.length}' files for movie.`; + } catch(e) { + console.log(`Failed process episodes. Error: '${e}'.`); + response.infoLog += `\nFailed process episodes. Error: '${e}'.`; + return response; + } + + console.log(`Renaming files for movie '${MovieID}'.`); + response.infoLog += `\nRenaming files for movie '${MovieID}'.`; + + // API call to rename the found Movie file IDs for the Movie ID + try { + await new Promise((resolve) => { + axios.post(url3, { + name: APICommand, + movieId: MovieID, + files: fileArray + }) + .then(function (res) { + console.log(`Got status code '${res.status}'.`) + response.infoLog += `\n☑ Got status code '${res.status}'.`; + resolve(); + }) + .catch(function (error) { + console.log(`Got error: ${error}`) + response.infoLog += `\nGot error: ${error}`; + resolve(); + }); + }); + } catch(e) { + console.log(`Failed API call. Error: '${e}'.`); + response.infoLog += `\nFailed API call. Error: '${e}'.`; + return response; + } + + // Sleep for set amount of time + console.log(`Sleeping '${sleepInterval}' ms.`); + response.infoLog += `\nSleeping '${sleepInterval}' ms.`; + await new Promise((resolve) => { + setTimeout(() => { + resolve(); + }, sleepInterval); + }); + + return response; +}; + +module.exports.details = details; +module.exports.plugin = plugin; From 7f6f210b3ad4b1ad9bd70e9d5522a45913624fbb Mon Sep 17 00:00:00 2001 From: aunefyren Date: Wed, 4 Oct 2023 13:27:33 +0200 Subject: [PATCH 3/9] Trying to improve linting --- ...ion_remove_stream_by_specified_property.js | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Community/Tdarr_Plugin_00td_action_remove_stream_by_specified_property.js b/Community/Tdarr_Plugin_00td_action_remove_stream_by_specified_property.js index 0ef970a1f..666ed4731 100644 --- a/Community/Tdarr_Plugin_00td_action_remove_stream_by_specified_property.js +++ b/Community/Tdarr_Plugin_00td_action_remove_stream_by_specified_property.js @@ -18,7 +18,8 @@ const details = () => ({ type: 'text', }, tooltip: - `Enter values of the stream codec type to process. Nothing/empty input means all types of streams will be inspected for processing. For example, if removing by codec_name on video streams, enter video: + `Enter values of the stream codec type to process. Nothing/empty input means all types of streams will be inspected for processing. + For example, if removing by codec_name on video streams, enter video: \\nExample:\\n video,subtitle,audio @@ -60,12 +61,13 @@ const details = () => ({ type: 'text', }, tooltip: - `Enter one or more properties to check for its existance. If the property is missing or null, the stream will be removed. Useful for fixing corrupt streams. For example, if codec_name is missing, the stream will be removed: + `Enter one or more properties to check for its existance. If the property is missing or null, the stream will be removed. + Useful for fixing corrupt streams. For example, if codec_name is missing, the stream will be removed: \\nExample:\\n codec_name `, - } + }, ], }); @@ -112,29 +114,27 @@ const plugin = (file, librarySettings, inputs, otherArguments) => { let streamToRemove = false; for (let i = 0; i < file.ffProbeData.streams.length; i += 1) { try { - // Skip if the codec_type is filtered out - if(codecTypeFilter.length != 0 && !codecTypeFilter.includes(String(file.ffProbeData.streams[i]["codec_type"]))) { + if(codecTypeFilter.length != 0 && !codecTypeFilter.includes(String(file.ffProbeData.streams[i]['codec_type']))) { continue; } // Check if chosen non-empty properties are empty // If they are empty, set emptyValue to true - var emptyValue = false; + let emptyValue = false; for (let j = 0; j < removeIfPropertyMissing.length; j += 1) { + response.infoLog += `DEBUG: stream ${i} property for ${removeIfPropertyMissing[j]} + is ${file.ffProbeData.streams[i][removeIfPropertyMissing[j]]} \n`; - response.infoLog += `DEBUG: stream ${i} property for ${removeIfPropertyMissing[j]} is ${file.ffProbeData.streams[i][removeIfPropertyMissing[j]]} \n`; - - if(file.ffProbeData.streams[i][removeIfPropertyMissing[j]] == 'undefined' || file.ffProbeData.streams[i][removeIfPropertyMissing[j]] == null) { + if (file.ffProbeData.streams[i][removeIfPropertyMissing[j]] === 'undefined' || file.ffProbeData.streams[i][removeIfPropertyMissing[j]] === null) { emptyValue = true; - response.infoLog += ` Removing stream ${i} which is has ${removeIfPropertyMissing[j]} missing` + response.infoLog += ` Removing stream ${i} which is has ${removeIfPropertyMissing[j]} missing`; break } } // If the value to remove is present OR an empty value is found, remove the stream if ((valuesToRemove.includes(String(file.ffProbeData.streams[i][propertyToCheck]))) || emptyValue) { - // Add to preset response.preset += ` -map -0:${i} `; From 3cf7c9c25e6fc5770166ee744fb8365ce292b895 Mon Sep 17 00:00:00 2001 From: aunefyren Date: Wed, 4 Oct 2023 13:32:40 +0200 Subject: [PATCH 4/9] Trying to improve linting again --- ...ion_remove_stream_by_specified_property.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Community/Tdarr_Plugin_00td_action_remove_stream_by_specified_property.js b/Community/Tdarr_Plugin_00td_action_remove_stream_by_specified_property.js index 666ed4731..5fb96449d 100644 --- a/Community/Tdarr_Plugin_00td_action_remove_stream_by_specified_property.js +++ b/Community/Tdarr_Plugin_00td_action_remove_stream_by_specified_property.js @@ -18,8 +18,8 @@ const details = () => ({ type: 'text', }, tooltip: - `Enter values of the stream codec type to process. Nothing/empty input means all types of streams will be inspected for processing. - For example, if removing by codec_name on video streams, enter video: + `Enter values of the stream codec type to process. Nothing/empty input means all types of streams will + be inspected for processing. For example, if removing by codec_name on video streams, enter video: \\nExample:\\n video,subtitle,audio @@ -61,8 +61,9 @@ const details = () => ({ type: 'text', }, tooltip: - `Enter one or more properties to check for its existance. If the property is missing or null, the stream will be removed. - Useful for fixing corrupt streams. For example, if codec_name is missing, the stream will be removed: + `Enter one or more properties to check for its existance. If the property is missing or null, + the stream will be removed. Useful for fixing corrupt streams. For example, if codec_name + is missing, the stream will be removed: \\nExample:\\n codec_name @@ -115,7 +116,10 @@ const plugin = (file, librarySettings, inputs, otherArguments) => { for (let i = 0; i < file.ffProbeData.streams.length; i += 1) { try { // Skip if the codec_type is filtered out - if(codecTypeFilter.length != 0 && !codecTypeFilter.includes(String(file.ffProbeData.streams[i]['codec_type']))) { + if( + codecTypeFilter.length !== 0 && + !codecTypeFilter.includes(String(file.ffProbeData.streams[i].codec_type)) + ) { continue; } @@ -129,7 +133,7 @@ const plugin = (file, librarySettings, inputs, otherArguments) => { if (file.ffProbeData.streams[i][removeIfPropertyMissing[j]] === 'undefined' || file.ffProbeData.streams[i][removeIfPropertyMissing[j]] === null) { emptyValue = true; response.infoLog += ` Removing stream ${i} which is has ${removeIfPropertyMissing[j]} missing`; - break + break; } } @@ -139,11 +143,10 @@ const plugin = (file, librarySettings, inputs, otherArguments) => { response.preset += ` -map -0:${i} `; // Log the old message if the reason is not empty values - if(!emptyValue) { + if (!emptyValue) { response.infoLog += ` Removing stream ${i} which is has ${propertyToCheck} or` + ` of ${file.ffProbeData.streams[i][propertyToCheck]} \n`; } - streamToRemove = true; } From aa80635f8cd8b215f181686d9b8be3aa8ef5ddbd Mon Sep 17 00:00:00 2001 From: aunefyren Date: Wed, 4 Oct 2023 13:35:37 +0200 Subject: [PATCH 5/9] Linting is hard --- ...00td_action_remove_stream_by_specified_property.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Community/Tdarr_Plugin_00td_action_remove_stream_by_specified_property.js b/Community/Tdarr_Plugin_00td_action_remove_stream_by_specified_property.js index 5fb96449d..6e21b76a5 100644 --- a/Community/Tdarr_Plugin_00td_action_remove_stream_by_specified_property.js +++ b/Community/Tdarr_Plugin_00td_action_remove_stream_by_specified_property.js @@ -116,10 +116,9 @@ const plugin = (file, librarySettings, inputs, otherArguments) => { for (let i = 0; i < file.ffProbeData.streams.length; i += 1) { try { // Skip if the codec_type is filtered out - if( - codecTypeFilter.length !== 0 && - !codecTypeFilter.includes(String(file.ffProbeData.streams[i].codec_type)) - ) { + if ( + codecTypeFilter.length !== 0 + && !codecTypeFilter.includes(String(file.ffProbeData.streams[i].codec_type))) { continue; } @@ -130,7 +129,9 @@ const plugin = (file, librarySettings, inputs, otherArguments) => { response.infoLog += `DEBUG: stream ${i} property for ${removeIfPropertyMissing[j]} is ${file.ffProbeData.streams[i][removeIfPropertyMissing[j]]} \n`; - if (file.ffProbeData.streams[i][removeIfPropertyMissing[j]] === 'undefined' || file.ffProbeData.streams[i][removeIfPropertyMissing[j]] === null) { + if ( + file.ffProbeData.streams[i][removeIfPropertyMissing[j]] === 'undefined' + || file.ffProbeData.streams[i][removeIfPropertyMissing[j]] === null) { emptyValue = true; response.infoLog += ` Removing stream ${i} which is has ${removeIfPropertyMissing[j]} missing`; break; From 21ae391a496013279bfdf3b383498e4b81bb11bd Mon Sep 17 00:00:00 2001 From: aunefyren Date: Wed, 4 Oct 2023 13:50:16 +0200 Subject: [PATCH 6/9] =?UTF-8?q?Linting=20=C3=A6=C3=A6=C3=A6=C3=A6=C3=A6?= =?UTF-8?q?=C3=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ion_remove_stream_by_specified_property.js | 31 +++---- ...lugin_f4k2_aune_refresh_files_in_sonarr.js | 63 ++++++------- ...Plugin_f4k3_aune_rename_files_in_sonarr.js | 89 +++++++++---------- ...lugin_f4k4_aune_refresh_files_in_radarr.js | 61 +++++++------ ...Plugin_f4k5_aune_rename_files_in_radarr.js | 79 ++++++++-------- 5 files changed, 158 insertions(+), 165 deletions(-) diff --git a/Community/Tdarr_Plugin_00td_action_remove_stream_by_specified_property.js b/Community/Tdarr_Plugin_00td_action_remove_stream_by_specified_property.js index 6e21b76a5..16bb20fd6 100644 --- a/Community/Tdarr_Plugin_00td_action_remove_stream_by_specified_property.js +++ b/Community/Tdarr_Plugin_00td_action_remove_stream_by_specified_property.js @@ -9,16 +9,14 @@ const details = () => ({ `, Version: '1.00', Tags: 'action', - Inputs: [ - { + Inputs: [{ name: 'codecTypeFilter', type: 'string', defaultValue: 'subtitle', inputUI: { type: 'text', }, - tooltip: - `Enter values of the stream codec type to process. Nothing/empty input means all types of streams will + tooltip: `Enter values of the stream codec type to process. Nothing/empty input means all types of streams will be inspected for processing. For example, if removing by codec_name on video streams, enter video: \\nExample:\\n @@ -32,8 +30,7 @@ const details = () => ({ inputUI: { type: 'text', }, - tooltip: - `Enter one stream property to check for values. + tooltip: `Enter one stream property to check for values. \\nExample:\\n codec_name @@ -46,8 +43,7 @@ const details = () => ({ inputUI: { type: 'text', }, - tooltip: - `Enter values of the property above to remove. For example, if removing by codec_name, could enter ac3,aac: + tooltip: `Enter values of the property above to remove. For example, if removing by codec_name, could enter ac3,aac: \\nExample:\\n ac3,aac @@ -60,8 +56,7 @@ const details = () => ({ inputUI: { type: 'text', }, - tooltip: - `Enter one or more properties to check for its existance. If the property is missing or null, + tooltip: `Enter one or more properties to check for its existance. If the property is missing or null, the stream will be removed. Useful for fixing corrupt streams. For example, if codec_name is missing, the stream will be removed: @@ -117,8 +112,8 @@ const plugin = (file, librarySettings, inputs, otherArguments) => { try { // Skip if the codec_type is filtered out if ( - codecTypeFilter.length !== 0 - && !codecTypeFilter.includes(String(file.ffProbeData.streams[i].codec_type))) { + codecTypeFilter.length !== 0 && + !codecTypeFilter.includes(String(file.ffProbeData.streams[i].codec_type))) { continue; } @@ -130,8 +125,8 @@ const plugin = (file, librarySettings, inputs, otherArguments) => { is ${file.ffProbeData.streams[i][removeIfPropertyMissing[j]]} \n`; if ( - file.ffProbeData.streams[i][removeIfPropertyMissing[j]] === 'undefined' - || file.ffProbeData.streams[i][removeIfPropertyMissing[j]] === null) { + file.ffProbeData.streams[i][removeIfPropertyMissing[j]] === 'undefined' || + file.ffProbeData.streams[i][removeIfPropertyMissing[j]] === null) { emptyValue = true; response.infoLog += ` Removing stream ${i} which is has ${removeIfPropertyMissing[j]} missing`; break; @@ -145,11 +140,11 @@ const plugin = (file, librarySettings, inputs, otherArguments) => { // Log the old message if the reason is not empty values if (!emptyValue) { - response.infoLog += ` Removing stream ${i} which is has ${propertyToCheck} or` - + ` of ${file.ffProbeData.streams[i][propertyToCheck]} \n`; + response.infoLog += ` Removing stream ${i} which is has ${propertyToCheck} or` + + ` of ${file.ffProbeData.streams[i][propertyToCheck]} \n`; } - streamToRemove = true; + streamToRemove = true; } } catch (err) { response.infoLog += ` Error reading stream ${i} ${propertyToCheck} \n`; @@ -170,4 +165,4 @@ const plugin = (file, librarySettings, inputs, otherArguments) => { }; module.exports.details = details; -module.exports.plugin = plugin; +module.exports.plugin = plugin; \ No newline at end of file diff --git a/Community/Tdarr_Plugin_f4k2_aune_refresh_files_in_sonarr.js b/Community/Tdarr_Plugin_f4k2_aune_refresh_files_in_sonarr.js index 3459d18d2..941d9c9e8 100644 --- a/Community/Tdarr_Plugin_f4k2_aune_refresh_files_in_sonarr.js +++ b/Community/Tdarr_Plugin_f4k2_aune_refresh_files_in_sonarr.js @@ -11,12 +11,13 @@ const details = () => ({ Name: 'Refresh files in Sonarr', Type: 'Video', Operation: 'Transcode', - Description: `Refreshes folder containing the current show in Sonarr so files are mapped properly. This is done using the Sonarr API. To do this action it needs the Show ID. This code attempts to retrieve the Show ID by using the folder name of the series.`, + Description: `Refreshes folder containing the current show in Sonarr so files are mapped properly. + This is done using the Sonarr API. To do this action it needs the Show ID. + This code attempts to retrieve the Show ID by using the folder name of the series.`, Version: '1.0', Tags: '3rd party,post-processing,configurable', - Inputs: [ - { + Inputs: [{ name: 'Url_Protocol', type: 'string', defaultValue: 'http', @@ -122,8 +123,8 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { const port = inputs.Sonarr_Port; const APIKey = inputs.Sonarr_APIKey; const sleepInterval = inputs.After_Sleep; - var term = ""; - var termUri = ""; + let term = ""; + let termUri = ""; const APIPathLookup = '/api/v3/series/lookup'; const APIPathCommand = '/api/v3/command'; const APICommand = 'RefreshSeries'; @@ -134,14 +135,14 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { } // Select connection type - var connection_type = null; + let connection_type = null; try { - if(SSL == "http") { + if (SSL == "http") { connection_type = http } else { connection_type = https } - } catch(e) { + } catch (e) { console.log(`Failed to compare SSL string. Error: ${e}`); connection_type = http } @@ -151,7 +152,7 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { term = file.file.split('/'); term = term[term.length - 3]; termUri = encodeURI(term); - } catch(e){ + } catch (e) { console.log(`Failed to split file name. Error: '${e}'.\n`) response.infoLog += `\nFailed to split file name. Error: '${e}'.`; return response @@ -162,9 +163,9 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { // Create variables for API call const url1 = `${SSL}://${IP}:${port}${APIPathLookup}?term=${termUri}&apikey=${APIKey}`; - var url1_body = ""; - var url2 = ``; - var SeriesID = 0; + let url1_body = ""; + let url2 = ``; + let SeriesID = 0; // API call to search for Series ID using the folder name try { @@ -174,11 +175,11 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { console.log(`Got status code '${res.statusCode}'.`) response.infoLog += `\nGot status code '${res.statusCode}'.`; - res.on("data", function(chunk) { + res.on("data", function (chunk) { url1_body += chunk; }); - res.on('end', function() { + res.on('end', function () { resolve(); }); @@ -188,7 +189,7 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { resolve(); }); }); - } catch(e) { + } catch (e) { console.log(`Failed API call. Error: '${e}'.`); response.infoLog += `\nFailed API call. Error: '${e}'.`; return response; @@ -199,7 +200,7 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { const APIresponse = JSON.parse(url1_body); SeriesID = APIresponse[0].id; url2 = `${SSL}://${IP}:${port}${APIPathCommand}?apikey=${APIKey}`; - } catch(e) { + } catch (e) { console.log(`Failed make JSON payload. Error: '${e}'.`); response.infoLog += `\nFailed make JSON payload. Error: '${e}'.`; return response; @@ -212,21 +213,21 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { try { await new Promise((resolve) => { axios.post(url2, { - name: APICommand, - seriesId: SeriesID - }) - .then(function (res) { - console.log(`Got status code '${res.status}'.`) - response.infoLog += `\n☑ Got status code '${res.status}'.`; - resolve(); - }) - .catch(function (error) { - console.log(`Got error: ${error}`) - response.infoLog += `\nGot error: ${error}`; - resolve(); - }); + name: APICommand, + seriesId: SeriesID + }) + .then(function (res) { + console.log(`Got status code '${res.status}'.`) + response.infoLog += `\n☑ Got status code '${res.status}'.`; + resolve(); + }) + .catch(function (error) { + console.log(`Got error: ${error}`) + response.infoLog += `\nGot error: ${error}`; + resolve(); + }); }); - } catch(e) { + } catch (e) { console.log(`Failed API call. Error: '${e}'.`); response.infoLog += `\nFailed API call. Error: '${e}'.`; return response; @@ -241,4 +242,4 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { }; module.exports.details = details; -module.exports.plugin = plugin; +module.exports.plugin = plugin; \ No newline at end of file diff --git a/Community/Tdarr_Plugin_f4k3_aune_rename_files_in_sonarr.js b/Community/Tdarr_Plugin_f4k3_aune_rename_files_in_sonarr.js index aecf4fb28..0a9b26a97 100644 --- a/Community/Tdarr_Plugin_f4k3_aune_rename_files_in_sonarr.js +++ b/Community/Tdarr_Plugin_f4k3_aune_rename_files_in_sonarr.js @@ -15,8 +15,7 @@ const details = () => ({ Version: '1.0', Tags: '3rd party,post-processing,configurable', - Inputs: [ - { + Inputs: [{ name: 'Url_Protocol', type: 'string', defaultValue: 'http', @@ -123,9 +122,9 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { const APIKey = inputs.Sonarr_APIKey; const sleepInterval = inputs.After_Sleep; const regex = '(S[0-9]{1,4}E[0-9]{1,2})'; - var seasonEpisodeMatch = ""; - var term = ""; - var termUri = ""; + let seasonEpisodeMatch = ""; + let term = ""; + let termUri = ""; const APIPathLookup = '/api/v3/series/lookup'; const APIPathEpisodefile = '/api/v3/episodefile'; const APIPathCommand = '/api/v3/command'; @@ -137,14 +136,14 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { } // Select connection type - var connection_type = null; + let connection_type = null; try { - if(SSL == "http") { + if (SSL == "http") { connection_type = http } else { connection_type = https } - } catch(e) { + } catch (e) { console.log(`Failed to compare SSL string. Error: ${e}`); connection_type = http } @@ -156,15 +155,15 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { termUri = encodeURI(term); // Use Regex to find SXXXXEXX part of file name and save it - var seasonEpisodeMatch_tmp = file.file.toString().match(regex) - if(seasonEpisodeMatch_tmp == null) { + let seasonEpisodeMatch_tmp = file.file.toString().match(regex) + if (seasonEpisodeMatch_tmp == null) { console.log(`Failed to find SXXEXX in filename.`) response.infoLog += `\nFailed to find SXXEXX in filename.`; return response } else { seasonEpisodeMatch = seasonEpisodeMatch_tmp[0]; } - } catch(e){ + } catch (e) { console.log(`Failed to split file name or find episode nr. Error: '${e}'.`) response.infoLog += `\nFailed to split file name or find episode nr. Error: '${e}'.`; return response @@ -178,11 +177,11 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { // Define variables to look for Series ID const url1 = `${SSL}://${IP}:${port}${APIPathLookup}?term=${termUri}&apikey=${APIKey}`; - var url2 = ``; - var url3 = ``; - var SeriesID = 0; - var url1_body = ""; - var url2_body = ""; + let url2 = ``; + let url3 = ``; + let SeriesID = 0; + let url1_body = ""; + let url2_body = ""; // API call to search for folder name to get Series ID try { @@ -192,11 +191,11 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { console.log(`Got status code '${res.statusCode}'.`) response.infoLog += `\nGot status code '${res.statusCode}'.`; - res.on("data", function(chunk) { + res.on("data", function (chunk) { url1_body += chunk; }); - res.on('end', function() { + res.on('end', function () { resolve(); }); @@ -206,7 +205,7 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { resolve(); }); }); - } catch(e) { + } catch (e) { console.log(`Failed API call. Error: '${e}'.`); response.infoLog += `\nFailed API call. Error: '${e}'.`; return response; @@ -218,14 +217,14 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { SeriesID = APIresponse[0].id; url2 = `${SSL}://${IP}:${port}${APIPathEpisodefile}?seriesId=${SeriesID}&includeImages=false&apikey=${APIKey}`; url3 = `${SSL}://${IP}:${port}${APIPathCommand}?apikey=${APIKey}`; - } catch(e) { + } catch (e) { console.log(`Failed make JSON payload. Error: '${e}'.`); response.infoLog += `\nFailed make JSON payload. Error: '${e}'.`; return response; } // Create array variable for Episode IDs - var fileArray = []; + let fileArray = []; console.log(`Searching for episode files for show '${SeriesID}'.`) response.infoLog += `\nSearching for episode files for show '${SeriesID}'.`; @@ -238,11 +237,11 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { console.log(`Got status code '${res.statusCode}'.`) response.infoLog += `\nGot status code '${res.statusCode}'.`; - res.on("data", function(chunk) { + res.on("data", function (chunk) { url2_body += chunk; }); - res.on('end', function() { + res.on('end', function () { resolve(); }); @@ -252,7 +251,7 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { resolve(); }); }); - } catch(e) { + } catch (e) { console.log(`Failed API call. Error: '${e}'.`); response.infoLog += `\nFailed API call. Error: '${e}'.`; return response; @@ -261,11 +260,11 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { // Parse API response of episode files. Find the episode ID which matches the episode name of the file try { const APIresponse2 = JSON.parse(url2_body); - for(var i = 0; i < APIresponse2.length; i++) { + for (let i = 0; i < APIresponse2.length; i++) { try { - var tmp_match = APIresponse2[i].path.toString().match(regex) - var tmp_match2 = tmp_match[0] - if(tmp_match2 == seasonEpisodeMatch) { + let tmp_match = APIresponse2[i].path.toString().match(regex) + let tmp_match2 = tmp_match[0] + if (tmp_match2 == seasonEpisodeMatch) { fileArray.push(APIresponse2[i].id) } } catch { @@ -274,7 +273,7 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { } console.log(`Found '${fileArray.length}' files for series.`); response.infoLog += `\nFound '${fileArray.length}' files for series.`; - } catch(e) { + } catch (e) { console.log(`Failed process episodes. Error: '${e}'.`); response.infoLog += `\nFailed process episodes. Error: '${e}'.`; return response; @@ -287,22 +286,22 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { try { await new Promise((resolve) => { axios.post(url3, { - name: APICommand, - seriesId: SeriesID, - files: fileArray - }) - .then(function (res) { - console.log(`Got status code '${res.status}'.`) - response.infoLog += `\n☑ Got status code '${res.status}'.`; - resolve(); - }) - .catch(function (error) { - console.log(`Got error: ${error}`) - response.infoLog += `\nGot error: ${error}`; - resolve(); - }); + name: APICommand, + seriesId: SeriesID, + files: fileArray + }) + .then(function (res) { + console.log(`Got status code '${res.status}'.`) + response.infoLog += `\n☑ Got status code '${res.status}'.`; + resolve(); + }) + .catch(function (error) { + console.log(`Got error: ${error}`) + response.infoLog += `\nGot error: ${error}`; + resolve(); + }); }); - } catch(e) { + } catch (e) { console.log(`Failed API call. Error: '${e}'.`); response.infoLog += `\nFailed API call. Error: '${e}'.`; return response; @@ -317,4 +316,4 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { }; module.exports.details = details; -module.exports.plugin = plugin; +module.exports.plugin = plugin; \ No newline at end of file diff --git a/Community/Tdarr_Plugin_f4k4_aune_refresh_files_in_radarr.js b/Community/Tdarr_Plugin_f4k4_aune_refresh_files_in_radarr.js index 699a63395..71f06bdb3 100644 --- a/Community/Tdarr_Plugin_f4k4_aune_refresh_files_in_radarr.js +++ b/Community/Tdarr_Plugin_f4k4_aune_refresh_files_in_radarr.js @@ -15,8 +15,7 @@ const details = () => ({ Version: '1.0', Tags: '3rd party,post-processing,configurable', - Inputs: [ - { + Inputs: [{ name: 'Url_Protocol', type: 'string', defaultValue: 'http', @@ -116,8 +115,8 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { const port = inputs.Radarr_Port; const APIKey = inputs.Radarr_APIKey; const sleepInterval = inputs.After_Sleep; - var term = ""; - var termUri = ""; + let term = ""; + let termUri = ""; const APIPathLookup = '/api/v3/movie/lookup'; const APIPathCommand = '/api/v3/command'; const APICommand = 'RefreshMovie'; @@ -128,14 +127,14 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { } // Select connection type - var connection_type = null; + let connection_type = null; try { - if(SSL == "http") { + if (SSL == "http") { connection_type = http } else { connection_type = https } - } catch(e) { + } catch (e) { console.log(`Failed to compare SSL string. Error: ${e}`); connection_type = http } @@ -145,7 +144,7 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { term = file.file.split('/'); term = term[term.length - 2]; termUri = encodeURI(term); - } catch(e){ + } catch (e) { console.log(`Failed to split file name. Error: '${e}'.\n`) response.infoLog += `\nFailed to split file name. Error: '${e}'.`; return response @@ -156,9 +155,9 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { // Create variables for API call const url1 = `${SSL}://${IP}:${port}${APIPathLookup}?term=${termUri}&apikey=${APIKey}`; - var url1_body = ""; - var url2 = ``; - var MovieID = 0; + let url1_body = ""; + let url2 = ``; + let MovieID = 0; // API call to search for Movie ID using the folder name try { @@ -168,11 +167,11 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { console.log(`Got status code '${res.statusCode}'.`) response.infoLog += `\nGot status code '${res.statusCode}'.`; - res.on("data", function(chunk) { + res.on("data", function (chunk) { url1_body += chunk; }); - res.on('end', function() { + res.on('end', function () { resolve(); }); @@ -182,7 +181,7 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { resolve(); }); }); - } catch(e) { + } catch (e) { console.log(`Failed API call. Error: '${e}'.`); response.infoLog += `\nFailed API call. Error: '${e}'.`; return response; @@ -193,7 +192,7 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { const APIresponse = JSON.parse(url1_body); MovieID = APIresponse[0].id; url2 = `${SSL}://${IP}:${port}${APIPathCommand}?apikey=${APIKey}`; - } catch(e) { + } catch (e) { console.log(`Failed make JSON payload. Error: '${e}'.`); response.infoLog += `\nFailed make JSON payload. Error: '${e}'.`; return response; @@ -206,21 +205,21 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { try { await new Promise((resolve) => { axios.post(url2, { - name: APICommand, - movieIds: [MovieID] - }) - .then(function (res) { - console.log(`Got status code '${res.status}'.`) - response.infoLog += `\n☑ Got status code '${res.status}'.`; - resolve(); - }) - .catch(function (error) { - console.log(`Got error: ${error}`) - response.infoLog += `\nGot error: ${error}`; - resolve(); - }); + name: APICommand, + movieIds: [MovieID] + }) + .then(function (res) { + console.log(`Got status code '${res.status}'.`) + response.infoLog += `\n☑ Got status code '${res.status}'.`; + resolve(); + }) + .catch(function (error) { + console.log(`Got error: ${error}`) + response.infoLog += `\nGot error: ${error}`; + resolve(); + }); }); - } catch(e) { + } catch (e) { console.log(`Failed API call. Error: '${e}'.`); response.infoLog += `\nFailed API call. Error: '${e}'.`; return response; @@ -229,7 +228,7 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { // Sleep for set amount of time console.log(`Sleeping '${sleepInterval}' ms.`); response.infoLog += `\nSleeping '${sleepInterval}' ms.`; - await new Promise((resolve) => { + await new Promise((resolve) => { setTimeout(() => { resolve(); }, sleepInterval); @@ -239,4 +238,4 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { }; module.exports.details = details; -module.exports.plugin = plugin; +module.exports.plugin = plugin; \ No newline at end of file diff --git a/Community/Tdarr_Plugin_f4k5_aune_rename_files_in_radarr.js b/Community/Tdarr_Plugin_f4k5_aune_rename_files_in_radarr.js index c88f8a025..54cbb4973 100644 --- a/Community/Tdarr_Plugin_f4k5_aune_rename_files_in_radarr.js +++ b/Community/Tdarr_Plugin_f4k5_aune_rename_files_in_radarr.js @@ -15,8 +15,7 @@ const details = () => ({ Version: '1.0', Tags: '3rd party,post-processing,configurable', - Inputs: [ - { + Inputs: [{ name: 'Url_Protocol', type: 'string', defaultValue: 'http', @@ -117,8 +116,8 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { const APIKey = inputs.Radarr_APIKey; const sleepInterval = inputs.After_Sleep; const regex = '(S[0-9]{1,4}E[0-9]{1,2})'; - var term = ""; - var termUri = ""; + let term = ""; + let termUri = ""; const APIPathLookup = '/api/v3/movie/lookup'; const APIPathMoviefile = '/api/v3/moviefile'; const APIPathCommand = '/api/v3/command'; @@ -130,14 +129,14 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { } // Select connection type - var connection_type = null; + let connection_type = null; try { - if(SSL == "http") { + if (SSL == "http") { connection_type = http } else { connection_type = https } - } catch(e) { + } catch (e) { console.log(`Failed to compare SSL string. Error: ${e}`); connection_type = http } @@ -147,7 +146,7 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { term = file.file.split('/'); term = term[term.length - 2]; termUri = encodeURI(term); - } catch(e){ + } catch (e) { console.log(`Failed to split file name. Error: '${e}'.`) response.infoLog += `\nFailed to split file name. Error: '${e}'.`; return response @@ -158,11 +157,11 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { // Define variables to look for Movie ID const url1 = `${SSL}://${IP}:${port}${APIPathLookup}?term=${termUri}&apikey=${APIKey}`; - var url2 = ``; - var url3 = ``; - var MovieID = 0; - var url1_body = ""; - var url2_body = ""; + let url2 = ``; + let url3 = ``; + let MovieID = 0; + let url1_body = ""; + let url2_body = ""; // API call to search for folder name to get Movie ID try { @@ -172,11 +171,11 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { console.log(`Got status code '${res.statusCode}'.`) response.infoLog += `\nGot status code '${res.statusCode}'.`; - res.on("data", function(chunk) { + res.on("data", function (chunk) { url1_body += chunk; }); - res.on('end', function() { + res.on('end', function () { resolve(); }); @@ -186,7 +185,7 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { resolve(); }); }); - } catch(e) { + } catch (e) { console.log(`Failed API call. Error: '${e}'.`); response.infoLog += `\nFailed API call. Error: '${e}'.`; return response; @@ -198,14 +197,14 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { MovieID = APIresponse[0].id; url2 = `${SSL}://${IP}:${port}${APIPathMoviefile}?movieId=${MovieID}&includeImages=false&apikey=${APIKey}`; url3 = `${SSL}://${IP}:${port}${APIPathCommand}?apikey=${APIKey}`; - } catch(e) { + } catch (e) { console.log(`Failed make JSON payload. Error: '${e}'.`); response.infoLog += `\nFailed make JSON payload. Error: '${e}'.`; return response; } // Create array variable for Movie file IDs - var fileArray = []; + let fileArray = []; console.log(`Searching for Movie file IDs for movie '${MovieID}'.`) response.infoLog += `\nSearching for Movie file IDs for movie '${MovieID}'.`; @@ -218,11 +217,11 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { console.log(`Got status code '${res.statusCode}'.`) response.infoLog += `\nGot status code '${res.statusCode}'.`; - res.on("data", function(chunk) { + res.on("data", function (chunk) { url2_body += chunk; }); - res.on('end', function() { + res.on('end', function () { resolve(); }); @@ -232,7 +231,7 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { resolve(); }); }); - } catch(e) { + } catch (e) { console.log(`Failed API call. Error: '${e}'.`); response.infoLog += `\nFailed API call. Error: '${e}'.`; return response; @@ -241,7 +240,7 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { // Parse API response of movie files IDs. Find the movie file ID try { const APIresponse2 = JSON.parse(url2_body); - for(var i = 0; i < APIresponse2.length; i++) { + for (let i = 0; i < APIresponse2.length; i++) { try { fileArray.push(APIresponse2[i].id) } catch { @@ -250,7 +249,7 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { } console.log(`Found '${fileArray.length}' files for movie.`); response.infoLog += `\nFound '${fileArray.length}' files for movie.`; - } catch(e) { + } catch (e) { console.log(`Failed process episodes. Error: '${e}'.`); response.infoLog += `\nFailed process episodes. Error: '${e}'.`; return response; @@ -263,22 +262,22 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { try { await new Promise((resolve) => { axios.post(url3, { - name: APICommand, - movieId: MovieID, - files: fileArray - }) - .then(function (res) { - console.log(`Got status code '${res.status}'.`) - response.infoLog += `\n☑ Got status code '${res.status}'.`; - resolve(); - }) - .catch(function (error) { - console.log(`Got error: ${error}`) - response.infoLog += `\nGot error: ${error}`; - resolve(); - }); + name: APICommand, + movieId: MovieID, + files: fileArray + }) + .then(function (res) { + console.log(`Got status code '${res.status}'.`) + response.infoLog += `\n☑ Got status code '${res.status}'.`; + resolve(); + }) + .catch(function (error) { + console.log(`Got error: ${error}`) + response.infoLog += `\nGot error: ${error}`; + resolve(); + }); }); - } catch(e) { + } catch (e) { console.log(`Failed API call. Error: '${e}'.`); response.infoLog += `\nFailed API call. Error: '${e}'.`; return response; @@ -287,7 +286,7 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { // Sleep for set amount of time console.log(`Sleeping '${sleepInterval}' ms.`); response.infoLog += `\nSleeping '${sleepInterval}' ms.`; - await new Promise((resolve) => { + await new Promise((resolve) => { setTimeout(() => { resolve(); }, sleepInterval); @@ -297,4 +296,4 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { }; module.exports.details = details; -module.exports.plugin = plugin; +module.exports.plugin = plugin; \ No newline at end of file From ba698f95d946c1303af3e41a7de76c29f9f3404a Mon Sep 17 00:00:00 2001 From: aunefyren Date: Wed, 4 Oct 2023 13:53:21 +0200 Subject: [PATCH 7/9] Used wrong linter --- ...ion_remove_stream_by_specified_property.js | 64 ++++++------- ...lugin_f4k2_aune_refresh_files_in_sonarr.js | 94 +++++++++--------- ...Plugin_f4k3_aune_rename_files_in_sonarr.js | 96 +++++++++---------- ...lugin_f4k4_aune_refresh_files_in_radarr.js | 94 +++++++++--------- ...Plugin_f4k5_aune_rename_files_in_radarr.js | 96 +++++++++---------- 5 files changed, 222 insertions(+), 222 deletions(-) diff --git a/Community/Tdarr_Plugin_00td_action_remove_stream_by_specified_property.js b/Community/Tdarr_Plugin_00td_action_remove_stream_by_specified_property.js index 16bb20fd6..a66da913e 100644 --- a/Community/Tdarr_Plugin_00td_action_remove_stream_by_specified_property.js +++ b/Community/Tdarr_Plugin_00td_action_remove_stream_by_specified_property.js @@ -10,60 +10,60 @@ const details = () => ({ Version: '1.00', Tags: 'action', Inputs: [{ - name: 'codecTypeFilter', - type: 'string', - defaultValue: 'subtitle', - inputUI: { - type: 'text', - }, - tooltip: `Enter values of the stream codec type to process. Nothing/empty input means all types of streams will + name: 'codecTypeFilter', + type: 'string', + defaultValue: 'subtitle', + inputUI: { + type: 'text', + }, + tooltip: `Enter values of the stream codec type to process. Nothing/empty input means all types of streams will be inspected for processing. For example, if removing by codec_name on video streams, enter video: \\nExample:\\n video,subtitle,audio `, + }, + { + name: 'propertyToCheck', + type: 'string', + defaultValue: '', + inputUI: { + type: 'text', }, - { - name: 'propertyToCheck', - type: 'string', - defaultValue: '', - inputUI: { - type: 'text', - }, - tooltip: `Enter one stream property to check for values. + tooltip: `Enter one stream property to check for values. \\nExample:\\n codec_name `, + }, + { + name: 'valuesToRemove', + type: 'string', + defaultValue: '', + inputUI: { + type: 'text', }, - { - name: 'valuesToRemove', - type: 'string', - defaultValue: '', - inputUI: { - type: 'text', - }, - tooltip: `Enter values of the property above to remove. For example, if removing by codec_name, could enter ac3,aac: + tooltip: `Enter values of the property above to remove. For example, if removing by codec_name, could enter ac3,aac: \\nExample:\\n ac3,aac `, + }, + { + name: 'removeIfPropertyMissing', + type: 'string', + defaultValue: '', + inputUI: { + type: 'text', }, - { - name: 'removeIfPropertyMissing', - type: 'string', - defaultValue: '', - inputUI: { - type: 'text', - }, - tooltip: `Enter one or more properties to check for its existance. If the property is missing or null, + tooltip: `Enter one or more properties to check for its existance. If the property is missing or null, the stream will be removed. Useful for fixing corrupt streams. For example, if codec_name is missing, the stream will be removed: \\nExample:\\n codec_name `, - }, + }, ], }); diff --git a/Community/Tdarr_Plugin_f4k2_aune_refresh_files_in_sonarr.js b/Community/Tdarr_Plugin_f4k2_aune_refresh_files_in_sonarr.js index 941d9c9e8..28b7ce9b3 100644 --- a/Community/Tdarr_Plugin_f4k2_aune_refresh_files_in_sonarr.js +++ b/Community/Tdarr_Plugin_f4k2_aune_refresh_files_in_sonarr.js @@ -18,74 +18,74 @@ const details = () => ({ Tags: '3rd party,post-processing,configurable', Inputs: [{ - name: 'Url_Protocol', - type: 'string', - defaultValue: 'http', - inputUI: { - type: 'dropdown', - options: [ - 'http', - 'https', - ], - }, - tooltip: ` + name: 'Url_Protocol', + type: 'string', + defaultValue: 'http', + inputUI: { + type: 'dropdown', + options: [ + 'http', + 'https', + ], + }, + tooltip: ` Specified the type of request to make, http:// or https:// \\nExample:\\n http \\nExample:\\n https`, + }, + { + name: 'Url_Sonarr', + type: 'string', + defaultValue: 'localhost', + inputUI: { + type: 'text', }, - { - name: 'Url_Sonarr', - type: 'string', - defaultValue: 'localhost', - inputUI: { - type: 'text', - }, - tooltip: ` + tooltip: ` Enter the IP address/URL Tdarr uses to reach Sonarr. \\nExample:\\n 192.168.0.10 \\nExample:\\n subdomain.domain.tld`, + }, + { + name: 'Sonarr_Port', + type: 'number', + defaultValue: 8989, + inputUI: { + type: 'text', }, - { - name: 'Sonarr_Port', - type: 'number', - defaultValue: 8989, - inputUI: { - type: 'text', - }, - tooltip: ` + tooltip: ` The port required to access Sonarr \\nExample:\\n 8989`, + }, + { + name: 'Sonarr_APIKey', + type: 'string', + defaultValue: '', + inputUI: { + type: 'text', }, - { - name: 'Sonarr_APIKey', - type: 'string', - defaultValue: '', - inputUI: { - type: 'text', - }, - tooltip: ` + tooltip: ` Enter the Sonarr API key. \\n You can find it within Sonarr at /settings/general. \\n\\n \\nExample:\\n 3ff1ae1c39a2a2a397315e15266dea48`, + }, + { + name: 'After_Sleep', + type: 'number', + defaultValue: 0, + inputUI: { + type: 'text', }, - { - name: 'After_Sleep', - type: 'number', - defaultValue: 0, - inputUI: { - type: 'text', - }, - tooltip: ` + tooltip: ` How many ms should Tdarr sleep to wait for Sonarr to finish afterward? \\n \\nExample:\\n 1000`, - }, + }, ], }); @@ -213,9 +213,9 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { try { await new Promise((resolve) => { axios.post(url2, { - name: APICommand, - seriesId: SeriesID - }) + name: APICommand, + seriesId: SeriesID + }) .then(function (res) { console.log(`Got status code '${res.status}'.`) response.infoLog += `\n☑ Got status code '${res.status}'.`; diff --git a/Community/Tdarr_Plugin_f4k3_aune_rename_files_in_sonarr.js b/Community/Tdarr_Plugin_f4k3_aune_rename_files_in_sonarr.js index 0a9b26a97..0d7b992af 100644 --- a/Community/Tdarr_Plugin_f4k3_aune_rename_files_in_sonarr.js +++ b/Community/Tdarr_Plugin_f4k3_aune_rename_files_in_sonarr.js @@ -16,74 +16,74 @@ const details = () => ({ Tags: '3rd party,post-processing,configurable', Inputs: [{ - name: 'Url_Protocol', - type: 'string', - defaultValue: 'http', - inputUI: { - type: 'dropdown', - options: [ - 'http', - 'https', - ], - }, - tooltip: ` + name: 'Url_Protocol', + type: 'string', + defaultValue: 'http', + inputUI: { + type: 'dropdown', + options: [ + 'http', + 'https', + ], + }, + tooltip: ` Specified the type of request to make, http:// or https:// \\nExample:\\n http \\nExample:\\n https`, + }, + { + name: 'Url_Sonarr', + type: 'string', + defaultValue: 'localhost', + inputUI: { + type: 'text', }, - { - name: 'Url_Sonarr', - type: 'string', - defaultValue: 'localhost', - inputUI: { - type: 'text', - }, - tooltip: ` + tooltip: ` Enter the IP address/URL Tdarr uses to reach Sonarr. \\nExample:\\n 192.168.0.10 \\nExample:\\n subdomain.domain.tld`, + }, + { + name: 'Sonarr_Port', + type: 'number', + defaultValue: 8989, + inputUI: { + type: 'text', }, - { - name: 'Sonarr_Port', - type: 'number', - defaultValue: 8989, - inputUI: { - type: 'text', - }, - tooltip: ` + tooltip: ` The port required to access Sonarr \\nExample:\\n 8989`, + }, + { + name: 'Sonarr_APIKey', + type: 'string', + defaultValue: '', + inputUI: { + type: 'text', }, - { - name: 'Sonarr_APIKey', - type: 'string', - defaultValue: '', - inputUI: { - type: 'text', - }, - tooltip: ` + tooltip: ` Enter the Sonarr API key. \\n You can find it within Sonarr at /settings/general. \\n\\n \\nExample:\\n 3ff1ae1c39a2a2a397315e15266dea48`, + }, + { + name: 'After_Sleep', + type: 'number', + defaultValue: 0, + inputUI: { + type: 'text', }, - { - name: 'After_Sleep', - type: 'number', - defaultValue: 0, - inputUI: { - type: 'text', - }, - tooltip: ` + tooltip: ` How many ms should Tdarr sleep to wait for Sonarr to finish afterward? \\n \\nExample:\\n 1000`, - }, + }, ], }); @@ -286,10 +286,10 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { try { await new Promise((resolve) => { axios.post(url3, { - name: APICommand, - seriesId: SeriesID, - files: fileArray - }) + name: APICommand, + seriesId: SeriesID, + files: fileArray + }) .then(function (res) { console.log(`Got status code '${res.status}'.`) response.infoLog += `\n☑ Got status code '${res.status}'.`; diff --git a/Community/Tdarr_Plugin_f4k4_aune_refresh_files_in_radarr.js b/Community/Tdarr_Plugin_f4k4_aune_refresh_files_in_radarr.js index 71f06bdb3..c7051a7e4 100644 --- a/Community/Tdarr_Plugin_f4k4_aune_refresh_files_in_radarr.js +++ b/Community/Tdarr_Plugin_f4k4_aune_refresh_files_in_radarr.js @@ -16,74 +16,74 @@ const details = () => ({ Tags: '3rd party,post-processing,configurable', Inputs: [{ - name: 'Url_Protocol', - type: 'string', - defaultValue: 'http', - inputUI: { - type: 'dropdown', - options: [ - 'http', - 'https', - ], - }, - tooltip: ` + name: 'Url_Protocol', + type: 'string', + defaultValue: 'http', + inputUI: { + type: 'dropdown', + options: [ + 'http', + 'https', + ], + }, + tooltip: ` Specified the type of request to make, http:// or https:// \\nExample:\\n http \\nExample:\\n https`, + }, + { + name: 'Url_Radarr', + type: 'string', + defaultValue: 'localhost', + inputUI: { + type: 'text', }, - { - name: 'Url_Radarr', - type: 'string', - defaultValue: 'localhost', - inputUI: { - type: 'text', - }, - tooltip: ` + tooltip: ` Enter the IP address/URL Tdarr uses to reach Radarr. \\nExample:\\n 192.168.0.10 \\nExample:\\n subdomain.domain.tld`, + }, + { + name: 'Radarr_Port', + type: 'number', + defaultValue: 7878, + inputUI: { + type: 'text', }, - { - name: 'Radarr_Port', - type: 'number', - defaultValue: 7878, - inputUI: { - type: 'text', - }, - tooltip: ` + tooltip: ` The port required to access Radarr \\nExample:\\n 7878`, + }, + { + name: 'Radarr_APIKey', + type: 'string', + defaultValue: '', + inputUI: { + type: 'text', }, - { - name: 'Radarr_APIKey', - type: 'string', - defaultValue: '', - inputUI: { - type: 'text', - }, - tooltip: ` + tooltip: ` Enter the Radarr API key. \\n You can find it within Radarr at /settings/general. \\n\\n \\nExample:\\n 3ff1ae1c39a2a2a397315e15266dea48`, + }, + { + name: 'After_Sleep', + type: 'number', + defaultValue: 0, + inputUI: { + type: 'text', }, - { - name: 'After_Sleep', - type: 'number', - defaultValue: 0, - inputUI: { - type: 'text', - }, - tooltip: ` + tooltip: ` How many ms should Tdarr sleep to wait for Radarr to finish afterward? \\n \\nExample:\\n 1000`, - }, + }, ], }); @@ -205,9 +205,9 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { try { await new Promise((resolve) => { axios.post(url2, { - name: APICommand, - movieIds: [MovieID] - }) + name: APICommand, + movieIds: [MovieID] + }) .then(function (res) { console.log(`Got status code '${res.status}'.`) response.infoLog += `\n☑ Got status code '${res.status}'.`; diff --git a/Community/Tdarr_Plugin_f4k5_aune_rename_files_in_radarr.js b/Community/Tdarr_Plugin_f4k5_aune_rename_files_in_radarr.js index 54cbb4973..80b14008e 100644 --- a/Community/Tdarr_Plugin_f4k5_aune_rename_files_in_radarr.js +++ b/Community/Tdarr_Plugin_f4k5_aune_rename_files_in_radarr.js @@ -16,74 +16,74 @@ const details = () => ({ Tags: '3rd party,post-processing,configurable', Inputs: [{ - name: 'Url_Protocol', - type: 'string', - defaultValue: 'http', - inputUI: { - type: 'dropdown', - options: [ - 'http', - 'https', - ], - }, - tooltip: ` + name: 'Url_Protocol', + type: 'string', + defaultValue: 'http', + inputUI: { + type: 'dropdown', + options: [ + 'http', + 'https', + ], + }, + tooltip: ` Specified the type of request to make, http:// or https:// \\nExample:\\n http \\nExample:\\n https`, + }, + { + name: 'Url_Radarr', + type: 'string', + defaultValue: 'localhost', + inputUI: { + type: 'text', }, - { - name: 'Url_Radarr', - type: 'string', - defaultValue: 'localhost', - inputUI: { - type: 'text', - }, - tooltip: ` + tooltip: ` Enter the IP address/URL Tdarr uses to reach Radarr. \\nExample:\\n 192.168.0.10 \\nExample:\\n subdomain.domain.tld`, + }, + { + name: 'Radarr_Port', + type: 'number', + defaultValue: 7878, + inputUI: { + type: 'text', }, - { - name: 'Radarr_Port', - type: 'number', - defaultValue: 7878, - inputUI: { - type: 'text', - }, - tooltip: ` + tooltip: ` The port required to access Radarr \\nExample:\\n 7878`, + }, + { + name: 'Radarr_APIKey', + type: 'string', + defaultValue: '', + inputUI: { + type: 'text', }, - { - name: 'Radarr_APIKey', - type: 'string', - defaultValue: '', - inputUI: { - type: 'text', - }, - tooltip: ` + tooltip: ` Enter the Radarr API key. \\n You can find it within Radarr at /settings/general. \\n\\n \\nExample:\\n 3ff1ae1c39a2a2a397315e15266dea48`, + }, + { + name: 'After_Sleep', + type: 'number', + defaultValue: 0, + inputUI: { + type: 'text', }, - { - name: 'After_Sleep', - type: 'number', - defaultValue: 0, - inputUI: { - type: 'text', - }, - tooltip: ` + tooltip: ` How many ms should Tdarr sleep to wait for Radarr to finish afterward? \\n \\nExample:\\n 1000`, - }, + }, ], }); @@ -262,10 +262,10 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { try { await new Promise((resolve) => { axios.post(url3, { - name: APICommand, - movieId: MovieID, - files: fileArray - }) + name: APICommand, + movieId: MovieID, + files: fileArray + }) .then(function (res) { console.log(`Got status code '${res.status}'.`) response.infoLog += `\n☑ Got status code '${res.status}'.`; From bf5e7de79e0935aeee7e3a59a93b7eacd9e31d28 Mon Sep 17 00:00:00 2001 From: aunefyren Date: Wed, 4 Oct 2023 14:26:25 +0200 Subject: [PATCH 8/9] Linting and new-line fixes --- ...ion_remove_stream_by_specified_property.js | 14 ++-- ...lugin_f4k2_aune_refresh_files_in_sonarr.js | 65 +++++++------- ...Plugin_f4k3_aune_rename_files_in_sonarr.js | 84 +++++++++---------- ...lugin_f4k4_aune_refresh_files_in_radarr.js | 52 ++++++------ ...Plugin_f4k5_aune_rename_files_in_radarr.js | 76 ++++++++--------- 5 files changed, 145 insertions(+), 146 deletions(-) diff --git a/Community/Tdarr_Plugin_00td_action_remove_stream_by_specified_property.js b/Community/Tdarr_Plugin_00td_action_remove_stream_by_specified_property.js index a66da913e..b02ca1062 100644 --- a/Community/Tdarr_Plugin_00td_action_remove_stream_by_specified_property.js +++ b/Community/Tdarr_Plugin_00td_action_remove_stream_by_specified_property.js @@ -112,8 +112,8 @@ const plugin = (file, librarySettings, inputs, otherArguments) => { try { // Skip if the codec_type is filtered out if ( - codecTypeFilter.length !== 0 && - !codecTypeFilter.includes(String(file.ffProbeData.streams[i].codec_type))) { + codecTypeFilter.length !== 0 + && !codecTypeFilter.includes(String(file.ffProbeData.streams[i].codec_type))) { continue; } @@ -125,8 +125,8 @@ const plugin = (file, librarySettings, inputs, otherArguments) => { is ${file.ffProbeData.streams[i][removeIfPropertyMissing[j]]} \n`; if ( - file.ffProbeData.streams[i][removeIfPropertyMissing[j]] === 'undefined' || - file.ffProbeData.streams[i][removeIfPropertyMissing[j]] === null) { + file.ffProbeData.streams[i][removeIfPropertyMissing[j]] === 'undefined' + || file.ffProbeData.streams[i][removeIfPropertyMissing[j]] === null) { emptyValue = true; response.infoLog += ` Removing stream ${i} which is has ${removeIfPropertyMissing[j]} missing`; break; @@ -140,8 +140,8 @@ const plugin = (file, librarySettings, inputs, otherArguments) => { // Log the old message if the reason is not empty values if (!emptyValue) { - response.infoLog += ` Removing stream ${i} which is has ${propertyToCheck} or` + - ` of ${file.ffProbeData.streams[i][propertyToCheck]} \n`; + response.infoLog += ` Removing stream ${i} which is has ${propertyToCheck} or` + + ` of ${file.ffProbeData.streams[i][propertyToCheck]} \n`; } streamToRemove = true; @@ -165,4 +165,4 @@ const plugin = (file, librarySettings, inputs, otherArguments) => { }; module.exports.details = details; -module.exports.plugin = plugin; \ No newline at end of file +module.exports.plugin = plugin; diff --git a/Community/Tdarr_Plugin_f4k2_aune_refresh_files_in_sonarr.js b/Community/Tdarr_Plugin_f4k2_aune_refresh_files_in_sonarr.js index 28b7ce9b3..b498ef3d3 100644 --- a/Community/Tdarr_Plugin_f4k2_aune_refresh_files_in_sonarr.js +++ b/Community/Tdarr_Plugin_f4k2_aune_refresh_files_in_sonarr.js @@ -106,7 +106,7 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { infoLog: 'Refresh Sonarr files starting.', }; - console.log("Refresh Sonarr files starting.") + //console.log('Refresh Sonarr files starting.'); const lib = require('../methods/lib')(); // eslint-disable-next-line no-unused-vars,no-param-reassign @@ -115,7 +115,7 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { const https = require('https'); const axios = require('axios'); - console.log("Loaded required packages.") + //console.log('Loaded required packages.'); // Create variables const SSL = inputs.Url_Protocol; @@ -123,8 +123,8 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { const port = inputs.Sonarr_Port; const APIKey = inputs.Sonarr_APIKey; const sleepInterval = inputs.After_Sleep; - let term = ""; - let termUri = ""; + let term = ''; + let termUri = ''; const APIPathLookup = '/api/v3/series/lookup'; const APIPathCommand = '/api/v3/command'; const APICommand = 'RefreshSeries'; @@ -137,13 +137,13 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { // Select connection type let connection_type = null; try { - if (SSL == "http") { + if (SSL == 'http') { connection_type = http } else { connection_type = https } } catch (e) { - console.log(`Failed to compare SSL string. Error: ${e}`); + //console.log(`Failed to compare SSL string. Error: ${e}`); connection_type = http } @@ -153,17 +153,17 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { term = term[term.length - 3]; termUri = encodeURI(term); } catch (e) { - console.log(`Failed to split file name. Error: '${e}'.\n`) - response.infoLog += `\nFailed to split file name. Error: '${e}'.`; + //console.log(`Failed to split file name. Error: '${e}'.\\n`); + response.infoLog += `\\nFailed to split file name. Error: '${e}'.`; return response } - console.log(`Searching for series '${term}'.`) - response.infoLog += `\nSearching for series '${term}'.`; + //console.log(`Searching for series '${term}'.`); + response.infoLog += `\\nSearching for series '${term}'.`; // Create variables for API call const url1 = `${SSL}://${IP}:${port}${APIPathLookup}?term=${termUri}&apikey=${APIKey}`; - let url1_body = ""; + let url1_body = ''; let url2 = ``; let SeriesID = 0; @@ -171,11 +171,10 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { try { await new Promise((resolve) => { connection_type.get(url1, (res) => { + //console.log(`Got status code '${res.statusCode}'.`); + response.infoLog += `\\nGot status code '${res.statusCode}'.`; - console.log(`Got status code '${res.statusCode}'.`) - response.infoLog += `\nGot status code '${res.statusCode}'.`; - - res.on("data", function (chunk) { + res.on('data', function (chunk) { url1_body += chunk; }); @@ -184,14 +183,14 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { }); }).on('error', (e) => { - console.log(`Failed to search for series. Error: '${e}'.`) - response.infoLog += `\nFailed to search for series. Error: '${e}'.`; + //console.log(`Failed to search for series. Error: '${e}'.`); + response.infoLog += `\\nFailed to search for series. Error: '${e}'.`; resolve(); }); }); } catch (e) { - console.log(`Failed API call. Error: '${e}'.`); - response.infoLog += `\nFailed API call. Error: '${e}'.`; + //console.log(`Failed API call. Error: '${e}'.`); + response.infoLog += `\\nFailed API call. Error: '${e}'.`; return response; } @@ -201,45 +200,45 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { SeriesID = APIresponse[0].id; url2 = `${SSL}://${IP}:${port}${APIPathCommand}?apikey=${APIKey}`; } catch (e) { - console.log(`Failed make JSON payload. Error: '${e}'.`); - response.infoLog += `\nFailed make JSON payload. Error: '${e}'.`; + //console.log(`Failed make JSON payload. Error: '${e}'.`); + response.infoLog += `\\nFailed make JSON payload. Error: '${e}'.`; return response; } - console.log(`Refreshing series '${SeriesID}'.`); - response.infoLog += `\nRefreshing series '${SeriesID}'.`; + //console.log(`Refreshing series '${SeriesID}'.`); + response.infoLog += `\\nRefreshing series '${SeriesID}'.`; // API request to send a command to refresh the files for the found Series ID try { await new Promise((resolve) => { axios.post(url2, { name: APICommand, - seriesId: SeriesID + seriesId: SeriesID, }) .then(function (res) { - console.log(`Got status code '${res.status}'.`) - response.infoLog += `\n☑ Got status code '${res.status}'.`; + //console.log(`Got status code '${res.status}'.`); + response.infoLog += `\\n☑ Got status code '${res.status}'.`; resolve(); }) .catch(function (error) { - console.log(`Got error: ${error}`) - response.infoLog += `\nGot error: ${error}`; + //console.log(`Got error: ${error}`); + response.infoLog += `\\nGot error: ${error}`; resolve(); }); }); } catch (e) { - console.log(`Failed API call. Error: '${e}'.`); - response.infoLog += `\nFailed API call. Error: '${e}'.`; + // console.log(`Failed API call. Error: '${e}'.`); + response.infoLog += `\\nFailed API call. Error: '${e}'.`; return response; } // Sleep for set amount of time - console.log(`Sleeping '${sleepInterval}' ms.`); - response.infoLog += `\nSleeping '${sleepInterval}' ms.`; + // console.log(`Sleeping '${sleepInterval}' ms.`); + response.infoLog += `\\nSleeping '${sleepInterval}' ms.`; await sleep(sleepInterval); return response; }; module.exports.details = details; -module.exports.plugin = plugin; \ No newline at end of file +module.exports.plugin = plugin; diff --git a/Community/Tdarr_Plugin_f4k3_aune_rename_files_in_sonarr.js b/Community/Tdarr_Plugin_f4k3_aune_rename_files_in_sonarr.js index 0d7b992af..d738b29e2 100644 --- a/Community/Tdarr_Plugin_f4k3_aune_rename_files_in_sonarr.js +++ b/Community/Tdarr_Plugin_f4k3_aune_rename_files_in_sonarr.js @@ -104,7 +104,7 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { infoLog: 'Rename Sonarr files starting.', }; - console.log("Rename Sonarr files starting.") + //console.log("Rename Sonarr files starting.") const lib = require('../methods/lib')(); // eslint-disable-next-line no-unused-vars,no-param-reassign @@ -113,7 +113,7 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { const https = require('https'); const axios = require('axios'); - console.log("Loaded required packages.") + //console.log("Loaded required packages.") // Defines variables const SSL = inputs.Url_Protocol; @@ -144,7 +144,7 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { connection_type = https } } catch (e) { - console.log(`Failed to compare SSL string. Error: ${e}`); + //console.log(`Failed to compare SSL string. Error: ${e}`); connection_type = http } @@ -157,23 +157,23 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { // Use Regex to find SXXXXEXX part of file name and save it let seasonEpisodeMatch_tmp = file.file.toString().match(regex) if (seasonEpisodeMatch_tmp == null) { - console.log(`Failed to find SXXEXX in filename.`) - response.infoLog += `\nFailed to find SXXEXX in filename.`; + //console.log(`Failed to find SXXEXX in filename.`) + response.infoLog += `\\nFailed to find SXXEXX in filename.`; return response } else { seasonEpisodeMatch = seasonEpisodeMatch_tmp[0]; } } catch (e) { - console.log(`Failed to split file name or find episode nr. Error: '${e}'.`) - response.infoLog += `\nFailed to split file name or find episode nr. Error: '${e}'.`; + //console.log(`Failed to split file name or find episode nr. Error: '${e}'.`) + response.infoLog += `\\nFailed to split file name or find episode nr. Error: '${e}'.`; return response } - console.log(`Landed on '${seasonEpisodeMatch}'.`) - response.infoLog += `\nLanded on '${seasonEpisodeMatch}'.`; + //console.log(`Landed on '${seasonEpisodeMatch}'.`) + response.infoLog += `\\nLanded on '${seasonEpisodeMatch}'.`; - console.log(`Searching for series '${term}'.`) - response.infoLog += `\nSearching for series '${term}'.`; + //console.log(`Searching for series '${term}'.`) + response.infoLog += `\\nSearching for series '${term}'.`; // Define variables to look for Series ID const url1 = `${SSL}://${IP}:${port}${APIPathLookup}?term=${termUri}&apikey=${APIKey}`; @@ -188,8 +188,8 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { await new Promise((resolve) => { connection_type.get(url1, (res) => { - console.log(`Got status code '${res.statusCode}'.`) - response.infoLog += `\nGot status code '${res.statusCode}'.`; + //console.log(`Got status code '${res.statusCode}'.`) + response.infoLog += `\\nGot status code '${res.statusCode}'.`; res.on("data", function (chunk) { url1_body += chunk; @@ -200,14 +200,14 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { }); }).on('error', (e) => { - console.log(`Failed to search for series. Error: '${e}'.`) - response.infoLog += `\nFailed to search for series. Error: '${e}'.`; + //console.log(`Failed to search for series. Error: '${e}'.`) + response.infoLog += `\\nFailed to search for series. Error: '${e}'.`; resolve(); }); }); } catch (e) { - console.log(`Failed API call. Error: '${e}'.`); - response.infoLog += `\nFailed API call. Error: '${e}'.`; + //console.log(`Failed API call. Error: '${e}'.`); + response.infoLog += `\\nFailed API call. Error: '${e}'.`; return response; } @@ -218,24 +218,24 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { url2 = `${SSL}://${IP}:${port}${APIPathEpisodefile}?seriesId=${SeriesID}&includeImages=false&apikey=${APIKey}`; url3 = `${SSL}://${IP}:${port}${APIPathCommand}?apikey=${APIKey}`; } catch (e) { - console.log(`Failed make JSON payload. Error: '${e}'.`); - response.infoLog += `\nFailed make JSON payload. Error: '${e}'.`; + //console.log(`Failed make JSON payload. Error: '${e}'.`); + response.infoLog += `\\nFailed make JSON payload. Error: '${e}'.`; return response; } // Create array variable for Episode IDs let fileArray = []; - console.log(`Searching for episode files for show '${SeriesID}'.`) - response.infoLog += `\nSearching for episode files for show '${SeriesID}'.`; + //console.log(`Searching for episode files for show '${SeriesID}'.`) + response.infoLog += `\\nSearching for episode files for show '${SeriesID}'.`; // API call to find Episode IDs for Series ID try { await new Promise((resolve) => { connection_type.get(url2, (res) => { - console.log(`Got status code '${res.statusCode}'.`) - response.infoLog += `\nGot status code '${res.statusCode}'.`; + //console.log(`Got status code '${res.statusCode}'.`) + response.infoLog += `\\nGot status code '${res.statusCode}'.`; res.on("data", function (chunk) { url2_body += chunk; @@ -246,14 +246,14 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { }); }).on('error', (e) => { - console.log(`Failed to search for files for series. Error: '${e}'.`) - response.infoLog += `\nFailed to search for files for series. Error: '${e}'.`; + //console.log(`Failed to search for files for series. Error: '${e}'.`) + response.infoLog += `\\nFailed to search for files for series. Error: '${e}'.`; resolve(); }); }); } catch (e) { - console.log(`Failed API call. Error: '${e}'.`); - response.infoLog += `\nFailed API call. Error: '${e}'.`; + //console.log(`Failed API call. Error: '${e}'.`); + response.infoLog += `\\nFailed API call. Error: '${e}'.`; return response; } @@ -271,16 +271,16 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { continue; } } - console.log(`Found '${fileArray.length}' files for series.`); - response.infoLog += `\nFound '${fileArray.length}' files for series.`; + //console.log(`Found '${fileArray.length}' files for series.`); + response.infoLog += `\\nFound '${fileArray.length}' files for series.`; } catch (e) { - console.log(`Failed process episodes. Error: '${e}'.`); - response.infoLog += `\nFailed process episodes. Error: '${e}'.`; + //console.log(`Failed process episodes. Error: '${e}'.`); + response.infoLog += `\\nFailed process episodes. Error: '${e}'.`; return response; } - console.log(`Renaming files for series '${SeriesID}'.`); - response.infoLog += `\nRenaming files for series '${SeriesID}'.`; + //console.log(`Renaming files for series '${SeriesID}'.`); + response.infoLog += `\\nRenaming files for series '${SeriesID}'.`; // API call to rename the found Episode IDs for the Series ID try { @@ -291,29 +291,29 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { files: fileArray }) .then(function (res) { - console.log(`Got status code '${res.status}'.`) - response.infoLog += `\n☑ Got status code '${res.status}'.`; + //console.log(`Got status code '${res.status}'.`) + response.infoLog += `\\n☑ Got status code '${res.status}'.`; resolve(); }) .catch(function (error) { - console.log(`Got error: ${error}`) - response.infoLog += `\nGot error: ${error}`; + //console.log(`Got error: ${error}`) + response.infoLog += `\\nGot error: ${error}`; resolve(); }); }); } catch (e) { - console.log(`Failed API call. Error: '${e}'.`); - response.infoLog += `\nFailed API call. Error: '${e}'.`; + //console.log(`Failed API call. Error: '${e}'.`); + response.infoLog += `\\nFailed API call. Error: '${e}'.`; return response; } // Sleep for set amount of time - console.log(`Sleeping '${sleepInterval}' ms.`); - response.infoLog += `\nSleeping '${sleepInterval}' ms.`; + //console.log(`Sleeping '${sleepInterval}' ms.`); + response.infoLog += `\\nSleeping '${sleepInterval}' ms.`; await sleep(sleepInterval); return response; }; module.exports.details = details; -module.exports.plugin = plugin; \ No newline at end of file +module.exports.plugin = plugin; diff --git a/Community/Tdarr_Plugin_f4k4_aune_refresh_files_in_radarr.js b/Community/Tdarr_Plugin_f4k4_aune_refresh_files_in_radarr.js index c7051a7e4..44f3db4ef 100644 --- a/Community/Tdarr_Plugin_f4k4_aune_refresh_files_in_radarr.js +++ b/Community/Tdarr_Plugin_f4k4_aune_refresh_files_in_radarr.js @@ -98,7 +98,7 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { infoLog: 'Refresh Radarr files starting.', }; - console.log("Refresh Radarr files starting.") + //console.log("Refresh Radarr files starting.") const lib = require('../methods/lib')(); // eslint-disable-next-line no-unused-vars,no-param-reassign @@ -107,7 +107,7 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { const https = require('https'); const axios = require('axios'); - console.log("Loaded required packages.") + //console.log("Loaded required packages.") // Create variables const SSL = inputs.Url_Protocol; @@ -135,7 +135,7 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { connection_type = https } } catch (e) { - console.log(`Failed to compare SSL string. Error: ${e}`); + //console.log(`Failed to compare SSL string. Error: ${e}`); connection_type = http } @@ -145,13 +145,13 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { term = term[term.length - 2]; termUri = encodeURI(term); } catch (e) { - console.log(`Failed to split file name. Error: '${e}'.\n`) - response.infoLog += `\nFailed to split file name. Error: '${e}'.`; + //console.log(`Failed to split file name. Error: '${e}'.\\n`) + response.infoLog += `\\nFailed to split file name. Error: '${e}'.`; return response } - console.log(`Searching for movie '${term}'.`) - response.infoLog += `\nSearching for movie '${term}'.`; + //console.log(`Searching for movie '${term}'.`) + response.infoLog += `\\nSearching for movie '${term}'.`; // Create variables for API call const url1 = `${SSL}://${IP}:${port}${APIPathLookup}?term=${termUri}&apikey=${APIKey}`; @@ -164,8 +164,8 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { await new Promise((resolve) => { connection_type.get(url1, (res) => { - console.log(`Got status code '${res.statusCode}'.`) - response.infoLog += `\nGot status code '${res.statusCode}'.`; + //console.log(`Got status code '${res.statusCode}'.`) + response.infoLog += `\\nGot status code '${res.statusCode}'.`; res.on("data", function (chunk) { url1_body += chunk; @@ -176,14 +176,14 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { }); }).on('error', (e) => { - console.log(`Failed to search for movie. Error: '${e}'.`) - response.infoLog += `\nFailed to search for movie. Error: '${e}'.`; + //console.log(`Failed to search for movie. Error: '${e}'.`) + response.infoLog += `\\nFailed to search for movie. Error: '${e}'.`; resolve(); }); }); } catch (e) { - console.log(`Failed API call. Error: '${e}'.`); - response.infoLog += `\nFailed API call. Error: '${e}'.`; + //console.log(`Failed API call. Error: '${e}'.`); + response.infoLog += `\\nFailed API call. Error: '${e}'.`; return response; } @@ -193,13 +193,13 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { MovieID = APIresponse[0].id; url2 = `${SSL}://${IP}:${port}${APIPathCommand}?apikey=${APIKey}`; } catch (e) { - console.log(`Failed make JSON payload. Error: '${e}'.`); - response.infoLog += `\nFailed make JSON payload. Error: '${e}'.`; + //console.log(`Failed make JSON payload. Error: '${e}'.`); + response.infoLog += `\\nFailed make JSON payload. Error: '${e}'.`; return response; } - console.log(`Refreshing movie '${MovieID}'.`); - response.infoLog += `\nRefreshing movie '${MovieID}'.`; + //console.log(`Refreshing movie '${MovieID}'.`); + response.infoLog += `\\nRefreshing movie '${MovieID}'.`; // API request to send a command to refresh the files for the found Movie ID try { @@ -209,25 +209,25 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { movieIds: [MovieID] }) .then(function (res) { - console.log(`Got status code '${res.status}'.`) - response.infoLog += `\n☑ Got status code '${res.status}'.`; + //console.log(`Got status code '${res.status}'.`) + response.infoLog += `\\n☑ Got status code '${res.status}'.`; resolve(); }) .catch(function (error) { - console.log(`Got error: ${error}`) - response.infoLog += `\nGot error: ${error}`; + //console.log(`Got error: ${error}`) + response.infoLog += `\\nGot error: ${error}`; resolve(); }); }); } catch (e) { - console.log(`Failed API call. Error: '${e}'.`); - response.infoLog += `\nFailed API call. Error: '${e}'.`; + //console.log(`Failed API call. Error: '${e}'.`); + response.infoLog += `\\nFailed API call. Error: '${e}'.`; return response; } // Sleep for set amount of time - console.log(`Sleeping '${sleepInterval}' ms.`); - response.infoLog += `\nSleeping '${sleepInterval}' ms.`; + //console.log(`Sleeping '${sleepInterval}' ms.`); + response.infoLog += `\\nSleeping '${sleepInterval}' ms.`; await new Promise((resolve) => { setTimeout(() => { resolve(); @@ -238,4 +238,4 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { }; module.exports.details = details; -module.exports.plugin = plugin; \ No newline at end of file +module.exports.plugin = plugin; diff --git a/Community/Tdarr_Plugin_f4k5_aune_rename_files_in_radarr.js b/Community/Tdarr_Plugin_f4k5_aune_rename_files_in_radarr.js index 80b14008e..d0873ad6a 100644 --- a/Community/Tdarr_Plugin_f4k5_aune_rename_files_in_radarr.js +++ b/Community/Tdarr_Plugin_f4k5_aune_rename_files_in_radarr.js @@ -98,7 +98,7 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { infoLog: 'Rename Radarr files starting.', }; - console.log("Rename Radarr files starting.") + //console.log("Rename Radarr files starting.") const lib = require('../methods/lib')(); // eslint-disable-next-line no-unused-vars,no-param-reassign @@ -107,7 +107,7 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { const https = require('https'); const axios = require('axios'); - console.log("Loaded required packages.") + //console.log("Loaded required packages.") // Defines variables const SSL = inputs.Url_Protocol; @@ -137,7 +137,7 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { connection_type = https } } catch (e) { - console.log(`Failed to compare SSL string. Error: ${e}`); + //console.log(`Failed to compare SSL string. Error: ${e}`); connection_type = http } @@ -147,13 +147,13 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { term = term[term.length - 2]; termUri = encodeURI(term); } catch (e) { - console.log(`Failed to split file name. Error: '${e}'.`) - response.infoLog += `\nFailed to split file name. Error: '${e}'.`; + //console.log(`Failed to split file name. Error: '${e}'.`) + response.infoLog += `\\nFailed to split file name. Error: '${e}'.`; return response } - console.log(`Searching for movie '${term}'.`) - response.infoLog += `\nSearching for movie '${term}'.`; + //console.log(`Searching for movie '${term}'.`) + response.infoLog += `\\nSearching for movie '${term}'.`; // Define variables to look for Movie ID const url1 = `${SSL}://${IP}:${port}${APIPathLookup}?term=${termUri}&apikey=${APIKey}`; @@ -168,8 +168,8 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { await new Promise((resolve) => { connection_type.get(url1, (res) => { - console.log(`Got status code '${res.statusCode}'.`) - response.infoLog += `\nGot status code '${res.statusCode}'.`; + //console.log(`Got status code '${res.statusCode}'.`) + response.infoLog += `\\nGot status code '${res.statusCode}'.`; res.on("data", function (chunk) { url1_body += chunk; @@ -180,14 +180,14 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { }); }).on('error', (e) => { - console.log(`Failed to search for movie. Error: '${e}'.`) - response.infoLog += `\nFailed to search for movie. Error: '${e}'.`; + //console.log(`Failed to search for movie. Error: '${e}'.`) + response.infoLog += `\\nFailed to search for movie. Error: '${e}'.`; resolve(); }); }); } catch (e) { - console.log(`Failed API call. Error: '${e}'.`); - response.infoLog += `\nFailed API call. Error: '${e}'.`; + //console.log(`Failed API call. Error: '${e}'.`); + response.infoLog += `\\nFailed API call. Error: '${e}'.`; return response; } @@ -198,24 +198,24 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { url2 = `${SSL}://${IP}:${port}${APIPathMoviefile}?movieId=${MovieID}&includeImages=false&apikey=${APIKey}`; url3 = `${SSL}://${IP}:${port}${APIPathCommand}?apikey=${APIKey}`; } catch (e) { - console.log(`Failed make JSON payload. Error: '${e}'.`); - response.infoLog += `\nFailed make JSON payload. Error: '${e}'.`; + //console.log(`Failed make JSON payload. Error: '${e}'.`); + response.infoLog += `\\nFailed make JSON payload. Error: '${e}'.`; return response; } // Create array variable for Movie file IDs let fileArray = []; - console.log(`Searching for Movie file IDs for movie '${MovieID}'.`) - response.infoLog += `\nSearching for Movie file IDs for movie '${MovieID}'.`; + //console.log(`Searching for Movie file IDs for movie '${MovieID}'.`) + response.infoLog += `\\nSearching for Movie file IDs for movie '${MovieID}'.`; // API call to find Movie file IDs for Movie ID try { await new Promise((resolve) => { connection_type.get(url2, (res) => { - console.log(`Got status code '${res.statusCode}'.`) - response.infoLog += `\nGot status code '${res.statusCode}'.`; + //console.log(`Got status code '${res.statusCode}'.`) + response.infoLog += `\\nGot status code '${res.statusCode}'.`; res.on("data", function (chunk) { url2_body += chunk; @@ -226,14 +226,14 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { }); }).on('error', (e) => { - console.log(`Failed to search for files for movie. Error: '${e}'.`) - response.infoLog += `\nFailed to search for files for movie. Error: '${e}'.`; + //console.log(`Failed to search for files for movie. Error: '${e}'.`) + response.infoLog += `\\nFailed to search for files for movie. Error: '${e}'.`; resolve(); }); }); } catch (e) { - console.log(`Failed API call. Error: '${e}'.`); - response.infoLog += `\nFailed API call. Error: '${e}'.`; + //console.log(`Failed API call. Error: '${e}'.`); + response.infoLog += `\\nFailed API call. Error: '${e}'.`; return response; } @@ -247,16 +247,16 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { continue; } } - console.log(`Found '${fileArray.length}' files for movie.`); - response.infoLog += `\nFound '${fileArray.length}' files for movie.`; + //console.log(`Found '${fileArray.length}' files for movie.`); + response.infoLog += `\\nFound '${fileArray.length}' files for movie.`; } catch (e) { - console.log(`Failed process episodes. Error: '${e}'.`); - response.infoLog += `\nFailed process episodes. Error: '${e}'.`; + //console.log(`Failed process episodes. Error: '${e}'.`); + response.infoLog += `\\nFailed process episodes. Error: '${e}'.`; return response; } - console.log(`Renaming files for movie '${MovieID}'.`); - response.infoLog += `\nRenaming files for movie '${MovieID}'.`; + //console.log(`Renaming files for movie '${MovieID}'.`); + response.infoLog += `\\nRenaming files for movie '${MovieID}'.`; // API call to rename the found Movie file IDs for the Movie ID try { @@ -267,25 +267,25 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { files: fileArray }) .then(function (res) { - console.log(`Got status code '${res.status}'.`) - response.infoLog += `\n☑ Got status code '${res.status}'.`; + //console.log(`Got status code '${res.status}'.`) + response.infoLog += `\\n☑ Got status code '${res.status}'.`; resolve(); }) .catch(function (error) { - console.log(`Got error: ${error}`) - response.infoLog += `\nGot error: ${error}`; + //console.log(`Got error: ${error}`) + response.infoLog += `\\nGot error: ${error}`; resolve(); }); }); } catch (e) { - console.log(`Failed API call. Error: '${e}'.`); - response.infoLog += `\nFailed API call. Error: '${e}'.`; + //console.log(`Failed API call. Error: '${e}'.`); + response.infoLog += `\\nFailed API call. Error: '${e}'.`; return response; } // Sleep for set amount of time - console.log(`Sleeping '${sleepInterval}' ms.`); - response.infoLog += `\nSleeping '${sleepInterval}' ms.`; + //console.log(`Sleeping '${sleepInterval}' ms.`); + response.infoLog += `\\nSleeping '${sleepInterval}' ms.`; await new Promise((resolve) => { setTimeout(() => { resolve(); @@ -296,4 +296,4 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { }; module.exports.details = details; -module.exports.plugin = plugin; \ No newline at end of file +module.exports.plugin = plugin; From 76fe7934bd1bf19bdf0132fbad795857ec8c13c5 Mon Sep 17 00:00:00 2001 From: aunefyren Date: Wed, 4 Oct 2023 14:36:57 +0200 Subject: [PATCH 9/9] Even better linting --- ...lugin_f4k2_aune_refresh_files_in_sonarr.js | 13 ++++---- ...Plugin_f4k3_aune_rename_files_in_sonarr.js | 33 +++++++++---------- ...lugin_f4k4_aune_refresh_files_in_radarr.js | 24 +++++++------- ...Plugin_f4k5_aune_rename_files_in_radarr.js | 30 ++++++++--------- 4 files changed, 47 insertions(+), 53 deletions(-) diff --git a/Community/Tdarr_Plugin_f4k2_aune_refresh_files_in_sonarr.js b/Community/Tdarr_Plugin_f4k2_aune_refresh_files_in_sonarr.js index b498ef3d3..1a56387f8 100644 --- a/Community/Tdarr_Plugin_f4k2_aune_refresh_files_in_sonarr.js +++ b/Community/Tdarr_Plugin_f4k2_aune_refresh_files_in_sonarr.js @@ -137,14 +137,14 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { // Select connection type let connection_type = null; try { - if (SSL == 'http') { - connection_type = http + if (SSL === 'http') { + connection_type = http; } else { - connection_type = https + connection_type = https; } } catch (e) { //console.log(`Failed to compare SSL string. Error: ${e}`); - connection_type = http + connection_type = http; } // Try to split file path to retrieve series folder name @@ -155,7 +155,7 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { } catch (e) { //console.log(`Failed to split file name. Error: '${e}'.\\n`); response.infoLog += `\\nFailed to split file name. Error: '${e}'.`; - return response + return response; } //console.log(`Searching for series '${term}'.`); @@ -164,7 +164,7 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { // Create variables for API call const url1 = `${SSL}://${IP}:${port}${APIPathLookup}?term=${termUri}&apikey=${APIKey}`; let url1_body = ''; - let url2 = ``; + let url2 = ''; let SeriesID = 0; // API call to search for Series ID using the folder name @@ -181,7 +181,6 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { res.on('end', function () { resolve(); }); - }).on('error', (e) => { //console.log(`Failed to search for series. Error: '${e}'.`); response.infoLog += `\\nFailed to search for series. Error: '${e}'.`; diff --git a/Community/Tdarr_Plugin_f4k3_aune_rename_files_in_sonarr.js b/Community/Tdarr_Plugin_f4k3_aune_rename_files_in_sonarr.js index d738b29e2..ca4b88713 100644 --- a/Community/Tdarr_Plugin_f4k3_aune_rename_files_in_sonarr.js +++ b/Community/Tdarr_Plugin_f4k3_aune_rename_files_in_sonarr.js @@ -11,7 +11,9 @@ const details = () => ({ Name: 'Rename files in Sonarr', Type: 'Video', Operation: 'Transcode', - Description: `Renames the files in the current show in Sonarr according to naming format. This is done using the Sonarr API. To do this action it needs the Show ID. This code attempts to retrieve the Show ID by using the folder name of the series. To rename the correct file we need the season and episode number. To find this SXXEXX needs to be present in the file name.`, + Description: `Renames the files in the current show in Sonarr according to naming format. This is done using the Sonarr API. + To do this action it needs the Show ID. This code attempts to retrieve the Show ID by using the folder name of the series. + To rename the correct file we need the season and episode number. To find this SXXEXX needs to be present in the file name.`, Version: '1.0', Tags: '3rd party,post-processing,configurable', @@ -95,7 +97,6 @@ function sleep(ms) { // eslint-disable-next-line no-unused-vars const plugin = async (file, librarySettings, inputs, otherArguments) => { - const response = { file, removeFromDB: false, @@ -104,7 +105,7 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { infoLog: 'Rename Sonarr files starting.', }; - //console.log("Rename Sonarr files starting.") + //console.log('Rename Sonarr files starting.') const lib = require('../methods/lib')(); // eslint-disable-next-line no-unused-vars,no-param-reassign @@ -113,7 +114,7 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { const https = require('https'); const axios = require('axios'); - //console.log("Loaded required packages.") + //console.log('Loaded required packages.') // Defines variables const SSL = inputs.Url_Protocol; @@ -122,9 +123,9 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { const APIKey = inputs.Sonarr_APIKey; const sleepInterval = inputs.After_Sleep; const regex = '(S[0-9]{1,4}E[0-9]{1,2})'; - let seasonEpisodeMatch = ""; - let term = ""; - let termUri = ""; + let seasonEpisodeMatch = ''; + let term = ''; + let termUri = ''; const APIPathLookup = '/api/v3/series/lookup'; const APIPathEpisodefile = '/api/v3/episodefile'; const APIPathCommand = '/api/v3/command'; @@ -138,14 +139,14 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { // Select connection type let connection_type = null; try { - if (SSL == "http") { - connection_type = http + if (SSL === 'http') { + connection_type = http; } else { - connection_type = https + connection_type = https; } } catch (e) { //console.log(`Failed to compare SSL string. Error: ${e}`); - connection_type = http + connection_type = http; } // Try to split file path to retrieve series folder name and season-episode number @@ -180,18 +181,17 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { let url2 = ``; let url3 = ``; let SeriesID = 0; - let url1_body = ""; - let url2_body = ""; + let url1_body = ''; + let url2_body = ''; // API call to search for folder name to get Series ID try { await new Promise((resolve) => { connection_type.get(url1, (res) => { - //console.log(`Got status code '${res.statusCode}'.`) response.infoLog += `\\nGot status code '${res.statusCode}'.`; - res.on("data", function (chunk) { + res.on('data', function (chunk) { url1_body += chunk; }); @@ -233,11 +233,10 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { try { await new Promise((resolve) => { connection_type.get(url2, (res) => { - //console.log(`Got status code '${res.statusCode}'.`) response.infoLog += `\\nGot status code '${res.statusCode}'.`; - res.on("data", function (chunk) { + res.on('data', function (chunk) { url2_body += chunk; }); diff --git a/Community/Tdarr_Plugin_f4k4_aune_refresh_files_in_radarr.js b/Community/Tdarr_Plugin_f4k4_aune_refresh_files_in_radarr.js index 44f3db4ef..fafe59e0a 100644 --- a/Community/Tdarr_Plugin_f4k4_aune_refresh_files_in_radarr.js +++ b/Community/Tdarr_Plugin_f4k4_aune_refresh_files_in_radarr.js @@ -89,7 +89,6 @@ const details = () => ({ // eslint-disable-next-line no-unused-vars const plugin = async (file, librarySettings, inputs, otherArguments) => { - const response = { file, removeFromDB: false, @@ -98,7 +97,7 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { infoLog: 'Refresh Radarr files starting.', }; - //console.log("Refresh Radarr files starting.") + //console.log('Refresh Radarr files starting.') const lib = require('../methods/lib')(); // eslint-disable-next-line no-unused-vars,no-param-reassign @@ -107,7 +106,7 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { const https = require('https'); const axios = require('axios'); - //console.log("Loaded required packages.") + //console.log('Loaded required packages.') // Create variables const SSL = inputs.Url_Protocol; @@ -115,8 +114,8 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { const port = inputs.Radarr_Port; const APIKey = inputs.Radarr_APIKey; const sleepInterval = inputs.After_Sleep; - let term = ""; - let termUri = ""; + let term = ''; + let termUri = ''; const APIPathLookup = '/api/v3/movie/lookup'; const APIPathCommand = '/api/v3/command'; const APICommand = 'RefreshMovie'; @@ -129,14 +128,14 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { // Select connection type let connection_type = null; try { - if (SSL == "http") { - connection_type = http + if (SSL == 'http') { + connection_type = http; } else { - connection_type = https + connection_type = https; } } catch (e) { //console.log(`Failed to compare SSL string. Error: ${e}`); - connection_type = http + connection_type = http; } // Try to split file path to retrieve movie folder name @@ -155,19 +154,18 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { // Create variables for API call const url1 = `${SSL}://${IP}:${port}${APIPathLookup}?term=${termUri}&apikey=${APIKey}`; - let url1_body = ""; - let url2 = ``; + let url1_body = ''; + let url2 = ''; let MovieID = 0; // API call to search for Movie ID using the folder name try { await new Promise((resolve) => { connection_type.get(url1, (res) => { - //console.log(`Got status code '${res.statusCode}'.`) response.infoLog += `\\nGot status code '${res.statusCode}'.`; - res.on("data", function (chunk) { + res.on('data', function (chunk) { url1_body += chunk; }); diff --git a/Community/Tdarr_Plugin_f4k5_aune_rename_files_in_radarr.js b/Community/Tdarr_Plugin_f4k5_aune_rename_files_in_radarr.js index d0873ad6a..13b9f6d75 100644 --- a/Community/Tdarr_Plugin_f4k5_aune_rename_files_in_radarr.js +++ b/Community/Tdarr_Plugin_f4k5_aune_rename_files_in_radarr.js @@ -11,7 +11,8 @@ const details = () => ({ Name: 'Rename files in Radarr', Type: 'Video', Operation: 'Transcode', - Description: `Renames the files in the current movie in Radarr according to naming format. This is done using the Radarr API. To do this action it needs the Movie ID. This code attempts to retrieve the Movie ID by using the folder name of the movie.`, + Description: `Renames the files in the current movie in Radarr according to naming format. This is done using the Radarr API. + To do this action it needs the Movie ID. This code attempts to retrieve the Movie ID by using the folder name of the movie.`, Version: '1.0', Tags: '3rd party,post-processing,configurable', @@ -98,7 +99,7 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { infoLog: 'Rename Radarr files starting.', }; - //console.log("Rename Radarr files starting.") + //console.log('Rename Radarr files starting.') const lib = require('../methods/lib')(); // eslint-disable-next-line no-unused-vars,no-param-reassign @@ -107,7 +108,7 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { const https = require('https'); const axios = require('axios'); - //console.log("Loaded required packages.") + //console.log('Loaded required packages.') // Defines variables const SSL = inputs.Url_Protocol; @@ -116,8 +117,8 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { const APIKey = inputs.Radarr_APIKey; const sleepInterval = inputs.After_Sleep; const regex = '(S[0-9]{1,4}E[0-9]{1,2})'; - let term = ""; - let termUri = ""; + let term = ''; + let termUri = ''; const APIPathLookup = '/api/v3/movie/lookup'; const APIPathMoviefile = '/api/v3/moviefile'; const APIPathCommand = '/api/v3/command'; @@ -131,14 +132,14 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { // Select connection type let connection_type = null; try { - if (SSL == "http") { - connection_type = http + if (SSL == 'http') { + connection_type = http; } else { - connection_type = https + connection_type = https; } } catch (e) { //console.log(`Failed to compare SSL string. Error: ${e}`); - connection_type = http + connection_type = http; } // Try to split file path to retrieve movie folder name @@ -160,25 +161,23 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { let url2 = ``; let url3 = ``; let MovieID = 0; - let url1_body = ""; - let url2_body = ""; + let url1_body = ''; + let url2_body = ''; // API call to search for folder name to get Movie ID try { await new Promise((resolve) => { connection_type.get(url1, (res) => { - //console.log(`Got status code '${res.statusCode}'.`) response.infoLog += `\\nGot status code '${res.statusCode}'.`; - res.on("data", function (chunk) { + res.on('data', function (chunk) { url1_body += chunk; }); res.on('end', function () { resolve(); }); - }).on('error', (e) => { //console.log(`Failed to search for movie. Error: '${e}'.`) response.infoLog += `\\nFailed to search for movie. Error: '${e}'.`; @@ -213,11 +212,10 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { try { await new Promise((resolve) => { connection_type.get(url2, (res) => { - //console.log(`Got status code '${res.statusCode}'.`) response.infoLog += `\\nGot status code '${res.statusCode}'.`; - res.on("data", function (chunk) { + res.on('data', function (chunk) { url2_body += chunk; });