Skip to main content

bpi_rs/live/
follow_up_live.rs

1use serde::{ Deserialize, Serialize };
2
3use crate::{ BilibiliRequest, BpiClient, BpiError, BpiResponse };
4
5#[derive(Debug, Serialize, Clone, Deserialize)]
6pub struct FollowUpLiveItem {
7    /// 房间号
8    pub roomid: i64,
9    /// 主播uid
10    pub uid: i64,
11    /// 主播名
12    pub uname: String,
13    /// 直播标题
14    pub title: String,
15    /// 主播头像
16    pub face: String,
17    /// 是否正在直播
18    pub live_status: i32,
19    /// 主播上一次直播结束的时间戳
20    pub record_live_time: i64,
21    /// 频道的名称
22    pub area_name_v2: String,
23    /// 房间公告
24    pub room_news: String,
25    /// 作用尚不明确,当主播正在直播时,为在线人数(可能)
26    pub text_small: String,
27    /// 房间封面图片的URL
28    pub room_cover: String,
29    /// 父分区id
30    pub parent_area_id: i32,
31    /// 分区id
32    pub area_id: i32,
33}
34
35#[derive(Debug, Serialize, Clone, Deserialize)]
36pub struct FollowUpLiveData {
37    /// 标题
38    pub title: String,
39
40    /// 每页的数据数量
41    #[serde(rename = "pageSize")]
42    pub page_size: i32,
43
44    /// 分页数量
45    #[serde(rename = "totalPage")]
46    pub total_page: i32,
47
48    /// UP直播情况列表
49    pub list: Vec<FollowUpLiveItem>,
50
51    /// 曾直播过的UP数量
52    pub count: i32,
53
54    /// 未直播过的UP数量
55    pub never_lived_count: i32,
56
57    /// 正在直播的UP数量
58    pub live_count: i32,
59
60    /// 作用尚不明确
61    pub never_lived_faces: Vec<String>,
62}
63
64#[derive(Debug, Serialize, Clone, Deserialize)]
65pub struct LiveRoom {
66    /// 直播间标题
67    pub title: String,
68    /// 直播间真实id
69    pub room_id: i64,
70    /// 目标用户mid
71    pub uid: i64,
72    /// 观看人数
73    pub online: i32,
74    /// 已经直播的时长(单位为秒)
75    pub live_time: i64,
76    /// 开播状态
77    pub live_status: i32,
78    /// 直播间短id
79    pub short_id: i32,
80    /// 分区id
81    pub area: i32,
82    /// 分区名称
83    pub area_name: String,
84    /// 二级分区id
85    pub area_v2_id: i32,
86    /// 二级分区名
87    pub area_v2_name: String,
88    /// 二级父分区名
89    pub area_v2_parent_name: String,
90    /// 二级父分区id
91    pub area_v2_parent_id: i32,
92    /// 用户名
93    pub uname: String,
94    /// 用户头像图片链接
95    pub face: String,
96    /// 标签名
97    pub tag_name: String,
98    /// 标签列表
99    pub tags: String,
100    /// 直播间封面图片链接
101    pub cover_from_user: String,
102    /// 关键帧图片链接
103    pub keyframe: String,
104    /// 未知
105    pub lock_till: String,
106    /// 未知
107    pub hidden_till: String,
108    /// 广播类型
109    pub broadcast_type: i32,
110    /// 直播间是否加密
111    pub is_encrypt: bool,
112    /// 直播间链接
113    pub link: String,
114    /// 用户昵称
115    pub nickname: String,
116    /// 直播间名称
117    pub roomname: String,
118    /// 直播间真实id
119    pub roomid: i64,
120}
121
122#[derive(Debug, Serialize, Clone, Deserialize)]
123pub struct LiveWebListData {
124    /// 正在直播的房间列表
125    pub rooms: Vec<LiveRoom>,
126    /// 正在直播的房间列表
127    pub list: Vec<LiveRoom>,
128    /// 关注列表中正在直播的人数
129    pub count: i32,
130    /// 关注列表中未开播的人数
131    pub not_living_num: i32,
132}
133
134impl BpiClient {
135    /// 获取用户关注的所有UP的直播情况
136    ///
137
138    /// # 文档
139    /// [查看API文档](https://github.com/SocialSisterYi/bilibili-API-collect/tree/master/docs/live)
140    pub async fn live_follow_up_list(
141        &self,
142        page: Option<i32>,
143        page_size: Option<i32>,
144        ignore_record: Option<i32>,
145        hit_ab: Option<bool>
146    ) -> Result<BpiResponse<FollowUpLiveData>, BpiError> {
147        let mut query = Vec::new();
148
149        if let Some(page) = page {
150            query.push(("page", page.to_string()));
151        }
152
153        if let Some(page_size) = page_size {
154            query.push(("page_size", page_size.to_string()));
155        }
156
157        if let Some(ignore_record) = ignore_record {
158            query.push(("ignoreRecord", ignore_record.to_string()));
159        }
160
161        if let Some(hit_ab) = hit_ab {
162            query.push(("hit_ab", hit_ab.to_string()));
163        }
164
165        self
166            .get("https://api.live.bilibili.com/xlive/web-ucenter/user/following")
167            .query(&query)
168            .send_bpi("获取用户关注的所有UP的直播情况").await
169    }
170
171    /// 获取用户关注的所有UP且正在直播的列表(PC端)
172    ///
173
174    /// # 文档
175    /// [查看API文档](https://github.com/SocialSisterYi/bilibili-API-collect/tree/master/docs/live)
176    pub async fn live_follow_up_web_list(
177        &self,
178        hit_ab: Option<bool>
179    ) -> Result<BpiResponse<LiveWebListData>, BpiError> {
180        let mut query = Vec::new();
181
182        if let Some(hit_ab) = hit_ab {
183            query.push(("hit_ab", hit_ab.to_string()));
184        }
185
186        self
187            .get("https://api.live.bilibili.com/xlive/web-ucenter/v1/xfetter/GetWebList")
188            .query(&query)
189            .send_bpi("获取用户关注的所有UP且正在直播的列表").await
190    }
191}
192
193#[cfg(test)]
194mod tests {
195    use super::*;
196
197    #[tokio::test]
198    async fn test_get_follow_up_live_list() {
199        let bpi = BpiClient::new();
200        let resp = bpi.live_follow_up_list(Some(1), Some(2), Some(1), Some(true)).await.unwrap();
201        tracing::info!("{:?}", resp);
202    }
203
204    #[tokio::test]
205    async fn test_get_follow_up_live_web_list() {
206        let bpi = BpiClient::new();
207        let resp = bpi.live_follow_up_web_list(Some(false)).await.unwrap();
208        tracing::info!("{:?}", resp);
209    }
210}