🐞 fix: 修复哔哩哔哩偶发性失败 #48 #54

This commit is contained in:
imsyy
2024-05-29 10:11:06 +08:00
parent ce5d381093
commit 13f019a5aa
4 changed files with 196 additions and 163 deletions

View File

@@ -42,12 +42,14 @@ export type RouterType = {
bilibili: {
bvid: string;
title: string;
desc: string;
pic: string;
owner: {
desc?: string;
pic?: string;
author?: string;
video_review?: number;
owner?: {
name: string;
};
stat: {
stat?: {
view: number;
};
short_link_v2?: string;

View File

@@ -53,6 +53,8 @@ const getList = async (options: Options, noCache: boolean) => {
},
noCache,
});
// 是否触发风控
if (result.data?.data?.list?.length > 0) {
const list = result.data.data.list;
return {
fromCache: result.fromCache,
@@ -60,7 +62,7 @@ const getList = async (options: Options, noCache: boolean) => {
data: list.map((v: RouterType["bilibili"]) => ({
id: v.bvid,
title: v.title,
desc: v.desc,
desc: v.desc || "该视频暂无简介",
cover: v.pic.replace(/http:/, "https:"),
author: v.owner.name,
hot: v.stat.view,
@@ -68,4 +70,33 @@ const getList = async (options: Options, noCache: boolean) => {
mobileUrl: `https://m.bilibili.com/video/${v.bvid}`,
})),
};
}
// 采用备用接口
else {
const url = `https://api.bilibili.com/x/web-interface/ranking?jsonp=jsonp?rid=${type}&type=1&callback=__jp0`;
const result = await get({
url,
headers: {
Referer: `https://www.bilibili.com/ranking/all`,
"User-Agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36",
},
noCache,
});
const list = result.data.data.list;
return {
fromCache: result.fromCache,
updateTime: result.updateTime,
data: list.map((v: RouterType["bilibili"]) => ({
id: v.bvid,
title: v.title,
desc: v.desc || "该视频暂无简介",
cover: v.pic.replace(/http:/, "https:"),
author: v.author,
hot: v.video_review,
url: `https://www.bilibili.com/video/${v.bvid}`,
mobileUrl: `https://m.bilibili.com/video/${v.bvid}`,
})),
};
}
};