commit 352fa38ef310a2a92eaac3344254fafeb955d149 Author: pk Date: Sat Nov 21 18:51:54 2026 +0000 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..755074d --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/cfg +/scripts/secrets.sh diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..c3613b8 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,91 @@ +version: "2.1" +services: + sonarr: + image: lscr.io/linuxserver/sonarr:latest + container_name: sonarr + environment: + - PUID=104 + - PGID=666 + - TZ=Europe/London + volumes: + - ./cfg/sonarr:/config + - ./scripts:/scripts + - /mnt/titan/media/shows:/media/shows:ro + - /mnt/titan/media/anime:/media/anime:ro + #- ./a:/media/anime + ports: + - 7101:8989 + restart: unless-stopped + + radarr: + image: lscr.io/linuxserver/radarr:latest + container_name: radarr + environment: + - PUID=104 + - PGID=666 + - TZ=Europe/London + volumes: + - ./cfg/radarr:/config + - ./scripts:/scripts + - /mnt/titan/media/movies:/media/movies:ro + #- ./a:/media/movies + ports: + - 7102:7878 + restart: unless-stopped + + lidarr: + image: lscr.io/linuxserver/lidarr:latest + container_name: lidarr + environment: + - PUID=104 + - PGID=666 + - TZ=Europe/London + volumes: + - ./cfg/lidarr:/config + - /mnt/titan/media/music:/media/music:ro + #- ./a:/media/music + ports: + - 7104:8686 + restart: unless-stopped + + jackett: + image: lscr.io/linuxserver/jackett:latest + container_name: jackett + environment: + - PUID=104 + - PGID=666 + - TZ=Europe/London +# - AUTO_UPDATE=true #optional +# - RUN_OPTS= #optional + volumes: + - ./cfg/jackett:/config + ports: + - 7103:9117 + restart: unless-stopped + + overseerr: + image: lscr.io/linuxserver/overseerr:latest + container_name: overseerr + environment: + - PUID=104 + - PGID=666 + - TZ=Europe/London + - PORT=7105 #optional + ports: + - 7105:7105 + volumes: + - ./cfg/overseerr:/config + restart: unless-stopped + + flaresolverr: + # DockerHub mirror flaresolverr/flaresolverr:latest + image: ghcr.io/flaresolverr/flaresolverr:latest + container_name: flaresolverr + environment: + - LOG_LEVEL=info + - LOG_HTML=false + - CAPTCHA_SOLVER=none + - TZ=Europe/London + ports: + - 7106:8191 + restart: unless-stopped diff --git a/scripts/bun-glibc b/scripts/bun-glibc new file mode 100755 index 0000000..b0e3ff6 Binary files /dev/null and b/scripts/bun-glibc differ diff --git a/scripts/bun-musl b/scripts/bun-musl new file mode 100755 index 0000000..46ac048 Binary files /dev/null and b/scripts/bun-musl differ diff --git a/scripts/helpers.js b/scripts/helpers.js new file mode 100644 index 0000000..39e9b05 --- /dev/null +++ b/scripts/helpers.js @@ -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 }; diff --git a/scripts/radarr_on_grab.js b/scripts/radarr_on_grab.js new file mode 100644 index 0000000..34118ba --- /dev/null +++ b/scripts/radarr_on_grab.js @@ -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(); diff --git a/scripts/radarr_on_grab.sh b/scripts/radarr_on_grab.sh new file mode 100755 index 0000000..44e1e50 --- /dev/null +++ b/scripts/radarr_on_grab.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +source /scripts/secrets.sh +/scripts/bun-musl /scripts/radarr_on_grab.js diff --git a/scripts/secrets.sh.example b/scripts/secrets.sh.example new file mode 100644 index 0000000..64f9023 --- /dev/null +++ b/scripts/secrets.sh.example @@ -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=