use serde::Deserialize; use serde_repr::*; #[derive(Deserialize, Debug)] pub struct RpcResponse { pub arguments: T, pub result: String, } impl RpcResponse { pub fn is_ok(&self) -> bool { self.result == "success" } } pub trait RpcResponseArgument {} #[derive(Deserialize, Debug, Clone)] #[serde(rename_all = "kebab-case")] pub struct SessionGet { pub blocklist_enabled: bool, pub download_dir: String, pub encryption: String, pub rpc_version: i32, pub rpc_version_minimum: i32, pub version: String, } impl RpcResponseArgument for SessionGet {} #[derive(Deserialize, Debug, Clone)] #[serde(rename_all = "camelCase")] pub struct SessionStats { pub torrent_count: i32, pub active_torrent_count: i32, pub paused_torrent_count: i32, pub download_speed: i64, pub upload_speed: i64, #[serde(rename = "current-stats")] pub current_stats: Stats, #[serde(rename = "cumulative-stats")] pub cumulative_stats: Stats, } impl RpcResponseArgument for SessionStats {} #[derive(Deserialize, Debug, Clone)] pub struct SessionClose {} impl RpcResponseArgument for SessionClose {} #[derive(Deserialize, Debug, Clone)] #[serde(rename_all = "kebab-case")] pub struct BlocklistUpdate { pub blocklist_size: Option, } impl RpcResponseArgument for BlocklistUpdate {} #[derive(Deserialize, Debug, Clone)] #[serde(rename_all = "kebab-case")] pub struct FreeSpace { pub path: String, pub size_bytes: i64, } impl RpcResponseArgument for FreeSpace {} #[derive(Deserialize, Debug, Clone)] #[serde(rename_all = "kebab-case")] pub struct PortTest { pub port_is_open: bool, } impl RpcResponseArgument for PortTest {} #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Serialize_repr, Deserialize_repr)] #[repr(u8)] pub enum TorrentStatus { Stopped = 0, QueuedToVerify = 1, Verifying = 2, QueuedToDownload = 3, Downloading = 4, QueuedToSeed = 5, Seeding = 6, } #[derive(Deserialize, Debug, Clone)] #[serde(rename_all = "camelCase")] pub struct Torrent { pub activity_date: Option, pub added_date: Option, pub done_date: Option, pub download_dir: Option, pub edit_date: Option, pub error: Option, pub error_string: Option, pub eta: Option, pub id: Option, pub is_finished: Option, pub is_private: Option, pub is_stalled: Option, pub labels: Option>, pub left_until_done: Option, pub metadata_percent_complete: Option, pub name: Option, pub hash_string: Option, pub peers_connected: Option, pub peers_getting_from_us: Option, pub peers_sending_to_us: Option, pub percent_done: Option, pub rate_download: Option, pub rate_upload: Option, pub recheck_progress: Option, pub seconds_seeding: Option, pub seed_ratio_limit: Option, pub size_when_done: Option, pub status: Option, pub torrent_file: Option, pub total_size: Option, pub trackers: Option>, pub upload_ratio: Option, pub uploaded_ever: Option, pub files: Option>, /// for each file in files, whether or not they will be downloaded (0 or 1) pub wanted: Option>, /// for each file in files, their download priority (low:-1,normal:0,high:1) pub priorities: Option>, pub file_stats: Option>, } #[derive(Deserialize, Debug, Clone)] #[serde(rename_all = "camelCase")] pub struct Stats { pub files_added: i32, pub downloaded_bytes: i64, pub uploaded_bytes: i64, pub seconds_active: i64, pub session_count: Option, } #[derive(Deserialize, Debug)] pub struct Torrents { pub torrents: Vec, } impl RpcResponseArgument for Torrents {} #[derive(Deserialize, Debug, Clone)] pub struct Trackers { pub id: i32, pub announce: String, } #[derive(Deserialize, Debug, Clone)] #[serde(rename_all = "camelCase")] pub struct File { pub length: i64, pub bytes_completed: i64, pub name: String, } #[derive(Deserialize, Debug, Clone)] #[serde(rename_all = "camelCase")] pub struct FileStat { pub bytes_completed: i64, pub wanted: bool, /// low: -1, normal: 0, high: 1 pub priority: i8, } #[derive(Deserialize, Debug)] pub struct Nothing {} impl RpcResponseArgument for Nothing {} #[derive(Deserialize, Debug)] #[serde(rename_all = "kebab-case")] pub enum TorrentAddedOrDuplicate { TorrentDuplicate(Torrent), TorrentAdded(Torrent), } impl RpcResponseArgument for TorrentAddedOrDuplicate {} #[derive(Deserialize, Debug)] pub struct TorrentRenamePath { pub path: Option, pub name: Option, pub id: Option, } impl RpcResponseArgument for TorrentRenamePath {}