holodex 0.3.3

A Rust wrapper of the Holodex v2 API.
Documentation
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
502
503
504
505
506
507
508
509
510
511
//! Builders for ergonomically creating various large structs.

use std::fmt::Display;

use chrono::{DateTime, Utc};
use serde::{self, Serialize};

use crate::errors::Error;

use super::{
    id::{ChannelId, VideoId},
    ChannelFilter, ChannelSortingCriteria, ChannelType, CommentSearch, ExtraVideoInfo, Language,
    Order, Organisation, SearchOrder, VideoFilter, VideoSearch, VideoSearchCondition,
    VideoSortingCriteria, VideoStatus, VideoType,
};

#[derive(Serialize, Debug, Default, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
/// Builder for creating a [`VideoFilter`].
pub struct VideoFilterBuilder {
    filter: VideoFilter,
}

impl VideoFilterBuilder {
    #[inline]
    #[must_use]
    /// Create a new `VideoFilterBuilder` with default values.
    pub fn new() -> Self {
        Self::default()
    }

    #[inline]
    #[must_use]
    /// Request extra information to be included with each video.
    pub fn include(mut self, include: &[ExtraVideoInfo]) -> Self {
        self.filter.include = include.to_vec();
        self
    }

    #[inline]
    #[must_use]
    /// Enable pagination.
    pub const fn paginated(mut self, paginated: bool) -> Self {
        self.filter.paginated = paginated;
        self
    }

    #[inline]
    #[must_use]
    /// Limit how many videos are returned. This will turn on pagination.
    pub const fn limit(mut self, limit: u32) -> Self {
        self.filter.limit = limit;
        self.filter.paginated = true;
        self
    }

    #[inline]
    #[must_use]
    /// Offset the results by the given amount. This will turn on pagination.
    pub const fn offset(mut self, offset: i32) -> Self {
        self.filter.offset = offset;
        self.filter.paginated = true;
        self
    }

    #[inline]
    #[must_use]
    /// Sort videos by the given criteria.
    pub const fn sort_by(mut self, sort_by: VideoSortingCriteria) -> Self {
        self.filter.sort_by = sort_by;
        self
    }

    #[inline]
    #[must_use]
    /// Sort videos in the given order.
    pub const fn order(mut self, order: Order) -> Self {
        self.filter.order = order;
        self
    }

    #[inline]
    #[must_use]
    #[allow(clippy::missing_const_for_fn)]
    /// Only return videos from the given channel.
    pub fn channel_id(mut self, channel_id: ChannelId) -> Self {
        self.filter.channel_id = Some(channel_id);
        self
    }

    #[inline]
    #[must_use]
    #[allow(clippy::missing_const_for_fn)]
    /// Only return videos with any of the given IDs.
    pub fn id(mut self, ids: &[VideoId]) -> Self {
        self.filter.id = ids.to_vec();
        self
    }

    #[inline]
    #[must_use]
    #[allow(clippy::missing_const_for_fn)]
    /// Only return videos from a channel part of the given organisation.
    pub fn organisation(mut self, org: Organisation) -> Self {
        self.filter.org = Some(org);
        self
    }

    #[inline]
    #[must_use]
    /// Only return videos in any of the given languages.
    pub fn language(mut self, lang: &[Language]) -> Self {
        self.filter.lang = lang.to_vec();
        self
    }

    #[inline]
    #[must_use]
    /// Only return videos scheduled to go live within the given amount of hours.
    pub const fn max_upcoming_hours(mut self, hours: u32) -> Self {
        self.filter.max_upcoming_hours = hours;
        self
    }

    #[inline]
    #[must_use]
    #[allow(clippy::missing_const_for_fn)]
    /// Only return videos mentioning the given channel.
    pub fn mentioned_channel_id(mut self, channel_id: ChannelId) -> Self {
        self.filter.mentioned_channel_id = Some(channel_id);
        self
    }

    #[inline]
    #[must_use]
    /// Only return videos related to the given topic.
    pub fn topic(mut self, topic: &str) -> Self {
        self.filter.topic = Some(topic.to_owned());
        self
    }

    #[inline]
    #[must_use]
    /// Only return videos of the given type.
    pub const fn video_type(mut self, video_type: VideoType) -> Self {
        self.filter.video_type = video_type;
        self
    }

    #[inline]
    #[must_use]
    /// Only return videos with any of the given statuses.
    pub fn status(mut self, status: &[VideoStatus]) -> Self {
        self.filter.status = status.to_vec();
        self
    }

    #[inline]
    #[must_use]
    /// Only return videos made available after the given time.
    pub const fn after(mut self, after: DateTime<Utc>) -> Self {
        self.filter.from = Some(after);
        self
    }

