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    /// 文档: https://github.com/SocialSisterYi/bilibili-API-collect/tree/master/docs/danmaku
17    ///
18    /// 参数
19    ///
20    /// | 名称 | 类型 | 说明 |
21    /// | ---- | ---- | ---- |
22    /// | `oid` | i64 | 视频 cid |
23    /// | `month` | &str | 形如 `2006-01` |
24    pub async fn danmaku_history_dates(
25        &self,
26        oid: i64,
27        month: &str,
28    ) -> Result<HistoryDatesResponse, BpiError> {
29        let params = vec![
30            ("type", "1".to_string()),
31            ("oid", oid.to_string()),
32            ("month", month.to_string()),
33        ];
34
35        let resp: HistoryDatesResponse = self
36            .get("https://api.bilibili.com/x/v2/dm/history/index")
37            .query(&params)
38            .send_bpi("查询历史弹幕日期")
39            .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}