1use serde::{ Deserialize, Serialize };
2
3use crate::{ BilibiliRequest, BpiClient, BpiError, BpiResponse };
4
5#[derive(Debug, Serialize, Clone, Deserialize)]
8pub struct WatchedShow {
9 pub switch: bool,
11 pub num: i32,
13 pub text_small: String,
15 pub text_large: String,
17 pub icon: String,
19 pub icon_location: i32,
21 pub icon_web: String,
23}
24
25#[derive(Debug, Serialize, Clone, Deserialize)]
26pub struct RecommendRoom {
27 pub head_box: Option<serde_json::Value>,
29 pub area_v2_id: i32,
31 pub area_v2_parent_id: i32,
33 pub area_v2_name: String,
35 pub area_v2_parent_name: String,
37 pub broadcast_type: i32,
39 pub cover: String,
41 pub link: String,
43 pub online: i32,
45 #[serde(rename = "pendant_Info")]
47 pub pendant_info: serde_json::Value,
48 pub roomid: i64,
50 pub title: String,
52 pub uname: String,
54 pub face: String,
56 pub verify: serde_json::Value,
58 pub uid: i64,
60 pub keyframe: String,
62 pub is_auto_play: i32,
64 pub head_box_type: i32,
66 pub flag: i32,
68 pub session_id: String,
70 pub show_callback: String,
72 pub click_callback: String,
74 pub special_id: i32,
76 pub watched_show: WatchedShow,
78 pub is_nft: i32,
80 pub nft_dmark: String,
82 pub is_ad: bool,
84 pub ad_transparent_content: Option<serde_json::Value>,
86 pub show_ad_icon: bool,
88 pub status: bool,
90 pub followers: i32,
92}
93
94#[derive(Debug, Serialize, Clone, Deserialize)]
95pub struct RecommendData {
96 pub recommend_room_list: Vec<RecommendRoom>,
98 pub top_room_id: i64,
100}
101
102impl BpiClient {
103 pub async fn live_recommend(&self) -> Result<BpiResponse<RecommendData>, BpiError> {
109 let params = [
110 ("platform", "web"),
111 ("web_location", "333.1007"),
112 ];
113
114 let resp = self
115 .get("https://api.live.bilibili.com/xlive/web-interface/v1/webMain/getMoreRecList")
116 .query(¶ms)
117 .send_bpi("主页获取直播推荐").await?;
118
119 Ok(resp)
120 }
121}
122
123#[cfg(test)]
124mod tests {
125 use super::*;
126
127 #[tokio::test]
128 async fn test_get_live_recommend() -> Result<(), Box<BpiError>> {
129 let bpi = BpiClient::new();
130 let resp = bpi.live_recommend().await?;
131
132 let data = resp.data.unwrap();
133
134 assert!(data.recommend_room_list.len() > 0);
135 Ok(())
136 }
137}