    #[inline]
    #[must_use]
    #[allow(clippy::missing_const_for_fn)]
    /// Consume the builder, returning the constructed filter.
    pub fn build(self) -> VideoFilter {
        self.filter
    }
}

impl Display for VideoFilterBuilder {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}({})", stringify!(VideoFilterBuilder), self.filter)
    }
}

impl From<VideoFilterBuilder> for VideoFilter {
    fn from(builder: VideoFilterBuilder) -> Self {
        builder.filter
    }
}

#[derive(Serialize, Debug, Default, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
/// Builder for creating a [`ChannelFilter`].
pub struct ChannelFilterBuilder {
    filter: ChannelFilter,
}

impl ChannelFilterBuilder {
    #[inline]
    #[must_use]
    /// Create a new `ChannelFilterBuilder` with default values.
    pub fn new() -> Self {
        Self::default()
    }

    #[inline]
    #[must_use]
    /// Sort channels by the given criteria.
    pub const fn sort_by(mut self, sort_by: ChannelSortingCriteria) -> Self {
        self.filter.sort_by = sort_by;
        self
    }

    #[inline]
    #[must_use]
    /// Sort channels in the given order.
    pub const fn order(mut self, order: Order) -> Self {
        self.filter.order = order;
        self
    }

    #[inline]
    #[must_use]
    /// Only return channels that uses any of the given languages as their main language.
    pub fn language(mut self, lang: &[Language]) -> Self {
        self.filter.languages = lang.to_vec();
        self
    }

    #[inline]
    #[must_use]
    /// Only return channels of the given type.
    pub const fn channel_type(mut self, channel_type: ChannelType) -> Self {
        self.filter.channel_type = Some(channel_type);
        self
    }

    #[inline]
    #[must_use]
    #[allow(clippy::missing_const_for_fn)]
    /// Only return channels part of the given organisation.
    pub fn organisation(mut self, organisation: Organisation) -> Self {
        self.filter.organisation = Some(organisation);
        self
    }

    #[inline]
    #[must_use]
    /// Limit the number of returned channels to the given value.
    ///
    /// Value must be between `0` and `50`, inclusive.
    pub const fn limit(mut self, limit: u32) -> Self {
        self.filter.limit = limit;
        self
    }

    #[inline]
    #[must_use]
    /// Offset the returned values by the given amount of places.
    pub const fn offset(mut self, offset: i32) -> Self {
        self.filter.offset = offset;
        self
    }

    /// Consume the builder, returning the constructed filter.
    ///
    /// # Errors
    /// Will return [`Error::FilterCreationError`] if the filter was constructed with invalid arguments.
    pub fn build(self) -> Result<ChannelFilter, Error> {
        match &self.filter.limit {
            0..=50 => (),
            _ => {
                return Err(Error::FilterCreationError(format!(
                "Could not instantiate {} with a limit of {}. Valid range is 0 to 50, inclusive.",
                stringify!(ChannelFilter),
                self.filter.limit
            )))
            }
        }

        Ok(self.filter)
    }
}

#[derive(Serialize, Debug, Default, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
/// Builder for creating a [`VideoSearch`].
pub struct VideoSearchBuilder {
    search: VideoSearch,
}

impl VideoSearchBuilder {
    #[inline]
    #[must_use]
    /// Create a new `VideoSearchBuilder` with default values.
    pub fn new() -> Self {
        Self::default()
    }

    #[inline]
    #[must_use]
    /// Only return videos that meet the given conditions.
    pub fn conditions(mut self, conditions: &[VideoSearchCondition]) -> Self {
        self.search.conditions = conditions.to_vec();
        self
    }

    #[inline]
    #[must_use]
    /// Enable pagination.
    pub const fn paginated(mut self, paginated: bool) -> Self {
        self.search.paginated = paginated;
        self
    }

    #[inline]
    #[must_use]
    /// Limit how many videos are returned. This will turn on pagination.
    pub const fn limit(mut self, limit: u32) -> Self {
        self.search.limit = limit;
        self.search.paginated = true;
        self
    }

    #[inline]
    #[must_use]
    /// Offset the results by the given amount. This will turn on pagination.
    pub const fn offset(mut self, offset: i32) -> Self {
        self.search.offset = offset;
        self.search.paginated = true;
        self
    }

    #[inline]
    #[must_use]
    /// In what order the videos should be returned.
    pub const fn order(mut self, order: SearchOrder) -> Self {
        self.search.sort_order = order;
        self
    }

    #[inline]
    #[must_use]
    #[allow(clippy::missing_const_for_fn)]
    /// Only return videos that involve all of the given channels.
    ///
    /// If two or more channel IDs are specified, only collabs with all of them will be returned,
    /// or if one channel is a clipper, it will only show clips of the other channels made by this clipper.
    pub fn channels(mut self, channels: &[ChannelId]) -> Self {
        self.search.channels = channels.to_vec();
        self
    }

