Skip to main content

bpi_rs/danmaku/
snapshot.rs

1//! 弹幕快照(最近产生的几条弹幕,最多20条)
2//!
3//! [文档入口](https://github.com/SocialSisterYi/bilibili-API-collect/tree/master/docs/danmaku)
4
5use crate::{ BilibiliRequest, BpiClient, BpiError, BpiResponse };
6
7pub type SnapshotResponse = BpiResponse<Vec<String>>;
8
9impl BpiClient {
10    /// 获取弹幕快照(最近产生的若干条,最多20条)
11    ///
12    /// # 文档
13    /// [查看API文档](https://github.com/SocialSisterYi/bilibili-API-collect/tree/master/docs/danmaku)
14    ///
15    /// # 参数
16    ///
17    /// | 名称 | 类型 | 说明 |
18    /// | ---- | ---- | ---- |
19    /// | `aid_or_bvid` | &str | 可传 `avid` (数字) 或 `bvid` (如 `BV...`) |
20    pub async fn danmaku_snapshot(&self, aid_or_bvid: &str) -> Result<SnapshotResponse, BpiError> {
21        let resp: SnapshotResponse = self
22            .get("https://api.bilibili.com/x/v2/dm/ajax")
23            .query(&[("aid", aid_or_bvid.to_string())])
24            .send_bpi("获取弹幕快照").await?;
25
26        Ok(resp)
27    }
28}
29
30#[cfg(test)]
31pub mod tests {
32    use super::*;
33
34    #[tokio::test]
35    async fn test_get_danmaku_snapshot() -> Result<(), Box<BpiError>> {
36        let bpi = BpiClient::new();
37        let result = bpi.danmaku_snapshot("BV1fK4y1t741").await?;
38
39        let data = result.into_data()?;
40        tracing::info!("{:#?}", data);
41
42        Ok(())
43    }
44}