Skip to content

Commit

Permalink
Merge pull request #43 from lawrencecurtis/patch-4
Browse files Browse the repository at this point in the history
*darr manually import trigger scripts
  • Loading branch information
revenz authored Aug 27, 2024
2 parents ac186bf + af4372e commit 7d87e47
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* @name Lidarr - Manually trigger import
* @description Manually tells Lidarr to rescan, run after last file in folder moved
* @author Lawrence / DoughDoze
* @revision 3
* @param {string} URI Lidarr root URI and port (e.g. http://lidarr:8686)
* @param {string} ApiKey API Key
* @output Command sent
*/
function Script(URI, ApiKey) {
URI = URI || Variables['Lidarr.URI']
ApiKey = ApiKey || Variables['Lidarr.ApiKey']

const lidarr = new Lidarr(URI, ApiKey);
if (lidarr.downloadedAlbumsScan(Variables.folder.FullName)) return 1;

return -1;
}

class Lidarr {
constructor(URI, ApiKey) {
if (!URI || !ApiKey) {
Logger.ELog("No credentials specified");
return -1;
}

this.URI = URI;
this.ApiKey = ApiKey;
}

downloadedAlbumsScan(path) {
let endpoint = `${this.URI}/api/v1/command`;
let commandBody = {
path: path,
name: "DownloadedAlbumsScan",
};

let jsonData = JSON.stringify(commandBody);
http.DefaultRequestHeaders.Add("X-API-Key", this.ApiKey);
let response = http.PostAsync(endpoint, JsonContent(jsonData)).Result;
http.DefaultRequestHeaders.Remove("X-API-Key");

if (response.IsSuccessStatusCode) {
let responseData = JSON.parse(
response.Content.ReadAsStringAsync().Result
);
Logger.ILog(responseData);
return responseData;
} else {
let error = response.Content.ReadAsStringAsync().Result;
Logger.WLog("API error: " + error);
return null;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* @name Radarr - Manually trigger import
* @description Manually tells Radarr to rescan, run after last file in folder moved
* @author Lawrence / DoughDoze
* @revision 1
* @param {string} URI Radarr root URI and port (e.g. http://radarr:7878)
* @param {string} ApiKey API Key
* @output Command sent
*/
function Script(URI, ApiKey) {
URI = URI || Variables["Radarr.URI"];
ApiKey = ApiKey || Variables["Radarr.ApiKey"];

const radarr = new Radarr(URI, ApiKey);
if (radarr.downloadedMoviesScan(Variables.folder.FullName)) return 1;

return -1;
}

class Radarr {
constructor(URI, ApiKey) {
if (!URI || !ApiKey) {
Logger.ELog("No credentials specified");
return -1;
}

this.URI = URI;
this.ApiKey = ApiKey;
}

downloadedMoviesScan(path) {
let endpoint = `${this.URI}/api/v3/command`;
let commandBody = {
path: path,
name: "downloadedMoviesScan",
};

let jsonData = JSON.stringify(commandBody);
http.DefaultRequestHeaders.Add("X-API-Key", this.ApiKey);
let response = http.PostAsync(endpoint, JsonContent(jsonData)).Result;
http.DefaultRequestHeaders.Remove("X-API-Key");

if (response.IsSuccessStatusCode) {
let responseData = JSON.parse(
response.Content.ReadAsStringAsync().Result
);
Logger.ILog(responseData);
return responseData;
} else {
let error = response.Content.ReadAsStringAsync().Result;
Logger.WLog("API error: " + error);
return null;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* @name Sonarr - Manually trigger import
* @description Manually tells Sonarr to rescan, run after last file in folder moved
* @author Lawrence / DoughDoze
* @revision 1
* @param {string} URI Sonarr root URI and port (e.g. http://sonarr:8989)
* @param {string} ApiKey API Key
* @output Command sent
*/
function Script(URI, ApiKey) {
URI = URI || Variables['Sonarr.URI']
ApiKey = ApiKey || Variables['Sonarr.ApiKey']

const sonarr = new Sonarr(URI, ApiKey);
if (sonarr.downloadedEpisodesScan(Variables.folder.FullName)) return 1;

return -1;
}

class Sonarr {
constructor(URI, ApiKey) {
if (!URI || !ApiKey) {
Logger.ELog("No credentials specified");
return -1;
}

this.URI = URI;
this.ApiKey = ApiKey;
}

downloadedEpisodesScan(path) {
let endpoint = `${this.URI}/api/v3/command`;
let commandBody = {
path: path,
name: "downloadedEpisodesScan",
};

let jsonData = JSON.stringify(commandBody);
http.DefaultRequestHeaders.Add("X-API-Key", this.ApiKey);
let response = http.PostAsync(endpoint, JsonContent(jsonData)).Result;
http.DefaultRequestHeaders.Remove("X-API-Key");

if (response.IsSuccessStatusCode) {
let responseData = JSON.parse(
response.Content.ReadAsStringAsync().Result
);
Logger.ILog(responseData);
return responseData;
} else {
let error = response.Content.ReadAsStringAsync().Result;
Logger.WLog("API error: " + error);
return null;
}
}
}

0 comments on commit 7d87e47

Please sign in to comment.