    #[inline]
    #[must_use]
    #[allow(clippy::missing_const_for_fn)]
    /// Only return videos from channels in the given organisation, or are clips from a channel in the organisation.
    pub fn organisations(mut self, organisations: &[Organisation]) -> Self {
        self.search.organisations = organisations.to_vec();
        self
    }

    #[inline]
    #[must_use]
    /// Only return videos in any of the given languages.
    pub fn languages(mut self, languages: &[Language]) -> Self {
        self.search.languages = languages.to_vec();
        self
    }

    #[inline]
    #[must_use]
    /// Only return videos that are related to any of the given topics.
    pub fn topics(mut self, topics: &[String]) -> Self {
        self.search.topics = topics.to_vec();
        self
    }

    #[inline]
    #[must_use]
    /// Only return videos that are any of the given types.
    pub fn types(mut self, types: &[VideoType]) -> Self {
        self.search.types = types.to_vec();
        self
    }

    #[inline]
    #[must_use]
    #[allow(clippy::missing_const_for_fn)]
    /// Consume the builder, returning the constructed search.
    pub fn build(self) -> VideoSearch {
        self.search
    }
}

impl From<VideoSearchBuilder> for VideoSearch {
    fn from(builder: VideoSearchBuilder) -> Self {
        builder.search
    }
}

#[derive(Serialize, Debug, Default, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
/// Builder for creating a [`CommentSearch`].
pub struct CommentSearchBuilder {
    search: CommentSearch,
}

impl CommentSearchBuilder {
    #[inline]
    #[must_use]
    /// Create a new `CommentSearchBuilder` with default values and the given substring to search for.
    pub fn new(search: &str) -> Self {
        Self {
            search: CommentSearch {
                search: search.to_owned(),
                ..CommentSearch::default()
            },
        }
    }

    #[inline]
    #[must_use]
    /// Enable pagination.
    pub const fn paginated(mut self, paginated: bool) -> Self {
        self.search.paginated = paginated;
        self
    }

    #[inline]
    #[must_use]
    /// Limit how many comments on videos are returned. This will turn on pagination.
    pub const fn limit(mut self, limit: u32) -> Self {
        self.search.limit = limit;
        self.search.paginated = true;
        self
    }

    #[inline]
    #[must_use]
    /// Offset the results by the given amount. This will turn on pagination.
    pub const fn offset(mut self, offset: i32) -> Self {
        self.search.offset = offset;
        self.search.paginated = true;
        self
    }

    #[inline]
    #[must_use]
    /// In what order the comments should be returned.
    pub const fn order(mut self, order: SearchOrder) -> Self {
        self.search.sort_order = order;
        self
    }

    #[inline]
    #[must_use]
    #[allow(clippy::missing_const_for_fn)]
    /// Only return comments on videos that involve all of the given channels.
    ///
    /// If two or more channel IDs are specified,
    /// only comments on collabs with all of them will be returned,
    /// or if one channel is a clipper,
    /// it will only return comments on clips of the other channels made by this clipper.
    pub fn channels(mut self, channels: &[ChannelId]) -> Self {
        self.search.channels = channels.to_vec();
        self
    }

    #[inline]
    #[must_use]
    #[allow(clippy::missing_const_for_fn)]
    /// Only return comments on videos from channels in the given organisation,
    /// or that are clips from a channel in the organisation.
    pub fn organisations(mut self, organisations: &[Organisation]) -> Self {
        self.search.organisations = organisations.to_vec();
        self
    }

    #[inline]
    #[must_use]
    /// Filter away any comments on clips that are not in any of the given languages.
    ///
    /// Comment on streams will always be included no matter their language.
    pub fn languages(mut self, languages: &[Language]) -> Self {
        self.search.languages = languages.to_vec();
        self
    }

    #[inline]
    #[must_use]
    /// Only return comments on videos that are related to any of the given topics.
    pub fn topics(mut self, topics: &[String]) -> Self {
        self.search.topics = topics.to_vec();
        self
    }

    #[inline]
    #[must_use]
    /// Only return comments on videos that are any of the given types.
    pub fn types(mut self, types: &[VideoType]) -> Self {
        self.search.types = types.to_vec();
        self
    }

    #[inline]
    #[must_use]
    #[allow(clippy::missing_const_for_fn)]
    /// Consume the builder, returning the constructed search.
    pub fn build(self) -> CommentSearch {
        self.search
    }
}

impl From<CommentSearchBuilder> for CommentSearch {
    fn from(builder: CommentSearchBuilder) -> Self {
        builder.search
    }
}