Files
arrs/scripts/helpers.js
T
2026-11-21 18:51:54 +00:00

63 lines
1.7 KiB
JavaScript

class Radarr {
constructor(url, apiKey) {
this.url = url;
this.apiKey = apiKey;
}
async getMovie(movieId) {
const response = await fetch(`${this.url}/api/v3/movie/${movieId}`, {
headers: {
'X-Api-Key': this.apiKey,
},
});
return response.json();
}
}
class Deluge {
constructor(url) {
this.url = url;
this.delugeRpcId = 1;
this.cookies = {};
}
async rpc(method, params, cookies = {}) {
const response = await fetch(`${this.url}/json`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Cookie: cookies,
},
body: JSON.stringify({ id: this.delugeRpcId++, method, params }),
});
return response;
}
async login(apiKey) {
const response = await this.rpc("auth.login", [apiKey]);
this.cookies = response.headers.getSetCookie()
?.map(cookie => cookie.split(";")[0])
.join("; ");
}
async getTorrentStatus(torrentId) {
const response = await this.rpc("web.get_torrent_status", [torrentId, ["download_location", "tracker_host"]], this.cookies);
return await response.json();
}
async moveTorrent(torrentId, newLocation) {
const response = await this.rpc("core.move_storage", [[torrentId], newLocation], this.cookies);
return await response.json();
}
async setTorrentLabel(torrentId, label) {
const response = await this.rpc("label.set_torrent", [torrentId, label], this.cookies);
return await response.json();
}
}
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
export { Radarr, Deluge, sleep };