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
mod client;
pub mod types;

pub use crate::{
    client::Client,
    types::{
        GetVideoResponse,
        MainPage,
    },
};

/// Client Error
#[derive(Debug, thiserror::Error)]
pub enum Error {
    /// HTTP Reqwest Error
    #[error(transparent)]
    Reqwest(#[from] reqwest::Error),

    /// invalid main page
    #[error("invalid main page")]
    InvalidMainPage(#[from] crate::types::main_page::FromHtmlError),

    /// a tokio task failed
    #[error(transparent)]
    TokioJoin(#[from] tokio::task::JoinError),
}

#[cfg(test)]
mod test {
    use super::*;

    /// The server appears to use cloudflare.
    /// This server will block requests from github's CI with a 403 HTTP status code.
    /// Therefore, only test this locally.
    #[tokio::test]
    #[ignore]
    async fn it_works() {
        let video_url = "https://www.reddit.com/r/dankvideos/comments/h8p0py/pp_removal_time/?utm_source=share&utm_medium=web2x";
        let client = Client::new();
        let main_page = client
            .get_main_page()
            .await
            .expect("failed to get main page");
        let vid = client
            .get_video(&main_page, video_url)
            .await
            .expect("failed to get video")
            .into_result()
            .expect("invalid api response");

        dbg!(vid);
    }
}