No description
Find a file
bjvanbemmel 9257c9356c accept empty 204 as a successful qbittorrent login
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-08 16:53:01 +02:00
internal accept empty 204 as a successful qbittorrent login 2026-10-08 16:53:01 +02:00
go.mod add streamkeep daemon 2026-10-08 16:25:43 +02:00
LICENSE add GPL-3.0-or-later license 2026-10-08 16:36:46 +02:00
main.go add interfaces, tests and graceful shutdown 2026-10-08 16:30:55 +02:00
main_test.go add interfaces, tests and graceful shutdown 2026-10-08 16:30:55 +02:00
README.md add GPL-3.0-or-later license 2026-10-08 16:36:46 +02:00

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.

  1. Every POLL (default 5s), streamkeep asks Jellyfin for its sessions. Any session with something playing counts as a stream. Paused playback counts too.
  2. On the first stream it pauses the torrents that are running and writes their hashes to paused.json.
  3. 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.