- Go 100%
|
|
||
|---|---|---|
| internal | ||
| go.mod | ||
| LICENSE | ||
| main.go | ||
| main_test.go | ||
| README.md | ||
streamkeep
Pauses qBittorrent while Jellyfin is streaming, and resumes it once playback has been quiet for a while.
Why
Downloads and seeds run on a Raspberry Pi 4 (vault) whose disk sits behind USB. While torrents saturate it, Jellyfin on the public server (bjvanbemmel) reads media over NFS too slowly and streams buffer. streamkeep gives playback priority over torrent traffic.
How it works
flowchart LR
viewers([Viewers]) -->|HTTPS| nginx
subgraph bjv["bjvanbemmel (public internet)"]
nginx --> jellyfin["Jellyfin :8096"]
arr["Sonarr / Radarr / Bazarr"]
sk["streamkeep (systemd)"]
mount["/vault (NFS mount)"]
jellyfin -->|reads media| mount
sk -->|"1. poll /Sessions every 5s"| jellyfin
end
subgraph vault["vault (Raspberry Pi 4, private network)"]
qbit["qBittorrent WebUI :8080"]
prowlarr["Prowlarr"]
nfsd["NFS server"]
disk[("USB HDD")]
qbit --> disk
nfsd --> disk
end
sk -->|"2. pause / resume"| qbit
mount <-->|NFS| nfsd
arr -->|search| prowlarr
arr -->|send downloads| qbit
Everything between the two servers travels over the WireGuard vault interface. vault is not reachable any other way.
- Every
POLL(default 5s), streamkeep asks Jellyfin for its sessions. Any session with something playing counts as a stream. Paused playback counts too. - On the first stream it pauses the torrents that are running and writes their hashes to
paused.json. - Once there has been no stream for
IDLE(default 5m), it resumes exactly those torrents and deletes the file.
Torrents you paused yourself are never resumed. paused.json also survives restarts: a restarted daemon picks up where it left off, and waits the full idle time before resuming.
If Jellyfin cannot be reached, streamkeep does nothing rather than guess. If qBittorrent cannot be reached, it retries on the next poll.
Configuration
All through environment variables.
| Variable | Default | Meaning |
|---|---|---|
JELLYFIN_URL |
required | Jellyfin base URL |
JELLYFIN_API_KEY |
required | API key (Dashboard → API Keys) |
QBIT_URL |
required | qBittorrent WebUI base URL |
QBIT_USER, QBIT_PASS |
required | WebUI credentials |
POLL |
5s |
How often to ask Jellyfin |
IDLE |
5m |
Quiet time before resuming |
STATE_DIRECTORY |
. |
Where paused.json lives (set by systemd's StateDirectory=) |
Keep the secrets in a root-only EnvironmentFile=, not in the unit.
Logs
Lines are prefixed with a syslog priority, so journalctl -u streamkeep -p warning shows only problems. Repeated failures are throttled: the first and every 60th are logged, followed by a "recovered" line.
Development
go test -race -cover ./...
License
GPL-3.0-or-later. See LICENSE.