bpi_rs/video/model.rs
1use serde::{Deserialize, Serialize};
2
3use crate::ids::{Aid, Bvid, Cid, Mid};
4
5/// Payload returned by `/x/web-interface/view`.
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct VideoView {
8 /// AV numeric video ID.
9 pub aid: Aid,
10 /// BV string video ID.
11 pub bvid: Bvid,
12 /// Number of video pages.
13 pub videos: u32,
14 /// Video title.
15 pub title: String,
16 /// Uploader information.
17 pub owner: VideoOwner,
18 /// Video statistics.
19 pub stat: VideoStat,
20 /// Default content/page ID.
21 pub cid: Cid,
22 /// Page list.
23 #[serde(default)]
24 pub pages: Vec<VideoPage>,
25}
26
27/// Payload returned by `/x/web-interface/view/detail`.
28#[derive(Debug, Clone, Serialize, Deserialize)]
29pub struct VideoDetail {
30 /// Main video view payload.
31 #[serde(rename = "View")]
32 pub view: VideoView,
33 /// Tags associated with the video.
34 #[serde(default, rename = "Tags")]
35 pub tags: Vec<VideoTag>,
36 /// Related videos returned by Bilibili's recommendation surface.
37 #[serde(default, rename = "Related")]
38 pub related: Vec<VideoRelated>,
39 /// Uploader card and space data. Kept raw because this is a display-oriented payload.
40 #[serde(default, rename = "Card")]
41 pub card: Option<serde_json::Value>,
42 /// Reply preview data. Kept raw because it changes with comment surface experiments.
43 #[serde(default, rename = "Reply")]
44 pub reply: Option<serde_json::Value>,
45}
46
47/// Uploader information embedded in a video view payload.
48#[derive(Debug, Clone, Serialize, Deserialize)]
49pub struct VideoOwner {
50 /// Uploader member ID.
51 pub mid: Mid,
52 /// Uploader display name.
53 pub name: String,
54 /// Uploader avatar URL.
55 pub face: String,
56}
57
58/// Stable statistic fields returned by the video view endpoint.
59#[derive(Debug, Clone, Serialize, Deserialize)]
60pub struct VideoStat {
61 /// AV numeric video ID.
62 pub aid: Aid,
63 /// View count.
64 pub view: u64,
65 /// Danmaku count.
66 pub danmaku: u64,
67 /// Reply count.
68 pub reply: u64,
69 /// Favorite count on newer payloads.
70 #[serde(default)]
71 pub favorite: Option<u64>,
72 /// Favorite count alias observed on some payloads.
73 #[serde(default)]
74 pub fav: Option<u64>,
75 /// Coin count.
76 pub coin: u64,
77 /// Share count.
78 pub share: u64,
79 /// Like count.
80 pub like: u64,
81}
82
83/// One page in a multi-part video.
84#[derive(Debug, Clone, Serialize, Deserialize)]
85pub struct VideoPage {
86 /// Content/page ID.
87 pub cid: Cid,
88 /// 1-based page index.
89 pub page: u32,
90 /// Page title.
91 pub part: String,
92 /// Duration in seconds.
93 pub duration: u64,
94}
95
96/// One video tag returned by the detail endpoint.
97#[derive(Debug, Clone, Serialize, Deserialize)]
98pub struct VideoTag {
99 /// Tag ID.
100 pub tag_id: u64,
101 /// Tag display name.
102 #[serde(default)]
103 pub tag_name: String,
104 /// Optional tag jump URL.
105 #[serde(default)]
106 pub jump_url: String,
107}
108
109/// Stable fields for a related video returned by the detail endpoint.
110#[derive(Debug, Clone, Serialize, Deserialize)]
111pub struct VideoRelated {
112 /// AV numeric video ID.
113 pub aid: Aid,
114 /// BV string video ID.
115 pub bvid: Bvid,
116 /// Related video title.
117 #[serde(default)]
118 pub title: String,
119 /// Default content/page ID when Bilibili returns it.
120 #[serde(default)]
121 pub cid: Option<Cid>,
122 /// Uploader information when present.
123 #[serde(default)]
124 pub owner: Option<VideoOwner>,
125 /// Video statistics when present.
126 #[serde(default)]
127 pub stat: Option<VideoStat>,
128}