Initial commit

This commit is contained in:
pk committed 2026-11-21 18:51:54 +00:00
commit 352fa38ef3
8 files changed
+207

No files matched your search

BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+62
View File
@@ -0,0 +1,62 @@
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 };
+45
View File
@@ -0,0 +1,45 @@
import { Radarr, Deluge, sleep } from './helpers.js';
const radarrEventtype = process.env.radarr_eventtype;
const radarrUrl = process.env.RADARR_URL;
const radarrApiKey = process.env.RADARR_API_KEY;
const radarrMovieId = process.env.radarr_movie_id
const radarrDownloadId = process.env.radarr_download_id
const delugeUrl = process.env.DELUGE_URL;
const delugeKey = process.env.DELUGE_PASS;
async function main() {
if (radarrEventtype !== 'Grab') {
console.log('Event type is not Grab, skipping');
return;
}
const radarr = new Radarr(radarrUrl, radarrApiKey);
const radarrMovie = await radarr.getMovie(radarrMovieId);
const deluge = new Deluge(delugeUrl);
await deluge.login(delugeKey);
for (let i = 0; i < 10; i++) {
const torrentStatus = await deluge.getTorrentStatus(radarrDownloadId.toLowerCase());
if (!torrentStatus.result?.download_location) {
// Torrent not found, wait and try again
await sleep(1000);
continue;
}
if (torrentStatus.result.tracker_host === "linkomanija.org") {
await deluge.setTorrentLabel(radarrDownloadId.toLowerCase(), "linkomanija");
}
if (torrentStatus.result.download_location !== radarrMovie.path) {
const moveStorage = await deluge.moveTorrent(radarrDownloadId.toLowerCase(), radarrMovie.path);
console.log('Moved torrent to', radarrMovie.path);
}
break;
}
}
await main();
+3
View File
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
source /scripts/secrets.sh
/scripts/bun-musl /scripts/radarr_on_grab.js
+4
View File
@@ -0,0 +1,4 @@
export RADARR_URL=http://10.0.3.36:7102
export RADARR_API_KEY=
export DELUGE_URL=http://10.0.3.36:8112
export DELUGE_PASS=