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
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
use std::collections::HashMap;
use reqwest::multipart;
use crate::{
error::Error,
models::{RssFeedCollection, RssRule},
};
impl super::Api {
/// Add RSS folder to help categorise torrents.
///
/// [official documentation](https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-5.0)#add-folder)
///
/// # Arguments
///
/// * `path` - Full path of added folder. Use `\\` instead of `/` as the delimiter. (e.g. "The Pirate Bay\\Top100")
///
/// # Example
///
/// ```no_run
/// use qbit::{Api, Credentials};
///
/// #[tokio::main]
/// async fn main() {
/// let credentials = Credentials::new("username", "password");
/// let client = Api::new_login("http://127.0.0.1/", credentials)
/// .await
/// .unwrap();
///
/// let result = client.rss_add_folder("folder").await;
///
/// assert!(result.is_ok());
/// }
/// ```
pub async fn rss_add_folder(&self, path: &str) -> Result<(), Error> {
let form = multipart::Form::new().text("path", path.to_string());
self._post("rss/addFolder")
.await?
.multipart(form)
.send()
.await?
.error_for_status()?;
Ok(())
}
/// Add RSS feed
///
/// [official documentation](https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-5.0)#add-feed)
///
/// # Arguments
/// * `feed_url` - URL of RSS feed (e.g. "http://thepiratebay.org/rss//top100/200")
/// * `path` - Full path of added feed. Use `\\` instead of `/` as the delimiter. (e.g. "The Pirate Bay\\Top100")
///
/// # Example
///
/// ```no_run
/// use qbit::{Api, Credentials};
///
/// #[tokio::main]
/// async fn main() {
/// let credentials = Credentials::new("username", "password");
/// let client = Api::new_login("http://127.0.0.1/", credentials)
/// .await
/// .unwrap();
///
/// client.rss_add_folder("folder").await.unwrap();
///
/// let feed = "http://thepiratebay.org/rss//top100/200";
/// let result = client.rss_add_feed(feed, Some("folder")).await;
///
/// assert!(result.is_ok());
/// }
/// ```
#[allow(rustdoc::bare_urls)]
pub async fn rss_add_feed(&self, feed_url: &str, path: Option<&str>) -> Result<(), Error> {
let form = multipart::Form::new()
.text("url", feed_url.to_string())
.text("path", path.unwrap_or_default().to_string());
self._post("rss/addFeed")
.await?
.multipart(form)
.send()
.await?
.error_for_status()?;
Ok(())
}
/// Removes folder or rss feed.
///
/// [official documentation](https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-5.0)#remove-item)
///
/// # Arguments
/// * `path` - Full path of removed item. Use `\\` instead of `/` as the delimiter. (e.g. "The Pirate Bay\\Top100")
///
/// # Example
///
/// ```no_run
/// use qbit::{Api, Credentials};
///
/// #[tokio::main]
/// async fn main() {
/// let credentials = Credentials::new("username", "password");
/// let client = Api::new_login("http://127.0.0.1/", credentials)
/// .await
/// .unwrap();
///
/// let result = client.rss_remove_item("remove\\this\\item").await;
///
/// assert!(result.is_ok());
/// }
/// ```
pub async fn rss_remove_item(&self, path: &str) -> Result<(), Error> {
let form = multipart::Form::new().text("path", path.to_string());
self._post("rss/removeItem")
.await?
.multipart(form)
.send()
.await?
.error_for_status()?;
Ok(())
}
/// Moves/renames folder or feed.
///
/// [official documentation](https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-5.0)#move-item)
///
/// # Arguments
/// * `item_path` - Current full path of item. Use `\\` instead of `/` as the delimiter. (e.g. "The Pirate Bay\\Top100")
/// * `dest_path` - New full path of item. Use `\\` instead of `/` as the delimiter. (e.g. "The Pirate Bay")
///
/// # Example
///
/// ```no_run
/// use qbit::{Api, Credentials};
///
/// #[tokio::main]
/// async fn main() {
/// let credentials = Credentials::new("username", "password");
/// let client = Api::new_login("http://127.0.0.1/", credentials)
/// .await
/// .unwrap();
///
/// let result = client.rss_move_item("move\\it", "to\\here").await;
///
/// assert!(result.is_ok());
/// }
/// ```
pub async fn rss_move_item(&self, item_path: &str, dest_path: &str) -> Result<(), Error> {
let form = multipart::Form::new()
.text("itemPath", item_path.to_string())
.text("destPath", dest_path.to_string());
self._post("rss/moveItem")
.await?
.multipart(form)
.send()
.await?
.error_for_status()?;
Ok(())
}
/// Get all RSS items
///
/// [official documentation](https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-5.0)#get-all-items)
///
/// # Arguments
///
/// * `withData` - Also return the articles of every feed.
///
/// # Returns
/// A `HashMap` where the keys are feed names and the values are `RssFeedCollection` objects.
/// The `RssFeedCollection` contains detailed information about each RSS feed, including its
/// articles if `withData` is set to true. `RssFeedCollection` can have nested `RssFeedCollection`
///
/// # Example
///
/// ```no_run
/// use qbit::{Api, Credentials};
///
/// #[tokio::main]
/// async fn main() {
/// let credentials = Credentials::new("username", "password");
/// let client = Api::new_login("http://127.0.0.1/", credentials)
/// .await
/// .unwrap();
///
/// let feed = client.rss_items(true).await.unwrap();
///
/// for item in feed {
/// println!("{:?}", item);
/// }
/// }
/// ```
pub async fn rss_items(
&self,
with_data: bool,
) -> Result<HashMap<String, RssFeedCollection>, Error> {
let query = vec![("withData", with_data)];
let feed = self
._get("rss/items")
.await?
.query(&query)
.send()
.await?
.error_for_status()?
.json::<HashMap<String, RssFeedCollection>>()
.await?;
Ok(feed)
}
/// Mark article / folder / feed as read
///
/// If `article_id` is set only the article is marked as read otherwise the whole
/// feed is going to be marked as read.
///
/// [official documentation](https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-5.0)#mark-as-read)
///
/// # Arguments
/// * `path` - Current full path of item. Use `\\` instead of `/` as the delimiter. (e.g. "The Pirate Bay\\Top100")
/// * `article_id` - ID of article
///
/// # Example
///
/// ```no_run
/// use qbit::{Api, Credentials};
///
/// #[tokio::main]
/// async fn main() {
/// let credentials = Credentials::new("username", "password");
/// let client = Api::new_login("http://127.0.0.1/", credentials)
/// .await
/// .unwrap();
///
/// let result = client.rss_mark_as_read("path\\to\\feed", None).await;
///
/// assert!(result.is_ok());
/// }
/// ```
pub async fn rss_mark_as_read(&self, path: &str, article_id: Option<u64>) -> Result<(), Error> {
let mut form = multipart::Form::new().text("path", path.to_string());
if let Some(article_id) = article_id {
form = form.text("articleId", article_id.to_string());
}
self._post("rss/markAsRead")
.await?
.multipart(form)
.send()
.await?
.error_for_status()?;
Ok(())
}
/// Refreshes folder or feed.
///
/// [official documentation](https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-5.0)#refresh-item)
///
/// # Arguments
/// * `item_path` - Current full path of item. Use `\\` instead of `/` as the delimiter. (e.g. "The Pirate Bay\\Top100")
///
/// # Example
///
/// ```no_run
/// use qbit::{Api, Credentials};
///
/// #[tokio::main]
/// async fn main() {
/// let credentials = Credentials::new("username", "password");
/// let client = Api::new_login("http://127.0.0.1/", credentials)
/// .await
/// .unwrap();
///
/// let result = client.rss_refresh_item("path\\to\\feed").await;
///
/// assert!(result.is_ok());
/// }
/// ```
pub async fn rss_refresh_item(&self, item_path: &str) -> Result<(), Error> {
let form = multipart::Form::new().text("itemPath", item_path.to_string());
self._post("rss/refreshItem")
.await?
.multipart(form)
.send()
.await?
.error_for_status()?;
Ok(())
}
/// Set RSS rule
///
/// [official documentation](https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-5.0)#set-auto-downloading-rule)
///
/// # Arguments
/// * `name` - Rule name (e.g. "Punisher")
/// * `def` - rule definition
///
/// # Example
///
/// ```no_run
/// use qbit::{Api, Credentials};
/// use qbit::models::RssRule;
///
/// #[tokio::main]
/// async fn main() {
/// let credentials = Credentials::new("username", "password");
/// let client = Api::new_login("http://127.0.0.1/", credentials)
/// .await
/// .unwrap();
///
/// let rule = RssRule::default();
/// let result = client.rss_set_rule("rule_name", rule).await;
///
/// assert!(result.is_ok());
/// }
/// ```
pub async fn rss_set_rule(&self, name: &str, def: RssRule) -> Result<(), Error> {
let form = multipart::Form::new()
.text("ruleName", name.to_string())
.text("ruleDef", serde_json::to_string(&def)?);
self._post("rss/setRule")
.await?
.multipart(form)
.send()
.await?
.error_for_status()?;
Ok(())
}
/// Rename RSS rule
///
/// [official documentation](https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-5.0)#rename-auto-downloading-rule)
///
/// # Arguments
/// * `name` - Rule name (e.g. "Punisher")
/// * `new_name` - New rule name (e.g. "The Punisher")
///
/// # Example
///
/// ```no_run
/// use qbit::{Api, Credentials};
///
/// #[tokio::main]
/// async fn main() {
/// let credentials = Credentials::new("username", "password");
/// let client = Api::new_login("http://127.0.0.1/", credentials)
/// .await
/// .unwrap();
///
/// let result = client.rss_rename_rule("old_name", "new_name").await;
///
/// assert!(result.is_ok());
/// }
/// ```
pub async fn rss_rename_rule(&self, name: &str, new_name: &str) -> Result<(), Error> {
let form = multipart::Form::new()
.text("ruleName", name.to_string())
.text("newRuleName", new_name.to_string());
self._post("rss/renameRule")
.await?
.multipart(form)
.send()
.await?
.error_for_status()?;
Ok(())
}
/// Remove RSS rule
///
/// [official documentation](https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-5.0)#remove-auto-downloading-rule)
///
/// # Arguments
/// * `name` - Rule name (e.g. "Punisher")
///
/// # Example
///
/// ```no_run
/// use qbit::{Api, Credentials};
///
/// #[tokio::main]
/// async fn main() {
/// let credentials = Credentials::new("username", "password");
/// let client = Api::new_login("http://127.0.0.1/", credentials)
/// .await
/// .unwrap();
///
/// let result = client.rss_remove_rule("rule_name").await;
///
/// assert!(result.is_ok());
/// }
/// ```
pub async fn rss_remove_rule(&self, name: &str) -> Result<(), Error> {
let form = multipart::Form::new().text("ruleName", name.to_string());
self._post("rss/removeRule")
.await?
.multipart(form)
.send()
.await?
.error_for_status()?;
Ok(())
}
/// Get all RSS rules
///
/// [official documentation](https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-5.0)#get-all-auto-downloading-rules)
///
/// # Example
///
/// ```no_run
/// use qbit::{Api, Credentials};
///
/// #[tokio::main]
/// async fn main() {
/// let credentials = Credentials::new("username", "password");
/// let client = Api::new_login("http://127.0.0.1/", credentials)
/// .await
/// .unwrap();
///
/// let rules = client.rss_rules().await.unwrap();
///
/// for rule in rules {
/// println!("{:?}", rule);
/// }
/// }
/// ```
pub async fn rss_rules(&self) -> Result<HashMap<String, RssRule>, Error> {
let rules = self
._get("rss/rules")
.await?
.send()
.await?
.error_for_status()?
.json::<HashMap<String, RssRule>>()
.await?;
Ok(rules)
}
/// Get all articles matching the given rule.
///
/// [official documentation](https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-5.0)#get-all-articles-matching-a-rule)
///
/// # Arguments
/// * `name` - Rule name (e.g. "Linux")
///
/// # Example
///
/// ```no_run
/// use qbit::{Api, Credentials};
///
/// #[tokio::main]
/// async fn main() {
/// let credentials = Credentials::new("username", "password");
/// let client = Api::new_login("http://127.0.0.1/", credentials)
/// .await
/// .unwrap();
///
/// let articles = client.rss_rules_articles("rule_name").await.unwrap();
///
/// for article in articles {
/// println!("{:?}", article);
/// }
/// }
/// ```
pub async fn rss_rules_articles(
&self,
name: &str,
) -> Result<HashMap<String, Vec<String>>, Error> {
let query = vec![("ruleName", name)];
let articles = self
._get("rss/matchingArticles")
.await?
.query(&query)
.send()
.await?
.error_for_status()?
.json::<HashMap<String, Vec<String>>>()
.await?;
Ok(articles)
}
}