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    /// 文档: https://github.com/SocialSisterYi/bilibili-API-collect/tree/master/docs/danmaku
13    ///
14    /// 参数
15    ///
16    /// | 名称 | 类型 | 说明 |
17    /// | ---- | ---- | ---- |
18    /// | `aid_or_bvid` | &str | 可传 `avid` (数字) 或 `bvid` (如 `BV...`) |
19    pub async fn danmaku_snapshot(&self, aid_or_bvid: &str) -> Result<SnapshotResponse, BpiError> {
20        let resp: SnapshotResponse = self
21            .get("https://api.bilibili.com/x/v2/dm/ajax")
22            .query(&[("aid", aid_or_bvid.to_string())])
23            .send_bpi("获取弹幕快照")
24            .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}