1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
use crate::error::AppError;
use super::super::types::{
BilibiliDynamicCard, BilibiliDynamicDetail, BilibiliLiveRoomInfo, BilibiliLiveRoomInit,
BilibiliUploaderTotalViews, BilibiliUserCard, BilibiliUserDynamicList, BilibiliUserSpaceInfo,
};
use super::{BilibiliFetcher, requests};
impl BilibiliFetcher {
/// Fetch one Bilibili user card payload.
///
/// # Errors
///
/// Returns an error when the upstream request fails or the response body
/// contains a non-zero Bilibili API status code.
#[doc(alias = "fetchUserCard")]
pub async fn fetch_user_card(&self, host_mid: u64) -> Result<BilibiliUserCard, AppError> {
self.fetch_json(&requests::user_card(self.api_base_url.as_ref(), host_mid)?)
.await
}
/// Fetch one page of Bilibili user dynamic items.
///
/// # Errors
///
/// Returns an error when the WBI keys cannot be resolved, the upstream
/// request fails, or the response body contains a non-zero API status code.
#[doc(alias = "fetchUserDynamicList")]
pub async fn fetch_user_dynamic_list(
&self,
host_mid: u64,
) -> Result<BilibiliUserDynamicList, AppError> {
let signed_url = self
.sign_wbi_url(&requests::user_dynamic_list(
self.api_base_url.as_ref(),
host_mid,
)?)
.await?;
self.fetch_json_with_referer(
&signed_url,
Some(&format!("https://space.bilibili.com/{host_mid}/dynamic")),
)
.await
}
/// Fetch one Bilibili user space payload signed with WBI parameters.
///
/// # Errors
///
/// Returns an error when the WBI keys cannot be resolved, the upstream
/// request fails, or the response body contains a non-zero API status code.
#[doc(alias = "fetchUserSpaceInfo")]
pub async fn fetch_user_space_info(
&self,
host_mid: u64,
) -> Result<BilibiliUserSpaceInfo, AppError> {
let signed_url = self
.sign_wbi_url(&requests::user_space_info(
self.api_base_url.as_ref(),
host_mid,
)?)
.await?;
self.fetch_json(&signed_url).await
}
/// Fetch the total play count payload for one Bilibili uploader.
///
/// # Errors
///
/// Returns an error when the upstream request fails or the response body
/// contains a non-zero Bilibili API status code.
#[doc(alias = "fetchUploaderTotalViews")]
pub async fn fetch_uploader_total_views(
&self,
host_mid: u64,
) -> Result<BilibiliUploaderTotalViews, AppError> {
self.fetch_json(&requests::uploader_total_views(
self.api_base_url.as_ref(),
host_mid,
)?)
.await
}
/// Fetch one Bilibili dynamic detail payload.
///
/// # Errors
///
/// Returns an error when the upstream request fails or the response body
/// contains a non-zero API status code.
#[doc(alias = "fetchDynamicDetail")]
pub async fn fetch_dynamic_detail(
&self,
dynamic_id: &str,
) -> Result<BilibiliDynamicDetail, AppError> {
self.fetch_json(&requests::dynamic_detail(
self.api_base_url.as_ref(),
dynamic_id,
)?)
.await
}
/// Fetch one Bilibili dynamic card payload.
///
/// # Errors
///
/// Returns an error when the upstream request fails or the response body
/// contains a non-zero API status code.
#[doc(alias = "fetchDynamicCard")]
pub async fn fetch_dynamic_card(
&self,
dynamic_id: &str,
) -> Result<BilibiliDynamicCard, AppError> {
self.fetch_json(&requests::dynamic_card(
self.vc_base_url.as_ref(),
dynamic_id,
)?)
.await
}
/// Fetch one Bilibili live room detail payload.
///
/// # Errors
///
/// Returns an error when the upstream request fails or the response body
/// contains a non-zero API status code.
#[doc(alias = "fetchLiveRoomInfo")]
pub async fn fetch_live_room_info(
&self,
room_id: u64,
) -> Result<BilibiliLiveRoomInfo, AppError> {
self.fetch_json(&requests::live_room_info(
self.live_base_url.as_ref(),
room_id,
)?)
.await
}
/// Fetch one Bilibili live room init payload.
///
/// # Errors
///
/// Returns an error when the upstream request fails or the response body
/// contains a non-zero API status code.
#[doc(alias = "fetchLiveRoomInitInfo")]
pub async fn fetch_live_room_init(
&self,
room_id: u64,
) -> Result<BilibiliLiveRoomInit, AppError> {
self.fetch_json(&requests::live_room_init(
self.live_base_url.as_ref(),
room_id,
)?)
.await
}
}