1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
// use std::fmt::Display;
use std::fmt::Display;
use derive_builder::Builder;
use serde::{Deserialize, Serialize};
use crate::models::{ContentLayout, ShareLimitAction, StopCondition};
#[cfg(feature = "qBittorrent-5_3")]
use crate::models::ShareLimitMode;
/// Torrent List/info parameter object
#[derive(Debug, Default, Builder, Clone, Deserialize, Serialize, PartialEq)]
pub struct TorrentListParams {
/// Filter torrent list by state. See FilterTorrentState for the allowed filters.
#[builder(setter(strip_option), default = None)]
pub filter: Option<FilterTorrentState>,
/// Get torrents with the given category (empty string means "without category"; no "category" parameter means "any category"). Remember to URL-encode the category name. For example, `My category` becomes `My%20category`
#[builder(setter(into, strip_option), default = None)]
pub category: Option<String>,
/// Get torrents with the given tag (empty string means "without tag"; no "tag" parameter means "any tag"). Remember to URL-encode the category name. For example, `My tag` becomes `My%20tag`
#[builder(setter(into, strip_option), default = None)]
pub tag: Option<String>,
/// Sort torrents by given key. They can be sorted using any field of the response's JSON array (see `TorrentSort`) as the sort key.
#[builder(setter(strip_option), default = None)]
pub sort: Option<TorrentSort>,
/// Enable reverse sorting. Defaults to `false` if not set
#[builder(setter(strip_option), default = None)]
pub reverse: Option<bool>,
/// Limit the number of torrents returned
#[builder(setter(into, strip_option), default = None)]
pub limit: Option<i32>,
/// Set offset (if less than 0, offset from end)
#[builder(setter(into, strip_option), default = None)]
pub offset: Option<i32>,
/// Filter by hashes.
#[builder(setter(into, strip_option), default = None)]
pub hashes: Option<Vec<String>>,
/// Filter by private status.
#[builder(setter(strip_option), default = None)]
pub is_private: Option<bool>,
/// Include torrent files in the response.
#[cfg(not(feature = "qBittorrent-5_1"))]
// https://github.com/qbittorrent/qBittorrent/pull/22750
#[builder(setter(strip_option), default = None)]
pub include_files: Option<bool>,
/// Include torrent trackers in the response.
#[builder(setter(strip_option), default = None)]
pub include_trackers: Option<bool>,
}
/// Possible Torrent states that can be filtered.
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
pub enum FilterTorrentState {
/// Every filter
All,
/// Only torrents which are downloading
Downloading,
/// Only torrents which are seeding
Seeding,
/// Only torrents which are completed
Completed,
/// Only torrents which are running (same as active, or checking disk files)
Running,
/// Only torrents which are stopped
Stopped,
/// Only torrents which are active (downloading, seeding, metadata, etc)
Active,
/// Only torrents which are inactive (stopped, stalled, errored)
Inactive,
/// Only torrents which are stalled (no data transfer, coverse both `StalledUploading` and `StalledDownloading`)
Stalled,
/// Only torrents which are stalled uploading (not seeding any data)
StalledUploading,
/// Only torrents which are stalled downloading (not receiving any data)
StalledDownloading,
/// Only torrents which are checking disk files
Checking,
/// Only torrents which are moving
Moving,
/// Only torrents which are errored. (Missing files, failed to write, etc)
Errored,
}
impl Display for FilterTorrentState {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}",
match self {
Self::All => String::from("all"),
Self::Downloading => String::from("downloading"),
Self::Seeding => String::from("seeding"),
Self::Completed => String::from("completed"),
Self::Running => String::from("running"),
Self::Stopped => String::from("stopped"),
Self::Active => String::from("active"),
Self::Inactive => String::from("inactive"),
Self::Stalled => String::from("stalled"),
Self::StalledUploading => String::from("stalled_uploading"),
Self::StalledDownloading => String::from("stalled_downloading"),
Self::Checking => String::from("checking"),
Self::Moving => String::from("moving"),
Self::Errored => String::from("errored"),
}
)
}
}
/// Torrent sort fields
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
pub enum TorrentSort {
/// Time when the torrent was added to the client
AddedOn,
/// Amount of data left to download
AmountLeft,
/// Whether this torrent is managed by Automatic Torrent Management
AutoTmm,
/// Percentage of file pieces currently available
Availability,
/// Category of the torrent
Category,
/// Amount of transfer data completed
Completed,
/// Time when the torrent completed
CompletionOn,
/// Torrent content path
ContentPath,
/// Torrent download speed limit.
DlLimit,
/// Torrent download speed
Dlspeed,
/// Amount of data downloaded
Downloaded,
/// Amount of data downloaded this session
DownloadedSession,
/// Torrent ETA
Eta,
/// First last piece are prioritized
FLPiecePrio,
/// Force start is enabled for this torrent
ForceStart,
/// Torrent hash
Hash,
/// True if torrent is from a private tracker
Private,
/// Last time when a chunk was downloaded/uploaded
LastActivity,
/// Magnet URI corresponding to this torrent
MagnetUri,
/// Maximum share ratio until torrent is stopped from seeding/uploading
MaxRatio,
/// Maximum seeding time until torrent is stopped from seeding
MaxSeedingTime,
/// Torrent name
Name,
/// Number of seeds in the swarm
NumComplete,
/// Number of leechers in the swarm
NumIncomplete,
/// Number of leechers connected to
NumLeechs,
/// Number of seeds connected to
NumSeeds,
/// Torrent priority
Priority,
/// Torrent progress
Progress,
/// Torrent share ratio.
Ratio,
/// Maximum share ratio limit for the torrent
RatioLimit,
/// Time until the next tracker reannounce
Reannounce,
/// Path where this torrent's data is stored
SavePath,
/// Torrent elapsed time while complete
SeedingTime,
/// Torrent elapsed time while complete limit
SeedingTimeLimit,
/// Time when this torrent was last seen complete
SeenComplete,
/// True if sequential download is enabled
SeqDl,
/// Total size of files selected for download
Size,
/// Torrent state.
State,
/// Super seeding state
SuperSeeding,
/// Tag list of the torrent
Tags,
/// Total active time
TimeActive,
/// Total size of all file in this torrent. Including unselected ones
TotalSize,
/// The first tracker with working status. Empty string if no tracker is working.
Tracker,
/// Torrent upload speed limit
UpLimit,
/// Amount of data uploaded
Uploaded,
/// Amount of data uploaded this session
UploadedSession,
/// Torrent upload speed
Upspeed,
}
impl Display for TorrentSort {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}",
match self {
Self::AddedOn => "added_on",
Self::AmountLeft => "amount_left",
Self::AutoTmm => "auto_tmm",
Self::Availability => "availability",
Self::Category => "category",
Self::Completed => "completed",
Self::CompletionOn => "completion_on",
Self::ContentPath => "content_path",
Self::DlLimit => "dl_limit",
Self::Dlspeed => "dlspeed",
Self::Downloaded => "downloaded",
Self::DownloadedSession => "downloaded_session",
Self::Eta => "eta",
Self::FLPiecePrio => "f_l_piece_prio",
Self::ForceStart => "force_start",
Self::Hash => "hash",
Self::Private => "private",
Self::LastActivity => "last_activity",
Self::MagnetUri => "magnet_uri",
Self::MaxRatio => "max_ratio",
Self::MaxSeedingTime => "max_seeding_time",
Self::Name => "name",
Self::NumComplete => "num_complete",
Self::NumIncomplete => "num_incomplete",
Self::NumLeechs => "num_leechs",
Self::NumSeeds => "num_seeds",
Self::Priority => "priority",
Self::Progress => "progress",
Self::Ratio => "ratio",
Self::RatioLimit => "ratio_limit",
Self::Reannounce => "reannounce",
Self::SavePath => "save_path",
Self::SeedingTime => "seeding_time",
Self::SeedingTimeLimit => "seeding_time_limit",
Self::SeenComplete => "seen_complete",
Self::SeqDl => "seq_dl",
Self::Size => "size",
Self::State => "state",
Self::SuperSeeding => "super_seeding",
Self::Tags => "tags",
Self::TimeActive => "time_active",
Self::TotalSize => "total_size",
Self::Tracker => "tracker",
Self::UpLimit => "up_limit",
Self::Uploaded => "uploaded",
Self::UploadedSession => "uploaded_session",
Self::Upspeed => "upspeed",
}
)
}
}
/// Add torrent parameter object
// https://github.com/qbittorrent/qBittorrent/blame/master/src/webui/api/torrentscontroller.cpp
#[derive(Debug, Default, Builder, Clone, Deserialize, Serialize, PartialEq)]
pub struct AddTorrent {
/// A list of torrent files or magnet links to be added.
///
/// This field is required and must contain at least one item.
#[builder(setter(into))]
pub torrents: AddTorrentType,
#[builder(setter(into, strip_option), default = None)]
#[cfg(not(feature = "qBittorrent-5_3"))]
// https://github.com/qbittorrent/qBittorrent/pull/24724
pub skip_checking: Option<bool>,
#[cfg(feature = "qBittorrent-5_3")]
// https://github.com/qbittorrent/qBittorrent/pull/24724
#[builder(setter(into, strip_option), default = None)]
pub seed_mode: Option<bool>,
/// Enable sequential download.
#[builder(setter(into, strip_option), default = None)]
pub sequential_download: Option<bool>,
/// Prioritize download first last piece.
#[builder(setter(into, strip_option), default = None)]
pub first_last_piece_prio: Option<bool>,
#[builder(setter(into, strip_option), default = None)]
pub forced: Option<bool>,
#[builder(setter(into, strip_option), default = None)]
pub add_to_queue_top: Option<bool>,
/// Add torrents in the stopped state.
#[builder(setter(into, strip_option), default = None)]
pub stopped: Option<bool>,
/// Download folder
#[builder(setter(into, strip_option), default = None)]
pub save_path: Option<String>,
#[builder(setter(into, strip_option), default = None)]
pub download_path: Option<String>,
#[builder(setter(into, strip_option), default = None)]
pub use_download_path: Option<bool>,
/// Category for the torrent
#[builder(setter(into, strip_option), default = None)]
pub category: Option<String>,
/// Tags for the torrent.
#[builder(setter(into, strip_option), default = None)]
pub tags: Option<Vec<String>>,
/// Rename torrent
#[builder(setter(into, strip_option), default = None)]
pub rename: Option<String>,
/// Set torrent upload speed limit. Unit in bytes/second
#[builder(setter(into, strip_option), default = None)]
pub upload_limit: Option<i32>,
/// Set torrent download speed limit. Unit in bytes/second
#[builder(setter(into, strip_option), default = None)]
pub download_limit: Option<i32>,
/// Set torrent share ratio limit
#[builder(setter(into, strip_option), default = None)]
pub ratio_limit: Option<f64>,
/// Set torrent seeding time limit. Unit in minutes
#[builder(setter(into, strip_option), default = None)]
pub seeding_time_limit: Option<i32>,
#[builder(setter(into, strip_option), default = None)]
pub inactive_seeding_time_limit: Option<i32>,
#[cfg(feature = "qBittorrent-5_3")]
#[builder(setter(into, strip_option), default = None)]
pub share_limit_mode: Option<ShareLimitMode>,
#[builder(setter(into, strip_option), default = None)]
pub share_limit_action: Option<ShareLimitAction>,
/// Whether Automatic Torrent Management should be used
#[builder(setter(into, strip_option), default = None)]
pub auto_tmm: Option<bool>,
#[builder(setter(into, strip_option), default = None)]
pub stop_condition: Option<StopCondition>,
/// The torrent subfolder layout.
#[builder(setter(into), default)]
pub content_layout: ContentLayout,
}
/// The type of torrent to add. Either `magnet` links or `.torrent` files.
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
pub enum AddTorrentType {
/// Magnet links to add
Links(Vec<String>),
/// Files to add
Files(Vec<TorrentFile>),
}
impl AddTorrentType {
/// Checks to see if we have either urls/files. (Can't add a torrent without these)
pub fn is_empty(&self) -> bool {
match self {
AddTorrentType::Links(items) => items.is_empty(),
AddTorrentType::Files(items) => items.is_empty(),
}
}
}
impl From<Vec<String>> for AddTorrentType {
fn from(value: Vec<String>) -> Self {
Self::Links(value)
}
}
impl From<String> for AddTorrentType {
fn from(value: String) -> Self {
Self::Links(vec![value])
}
}
/// Information about the torrent file
#[derive(Debug, Deserialize, Serialize, Clone, Default, PartialEq)]
pub struct TorrentFile {
/// Name of file
pub filename: String,
/// Data stored in the file. (just fs::read would work)
pub data: Vec<u8>,
}
impl From<Vec<TorrentFile>> for AddTorrentType {
fn from(value: Vec<TorrentFile>) -> Self {
Self::Files(value)
}
}
impl From<TorrentFile> for AddTorrentType {
fn from(value: TorrentFile) -> Self {
Self::Files(vec![value])
}
}
impl Default for AddTorrentType {
fn default() -> Self {
AddTorrentType::Links(vec![])
}
}