Skip to main content

bpi_rs/live/
live_area.rs

1use serde::{ Deserialize, Serialize };
2
3use crate::{ BilibiliRequest, BpiClient, BpiError, BpiResponse };
4
5// ================= 数据结构 =================
6
7#[derive(Debug, Serialize, Clone, Deserialize)]
8pub struct LiveSubArea {
9    /// 子分区id
10    pub id: String,
11    /// 父分区id
12    pub parent_id: String,
13    /// 旧分区id
14    pub old_area_id: String,
15    /// 子分区名
16    pub name: String,
17    /// 活动id
18    pub act_id: String,
19    /// pk状态
20    pub pk_status: String,
21    /// 是否为热门分区
22    pub hot_status: i32,
23    /// 锁定状态
24    pub lock_status: String,
25    /// 子分区标志图片url
26    pub pic: String,
27    /// 父分区名
28    pub parent_name: String,
29    /// 区域类型
30    pub area_type: i32,
31}
32
33#[derive(Debug, Serialize, Clone, Deserialize)]
34pub struct LiveParentArea {
35    /// 父分区id
36    pub id: i32,
37    /// 父分区名
38    pub name: String,
39    /// 子分区列表
40    pub list: Vec<LiveSubArea>,
41}
42
43impl BpiClient {
44    /// 获取全部直播间分区列表
45    ///
46
47    /// # 文档
48    /// [查看API文档](https://github.com/SocialSisterYi/bilibili-API-collect/tree/master/docs/live)
49    pub async fn live_area_list(&self) -> Result<BpiResponse<Vec<LiveParentArea>>, BpiError> {
50        let resp = self
51            .get("https://api.live.bilibili.com/room/v1/Area/getList")
52            .send_bpi("获取全部直播间分区列表").await?;
53
54        Ok(resp)
55    }
56}
57
58#[cfg(test)]
59mod tests {
60    use super::*;
61
62    #[tokio::test]
63    async fn test_get_live_area_list() -> Result<(), Box<BpiError>> {
64        let bpi = BpiClient::new();
65        let resp = bpi.live_area_list().await?;
66
67        let data = resp.data.unwrap();
68        assert!(data.len() > 0);
69        Ok(())
70    }
71}