tiktok/
lib.rs

1mod client;
2mod model;
3
4pub use self::client::Client;
5pub use self::model::FeedCursor;
6pub use self::model::Post;
7pub use url::Url;
8
9#[derive(Debug, thiserror::Error)]
10pub enum Error {
11    /// Reqwest HTTP error
12    #[error(transparent)]
13    Reqwest(#[from] reqwest::Error),
14
15    /// A Tokio task failed to join
16    #[error(transparent)]
17    TokioJoin(#[from] tokio::task::JoinError),
18}
19
20#[cfg(test)]
21mod test {
22    use super::*;
23
24    // Broken URLs.
25    // Were they deleted?
26    // Old URL format?
27    // "https://vm.tiktok.com/TTPdrksrdc/"
28    // "https://www.tiktok.com/t/ZTRQsJaw1/"
29    const POST_URLS: &[&str] = &["https://www.tiktok.com/@von.jakoba/video/7270331232595021098"];
30
31    // The IID we use has been banned.
32    // We need to get another one.
33    #[tokio::test]
34    #[ignore]
35    async fn get_feed_post() {
36        let client = Client::new();
37        for url in POST_URLS {
38            let video_id = Url::parse(url)
39                .expect("failed to parse url")
40                .path_segments()
41                .expect("missing path")
42                .next_back()
43                .expect("missing video id")
44                .parse()
45                .expect("invalid video id");
46            let feed_cursor = client
47                .get_feed(Some(video_id))
48                .await
49                .expect("failed to get post");
50            let entry = feed_cursor.aweme_list.first().expect("missing entry");
51            assert!(entry.aweme_id == video_id);
52
53            let download_url = entry
54                .video
55                .download_addr
56                .url_list
57                .first()
58                .expect("missing download url");
59            client
60                .client
61                .get(download_url.as_str())
62                .send()
63                .await
64                .expect("failed to send request")
65                .error_for_status()
66                .expect("invalid status code")
67                .bytes()
68                .await
69                .expect("failed to download");
70        }
71    }
72}