use serde::{ Deserialize, Serialize };
use crate::{ BilibiliRequest, BpiClient, BpiError, BpiResponse };
#[derive(Debug, Serialize, Clone, Deserialize)]
pub struct WatchedShow {
pub switch: bool,
pub num: i32,
pub text_small: String,
pub text_large: String,
pub icon: String,
pub icon_location: i32,
pub icon_web: String,
}
#[derive(Debug, Serialize, Clone, Deserialize)]
pub struct RecommendRoom {
pub head_box: Option<serde_json::Value>,
pub area_v2_id: i32,
pub area_v2_parent_id: i32,
pub area_v2_name: String,
pub area_v2_parent_name: String,
pub broadcast_type: i32,
pub cover: String,
pub link: String,
pub online: i32,
#[serde(rename = "pendant_Info")]
pub pendant_info: serde_json::Value,
pub roomid: i64,
pub title: String,
pub uname: String,
pub face: String,
pub verify: serde_json::Value,
pub uid: i64,
pub keyframe: String,
pub is_auto_play: i32,
pub head_box_type: i32,
pub flag: i32,
pub session_id: String,
pub show_callback: String,
pub click_callback: String,
pub special_id: i32,
pub watched_show: WatchedShow,
pub is_nft: i32,
pub nft_dmark: String,
pub is_ad: bool,
pub ad_transparent_content: Option<serde_json::Value>,
pub show_ad_icon: bool,
pub status: bool,
pub followers: i32,
}
#[derive(Debug, Serialize, Clone, Deserialize)]
pub struct RecommendData {
pub recommend_room_list: Vec<RecommendRoom>,
pub top_room_id: i64,
}
impl BpiClient {
pub async fn live_recommend(&self) -> Result<BpiResponse<RecommendData>, BpiError> {
let params = [
("platform", "web"),
("web_location", "333.1007"),
];
let resp = self
.get("https://api.live.bilibili.com/xlive/web-interface/v1/webMain/getMoreRecList")
.query(¶ms)
.send_bpi("主页获取直播推荐").await?;
Ok(resp)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[tokio::test]
async fn test_get_live_recommend() -> Result<(), Box<BpiError>> {
let bpi = BpiClient::new();
let resp = bpi.live_recommend().await?;
let data = resp.data.unwrap();
assert!(data.recommend_room_list.len() > 0);
Ok(())
}
}