feat(route): bilibili live keyframe (#18334)
This commit is contained in:
parent
905062f10c
commit
201fac26cc
|
|
@ -169,15 +169,15 @@ const getLiveIDFromShortID = (shortID) => {
|
|||
});
|
||||
};
|
||||
|
||||
const getUsernameFromLiveID = (liveID) => {
|
||||
const key = `bili-username-from-liveID-${liveID}`;
|
||||
const getUserInfoFromLiveID = (liveID) => {
|
||||
const key = `bili-userinfo-from-liveID-${liveID}`;
|
||||
return cache.tryGet(key, async () => {
|
||||
const { data: nameResponse } = await got(`https://api.live.bilibili.com/live_user/v1/UserInfo/get_anchor_in_room?roomid=${liveID}`, {
|
||||
headers: {
|
||||
Referer: `https://live.bilibili.com/${liveID}`,
|
||||
},
|
||||
});
|
||||
return nameResponse.data.info.uname;
|
||||
return nameResponse.data.info;
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -280,7 +280,7 @@ export default {
|
|||
getUsernameFromUID,
|
||||
getUsernameAndFaceFromUID,
|
||||
getLiveIDFromShortID,
|
||||
getUsernameFromLiveID,
|
||||
getUserInfoFromLiveID,
|
||||
getVideoNameFromId,
|
||||
getCidFromId,
|
||||
getAidFromBvid,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
import { Route } from '@/types';
|
||||
import got from '@/utils/got';
|
||||
import { DataItem, Route } from '@/types';
|
||||
import ofetch from '@/utils/ofetch';
|
||||
import cache from './cache';
|
||||
import { decodeHTML } from 'entities';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
import timezone from '@/utils/timezone';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/live/room/:roomID',
|
||||
|
|
@ -32,33 +35,32 @@ async function handler(ctx) {
|
|||
if (Number.parseInt(roomID, 10) < 10000) {
|
||||
roomID = await cache.getLiveIDFromShortID(roomID);
|
||||
}
|
||||
const name = await cache.getUsernameFromLiveID(roomID);
|
||||
const info = await cache.getUserInfoFromLiveID(roomID);
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: `https://api.live.bilibili.com/room/v1/Room/get_info?room_id=${roomID}&from=room`,
|
||||
const response = await ofetch(`https://api.live.bilibili.com/room/v1/Room/get_info?room_id=${roomID}&from=room`, {
|
||||
headers: {
|
||||
Referer: `https://live.bilibili.com/${roomID}`,
|
||||
},
|
||||
});
|
||||
const data = response.data.data;
|
||||
const data = response.data;
|
||||
|
||||
const liveItem = [];
|
||||
const liveItem: DataItem[] = [];
|
||||
|
||||
if (data.live_status === 1) {
|
||||
liveItem.push({
|
||||
title: `${data.title} ${data.live_time}`,
|
||||
description: `${data.title}<br>${data.description}`,
|
||||
pubDate: new Date(data.live_time.replace(' ', 'T') + '+08:00').toUTCString(),
|
||||
description: `<img src="${data.keyframe}"><br>${decodeHTML(data.description)}`,
|
||||
pubDate: timezone(parseDate(data.live_time), 8),
|
||||
guid: `https://live.bilibili.com/${roomID} ${data.live_time}`,
|
||||
link: `https://live.bilibili.com/${roomID}`,
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
title: `${name} 直播间开播状态`,
|
||||
title: `${info.uname} 直播间开播状态`,
|
||||
link: `https://live.bilibili.com/${roomID}`,
|
||||
description: `${name} 直播间开播状态`,
|
||||
description: `${info.uname} 直播间开播状态`,
|
||||
image: info.face,
|
||||
item: liveItem,
|
||||
allowEmpty: true,
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue