@bililive-tools/bilibili-recorder 1.4.1 → 1.5.1
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/README.md +1 -0
- package/lib/danma.d.ts +6 -1
- package/lib/danma.js +8 -6
- package/lib/index.js +8 -2
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -43,6 +43,7 @@ interface Options {
|
|
|
43
43
|
disableProvideCommentsWhenRecording?: boolean; // 禁用弹幕录制
|
|
44
44
|
saveGiftDanma?: boolean; // 保存礼物弹幕,包含舰长
|
|
45
45
|
saveSCDanma?: boolean; // 保存SC
|
|
46
|
+
useServerTimestamp?: boolean; // 控制弹幕是否使用服务端时间戳,默认为true
|
|
46
47
|
saveCover?: boolean; // 保存封面
|
|
47
48
|
auth?: string; // 登录所需cookie
|
|
48
49
|
uid?: number; // cookie所有者uid,用于弹幕录制
|
package/lib/danma.d.ts
CHANGED
|
@@ -5,7 +5,12 @@ declare class DanmaClient extends EventEmitter {
|
|
|
5
5
|
private auth;
|
|
6
6
|
private uid;
|
|
7
7
|
private retryCount;
|
|
8
|
-
|
|
8
|
+
private useServerTimestamp;
|
|
9
|
+
constructor(roomId: number, { auth, uid, useServerTimestamp, }: {
|
|
10
|
+
auth: string | undefined;
|
|
11
|
+
uid: number | undefined;
|
|
12
|
+
useServerTimestamp?: boolean;
|
|
13
|
+
});
|
|
9
14
|
start(): Promise<void>;
|
|
10
15
|
stop(): void;
|
|
11
16
|
}
|
package/lib/danma.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EventEmitter } from "node:events";
|
|
2
|
-
import { startListen } from "
|
|
2
|
+
import { startListen } from "blive-message-listener";
|
|
3
3
|
import { getBuvidConf } from "./bilibili_api.js";
|
|
4
4
|
// 全局缓存,一天过期时间 (24 * 60 * 60 * 1000 ms)
|
|
5
5
|
const CACHE_DURATION = 24 * 60 * 60 * 1000;
|
|
@@ -47,11 +47,13 @@ class DanmaClient extends EventEmitter {
|
|
|
47
47
|
auth;
|
|
48
48
|
uid;
|
|
49
49
|
retryCount = 10;
|
|
50
|
-
|
|
50
|
+
useServerTimestamp;
|
|
51
|
+
constructor(roomId, { auth, uid, useServerTimestamp, }) {
|
|
51
52
|
super();
|
|
52
53
|
this.roomId = roomId;
|
|
53
54
|
this.auth = auth;
|
|
54
55
|
this.uid = uid;
|
|
56
|
+
this.useServerTimestamp = useServerTimestamp ?? true;
|
|
55
57
|
}
|
|
56
58
|
async start() {
|
|
57
59
|
const info = await getCachedBuvidConf();
|
|
@@ -64,7 +66,7 @@ class DanmaClient extends EventEmitter {
|
|
|
64
66
|
return;
|
|
65
67
|
const comment = {
|
|
66
68
|
type: "comment",
|
|
67
|
-
timestamp: msg.body.timestamp,
|
|
69
|
+
timestamp: this.useServerTimestamp ? msg.body.timestamp : Date.now(),
|
|
68
70
|
text: content,
|
|
69
71
|
color: msg.body.content_color,
|
|
70
72
|
mode: msg.body.type,
|
|
@@ -84,7 +86,7 @@ class DanmaClient extends EventEmitter {
|
|
|
84
86
|
const content = msg.body.content.replaceAll(/[\r\n]/g, "");
|
|
85
87
|
const comment = {
|
|
86
88
|
type: "super_chat",
|
|
87
|
-
timestamp: msg.raw.send_time,
|
|
89
|
+
timestamp: this.useServerTimestamp ? msg.raw.send_time : Date.now(),
|
|
88
90
|
text: content,
|
|
89
91
|
price: msg.body.price,
|
|
90
92
|
sender: {
|
|
@@ -102,7 +104,7 @@ class DanmaClient extends EventEmitter {
|
|
|
102
104
|
onGuardBuy: (msg) => {
|
|
103
105
|
const gift = {
|
|
104
106
|
type: "guard",
|
|
105
|
-
timestamp: msg.timestamp,
|
|
107
|
+
timestamp: this.useServerTimestamp ? msg.timestamp : Date.now(),
|
|
106
108
|
name: msg.body.gift_name,
|
|
107
109
|
price: msg.body.price,
|
|
108
110
|
count: 1,
|
|
@@ -122,7 +124,7 @@ class DanmaClient extends EventEmitter {
|
|
|
122
124
|
onGift: (msg) => {
|
|
123
125
|
const gift = {
|
|
124
126
|
type: "give_gift",
|
|
125
|
-
timestamp: msg
|
|
127
|
+
timestamp: this.useServerTimestamp ? msg?.raw?.data?.timestamp * 1000 : Date.now(),
|
|
126
128
|
name: msg.body.gift_name,
|
|
127
129
|
count: msg.body.amount,
|
|
128
130
|
price: msg.body.coin_type === "silver" ? 0 : msg.body.price / 1000,
|
package/lib/index.js
CHANGED
|
@@ -19,6 +19,7 @@ function createRecorder(opts) {
|
|
|
19
19
|
qualityMaxRetry: opts.qualityRetry ?? 0,
|
|
20
20
|
qualityRetry: opts.qualityRetry ?? 0,
|
|
21
21
|
useM3U8Proxy: opts.useM3U8Proxy ?? false,
|
|
22
|
+
useServerTimestamp: opts.useServerTimestamp ?? true,
|
|
22
23
|
m3u8ProxyUrl: opts.m3u8ProxyUrl,
|
|
23
24
|
formatName: opts.formatName ?? "auto",
|
|
24
25
|
codecName: opts.codecName ?? "auto",
|
|
@@ -252,7 +253,11 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, isManualStart, b
|
|
|
252
253
|
}
|
|
253
254
|
this.emit("progress", progress);
|
|
254
255
|
});
|
|
255
|
-
let danmaClient = new DanmaClient(roomId,
|
|
256
|
+
let danmaClient = new DanmaClient(roomId, {
|
|
257
|
+
auth: this.auth,
|
|
258
|
+
uid: this.uid,
|
|
259
|
+
useServerTimestamp: this.useServerTimestamp,
|
|
260
|
+
});
|
|
256
261
|
if (!this.disableProvideCommentsWhenRecording) {
|
|
257
262
|
danmaClient.on("Message", (msg) => {
|
|
258
263
|
const extraDataController = recorder.getExtraDataController();
|
|
@@ -301,8 +306,8 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, isManualStart, b
|
|
|
301
306
|
return;
|
|
302
307
|
this.state = "stopping-record";
|
|
303
308
|
intervalId && clearInterval(intervalId);
|
|
304
|
-
danmaClient.stop();
|
|
305
309
|
try {
|
|
310
|
+
danmaClient.stop();
|
|
306
311
|
await recorder.stop();
|
|
307
312
|
}
|
|
308
313
|
catch (err) {
|
|
@@ -349,6 +354,7 @@ export const provider = {
|
|
|
349
354
|
title: info.title,
|
|
350
355
|
owner: info.owner,
|
|
351
356
|
uid: info.uid,
|
|
357
|
+
avatar: info.avatar,
|
|
352
358
|
};
|
|
353
359
|
},
|
|
354
360
|
createRecorder(opts) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bililive-tools/bilibili-recorder",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "bililive-tools bilibili recorder implemention",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -34,12 +34,12 @@
|
|
|
34
34
|
"author": "renmu123",
|
|
35
35
|
"license": "LGPL",
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"blive-message-listener": "^0.5.
|
|
37
|
+
"blive-message-listener": "^0.5.1",
|
|
38
38
|
"mitt": "^3.0.1",
|
|
39
39
|
"tiny-bilibili-ws": "^1.0.2",
|
|
40
40
|
"lodash-es": "^4.17.21",
|
|
41
41
|
"axios": "^1.7.8",
|
|
42
|
-
"@bililive-tools/manager": "^1.
|
|
42
|
+
"@bililive-tools/manager": "^1.4.1"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
45
|
"build": "tsc",
|