@floating-live/bilibili 0.15.2 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/index.d.ts +5 -5
- package/index.js +5 -21
- package/package.json +7 -7
- package/parser.d.ts +10 -6
- package/parser.js +472 -422
- package/plugin.d.ts +26 -29
- package/plugin.js +63 -67
- package/room.d.ts +108 -74
- package/room.js +315 -228
- package/types.d.ts +39 -484
- package/types.js +1 -2
- package/utils/fingerprint.d.ts +98 -0
- package/utils/fingerprint.js +642 -0
- package/utils/fp2.d.ts +7 -0
- package/utils/fp2.js +234 -0
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -0
- package/utils/lsid.d.ts +1 -0
- package/utils/lsid.js +15 -0
- package/utils/randomImage.d.ts +2 -0
- package/utils/randomImage.js +107 -0
- package/utils/request.d.ts +32 -0
- package/utils/request.js +181 -0
- package/utils/uuid.d.ts +1 -0
- package/utils/uuid.js +45 -0
- package/index.ts +0 -5
- package/parser.ts +0 -433
- package/plugin.ts +0 -103
- package/room.ts +0 -270
- package/tsconfig.json +0 -14
- package/types.ts +0 -503
- package/utils.d.ts +0 -18
- package/utils.js +0 -138
- package/utils.ts +0 -145
package/plugin.d.ts
CHANGED
|
@@ -1,29 +1,26 @@
|
|
|
1
|
-
import
|
|
2
|
-
interface BilibiliLoginInfo {
|
|
3
|
-
credentials: string;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
constructor(main: FloatingLive);
|
|
28
|
-
}
|
|
29
|
-
export default PluginBilibili;
|
|
1
|
+
import { BasePlugin, PluginContext } from "floating-live";
|
|
2
|
+
interface BilibiliLoginInfo {
|
|
3
|
+
credentials: string;
|
|
4
|
+
userId: number;
|
|
5
|
+
}
|
|
6
|
+
declare module "floating-live" {
|
|
7
|
+
interface AppCommandMap {
|
|
8
|
+
"bilibili.credentials.check": (credentials: string) => Promise<BilibiliLoginInfo>;
|
|
9
|
+
"bilibili.login.qrcode.get": () => Promise<{
|
|
10
|
+
key: string;
|
|
11
|
+
url: string;
|
|
12
|
+
}>;
|
|
13
|
+
"bilibili.login.qrcode.poll": (key: string) => Promise<{
|
|
14
|
+
status: number;
|
|
15
|
+
credentials?: string;
|
|
16
|
+
}>;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export interface PluginOptions {
|
|
20
|
+
userAgent: string;
|
|
21
|
+
}
|
|
22
|
+
export declare class PluginBilibili extends BasePlugin {
|
|
23
|
+
static pluginName: string;
|
|
24
|
+
init(ctx: PluginContext): void;
|
|
25
|
+
}
|
|
26
|
+
export default PluginBilibili;
|
package/plugin.js
CHANGED
|
@@ -1,67 +1,63 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
exports.PluginBilibili = PluginBilibili;
|
|
66
|
-
PluginBilibili.pluginName = "bilibili";
|
|
67
|
-
exports.default = PluginBilibili;
|
|
1
|
+
import { BasePlugin, } from "floating-live";
|
|
2
|
+
import { RoomBilibili } from "./room";
|
|
3
|
+
import { checkLoginQRcode, qrcodeGenerate } from "./utils";
|
|
4
|
+
import { requestGetInfoByRoom, getLoginUid, Cookies, } from "bilibili-live-danmaku";
|
|
5
|
+
import { parseGetInfoByRoom } from "./parser";
|
|
6
|
+
const platformInfo = {
|
|
7
|
+
name: "bilibili",
|
|
8
|
+
membership: {
|
|
9
|
+
id: "guard",
|
|
10
|
+
name: "大航海",
|
|
11
|
+
level: ["", "总督", "提督", "舰长"],
|
|
12
|
+
},
|
|
13
|
+
gift: {
|
|
14
|
+
action: "投喂",
|
|
15
|
+
},
|
|
16
|
+
currency: {
|
|
17
|
+
silver: {
|
|
18
|
+
name: "银瓜子",
|
|
19
|
+
ratio: 1,
|
|
20
|
+
},
|
|
21
|
+
gold: {
|
|
22
|
+
name: "电池",
|
|
23
|
+
ratio: 100,
|
|
24
|
+
money: 1000,
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
stats: {
|
|
28
|
+
view: "看过",
|
|
29
|
+
online: "在线",
|
|
30
|
+
like: "点赞",
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
export class PluginBilibili extends BasePlugin {
|
|
34
|
+
init(ctx) {
|
|
35
|
+
ctx.whenRegister("platform", (platform) => {
|
|
36
|
+
platform.register("bilibili", platformInfo, ctx.signal);
|
|
37
|
+
});
|
|
38
|
+
ctx.registerCommand("bilibili.room.create", (e, id, options) => {
|
|
39
|
+
return new RoomBilibili(Number(id), options);
|
|
40
|
+
});
|
|
41
|
+
ctx.registerCommand("bilibili.room.data", async (e, id) => {
|
|
42
|
+
const rawInfo = await requestGetInfoByRoom(parseInt("" + id));
|
|
43
|
+
return parseGetInfoByRoom(rawInfo);
|
|
44
|
+
});
|
|
45
|
+
ctx.registerCommand("bilibili.credentials.check", async (e, credentials) => {
|
|
46
|
+
const buvid = new Cookies(credentials).get("buvid3");
|
|
47
|
+
const userId = await getLoginUid({ cookie: credentials });
|
|
48
|
+
return {
|
|
49
|
+
credentials,
|
|
50
|
+
userId,
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
ctx.registerCommand("bilibili.login.qrcode.get", () => {
|
|
54
|
+
return qrcodeGenerate();
|
|
55
|
+
});
|
|
56
|
+
ctx.registerCommand("bilibili.login.qrcode.poll", async (e, key) => {
|
|
57
|
+
const [status, credentials] = await checkLoginQRcode(key);
|
|
58
|
+
return { status, credentials };
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
PluginBilibili.pluginName = "bilibili";
|
|
63
|
+
export default PluginBilibili;
|
package/room.d.ts
CHANGED
|
@@ -1,74 +1,108 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
/** 配置项 */
|
|
6
|
-
export interface RoomOptions {
|
|
7
|
-
/**
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
1
|
+
import { BilibiliRoomData, ConnectTokens } from "./types";
|
|
2
|
+
import { LiveWS, ResponseData } from "bilibili-live-danmaku";
|
|
3
|
+
import { FetchOptions } from "./utils";
|
|
4
|
+
import { UserInfo, LiveRoomStatsInfo, LiveRoomDetailInfo, LiveRoom } from "floating-live";
|
|
5
|
+
/** 配置项 */
|
|
6
|
+
export interface RoomOptions {
|
|
7
|
+
/** 是否自动初始化(默认为true) */
|
|
8
|
+
init?: boolean;
|
|
9
|
+
/** 生成房间后是否立即打开 */
|
|
10
|
+
open?: boolean;
|
|
11
|
+
/** 自动重连(默认为false) */
|
|
12
|
+
autoReconnect?: boolean;
|
|
13
|
+
/** 登录凭据,若为空,则初始化时自动生成 */
|
|
14
|
+
credentials?: string;
|
|
15
|
+
/** 连接凭证,若为空,则初始化时自动生成 */
|
|
16
|
+
tokens?: ConnectTokens;
|
|
17
|
+
/** 预设置的房间数据,若设置,将不会自动更新直播间数据 */
|
|
18
|
+
data?: BilibiliRoomData;
|
|
19
|
+
/** 断线重连间隔(默认值为500ms) */
|
|
20
|
+
connectInterval?: number;
|
|
21
|
+
/** 连接超时阈值(默认值为45000ms) */
|
|
22
|
+
connectTimeout?: number;
|
|
23
|
+
/** 自定义fetchData */
|
|
24
|
+
customFetchData?: (id: number | string) => Promise<BilibiliRoomData>;
|
|
25
|
+
/** 自定义fetchTokens */
|
|
26
|
+
customFetchTokens?: (roomId: number) => Promise<ConnectTokens>;
|
|
27
|
+
/** 自定义fetch函数 */
|
|
28
|
+
fetch?: (input: string | URL, init?: RequestInit) => Promise<Response>;
|
|
29
|
+
}
|
|
30
|
+
declare const symbolAbortController: unique symbol;
|
|
31
|
+
interface ClientWithAbortController extends LiveWS {
|
|
32
|
+
[symbolAbortController]: AbortController;
|
|
33
|
+
}
|
|
34
|
+
export declare class RoomBilibili extends LiveRoom implements BilibiliRoomData {
|
|
35
|
+
#private;
|
|
36
|
+
/** 平台id */
|
|
37
|
+
readonly platform: string;
|
|
38
|
+
/** 直播间号 */
|
|
39
|
+
readonly id: number;
|
|
40
|
+
/** 直播间room_id */
|
|
41
|
+
roomId: number;
|
|
42
|
+
/** 直播间短房号 */
|
|
43
|
+
shortId: number;
|
|
44
|
+
/** 房间信息 */
|
|
45
|
+
detail: LiveRoomDetailInfo;
|
|
46
|
+
stats: LiveRoomStatsInfo;
|
|
47
|
+
/** 是否连接上房间 */
|
|
48
|
+
connected: boolean;
|
|
49
|
+
/** 主播信息 */
|
|
50
|
+
anchor: UserInfo;
|
|
51
|
+
/** 直播间弹幕api客户端 */
|
|
52
|
+
client: ClientWithAbortController | null;
|
|
53
|
+
/** 断线重连间隔 */
|
|
54
|
+
connectInterval: number;
|
|
55
|
+
/** 连接超时阈值 */
|
|
56
|
+
connectTimeout: number;
|
|
57
|
+
/** 自动重连 */
|
|
58
|
+
autoReconnect: boolean;
|
|
59
|
+
/** 是否初始化 */
|
|
60
|
+
whenInit: Promise<RoomBilibili>;
|
|
61
|
+
/** 用户代理 */
|
|
62
|
+
userAgent?: string;
|
|
63
|
+
/** 是否处于重连状态 */
|
|
64
|
+
private reconnecting;
|
|
65
|
+
/** 最后一次连接时间 */
|
|
66
|
+
private lastConnectionTime;
|
|
67
|
+
/** 自定义fetchData */
|
|
68
|
+
customFetchData?: (id: number | string) => BilibiliRoomData;
|
|
69
|
+
/** 自定义fetchTokens */
|
|
70
|
+
customFetchTokens?: (roomId: number, credentials: string) => Promise<ConnectTokens>;
|
|
71
|
+
/** 自定义fetch函数 */
|
|
72
|
+
fetch: (input: RequestInfo | URL, init?: RequestInit | undefined) => Promise<Response>;
|
|
73
|
+
constructor(
|
|
74
|
+
/** 房间id */
|
|
75
|
+
id: number, options?: RoomOptions);
|
|
76
|
+
/** 初始化
|
|
77
|
+
* 自动获取并设置 `credentials` ,自动获取房间信息和连接 `token`
|
|
78
|
+
*/
|
|
79
|
+
protected init(options?: RoomOptions): Promise<void>;
|
|
80
|
+
/** 更新房间信息 */
|
|
81
|
+
update(): Promise<BilibiliRoomData>;
|
|
82
|
+
/** 获取房间信息 */
|
|
83
|
+
fetchData(): Promise<BilibiliRoomData>;
|
|
84
|
+
/** 设置直播间数据 */
|
|
85
|
+
setData({ roomId, shortId, status, timestamp, detail, stats, anchor, liveId, openStatus, available, }: BilibiliRoomData): import("floating-live").LiveRoomData;
|
|
86
|
+
/** 开启直播间监听 */
|
|
87
|
+
open(): Promise<void>;
|
|
88
|
+
/** 设置登录凭据 */
|
|
89
|
+
setCredentials(credentials: string, updateTokens?: boolean): Promise<void>;
|
|
90
|
+
/** 更新连接tokens */
|
|
91
|
+
updateTokens(): Promise<void>;
|
|
92
|
+
/** 请求连接tokens */
|
|
93
|
+
fetchTokens(credentials?: string): Promise<ConnectTokens>;
|
|
94
|
+
/** 设置直播连接tokens */
|
|
95
|
+
setTokens(tokens: ConnectTokens): void;
|
|
96
|
+
/** 无缝重连 */
|
|
97
|
+
reconnect(): void;
|
|
98
|
+
private emitConnention;
|
|
99
|
+
/** 打开直播弹幕客户端 */
|
|
100
|
+
private openWebsocketClient;
|
|
101
|
+
/** 创建直播弹幕客户端 */
|
|
102
|
+
private initClient;
|
|
103
|
+
/** 关闭直播间监听 */
|
|
104
|
+
close(): void;
|
|
105
|
+
}
|
|
106
|
+
export default RoomBilibili;
|
|
107
|
+
/** 获取房间信息 */
|
|
108
|
+
export declare function requestGetInfoByRoom(id: number, options?: FetchOptions): Promise<ResponseData.GetInfoByRoom>;
|