@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/utils.ts
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import { RoomInfo } from "floating-live";
|
|
2
|
-
import { RawInfo } from "./types";
|
|
3
|
-
|
|
4
|
-
const USER_AGENT =
|
|
5
|
-
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36 Edg/117.0.2045.36";
|
|
6
|
-
|
|
7
|
-
/** API-当前登录用户信息 */
|
|
8
|
-
const UID_INIT_URL = "https://api.bilibili.com/x/web-interface/nav";
|
|
9
|
-
/** API-获取BUVID */
|
|
10
|
-
const BUVID_INIT_URL = "https://data.bilibili.com/v/";
|
|
11
|
-
|
|
12
|
-
const ROOM_INIT_URL =
|
|
13
|
-
"https://api.live.bilibili.com/xlive/web-room/v1/index/getInfoByRoom";
|
|
14
|
-
|
|
15
|
-
const DANMAKU_SERVER_CONF_URL =
|
|
16
|
-
"https://api.live.bilibili.com/xlive/web-room/v1/index/getDanmuInfo";
|
|
17
|
-
|
|
18
|
-
export function getCookie(headers: Headers) {
|
|
19
|
-
const cookies: string[] = [];
|
|
20
|
-
headers.forEach((val, key) => {
|
|
21
|
-
if (key == "set-cookie") {
|
|
22
|
-
const [c] = val.split(";");
|
|
23
|
-
cookies.push(c);
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
const cookie = cookies.join("; ");
|
|
27
|
-
return cookie;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function parseCookieString(str: string) {
|
|
31
|
-
const cookie: Record<string, string> = {};
|
|
32
|
-
str.split(";").forEach((item) => {
|
|
33
|
-
if (!item) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
const arr = item.split("=");
|
|
37
|
-
const key = arr[0]?.trim();
|
|
38
|
-
const val = arr[1]?.trim();
|
|
39
|
-
cookie[key] = val;
|
|
40
|
-
});
|
|
41
|
-
return cookie;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/** 获取登录用户的uid */
|
|
45
|
-
export async function getLoginUid(cookie: string = ""): Promise<number> {
|
|
46
|
-
// cookie若缺少SESSDATA,一定属于未登录状态,uid返回0
|
|
47
|
-
if (!parseCookieString(cookie)["SESSDATA"]) return 0;
|
|
48
|
-
const res = await fetch(UID_INIT_URL, {
|
|
49
|
-
headers: {
|
|
50
|
-
Cookie: cookie,
|
|
51
|
-
"User-Agent": USER_AGENT,
|
|
52
|
-
},
|
|
53
|
-
}).then((res) => res.json());
|
|
54
|
-
if (res.code == 0) {
|
|
55
|
-
return res.data.mid;
|
|
56
|
-
} else {
|
|
57
|
-
// code = -101 => 账号未登录
|
|
58
|
-
return 0;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/** 获取buvid */
|
|
63
|
-
export async function getBuvid(cookie: string = "") {
|
|
64
|
-
const res = await fetch(BUVID_INIT_URL, {
|
|
65
|
-
headers: {
|
|
66
|
-
Cookie: cookie,
|
|
67
|
-
"User-Agent": USER_AGENT,
|
|
68
|
-
},
|
|
69
|
-
});
|
|
70
|
-
const resCookie = getCookie(res.headers);
|
|
71
|
-
if (!resCookie) return;
|
|
72
|
-
return parseCookieString(resCookie)["buvid2"];
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/** 获取直播间弹幕token */
|
|
76
|
-
export async function getToken(roomId: number, cookie: string = "") {
|
|
77
|
-
return await fetch(`${DANMAKU_SERVER_CONF_URL}?id=${roomId}`, {
|
|
78
|
-
headers: {
|
|
79
|
-
Cookie: cookie,
|
|
80
|
-
"User-Agent": USER_AGENT,
|
|
81
|
-
},
|
|
82
|
-
})
|
|
83
|
-
.then((res) => res.json())
|
|
84
|
-
.then((res) => {
|
|
85
|
-
return res.data?.token;
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/** 生成登录二维码 */
|
|
90
|
-
export async function generateLoginQRcode() {
|
|
91
|
-
const res = await fetch(
|
|
92
|
-
"https://passport.bilibili.com/x/passport-login/web/qrcode/generate",
|
|
93
|
-
{
|
|
94
|
-
headers: {
|
|
95
|
-
"User-Agent": USER_AGENT,
|
|
96
|
-
},
|
|
97
|
-
}
|
|
98
|
-
).then((res) => res.json());
|
|
99
|
-
return {
|
|
100
|
-
url: res.data.url,
|
|
101
|
-
key: res.data.qrcode_key,
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/** 检测登录二维码 */
|
|
106
|
-
export async function checkLoginQRcode(
|
|
107
|
-
key: string
|
|
108
|
-
): Promise<[number, string?]> {
|
|
109
|
-
const res = await fetch(
|
|
110
|
-
`https://passport.bilibili.com/x/passport-login/web/qrcode/poll?qrcode_key=${key}`,
|
|
111
|
-
{
|
|
112
|
-
headers: {
|
|
113
|
-
"User-Agent": USER_AGENT,
|
|
114
|
-
},
|
|
115
|
-
}
|
|
116
|
-
);
|
|
117
|
-
const { code, message } = (await res.json()).data;
|
|
118
|
-
if (code == 86101) {
|
|
119
|
-
// 未扫码
|
|
120
|
-
return [1];
|
|
121
|
-
} else if (code == 86090) {
|
|
122
|
-
// 等待确认
|
|
123
|
-
return [2];
|
|
124
|
-
} else if (code == 0) {
|
|
125
|
-
const cookie = getCookie(res.headers);
|
|
126
|
-
console.log(cookie);
|
|
127
|
-
return [0, cookie];
|
|
128
|
-
} else if (code == 86038) {
|
|
129
|
-
// 二维码失效
|
|
130
|
-
return [-1];
|
|
131
|
-
} else {
|
|
132
|
-
// 其他错误
|
|
133
|
-
console.log(`${code} ${message}`);
|
|
134
|
-
throw message;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/** 获取房间id */
|
|
139
|
-
export async function getInfoByRoom(id: number): Promise<RawInfo> {
|
|
140
|
-
return await fetch(ROOM_INIT_URL + `?room_id=${id}`, {
|
|
141
|
-
method: "GET",
|
|
142
|
-
})
|
|
143
|
-
.then((response) => response.json())
|
|
144
|
-
.then((data) => data.data);
|
|
145
|
-
}
|