Skip to main content

bpi_rs/manga/
season.rs

1//! 漫画赛季
2//!
3//! [查看 API 文档](https://github.com/SocialSisterYi/bilibili-API-collect/blob/master/docs/manga/Season.md)
4
5use crate::{ BilibiliRequest, BpiClient, BpiError, BpiResponse };
6use serde::{ Deserialize, Serialize };
7
8// ================= 数据结构 =================
9
10/// 赛季任务信息
11#[derive(Debug, Serialize, Clone, Deserialize)]
12pub struct SeasonTask {
13    // 任务相关字段
14    #[serde(default)]
15    pub id: String,
16    #[serde(default)]
17    pub title: String,
18    // 其他字段根据实际需要添加
19}
20
21/// 赛季奖励信息
22#[derive(Debug, Serialize, Clone, Deserialize)]
23pub struct SeasonWelfare {
24    // 奖励相关字段
25    #[serde(default)]
26    pub id: String,
27    #[serde(default)]
28    pub title: String,
29    // 其他字段根据实际需要添加
30}
31
32/// 赛季文案信息
33#[derive(Debug, Serialize, Clone, Deserialize)]
34pub struct SeasonText {
35    // 文案相关字段
36    #[serde(default)]
37    pub title: String,
38    // 其他字段根据实际需要添加
39}
40
41/// 赛季排名信息
42#[derive(Debug, Serialize, Clone, Deserialize)]
43pub struct SeasonRank {
44    // 排名相关字段
45    // 根据实际需要添加
46}
47
48/// 赛季信息数据
49#[derive(Debug, Serialize, Clone, Deserialize)]
50pub struct SeasonInfoData {
51    /// 当前时间字符串,ISO 8601格式
52    pub current_time: String,
53    /// 赛季开始时间,ISO 8601格式
54    pub start_time: String,
55    /// 赛季结束时间,ISO 8601格式
56    pub end_time: String,
57    /// 拥有积分,未登录为0
58    pub remain_amount: i32,
59    /// 第几个赛季
60    pub season_id: String,
61    /// 待领取奖励的任务,未登录/没有可领取时为空数组
62    pub tasks: Vec<SeasonTask>,
63    /// 赛季奖励
64    pub welfare: Vec<SeasonWelfare>,
65    /// 版头图片
66    pub cover: String,
67    /// 今日的任务完成情况
68    pub today_tasks: Vec<SeasonTask>,
69    /// 赛季相关文案,未登录为null
70    #[serde(default)]
71    pub text: Option<SeasonText>,
72    /// 赛季标题
73    pub season_title: String,
74    /// 排名信息
75    #[serde(default)]
76    pub rank: Option<SeasonRank>,
77    // 其他字段根据实际需要添加
78}
79
80pub type SeasonInfoResponse = BpiResponse<SeasonInfoData>;
81
82// ================= 实现 =================
83
84impl BpiClient {
85    /// 获取漫画赛季信息
86    ///
87    /// # 文档
88    /// [查看API文档](https://github.com/SocialSisterYi/bilibili-API-collect/tree/master/docs/manga)
89    pub async fn manga_season_info(&self) -> Result<SeasonInfoResponse, BpiError> {
90        self
91            .post("https://manga.bilibili.com/twirp/user.v1.Season/GetSeasonInfo")
92            .send_bpi("获取漫画赛季信息").await
93    }
94}
95
96#[cfg(test)]
97mod tests {
98    use super::*;
99
100    #[tokio::test]
101    async fn test_get_manga_season_info() -> Result<(), Box<BpiError>> {
102        let bpi = BpiClient::new();
103
104        let result = bpi.manga_season_info().await?;
105
106        // 不需要登录也可以获取基本信息
107
108        let data = result.into_data()?;
109
110        tracing::info!("{:#?}", data);
111
112        Ok(())
113    }
114}