feat(route): douyu room api update with fallback (#15401)
* feat(route): douyu room api update with fallback * style: auto format --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
github-actions[bot]
parent
cc044ac533
commit
e54a5f1083
+59
-19
@@ -20,37 +20,77 @@ export const route: Route = {
|
||||
},
|
||||
],
|
||||
name: '直播间开播',
|
||||
maintainers: ['DIYgod'],
|
||||
maintainers: ['DIYgod', 'ChaosTong'],
|
||||
handler,
|
||||
};
|
||||
|
||||
async function handler(ctx) {
|
||||
const id = ctx.req.param('id');
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: `http://open.douyucdn.cn/api/RoomApi/room/${id}`,
|
||||
headers: {
|
||||
Referer: `https://www.douyu.com/${id}`,
|
||||
},
|
||||
});
|
||||
|
||||
const data = response.data.data;
|
||||
|
||||
let data;
|
||||
let item;
|
||||
if (data.online !== 0) {
|
||||
item = [
|
||||
{
|
||||
title: `开播: ${data.room_name}`,
|
||||
pubDate: new Date(data.start_time).toUTCString(),
|
||||
guid: data.start_time,
|
||||
link: `https://www.douyu.com/${id}`,
|
||||
let room_thumb;
|
||||
try {
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: `https://www.douyu.com/betard/${id}`,
|
||||
});
|
||||
|
||||
if (!response.data.room) {
|
||||
throw new Error('Invalid response');
|
||||
}
|
||||
|
||||
data = response.data.room;
|
||||
room_thumb = data.room_pic;
|
||||
|
||||
if (data.show_status === 1) {
|
||||
item =
|
||||
data.videoLoop === 1
|
||||
? [
|
||||
{
|
||||
title: `视频轮播: ${data.room_name}`,
|
||||
pubDate: new Date(data.show_time * 1000).toUTCString(),
|
||||
guid: data.show_time,
|
||||
link: `https://www.douyu.com/${id}`,
|
||||
},
|
||||
]
|
||||
: [
|
||||
{
|
||||
title: `开播: ${data.room_name}`,
|
||||
pubDate: new Date(data.show_time * 1000).toUTCString(),
|
||||
guid: data.show_time,
|
||||
link: `https://www.douyu.com/${id}`,
|
||||
},
|
||||
];
|
||||
}
|
||||
// make a fallback to the old api
|
||||
} catch {
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: `http://open.douyucdn.cn/api/RoomApi/room/${id}`,
|
||||
headers: {
|
||||
Referer: `https://www.douyu.com/${id}`,
|
||||
},
|
||||
];
|
||||
});
|
||||
|
||||
data = response.data.data;
|
||||
room_thumb = data.room_thumb;
|
||||
|
||||
if (data.online !== 0) {
|
||||
item = [
|
||||
{
|
||||
title: `开播: ${data.room_name}`,
|
||||
pubDate: new Date(data.start_time).toUTCString(),
|
||||
guid: data.start_time,
|
||||
link: `https://www.douyu.com/${id}`,
|
||||
},
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
title: `${data.owner_name}的斗鱼直播间`,
|
||||
image: room_thumb,
|
||||
link: `https://www.douyu.com/${id}`,
|
||||
item,
|
||||
allowEmpty: true,
|
||||
|
||||
Reference in New Issue
Block a user