mirror of
https://github.com/lanyeeee/bilibili-video-downloader.git
synced 2026-09-08 09:06:53 +08:00
fix: 修复番剧无法获取智能修复下载链接的问题
This commit is contained in:
@@ -22,9 +22,9 @@ use crate::{
|
|||||||
protobuf::DmSegMobileReply,
|
protobuf::DmSegMobileReply,
|
||||||
types::{
|
types::{
|
||||||
bangumi_follow_info::BangumiFollowInfo, bangumi_info::BangumiInfo,
|
bangumi_follow_info::BangumiFollowInfo, bangumi_info::BangumiInfo,
|
||||||
bangumi_media_url::BangumiMediaUrl, cheese_info::CheeseInfo,
|
bangumi_media_url::BangumiMediaUrl, bangumi_media_url_v2::BangumiMediaUrlV2,
|
||||||
cheese_media_url::CheeseMediaUrl, fav_folders::FavFolders, fav_info::FavInfo,
|
cheese_info::CheeseInfo, cheese_media_url::CheeseMediaUrl, fav_folders::FavFolders,
|
||||||
get_bangumi_follow_info_params::GetBangumiFollowInfoParams,
|
fav_info::FavInfo, get_bangumi_follow_info_params::GetBangumiFollowInfoParams,
|
||||||
get_bangumi_info_params::GetBangumiInfoParams, get_cheese_info_params::GetCheeseInfoParams,
|
get_bangumi_info_params::GetBangumiInfoParams, get_cheese_info_params::GetCheeseInfoParams,
|
||||||
get_fav_info_params::GetFavInfoParams, get_history_info_params::GetHistoryInfoParams,
|
get_fav_info_params::GetFavInfoParams, get_history_info_params::GetHistoryInfoParams,
|
||||||
get_normal_info_params::GetNormalInfoParams,
|
get_normal_info_params::GetNormalInfoParams,
|
||||||
@@ -399,6 +399,15 @@ impl BiliClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_bangumi_url(&self, cid: i64) -> anyhow::Result<BangumiMediaUrl> {
|
pub async fn get_bangumi_url(&self, cid: i64) -> anyhow::Result<BangumiMediaUrl> {
|
||||||
|
let media_url_v2 = self.get_bangumi_url_v2(cid).await?;
|
||||||
|
if media_url_v2.video_info.is_drm {
|
||||||
|
self.get_bangumi_url_v1(cid).await
|
||||||
|
} else {
|
||||||
|
Ok(media_url_v2.video_info)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn get_bangumi_url_v1(&self, cid: i64) -> anyhow::Result<BangumiMediaUrl> {
|
||||||
let params = json!({
|
let params = json!({
|
||||||
"cid": cid,
|
"cid": cid,
|
||||||
"qn": 127,
|
"qn": 127,
|
||||||
@@ -442,6 +451,51 @@ impl BiliClient {
|
|||||||
Ok(media_url)
|
Ok(media_url)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn get_bangumi_url_v2(&self, cid: i64) -> anyhow::Result<BangumiMediaUrlV2> {
|
||||||
|
let params = json!({
|
||||||
|
"cid": cid,
|
||||||
|
"qn": 127,
|
||||||
|
"fnval": 4048,
|
||||||
|
"drm_tech_type": 2,
|
||||||
|
"from_client": "BROWSER",
|
||||||
|
});
|
||||||
|
// 发送获取番剧url的请求
|
||||||
|
let request = self
|
||||||
|
.api_client
|
||||||
|
.read()
|
||||||
|
.get("https://api.bilibili.com/pgc/player/web/v2/playurl")
|
||||||
|
.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 == -10403 {
|
||||||
|
return Err(anyhow!(
|
||||||
|
"地区限制,请使用代理或切换线路后重试: {bili_resp:?}"
|
||||||
|
));
|
||||||
|
} else 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解析为BangumiMediaUrlV2
|
||||||
|
let data_str = data.to_string();
|
||||||
|
let media_url: BangumiMediaUrlV2 = serde_json::from_str(&data_str)
|
||||||
|
.context(format!("将data解析为BangumiMediaUrlV2失败: {data_str}"))?;
|
||||||
|
|
||||||
|
Ok(media_url)
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn get_cheese_url(&self, ep_id: i64) -> anyhow::Result<CheeseMediaUrl> {
|
pub async fn get_cheese_url(&self, ep_id: i64) -> anyhow::Result<CheeseMediaUrl> {
|
||||||
let params = json!({
|
let params = json!({
|
||||||
"ep_id": ep_id,
|
"ep_id": ep_id,
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use specta::Type;
|
||||||
|
|
||||||
|
use crate::types::bangumi_media_url::BangumiMediaUrl;
|
||||||
|
|
||||||
|
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize, Type)]
|
||||||
|
#[serde(default)]
|
||||||
|
pub struct BangumiMediaUrlV2 {
|
||||||
|
pub play_view_business_info: PlayViewBusinessInfo,
|
||||||
|
pub video_info: BangumiMediaUrl,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize, Type)]
|
||||||
|
#[serde(default)]
|
||||||
|
pub struct PlayViewBusinessInfo {
|
||||||
|
pub episode_info: EpisodeInfoInBangumi,
|
||||||
|
pub season_info: SeasonInfoInBangumi,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize, Type)]
|
||||||
|
#[serde(default)]
|
||||||
|
pub struct EpisodeInfoInBangumi {
|
||||||
|
pub aid: i64,
|
||||||
|
pub bvid: String,
|
||||||
|
pub cid: i64,
|
||||||
|
pub delivery_business_fragment_video: bool,
|
||||||
|
pub delivery_fragment_video: bool,
|
||||||
|
pub ep_id: i64,
|
||||||
|
pub ep_status: i64,
|
||||||
|
pub interaction: Interaction,
|
||||||
|
pub long_title: String,
|
||||||
|
pub title: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize, Type)]
|
||||||
|
#[serde(default)]
|
||||||
|
pub struct Interaction {
|
||||||
|
pub interaction: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize, Type)]
|
||||||
|
#[serde(default)]
|
||||||
|
pub struct SeasonInfoInBangumi {
|
||||||
|
pub season_id: i64,
|
||||||
|
pub season_type: i64,
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ pub mod available_media_formats;
|
|||||||
pub mod bangumi_follow_info;
|
pub mod bangumi_follow_info;
|
||||||
pub mod bangumi_info;
|
pub mod bangumi_info;
|
||||||
pub mod bangumi_media_url;
|
pub mod bangumi_media_url;
|
||||||
|
pub mod bangumi_media_url_v2;
|
||||||
pub mod cheese_info;
|
pub mod cheese_info;
|
||||||
pub mod cheese_media_url;
|
pub mod cheese_media_url;
|
||||||
pub mod codec_type;
|
pub mod codec_type;
|
||||||
|
|||||||
Reference in New Issue
Block a user