Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This is my blocklist script for sonarr / radarr #15

Merged
merged 5 commits into from
May 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions Scripts/Flow/Video/Video - Blocklist sonarr or radarr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
* This script will search the active queue and blocklist and research
* For use alongside this strategy https://fileflows.com/docs/guides/sonarr-radarr
* @author Lawrence Curtis
* @version 1.0.0
* @revision 1
* @param {string} URI Radarr/Sonarr root URI and port (e.g. http://radarr:1234)
* @param {string} ApiKey API Key
* @output Item blocklisted
* @output Item not found
*/
function Script(URI, ApiKey) {
const blocklist = new Blocklist(URI, ApiKey);
return blocklist.check(Variables.folder.Name);
}

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

this.uri = uri;
this.apikey = apikey;
}

getUrl(endpoint) {
let url = "" + this.uri;
if (url.endsWith("/") === false) url += "/";
if (!endpoint.includes("?")) {
endpoint = `${endpoint}?`;
} else {
endpoint = `${endpoint}&`;
}
return `${url}api/v3/${endpoint}apikey=${this.apikey}`;
}

getJson(endpoint) {
let url = this.getUrl(endpoint);
let response = http.GetAsync(url).Result;

let body = response.Content.ReadAsStringAsync().Result;
if (!response.IsSuccessStatusCode) {
Logger.WLog("Unable to fetch: " + endpoint + "\n" + body);
return null;
}
return JSON.parse(body);
}

deleteJson(endpoint) {
let url = this.getUrl(endpoint);
return http.DeleteAsync(url).Result;
}

check(path) {
let queue = this.getJson("queue?pageSize=9999");
if(!queue)
return 2;

let found = false;

queue.records.forEach((item) => {
if (path.includes(item.title)) {
Logger.ILog(`Removing item ${item.title} from ${item.downloadClient}`);
found = true;
let endpoint = `queue/${item.id}?blocklist=true`;
this.deleteJson(endpoint);
}
});

if (found) {
return 1;
} else {
return 2;
}
}
}
Loading