class

ArrJanitor::DownloadClient::QBittorrent

Inherits ArrJanitor::DownloadClient < Reference < Object

A qBittorrent download client, backed by the qbittorrent shard.

qBittorrent's WebUI authenticates with username/password (cookie session), not an API key, so this implementation always takes user + pass. Login is performed lazily on the first files_for / info_for call and the session is reused.

Constructors

new(base_url : String, username : String, password : String)
Source

Class methods

extract_paths(files : Array(::QBittorrent::Model::TorrentFile)) : Array(String)

Extracts the file paths from a list of qBittorrent TorrentFiles, dropping entries whose name is nil. Pure (no I/O) so it is unit-testable without a live server.

Source
snapshot_from(info : ::QBittorrent::Model::TorrentInfo, fallback_hash : String = "") : TorrentSnapshot

Maps a qBittorrent TorrentInfo into a client-agnostic snapshot. state is the wire token (TorrentState#to_api); added_on is the epoch converted to UTC. Pure (no I/O) so it is unit-testable without a live server.

Source
snapshot_from_list(hash : String, infos : Array(::QBittorrent::Model::TorrentInfo)) : TorrentSnapshot

Maps the first TorrentInfo in infos into a snapshot. An empty list (the hash is not in the client) raises TorrentNotFound. Pure (no I/O) so it is unit-testable without a live server.

Source
translate_api_error(hash : String, ex : ::QBittorrent::ApiError) : Error

Maps a ::QBittorrent::ApiError onto this abstraction's error types: HTTP 404 (torrent no longer present) becomes TorrentNotFound; any other non-2xx becomes a generic Error carrying the original as its cause. Pure (no I/O) so the translation is unit-testable without a live server.

Source

Instance methods

files_for(hash : String) : Array(String)

Lists the file paths inside the torrent hash. Ensures a session (the underlying client logs in on demand) and maps each returned TorrentFile to its name, dropping any nil entries.

Translates qBittorrent API failures into this abstraction's own error types so callers never need to know about ::QBittorrent::ApiError: a 404 (torrent no longer in the client) becomes TorrentNotFound, any other non-2xx becomes Error.

Source
info_for(hash : String) : TorrentSnapshot

Fetches a snapshot of the torrent hash. Ensures a session and maps the first TorrentInfo into a TorrentSnapshot. An empty result (torrent no longer in the client) becomes TorrentNotFound, matching the HTTP 404 translation on files_for.

Source