mirror of
https://github.com/lanyeeee/bilibili-video-downloader.git
synced 2026-09-09 09:36:46 +08:00
feat: 后端支持获取稍后再看内容
This commit is contained in:
@@ -21,6 +21,7 @@ use crate::{
|
||||
get_fav_info_params::GetFavInfoParams, get_normal_info_params::GetNormalInfoParams,
|
||||
normal_info::NormalInfo, normal_media_url::NormalMediaUrl, player_info::PlayerInfo,
|
||||
qrcode_data::QrcodeData, qrcode_status::QrcodeStatus, user_info::UserInfo,
|
||||
watch_later_info::WatchLaterInfo,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -500,6 +501,41 @@ impl BiliClient {
|
||||
Ok(fav_info)
|
||||
}
|
||||
|
||||
pub async fn get_watch_later_info(&self, page: i32) -> anyhow::Result<WatchLaterInfo> {
|
||||
// 发送获取稍后观看信息的请求
|
||||
let params = json!({"ps": 20, "pn": page});
|
||||
let request = self
|
||||
.api_client
|
||||
.read()
|
||||
.get("https://api.bilibili.com/x/v2/history/toview")
|
||||
.query(¶ms)
|
||||
.header("cookie", self.get_cookie());
|
||||
let http_resp = request.send().await?;
|
||||
// 检查http响应状态码
|
||||
let status = http_resp.status();
|
||||
let body = http_resp.text().await?;
|
||||
if status != StatusCode::OK {
|
||||
return Err(anyhow!("预料之外的状态码({status}): {body}"));
|
||||
}
|
||||
// 尝试将body解析为BiliResp
|
||||
let bili_resp: BiliResp =
|
||||
serde_json::from_str(&body).context(format!("将body解析为BiliResp失败: {body}"))?;
|
||||
// 检查BiliResp的code字段
|
||||
if bili_resp.code != 0 {
|
||||
return Err(anyhow!("预料之外的code: {bili_resp:?}"));
|
||||
}
|
||||
// 检查BiliResp的data是否存在
|
||||
let Some(data) = bili_resp.data else {
|
||||
return Err(anyhow!("BiliResp中不存在data字段: {bili_resp:?}"));
|
||||
};
|
||||
// 尝试将data解析为WatchLaterInfo
|
||||
let data_str = data.to_string();
|
||||
let watch_later_info: WatchLaterInfo = serde_json::from_str(&data_str)
|
||||
.context(format!("将data解析为WatchLaterInfo失败: {data_str}"))?;
|
||||
|
||||
Ok(watch_later_info)
|
||||
}
|
||||
|
||||
fn get_cookie(&self) -> String {
|
||||
let sessdata = self.app.get_config().read().sessdata.clone();
|
||||
format!("SESSDATA={sessdata}")
|
||||
|
||||
@@ -13,6 +13,7 @@ use crate::{
|
||||
get_fav_info_params::GetFavInfoParams, get_normal_info_params::GetNormalInfoParams,
|
||||
normal_info::NormalInfo, normal_media_url::NormalMediaUrl, player_info::PlayerInfo,
|
||||
qrcode_data::QrcodeData, qrcode_status::QrcodeStatus, user_info::UserInfo,
|
||||
watch_later_info::WatchLaterInfo,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -210,3 +211,14 @@ pub async fn get_fav_info(app: AppHandle, params: GetFavInfoParams) -> CommandRe
|
||||
.map_err(|err| CommandError::from("获取收藏夹内容失败", err))?;
|
||||
Ok(fav_info)
|
||||
}
|
||||
|
||||
#[tauri::command(async)]
|
||||
#[specta::specta]
|
||||
pub async fn get_watch_later_info(app: AppHandle, page: i32) -> CommandResult<WatchLaterInfo> {
|
||||
let bili_client = app.get_bili_client();
|
||||
let watch_later_info = bili_client
|
||||
.get_watch_later_info(page)
|
||||
.await
|
||||
.map_err(|err| CommandError::from("获取稍后观看内容失败", err))?;
|
||||
Ok(watch_later_info)
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ pub fn run() {
|
||||
get_player_info,
|
||||
get_fav_folders,
|
||||
get_fav_info,
|
||||
get_watch_later_info,
|
||||
])
|
||||
.events(tauri_specta::collect_events![LogEvent]);
|
||||
|
||||
|
||||
@@ -15,3 +15,4 @@ pub mod player_info;
|
||||
pub mod qrcode_data;
|
||||
pub mod qrcode_status;
|
||||
pub mod user_info;
|
||||
pub mod watch_later_info;
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use specta::Type;
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize, Type)]
|
||||
pub struct WatchLaterInfo {
|
||||
pub count: i64,
|
||||
pub list: Vec<MediaInWatchLater>,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize, Type)]
|
||||
pub struct MediaInWatchLater {
|
||||
pub aid: i64,
|
||||
pub videos: i64,
|
||||
pub tid: i64,
|
||||
pub tname: String,
|
||||
pub copyright: i64,
|
||||
pub pic: String,
|
||||
pub title: String,
|
||||
pub pubdate: i64,
|
||||
pub ctime: i64,
|
||||
pub desc: String,
|
||||
pub state: i64,
|
||||
pub duration: i64,
|
||||
pub redirect_url: Option<String>,
|
||||
pub mission_id: Option<i64>,
|
||||
pub rights: RightsInWatchLater,
|
||||
pub owner: OwnerInWatchLater,
|
||||
pub stat: StatInWatchLater,
|
||||
pub dynamic: String,
|
||||
pub dimension: DimensionInWatchLater,
|
||||
pub short_link_v2: String,
|
||||
pub up_from_v2: Option<i64>,
|
||||
pub first_frame: Option<String>,
|
||||
pub pub_location: Option<String>,
|
||||
pub cover43: String,
|
||||
pub tidv2: i64,
|
||||
pub tnamev2: String,
|
||||
pub pid_v2: i64,
|
||||
pub pid_name_v2: String,
|
||||
pub page: PageInWatchLater,
|
||||
pub count: i64,
|
||||
pub cid: i64,
|
||||
pub progress: i64,
|
||||
pub add_at: i64,
|
||||
pub bvid: String,
|
||||
pub uri: String,
|
||||
pub enable_vt: i64,
|
||||
pub view_text_1: String,
|
||||
pub card_type: i64,
|
||||
pub left_icon_type: i64,
|
||||
pub left_text: String,
|
||||
pub right_icon_type: i64,
|
||||
pub right_text: String,
|
||||
pub arc_state: i64,
|
||||
pub pgc_label: String,
|
||||
pub show_up: bool,
|
||||
pub forbid_fav: bool,
|
||||
pub forbid_sort: bool,
|
||||
pub season_title: String,
|
||||
pub long_title: String,
|
||||
pub index_title: String,
|
||||
pub c_source: String,
|
||||
pub season_id: Option<i64>,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize, Type)]
|
||||
pub struct RightsInWatchLater {
|
||||
pub bp: i64,
|
||||
pub elec: i64,
|
||||
pub download: i64,
|
||||
pub movie: i64,
|
||||
pub pay: i64,
|
||||
pub hd5: i64,
|
||||
pub no_reprint: i64,
|
||||
pub autoplay: i64,
|
||||
pub ugc_pay: i64,
|
||||
pub is_cooperation: i64,
|
||||
pub ugc_pay_preview: i64,
|
||||
pub no_background: i64,
|
||||
pub arc_pay: i64,
|
||||
pub pay_free_watch: i64,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize, Type)]
|
||||
pub struct OwnerInWatchLater {
|
||||
pub mid: i64,
|
||||
pub name: String,
|
||||
pub face: String,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize, Type)]
|
||||
pub struct StatInWatchLater {
|
||||
pub aid: i64,
|
||||
pub view: i64,
|
||||
pub danmaku: i64,
|
||||
pub reply: i64,
|
||||
pub favorite: i64,
|
||||
pub coin: i64,
|
||||
pub share: i64,
|
||||
pub now_rank: i64,
|
||||
pub his_rank: i64,
|
||||
pub like: i64,
|
||||
pub dislike: i64,
|
||||
pub vt: i64,
|
||||
pub vv: i64,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize, Type)]
|
||||
pub struct DimensionInWatchLater {
|
||||
pub width: i64,
|
||||
pub height: i64,
|
||||
pub rotate: i64,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize, Type)]
|
||||
pub struct PageInWatchLater {
|
||||
pub cid: i64,
|
||||
pub page: i64,
|
||||
pub from: String,
|
||||
pub part: String,
|
||||
pub duration: i64,
|
||||
pub vid: String,
|
||||
pub weblink: String,
|
||||
pub dimension: DimensionInWatchLater,
|
||||
pub first_frame: Option<String>,
|
||||
pub ctime: i64,
|
||||
}
|
||||
Reference in New Issue
Block a user