qb_api/
data.rs

1//! Structs returned by api queries
2
3use derive_getters::Getters;
4use serde::{Deserialize, Serialize};
5
6/// Overall metadata about this qbit client
7#[derive(Debug, Deserialize, Getters)]
8pub struct MainData {
9    rid: u64,
10    full_update: bool,
11    torrents: Torrent,
12    torrents_removed: Vec<String>,
13    categories: Category,
14    categories_removed: Vec<String>,
15    tags: Vec<String>,
16    tags_removed: Vec<String>,
17    queueing: bool,
18    server_state: ServerState,
19}
20
21#[derive(Debug, Deserialize, Getters, Clone)]
22pub struct Torrent {
23    added_on: u32,
24    amount_left: u64,
25    auto_tmm: bool,
26    category: String,
27    completed: i64,
28    completion_on: i32,
29    dl_limit: i64,
30    dlspeed: i64,
31    downloaded: i64,
32    downloaded_session: i64,
33    eta: i64,
34    f_l_piece_prio: Option<bool>,
35    force_start: bool,
36    pub(crate) hash: Hash,
37    last_activity: i64,
38    magnet_uri: String,
39    max_ratio: f64,
40    max_seeding_time: i64,
41    name: String,
42    num_complete: i64,
43    num_incomplete: i64,
44    num_leechs: i64,
45    num_seeds: i64,
46    priority: i64,
47    progress: f64,
48    ratio: f64,
49    ratio_limit: f64,
50    save_path: String,
51    seeding_time_limit: i64,
52    seen_complete: i64,
53    seq_dl: bool,
54    size: i64,
55    state: State,
56    super_seeding: bool,
57    tags: String,
58    time_active: i64,
59    total_size: i64,
60    tracker: String,
61    up_limit: i64,
62    uploaded: i64,
63    uploaded_session: i64,
64    upspeed: i64,
65}
66
67#[derive(Serialize, Deserialize, Debug, Clone, Getters)]
68pub struct Tracker {
69    url: String,
70    #[getter(skip)]
71    status: i32,
72    // TODO: fix this since some people do things non standard with "/" here
73    // tier: u32,
74    num_peers: i32,
75    // TODO: documentation says these will be returned but the fields do not appear
76    // num_seeds: i32,
77    // num_leeches: i32,
78    // num_downloaded: i64,
79    msg: String,
80}
81
82impl Tracker {
83    pub fn status(&self) -> TrackerStatus {
84        match self.status {
85            0 => TrackerStatus::TrackerDisabled,
86            1 => TrackerStatus::NotContacted,
87            2 => TrackerStatus::Working,
88            3 => TrackerStatus::Updating,
89            4 => TrackerStatus::NotWorking,
90            _ => TrackerStatus::UnknownResponse,
91        }
92    }
93}
94
95#[derive(Serialize, Deserialize, Debug, Clone)]
96pub enum TrackerStatus {
97    TrackerDisabled,
98    NotContacted,
99    Working,
100    Updating,
101    NotWorking,
102    UnknownResponse,
103}
104
105#[derive(Clone, Debug, Deserialize, Serialize, Getters)]
106pub struct TorrentProperties {
107    save_path: String,
108    creation_date: u32,
109    piece_size: i64,
110    comment: String,
111    total_wasted: i64,
112    total_uploaded: i64,
113    total_uploaded_session: i64,
114    total_downloaded: i64,
115    total_downloaded_session: i64,
116    up_limit: i64,
117    dl_limit: i64,
118    time_elapsed: i64,
119    seeding_time: i64,
120    nb_connections: i64,
121    nb_connections_limit: i64,
122    share_ratio: f64,
123    addition_date: i64,
124    completion_date: i64,
125    created_by: String,
126    dl_speed_avg: i64,
127    dl_speed: i64,
128    eta: i64,
129    last_seen: i64,
130    peers: i64,
131    peers_total: i64,
132    pieces_have: u64,
133    pieces_num: i64,
134    reannounce: i64,
135    seeds: i64,
136    seeds_total: i64,
137    total_size: u64,
138    up_speed_avg: i64,
139    up_speed: i64,
140}
141
142#[derive(Debug, Deserialize, Copy, Clone, Eq, PartialEq)]
143pub enum State {
144    #[serde(rename = "error")]
145    Error,
146    #[serde(rename = "missingFiles")]
147    MissingFiles,
148    #[serde(rename = "uploading")]
149    Uploading,
150    #[serde(rename = "stoppedUP")]
151    StoppedUP,
152    #[serde(rename = "queuedUP")]
153    QueuedUP,
154    #[serde(rename = "stalledUP")]
155    StalledUP,
156    #[serde(rename = "checkingUP")]
157    CheckingUP,
158    #[serde(rename = "forcedUP")]
159    ForcedUP,
160    #[serde(rename = "allocating")]
161    Allocating,
162    #[serde(rename = "downloading")]
163    Downloading,
164    #[serde(rename = "metaDL")]
165    MetaDL,
166    #[serde(rename = "stoppedDL")]
167    StoppedDL,
168    #[serde(rename = "queuedDL")]
169    QueuedDL,
170    #[serde(rename = "stalledDL")]
171    StalledDL,
172    #[serde(rename = "checkingDL")]
173    CheckingDL,
174    #[serde(rename = "forcedDL")]
175    ForceDL,
176    #[serde(rename = "checkingResumeData")]
177    CheckingResumeData,
178    #[serde(rename = "moving")]
179    Moving,
180    #[serde(rename = "unknown")]
181    Unknown,
182}
183
184#[derive(Debug, Deserialize, Getters)]
185pub struct TransferInfo {
186    dl_info_speed: u64,
187    dl_info_data: u64,
188    up_info_speed: u64,
189    up_info_data: u64,
190    dl_rate_limit: u64,
191    up_rate_limit: u64,
192    dht_nodes: u64,
193    connection_status: ConnectionStatus,
194}
195
196#[derive(Debug, Deserialize)]
197pub enum ConnectionStatus {
198    #[serde(rename = "connected")]
199    Connected,
200    #[serde(rename = "firewalled")]
201    Firewalled,
202    #[serde(rename = "disconnected")]
203    Disconnected,
204}
205
206#[derive(Debug, Deserialize, Getters)]
207pub struct GlobalTransferInfo {
208    /// Global download rate (bytes/s)
209    dl_info_speed: i64,
210    /// Data downloaded this session (bytes)
211    dl_info_data: i64,
212    /// Global upload rate (bytes/s)
213    up_info_speed: i64,
214    /// Data uploaded this session (bytes)
215    up_info_data: i64,
216    /// Download rate limit (bytes/s)
217    dl_rate_limit: i64,
218    /// Upload rate limit (bytes/s)
219    up_rate_limit: i64,
220    /// DHT nodes connected to
221    dht_nodes: i64,
222    connection_status: ConnectionStatus,
223}
224
225#[derive(Debug, Copy, Clone, Eq, PartialEq)]
226pub enum AlternateLimits {
227    /// Alternative limits are in effect
228    Enabled,
229    /// Run at full speed
230    Disabled,
231}
232
233#[derive(Debug, Deserialize, Serialize, Getters)]
234pub struct TorrentInfo {
235    hash: Hash,
236    name: String,
237    size: i64,
238    progress: f64,
239    priority: i16,
240    is_seed: Option<bool>,
241    piece_range: Vec<i64>,
242    availability: f64,
243}
244
245#[derive(Debug, Deserialize, Default, Getters)]
246pub struct Category {
247    name: String,
248    #[serde(rename = "savePath")]
249    save_path: String,
250}
251
252#[derive(Debug, Deserialize)]
253pub struct ServerState {}
254
255#[derive(Debug, Deserialize)]
256pub struct Peer {}
257
258#[derive(Debug, Deserialize, Getters)]
259pub struct BuildInfo {
260    qt: String,
261    libtorrent: String,
262    boost: String,
263    openssl: String,
264    bitness: i64,
265}
266
267#[derive(Deserialize, Debug)]
268pub struct Preferences {}
269
270#[derive(Deserialize, Debug, Getters)]
271pub struct Log {
272    id: u64,
273    message: String,
274    timestamp: u64,
275    #[serde(rename = "type")]
276    level: u64,
277}
278
279#[derive(Deserialize, Serialize, Debug, Clone, Default, Hash)]
280#[serde(transparent)]
281pub struct Hash {
282    pub(crate) hash: String,
283}
284
285impl From<String> for Hash {
286    fn from(f: String) -> Self {
287        Hash { hash: f }
288    }
289}
290
291impl std::ops::Deref for Hash {
292    type Target = String;
293    fn deref(&self) -> &Self::Target {
294        &self.hash
295    }
296}