Client¶
Client for ruTorrent.
- exception xirvik.client.UnexpectedruTorrentError¶
Raised when an unexpected error occurs.
-
class xirvik.client.ruTorrentClient(host: str, name: str | None =
None, password: str | None =None, max_retries: int =10, netrc_path: str | Path | None =None, backoff_factor: int =1)¶ ruTorrent client class.
Reference on RPC returned fields.
- Parameters:¶
- host : str¶
Hostname with no protocol.
- name : str | None¶
Username.
If no name and no password are passed,
~/.netrcwill be searched with the host provided. The path can be overridden with thenetrc_pathargument.- password : str | None¶
Password.
- max_retries : int¶
Number of tries to retry any request.
- netrc_path : str | None¶
netrc file path.
- backoff_factor : int¶
Factor used to calculate back-off time when retrying requests.
- Raises:¶
ValueError – If no netrc entry is found for the host, or if username or password is not provided.
-
async add_torrent(filepath: str, *, start_now: bool =
True) None¶ Add a torrent. Use
start_now=Falseto start paused.
- async delete(hash_: str) None¶
Delete a torrent and its files by hash.
Use the remove() method to remove the torrent but keep the data.
Returns if successful. Faults are converted to
xmlrpc.Faultexceptions.
-
async edit_torrents(hashes: Iterable[str], *, comment: str | None =
None, private: bool | None =None, trackers: Iterable[str] | None =None) niquests.Response¶ Edit torrent properties.
- host¶
Hostname with no protocol.
- async list_all_files() AsyncIterator[TorrentTrackedFile]¶
List all files tracked by rTorrent.
If there are thousands of torrents, this may take well over 10 minutes.
Returns a generator of tracked files.
- Yields:¶
TorrentTrackedFile – Named tuple with file information.
- async list_files(hash_: str) AsyncIterator[TorrentTrackedFile]¶
List files for a given torrent hash.
Returns a generator of named tuples with fields (in this order): - name - total number of pieces - number of pieces downloaded - size in bytes - priority - download strategy
Example use:
async for name, pieces, pieces_dl, size, priority, dl_strategy in client.list_files():
- async list_torrents() AsyncIterator[TorrentInfo]¶
Get all torrent information.
-
async move_torrent(torrent_hash: str, target_dir: str, *, fast_resume: bool =
True) None¶ Move a torrent’s files to somewhere else on the server.
- name¶
Username for authentication.
- password¶
Password for authentication.
- async remove(hash_: str) None¶
Remove a torrent from the client but keep the data.
Use the delete() method to remove and delete the torrent data.
Returns if successful. Can raise a
HTTPErrorexception.
Utilities¶
Utility functions.
- xirvik.utils.parse_header(line: str) tuple[str, dict[str, str]]¶
Parse a Content-type like header.
Return the main content-type and a dictionary of options.
Typing utilities¶
Typing helpers.
- class xirvik.typing.FileDownloadStrategy(*values)¶
Single file download strategy.
-
NORMAL =
0¶ Also known as ‘trailing chunk first’.
-
NORMAL =
- class xirvik.typing.FilePriority(*values)¶
Single file priority.
These are based on ruTorrent’s code, not rTorrent’s.
- class xirvik.typing.TorrentInfo(hash: str, is_open: bool, is_hash_checking: bool, is_hash_checked: bool, state: State, name: str, size_bytes: int, completed_chunks: int, size_chunks: int, bytes_done: int, up_total: int, ratio: float, up_rate: int, down_rate: int, chunk_size: int, custom1: str, peers_accounted: int, peers_not_connected: int, peers_connected: int, peers_complete: int, left_bytes: int, priority: int, state_changed: datetime | None, skip_total: int, hashing: HashingState, chunks_hashed: int, base_path: str, creation_date: datetime | None, tracker_focus: int, is_active: bool, message: str, custom2: str, free_diskspace: int, is_private: bool, is_multi_file: bool, finished: datetime | None)¶
Torrent information.
- creation_date : datetime | None¶
Date torrent was added to the client. Can be
Noneif this was not captured, or possibly due to a crash.
- hashing : HashingState¶
Alias for field number 24
- class xirvik.typing.TorrentTrackedFile(name: str, number_of_pieces: int, downloaded_pieces: int, size_bytes: int, priority_id: FilePriority, download_strategy_id: FileDownloadStrategy)¶
Contains information about a single file within a torrent.
- download_strategy_id : FileDownloadStrategy¶
Download strategy.
- priority_id : FilePriority¶
Download priority.