use serde::{ Deserialize, Serialize };
use crate::{ BilibiliRequest, BpiClient, BpiError, BpiResponse };
#[derive(Debug, Serialize, Clone, Deserialize)]
pub struct FollowUpLiveItem {
pub roomid: i64,
pub uid: i64,
pub uname: String,
pub title: String,
pub face: String,
pub live_status: i32,
pub record_live_time: i64,
pub area_name_v2: String,
pub room_news: String,
pub text_small: String,
pub room_cover: String,
pub parent_area_id: i32,
pub area_id: i32,
}
#[derive(Debug, Serialize, Clone, Deserialize)]
pub struct FollowUpLiveData {
pub title: String,
#[serde(rename = "pageSize")]
pub page_size: i32,
#[serde(rename = "totalPage")]
pub total_page: i32,
pub list: Vec<FollowUpLiveItem>,
pub count: i32,
pub never_lived_count: i32,
pub live_count: i32,
pub never_lived_faces: Vec<String>,
}
#[derive(Debug, Serialize, Clone, Deserialize)]
pub struct LiveRoom {
pub title: String,
pub room_id: i64,
pub uid: i64,
pub online: i32,
pub live_time: i64,
pub live_status: i32,
pub short_id: i32,
pub area: i32,
pub area_name: String,
pub area_v2_id: i32,
pub area_v2_name: String,
pub area_v2_parent_name: String,
pub area_v2_parent_id: i32,
pub uname: String,
pub face: String,
pub tag_name: String,
pub tags: String,
pub cover_from_user: String,
pub keyframe: String,
pub lock_till: String,
pub hidden_till: String,
pub broadcast_type: i32,
pub is_encrypt: bool,
pub link: String,
pub nickname: String,
pub roomname: String,
pub roomid: i64,
}
#[derive(Debug, Serialize, Clone, Deserialize)]
pub struct LiveWebListData {
pub rooms: Vec<LiveRoom>,
pub list: Vec<LiveRoom>,
pub count: i32,
pub not_living_num: i32,
}
impl BpiClient {
pub async fn live_follow_up_list(
&self,
page: Option<i32>,
page_size: Option<i32>,
ignore_record: Option<i32>,
hit_ab: Option<bool>
) -> Result<BpiResponse<FollowUpLiveData>, BpiError> {
let mut query = Vec::new();
if let Some(page) = page {
query.push(("page", page.to_string()));
}
if let Some(page_size) = page_size {
query.push(("page_size", page_size.to_string()));
}
if let Some(ignore_record) = ignore_record {
query.push(("ignoreRecord", ignore_record.to_string()));
}
if let Some(hit_ab) = hit_ab {
query.push(("hit_ab", hit_ab.to_string()));
}
self
.get("https://api.live.bilibili.com/xlive/web-ucenter/user/following")
.query(&query)
.send_bpi("获取用户关注的所有UP的直播情况").await
}
pub async fn live_follow_up_web_list(
&self,
hit_ab: Option<bool>
) -> Result<BpiResponse<LiveWebListData>, BpiError> {
let mut query = Vec::new();
if let Some(hit_ab) = hit_ab {
query.push(("hit_ab", hit_ab.to_string()));
}
self
.get("https://api.live.bilibili.com/xlive/web-ucenter/v1/xfetter/GetWebList")
.query(&query)
.send_bpi("获取用户关注的所有UP且正在直播的列表").await
}
}
#[cfg(test)]
mod tests {
use super::*;
#[tokio::test]
async fn test_get_follow_up_live_list() {
let bpi = BpiClient::new();
let resp = bpi.live_follow_up_list(Some(1), Some(2), Some(1), Some(true)).await.unwrap();
tracing::info!("{:?}", resp);
}
#[tokio::test]
async fn test_get_follow_up_live_web_list() {
let bpi = BpiClient::new();
let resp = bpi.live_follow_up_web_list(Some(false)).await.unwrap();
tracing::info!("{:?}", resp);
}
}