更新B站的api接口

This commit is contained in:
xys20071111 2022-12-16 21:32:43 +08:00
parent 7a5475b93c
commit c066a5a8c4
No known key found for this signature in database
GPG Key ID: 29CB7FFE349CFD03
2 changed files with 13 additions and 7 deletions

View File

@ -32,19 +32,21 @@ export class DanmakuReceiver extends EventEmitter {
} }
public async connect() { public async connect() {
const roomConfig = await (await fetch( const roomConfig = await (await fetch(
`https://api.live.bilibili.com/room/v1/Danmu/getConf?room_id=${this.roomId}&platform=pc&player=web`, `https://api.live.bilibili.com/xlive/web-room/v1/index/getDanmuInfo?id=${this.roomId}&type=0`,
{ {
headers: { headers: {
cookie, Cookie: cookie,
"user-agent": "User-Agent":
"Mozilla/5.0 (X11 Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36", "Mozilla/5.0 (X11 Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36",
host: "api.live.bilibili.com", Host: "api.live.bilibili.com",
Origin: 'https://live.bilibili.com',
Referer: `https://live.bilibili.com/${this.roomId}?broadcast_type=0`
}, },
}, },
)).json() )).json()
this.ws = new WebSocket( this.ws = new WebSocket(
`wss://${roomConfig.data.host_server_list[0].host}:${ `wss://${roomConfig.data.host_list[0].host}:${
roomConfig.data.host_server_list[0].wss_port roomConfig.data.host_list[0].wss_port
}/sub`, }/sub`,
) )
this.ws.onopen = () => { this.ws.onopen = () => {
@ -54,6 +56,7 @@ export class DanmakuReceiver extends EventEmitter {
platform: "web", platform: "web",
uid: config.verify.uid, uid: config.verify.uid,
key: roomConfig.data.token, key: roomConfig.data.token,
type: 2
}) })
this.ws!.send(this.generatePacket( this.ws!.send(this.generatePacket(
1, 1,

View File

@ -22,7 +22,10 @@ if (!config.disable_super_chat_action) {
globalThis.onunload = () => { globalThis.onunload = () => {
printLog('主程序', '退出') printLog('主程序', '退出')
} }
danmakuReceiver.on('closed', () => danmakuReceiver.connect()) danmakuReceiver.on('closed', () => {
printLog('主程序', '掉线了')
danmakuReceiver.connect()
})
danmakuReceiver.on('LIVE', onLiveStart) danmakuReceiver.on('LIVE', onLiveStart)
danmakuReceiver.on('PREPARING', onLiveEnd) danmakuReceiver.on('PREPARING', onLiveEnd)
danmakuReceiver.on('DANMU_MSG', receiveDanmaku) danmakuReceiver.on('DANMU_MSG', receiveDanmaku)