reddit_tube/
lib.rs

1mod client;
2pub mod types;
3
4pub use crate::{
5    client::Client,
6    types::{
7        GetVideoResponse,
8        MainPage,
9    },
10};
11
12/// Client Error
13#[derive(Debug, thiserror::Error)]
14pub enum Error {
15    /// HTTP Reqwest Error
16    #[error(transparent)]
17    Reqwest(#[from] reqwest::Error),
18
19    /// invalid main page
20    #[error("invalid main page")]
21    InvalidMainPage(#[from] crate::types::main_page::FromHtmlError),
22
23    /// a tokio task failed
24    #[error(transparent)]
25    TokioJoin(#[from] tokio::task::JoinError),
26}
27
28#[cfg(test)]
29mod test {
30    use super::*;
31
32    /// The server appears to use cloudflare.
33    /// This server will block requests from github's CI with a 403 HTTP status code.
34    /// Therefore, only test this locally.
35    #[tokio::test]
36    #[ignore]
37    async fn it_works() {
38        let video_url = "https://www.reddit.com/r/dankvideos/comments/h8p0py/pp_removal_time/?utm_source=share&utm_medium=web2x";
39        let client = Client::new();
40        let main_page = client
41            .get_main_page()
42            .await
43            .expect("failed to get main page");
44        let vid = client
45            .get_video(&main_page, video_url)
46            .await
47            .expect("failed to get video")
48            .into_result()
49            .expect("invalid api response");
50
51        dbg!(vid);
52    }
53}