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
use std::{
borrow::Borrow,
path::{Path, PathBuf},
};
use serde::Serialize;
use crate::{Error, Qbit, Result, ext::*, model::*};
impl Qbit {
/// Return the qBittorrent application version.
pub async fn get_version(&self) -> Result<String> {
self.get("app/version")
.await?
.text()
.await
.map_err(Into::into)
}
/// Return the qBittorrent Web API version.
pub async fn get_webapi_version(&self) -> Result<String> {
self.get("app/webapiVersion")
.await?
.text()
.await
.map_err(Into::into)
}
/// Return qBittorrent build information and dependency versions.
pub async fn get_build_info(&self) -> Result<BuildInfo> {
self.get("app/buildInfo")
.await?
.json()
.await
.map_err(Into::into)
}
/// Get process info, including launch time.
///
/// Added in qBittorrent 5.2.0 (Web API v2.15.1).
pub async fn get_process_info(&self) -> Result<ProcessInfo> {
self.get("app/processInfo")
.await?
.json()
.await
.map_err(Into::into)
}
/// Get cookies stored in the qBittorrent WebUI.
///
/// Added in qBittorrent 5.2.0 (Web API v2.11.3).
pub async fn get_cookies(&self) -> Result<Vec<CookieEntry>> {
self.get("app/cookies")
.await?
.json()
.await
.map_err(Into::into)
}
/// Set cookies for the qBittorrent WebUI.
///
/// Added in qBittorrent 5.2.0 (Web API v2.11.3).
pub async fn set_cookies(&self, cookies: &[SetCookieArg]) -> Result<()> {
#[derive(Serialize)]
struct Arg<'a> {
cookies: &'a str,
}
let json = serde_json::to_string(cookies)?;
self.post_with("app/setCookies", &Arg { cookies: &json })
.await?
.end()
}
/// Shut down the qBittorrent application.
pub async fn shutdown(&self) -> Result<()> {
self.post("app/shutdown").await?.end()
}
/// Return the application preferences.
pub async fn get_preferences(&self) -> Result<Preferences> {
self.get("app/preferences")
.await?
.json()
.await
.map_err(Into::into)
}
/// Update the supplied application preferences.
pub async fn set_preferences(
&self,
preferences: impl Borrow<Preferences> + Send + Sync,
) -> Result<()> {
#[derive(Serialize)]
struct Arg {
json: String,
}
self.post_with(
"app/setPreferences",
&Arg {
json: serde_json::to_string(preferences.borrow())?,
},
)
.await?
.end()
}
/// Get free disk space at the given path (in bytes).
///
/// Added in qBittorrent 5.2.0 (Web API v2.15.2).
pub async fn get_free_space_at_path(
&self,
path: impl AsRef<Path> + Send + Sync,
) -> Result<u64> {
#[derive(Serialize)]
struct Arg<'a> {
path: &'a Path,
}
self.get_with(
"app/getFreeSpaceAtPathAction",
&Arg {
path: path.as_ref(),
},
)
.await?
.text()
.await
.map_err(Into::into)
.and_then(|s| {
s.parse::<u64>().map_err(|_| Error::BadResponse {
explain: "getFreeSpaceAtPathAction returned non-numeric response",
})
})
}
/// Return the default path used to save torrent content.
pub async fn get_default_save_path(&self) -> Result<PathBuf> {
self.get("app/defaultSavePath")
.await?
.text()
.await
.map_err(Into::into)
.map(PathBuf::from)
}
}