bpi_rs/web_widget/
banner.rs

1//! B站分区轮播图相关接口
2//!
3//! 文档: https://socialsisteryi.github.io/bilibili-API-collect/docs/web_widget/banner.html
4use crate::video::video_zone_v2::VideoPartitionV2;
5use crate::{ BilibiliRequest, BpiClient, BpiError, BpiResponse };
6use serde::{ Deserialize, Serialize };
7
8/// 轮播图对象
9#[derive(Debug, Clone, Deserialize, Serialize)]
10pub struct RegionBanner {
11    pub image: String, // 封面资源路径
12    pub title: String, // 封面标题
13    pub sub_title: String, // 封面子标题
14    pub url: String, // 点击后的跳转链接
15    pub rid: i64, // 分区 ID
16}
17
18/// 轮播图响应数据
19#[derive(Debug, Clone, Deserialize, Serialize)]
20pub struct RegionBannerData {
21    pub region_banner_list: Vec<RegionBanner>, // 轮播图列表
22}
23
24impl BpiClient {
25    /// 获取各分区的轮播图(Web端)
26    ///
27    /// 文档: https://socialsisteryi.github.io/bilibili-API-collect/docs/web_widget/banner.html#获取各分区的轮播图
28    ///
29    /// # 参数
30    /// | 名称        | 类型                | 说明         |
31    /// | ----------- | -------------------| ------------|
32    /// | `region_id` | VideoPartitionV2    | 分区 ID      |
33    pub async fn web_widget_region_banner(
34        &self,
35        region_id: VideoPartitionV2
36    ) -> Result<BpiResponse<RegionBannerData>, BpiError> {
37        let query = vec![("region_id", region_id.tid().to_string())];
38
39        self
40            .get("https://api.bilibili.com/x/web-show/region/banner")
41            .query(&query)
42            .send_bpi("获取各分区的轮播图").await
43    }
44}
45
46#[cfg(test)]
47mod tests {
48    use super::*;
49    use crate::video::video_zone_v2::{ Douga, VideoPartitionV2 };
50
51    use tracing::info;
52
53    #[tokio::test]
54    async fn test_get_region_banner() {
55        let bpi = BpiClient::new();
56        // 例如 region_id = 1 (动画)
57        let resp = bpi.web_widget_region_banner(VideoPartitionV2::Douga(Douga::Douga)).await;
58        info!("响应: {:?}", resp);
59        assert!(resp.is_ok());
60
61        let data = resp.unwrap().data.unwrap();
62        info!("分区轮播图: {:?}", data);
63    }
64}