Skip to main content

bpi_rs/danmaku/
history.rs

1//! 历史弹幕 API
2//!
3//! [文档入口](https://github.com/SocialSisterYi/bilibili-API-collect/tree/master/docs/danmaku)
4
5use crate::{ BilibiliRequest, BpiClient, BpiError, BpiResponse };
6use serde::{ Deserialize, Serialize };
7
8#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct HistoryDatesResponseData(Vec<String>);
10
11pub type HistoryDatesResponse = BpiResponse<Vec<String>>;
12
13impl BpiClient {
14    /// 查询历史弹幕日期
15    ///
16    /// # 文档
17    /// [查看API文档](https://github.com/SocialSisterYi/bilibili-API-collect/tree/master/docs/danmaku)
18    ///
19    /// # 参数
20    ///
21    /// | 名称 | 类型 | 说明 |
22    /// | ---- | ---- | ---- |
23    /// | `oid` | i64 | 视频 cid |
24    /// | `month` | &str | 形如 `2006-01` |
25    pub async fn danmaku_history_dates(
26        &self,
27        oid: i64,
28        month: &str
29    ) -> Result<HistoryDatesResponse, BpiError> {
30        let params = vec![
31            ("type", "1".to_string()),
32            ("oid", oid.to_string()),
33            ("month", month.to_string())
34        ];
35
36        let resp: HistoryDatesResponse = self
37            .get("https://api.bilibili.com/x/v2/dm/history/index")
38            .query(&params)
39            .send_bpi("查询历史弹幕日期").await?;
40
41        Ok(resp)
42    }
43}
44
45#[cfg(test)]
46mod tests {
47    use super::*;
48
49    #[tokio::test]
50    async fn test_get_history_dates() -> Result<(), Box<BpiError>> {
51        let bpi = BpiClient::new();
52        let result = bpi.danmaku_history_dates(144541892, "2022-01").await?;
53        let data = result.into_data()?;
54        tracing::info!("{:#?}", data);
55
56        Ok(())
57    }
58}