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
//! Contains tons of structs used by the library
//!
//! All examples here are based off the [Torznab spec](https://torznab.github.io/spec-1.3-draft/torznab/Specification-v1.3.html)'s `/api?caps` example.
use HashMap;
pub type AuthFunc = fn ;
pub type SearchFunc = fn ;
// TODO: Redo this all so that is uses builders with `AsRef<str>` arguments instead
/// The maximum and defaults for the `limit` parameter in queries
/// `max` is the maximum number of results the program can return
/// `default` is the default number of results the program will return
///
/// Example:
/// ```
/// let query_limits = Limits {
/// max: 100, // maximum of 100 results per search query
/// default: 50, // default of 50
/// };
/// ```
/// A struct holding the info for a type of search
///
/// Example:
/// ```
/// let tv_query_search_info = SearchInfo {
/// search_type: "tv-search".to_string(),
/// available: true,
/// supported_params: vec!["q", "rid", "tvdbid", "season", "ep"]
/// .into_iter().map(|i| i.to_string()).collect::<String>(), // this bit's just to make all the `str`s to `String`s
/// };
/// ```
/// Contains subcategories, for use in [`Category`]
///
/// Example:
/// ```
/// let subcat = Subcategory {
/// id: 2010,
/// name: "Foreign".to_string(),
/// };
/// ```
/// Contains a category, for use in [`Caps`] and searches as a query parameter
///
/// Example, using `subcat` from the [`Subcategory`] example:
/// ```
/// let category = Category {
/// id: 2000,
/// name: "Movies".to_string(),
/// subcategory: vec![subcat],
/// };
/// ```
/// Contains a genre, for use in [`Caps`] and searches as a query parameter
///
/// Example:
/// ```
/// let genre = Genre {
/// id: 1,
/// category_id: 5000,
/// name: "Kids".to_string(),
/// };
/// ```
/// Contains a tag, for use in [`Caps`] and searches as a query parameter
///
/// Example:
///
/// ```
/// let tag = Tag {
/// name: "trusted".to_string(),
/// description: "Uploader has high reputation".to_string(),
/// };
/// ```
/// Holds the configuration for the capabilities of the Torznab server (used in `/api?t=caps`)
///
/// <div class="warning">Note that this library might not support all the capabilities listed in yet, so check the README before listing capabilities, or just accept that unsupported capabilities will return error 501.
///
/// It's recommended to add any capabilities you want, and set `available` to `false` in the [`Caps`] struct for any currently unsupported search types.</div>
///
/// Example, using other examples:
/// ```
/// let mut info: HashMap<String, String> = HashMap::new();
/// info.insert("version".to_string(), "1.1".to_string());
///
/// let caps_data = Caps {
/// server_info: Some(info),
/// limits: query_limits,
/// searching: vec![tv_query_search_info],
/// categories: vec![category],
/// genres: Some(vec![genre]),
/// tags: Some(vec![tag]),
/// };
/// ```
/// A struct that holds configuration for torznab-toolkit
/// The search function (`/api?t=search`) and capabilities (`/api?t=caps` - struct [`Caps`]) are required
/// Everything else is optional
///
/// Example, using other examples:
/// ```
/// fn search_func(parameters: SearchParameters) -> Result<Vec<Torrent>, String> {
/// let torrent = /* see `Torrent` example */
/// return torrent;
/// }
///
/// fn auth_func(apikey: String) -> Result<bool, String> {
/// if apikey == "letmein".to_string() {
/// return Ok(true);
/// }
/// return Ok(false);
/// }
///
/// let conf = Config {
/// search: search,
/// auth: Some(auth),
/// caps: caps_data,
/// }
/// ```
/// Holds the parameters for a search query
/// Holds the info for a torrent
///
/// Any attributes not listed here are optional, and can be put in `other_attributes`; **however**, the following are recommended:
/// - `seeders`
/// - `leechers`
/// - `peers`
/// - `infohash`
/// - `link` (link to a webpage; if not specified, will fallback to `torrent_file_url`, then `magnet_uri`)
///
/// <div class="warning">One of either `torrent_file_url` or `magnet_uri` are required.</div>
/// Example:
/// ```
/// let torrent = Torrent {
/// title: "totally normal torrent".to_string(),
/// description: None,
/// size: 2484345508,
/// category_ids: vec![1010],
/// torrent_file_url: Some("http://localhost/totally-normal.torrent".to_string()),
/// magnet_uri: Some("magnet:?xt=urn:btih:blahblahblahdothechachacha".to_string()),
/// other_attributes: None,
/// };
/// ```