Skip to content

qBittorrent Module API Explanation

The qBittorrent module monitors real-time seeding and downloading bandwidth utilization.


API Execution Logic

The module locates the service matching the identifier qbittorrent. It retrieves the administrative credentials (QBITTORRENT_USERNAME and QBITTORRENT_PASSWORD) to execute session token checks.

Authentication Caching and Token Management

qBittorrent does not support static API token authorization; it requires cookie session authentication. To avoid logging in on every 5-second dashboard refresh, the module implements cookie caching:

  1. Login Helper: A helper function sends a POST request to /api/v2/auth/login containing the username and password in url-encoded format.
  2. Cookie Parsing: Upon successful login, the set-cookie header is parsed to extract the session ID cookie. The session cookie is cached in memory for 2 hours.

Telemetry Request Execution

Once authenticated, the module queries /api/v2/sync/maindata?rid=0 with the cached session cookie.

  • Token Expiry Retry: If the request returns an HTTP 403 status (indicating an expired session cookie), the cookie is cleared immediately. The module logs in again to refresh the cookie and retries the sync query once.

Data Parsing and Unit Conversion

The JSON payload contains server transfer rates. The module extracts:

  • dl_info_speed: The download rate in bytes.
  • up_info_speed: The upload rate in bytes.

  • Primary Metric: The download speed converted to megabytes per second (divided by \(1024^2\)).

  • Secondary Metric: The upload speed converted to megabytes per second (divided by \(1024^2\)).

Caching Strategy

The sync details are cached in memory for 30 seconds (TTL) with a stale window of 300 seconds.