Skip to main content

ybd_core/model/
collection.rs

1//! 收藏夹返回的数据格式
2
3use serde::{Deserialize, Serialize};
4use serde_json::Value;
5
6use crate::error::{Error, Result};
7
8#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
9#[serde(rename_all = "camelCase")]
10pub struct CollectionUrlResponse {
11        pub code: i64,
12        pub message: String,
13        pub ttl: i64,
14        pub data: CollectionData,
15}
16
17impl CollectionUrlResponse {
18        pub fn get_data(&self) -> Result<&CollectionData> {
19                self.valid()?;
20                Ok(&self.data)
21        }
22
23        fn valid(&self) -> Result<()> {
24                match self.code {
25                        0 => Ok(()),
26                        -101 => Err(Error::Normal("账号未登录".into())),
27                        -403 => Err(Error::Normal("权限不足,可能需要大会员".into())),
28                        -404 => Err(Error::Normal("视频不存在".into())),
29                        -412 => Err(Error::Normal("请求被拦截,请稍后再试".into())),
30                        -10403 => Err(Error::Normal("地区限制,无法观看".into())),
31                        _ => Err(Error::Normal(format!("未知错误码: {}", self.code))),
32                }
33        }
34}
35
36#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
37#[serde(rename_all = "camelCase")]
38pub struct CollectionData {
39        pub info: Info,
40        pub medias: Vec<Media>,
41        #[serde(rename = "has_more")]
42        pub has_more: bool,
43        pub ttl: i64,
44}
45
46#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
47#[serde(rename_all = "camelCase")]
48pub struct Info {
49        pub id: i64,
50        pub fid: i64,
51        pub mid: i64,
52        pub attr: i64,
53        pub title: String,
54        pub cover: String,
55        pub upper: Upper,
56        #[serde(rename = "cover_type")]
57        pub cover_type: i64,
58        #[serde(rename = "cnt_info")]
59        pub cnt_info: CntInfo,
60        #[serde(rename = "type")]
61        pub type_field: i64,
62        pub intro: Option<String>,
63        pub ctime: i64,
64        pub mtime: i64,
65        pub state: i64,
66        #[serde(rename = "fav_state")]
67        pub fav_state: i64,
68        #[serde(rename = "like_state")]
69        pub like_state: i64,
70        #[serde(rename = "media_count")]
71        pub media_count: i64,
72        #[serde(rename = "is_top")]
73        pub is_top: bool,
74        #[serde(rename = "is_kid_playlist")]
75        pub is_kid_playlist: bool,
76        #[serde(rename = "kid_playlist_desc")]
77        pub kid_playlist_desc: String,
78}
79
80#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
81#[serde(rename_all = "camelCase")]
82pub struct Upper {
83        pub mid: i64,
84        pub name: String,
85        pub face: String,
86        pub followed: bool,
87        #[serde(rename = "vip_type")]
88        pub vip_type: i64,
89        #[serde(rename = "vip_statue")]
90        pub vip_statue: i64,
91}
92
93#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
94#[serde(rename_all = "camelCase")]
95pub struct CntInfo {
96        pub collect: i64,
97        pub play: i64,
98        #[serde(rename = "thumb_up")]
99        pub thumb_up: i64,
100        pub share: i64,
101}
102
103#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
104#[serde(rename_all = "camelCase")]
105pub struct Media {
106        pub id: i64,
107        #[serde(rename = "type")]
108        pub type_field: i64,
109        pub title: String,
110        pub cover: String,
111        pub intro: String,
112        pub page: i64,
113        pub duration: i64,
114        pub upper: Upper2,
115        pub attr: i64,
116        #[serde(rename = "cnt_info")]
117        pub cnt_info: CntInfo2,
118        pub link: String,
119        pub ctime: i64,
120        pub pubtime: i64,
121        #[serde(rename = "fav_time")]
122        pub fav_time: i64,
123        #[serde(rename = "bv_id")]
124        pub bv_id: String,
125        pub bvid: String,
126        pub season: Value,
127        pub ogv: Value,
128        pub ugc: Ugc,
129        #[serde(rename = "media_list_link")]
130        pub media_list_link: String,
131}
132
133#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
134#[serde(rename_all = "camelCase")]
135pub struct Upper2 {
136        pub mid: i64,
137        pub name: String,
138        pub face: String,
139        #[serde(rename = "jump_link")]
140        pub jump_link: Option<String>,
141}
142
143#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
144#[serde(rename_all = "camelCase")]
145pub struct CntInfo2 {
146        pub collect: i64,
147        pub play: i64,
148        pub danmaku: i64,
149        pub vt: i64,
150        #[serde(rename = "play_switch")]
151        pub play_switch: i64,
152        pub reply: i64,
153        #[serde(rename = "view_text_1")]
154        pub view_text_1: String,
155}
156
157#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
158#[serde(rename_all = "camelCase")]
159pub struct Ugc {
160        #[serde(rename = "first_cid")]
161        pub first_cid: i64,
162}