@bililive-tools/bilibili-recorder 1.5.1 → 1.7.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/README.md +1 -0
- package/lib/danma.d.ts +1 -1
- package/lib/danma.js +17 -17
- package/lib/index.js +31 -21
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -53,6 +53,7 @@ interface Options {
|
|
|
53
53
|
m3u8ProxyUrl?: string; // 代理链接,文档待补充
|
|
54
54
|
videoFormat?: "auto"; // 视频格式: "auto", "ts", "mkv" ,auto模式下, 分段使用 "ts",不分段使用 "mp4"
|
|
55
55
|
onlyAudio?: boolean; // 只录制音频,默认为否
|
|
56
|
+
recorderType?: "auto" | "ffmpeg" | "mesio"; // 底层录制器,使用mesio时videoFormat参数无效
|
|
56
57
|
}
|
|
57
58
|
```
|
|
58
59
|
|
package/lib/danma.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ declare class DanmaClient extends EventEmitter {
|
|
|
8
8
|
private useServerTimestamp;
|
|
9
9
|
constructor(roomId: number, { auth, uid, useServerTimestamp, }: {
|
|
10
10
|
auth: string | undefined;
|
|
11
|
-
uid: number
|
|
11
|
+
uid: number;
|
|
12
12
|
useServerTimestamp?: boolean;
|
|
13
13
|
});
|
|
14
14
|
start(): Promise<void>;
|
package/lib/danma.js
CHANGED
|
@@ -74,10 +74,10 @@ class DanmaClient extends EventEmitter {
|
|
|
74
74
|
uid: String(msg.body.user.uid),
|
|
75
75
|
name: msg.body.user.uname,
|
|
76
76
|
avatar: msg.body.user.face,
|
|
77
|
-
extra: {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
},
|
|
77
|
+
// extra: {
|
|
78
|
+
// badgeName: msg.body.user?.badge?.name,
|
|
79
|
+
// badgeLevel: msg.body.user?.badge?.level,
|
|
80
|
+
// },
|
|
81
81
|
},
|
|
82
82
|
};
|
|
83
83
|
this.emit("Message", comment);
|
|
@@ -93,10 +93,10 @@ class DanmaClient extends EventEmitter {
|
|
|
93
93
|
uid: String(msg.body.user.uid),
|
|
94
94
|
name: msg.body.user.uname,
|
|
95
95
|
avatar: msg.body.user.face,
|
|
96
|
-
extra: {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
},
|
|
96
|
+
// extra: {
|
|
97
|
+
// badgeName: msg.body.user?.badge?.name,
|
|
98
|
+
// badgeLevel: msg.body.user?.badge?.level,
|
|
99
|
+
// },
|
|
100
100
|
},
|
|
101
101
|
};
|
|
102
102
|
this.emit("Message", comment);
|
|
@@ -106,17 +106,17 @@ class DanmaClient extends EventEmitter {
|
|
|
106
106
|
type: "guard",
|
|
107
107
|
timestamp: this.useServerTimestamp ? msg.timestamp : Date.now(),
|
|
108
108
|
name: msg.body.gift_name,
|
|
109
|
-
price: msg.body.price,
|
|
109
|
+
price: msg.body.price / 1000,
|
|
110
110
|
count: 1,
|
|
111
111
|
level: msg.body.guard_level,
|
|
112
112
|
sender: {
|
|
113
113
|
uid: String(msg.body.user.uid),
|
|
114
114
|
name: msg.body.user.uname,
|
|
115
115
|
avatar: msg.body.user.face,
|
|
116
|
-
extra: {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
},
|
|
116
|
+
// extra: {
|
|
117
|
+
// badgeName: msg.body.user?.badge?.name,
|
|
118
|
+
// badgeLevel: msg.body.user?.badge?.level,
|
|
119
|
+
// },
|
|
120
120
|
},
|
|
121
121
|
};
|
|
122
122
|
this.emit("Message", gift);
|
|
@@ -132,10 +132,10 @@ class DanmaClient extends EventEmitter {
|
|
|
132
132
|
uid: String(msg.body.user.uid),
|
|
133
133
|
name: msg.body.user.uname,
|
|
134
134
|
avatar: msg.body.user.face,
|
|
135
|
-
extra: {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
},
|
|
135
|
+
// extra: {
|
|
136
|
+
// badgeName: msg.body.user?.badge?.name,
|
|
137
|
+
// badgeLevel: msg.body.user?.badge?.level,
|
|
138
|
+
// },
|
|
139
139
|
},
|
|
140
140
|
extra: {
|
|
141
141
|
hits: msg.body.combo?.combo_num,
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import mitt from "mitt";
|
|
3
|
-
import { defaultFromJSON, defaultToJSON, genRecorderUUID, genRecordUUID, utils,
|
|
3
|
+
import { defaultFromJSON, defaultToJSON, genRecorderUUID, genRecordUUID, utils, createBaseRecorder, } from "@bililive-tools/manager";
|
|
4
4
|
import { getInfo, getStream, getLiveStatus, getStrictStream } from "./stream.js";
|
|
5
5
|
import { ensureFolderExist, hasKeyword } from "./utils.js";
|
|
6
6
|
import DanmaClient from "./danma.js";
|
|
@@ -23,6 +23,7 @@ function createRecorder(opts) {
|
|
|
23
23
|
m3u8ProxyUrl: opts.m3u8ProxyUrl,
|
|
24
24
|
formatName: opts.formatName ?? "auto",
|
|
25
25
|
codecName: opts.codecName ?? "auto",
|
|
26
|
+
recorderType: opts.recorderType ?? "ffmpeg",
|
|
26
27
|
getChannelURL() {
|
|
27
28
|
return `https://live.bilibili.com/${this.channelId}`;
|
|
28
29
|
},
|
|
@@ -85,16 +86,22 @@ const ffmpegInputOptions = [
|
|
|
85
86
|
const checkLiveStatusAndRecord = async function ({ getSavePath, isManualStart, banLiveId, }) {
|
|
86
87
|
if (this.recordHandle != null)
|
|
87
88
|
return this.recordHandle;
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
89
|
+
try {
|
|
90
|
+
const { living, liveId, owner: _owner, title: _title } = await getLiveStatus(this.channelId);
|
|
91
|
+
this.liveInfo = {
|
|
92
|
+
living,
|
|
93
|
+
owner: _owner,
|
|
94
|
+
title: _title,
|
|
95
|
+
avatar: "",
|
|
96
|
+
cover: "",
|
|
97
|
+
liveId: liveId,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
this.state = "check-error";
|
|
102
|
+
throw error;
|
|
103
|
+
}
|
|
104
|
+
if (this.liveInfo.liveId === banLiveId) {
|
|
98
105
|
this.tempStopIntervalCheck = true;
|
|
99
106
|
}
|
|
100
107
|
else {
|
|
@@ -102,7 +109,7 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, isManualStart, b
|
|
|
102
109
|
}
|
|
103
110
|
if (this.tempStopIntervalCheck)
|
|
104
111
|
return null;
|
|
105
|
-
if (!living)
|
|
112
|
+
if (!this.liveInfo.living)
|
|
106
113
|
return null;
|
|
107
114
|
// 检查标题是否包含关键词,如果包含则不自动录制
|
|
108
115
|
// 手动开始录制时不检查标题关键词
|
|
@@ -110,11 +117,11 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, isManualStart, b
|
|
|
110
117
|
this.titleKeywords &&
|
|
111
118
|
typeof this.titleKeywords === "string" &&
|
|
112
119
|
this.titleKeywords.trim()) {
|
|
113
|
-
const hasTitleKeyword = hasKeyword(
|
|
120
|
+
const hasTitleKeyword = hasKeyword(this.liveInfo.title, this.titleKeywords);
|
|
114
121
|
if (hasTitleKeyword) {
|
|
115
122
|
this.emit("DebugLog", {
|
|
116
123
|
type: "common",
|
|
117
|
-
text: `跳过录制:直播间标题 "${
|
|
124
|
+
text: `跳过录制:直播间标题 "${this.liveInfo.title}" 包含关键词 "${this.titleKeywords}"`,
|
|
118
125
|
});
|
|
119
126
|
return null;
|
|
120
127
|
}
|
|
@@ -146,8 +153,9 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, isManualStart, b
|
|
|
146
153
|
});
|
|
147
154
|
}
|
|
148
155
|
catch (err) {
|
|
149
|
-
this.qualityRetry
|
|
150
|
-
|
|
156
|
+
if (this.qualityRetry > 0)
|
|
157
|
+
this.qualityRetry -= 1;
|
|
158
|
+
this.state = "check-error";
|
|
151
159
|
throw err;
|
|
152
160
|
}
|
|
153
161
|
this.state = "recording";
|
|
@@ -159,7 +167,7 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, isManualStart, b
|
|
|
159
167
|
let url = stream.url;
|
|
160
168
|
let intervalId = null;
|
|
161
169
|
if (this.useM3U8Proxy && streamOptions.protocol_name === "http_hls") {
|
|
162
|
-
url = `${this.m3u8ProxyUrl}?id=${this.id}`;
|
|
170
|
+
url = `${this.m3u8ProxyUrl}?id=${this.id}&format=hls`;
|
|
163
171
|
this.emit("DebugLog", {
|
|
164
172
|
type: "common",
|
|
165
173
|
text: `is hls stream, use proxy: ${url}`,
|
|
@@ -193,18 +201,20 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, isManualStart, b
|
|
|
193
201
|
isEnded = true;
|
|
194
202
|
this.emit("DebugLog", {
|
|
195
203
|
type: "common",
|
|
196
|
-
text: `
|
|
204
|
+
text: `record end, reason: ${JSON.stringify(args, (_, v) => (v instanceof Error ? v.stack : v))}`,
|
|
197
205
|
});
|
|
198
206
|
const reason = args[0] instanceof Error ? args[0].message : String(args[0]);
|
|
199
207
|
this.recordHandle?.stop(reason);
|
|
200
208
|
};
|
|
201
|
-
|
|
209
|
+
let recorderType = this.recorderType === "mesio" ? "mesio" : "ffmpeg";
|
|
210
|
+
const recorder = createBaseRecorder(recorderType, {
|
|
202
211
|
url: url,
|
|
203
212
|
outputOptions: ffmpegOutputOptions,
|
|
204
213
|
inputOptions: ffmpegInputOptions,
|
|
214
|
+
mesioOptions: ["-H", "Referer:https://live.bilibili.com/"],
|
|
205
215
|
segment: this.segment ?? 0,
|
|
206
216
|
getSavePath: (opts) => getSavePath({ owner, title: opts.title ?? title, startTime: opts.startTime }),
|
|
207
|
-
|
|
217
|
+
formatName: streamOptions.format_name,
|
|
208
218
|
disableDanma: this.disableProvideCommentsWhenRecording,
|
|
209
219
|
videoFormat: this.videoFormat,
|
|
210
220
|
}, onEnd, async () => {
|
|
@@ -255,7 +265,7 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, isManualStart, b
|
|
|
255
265
|
});
|
|
256
266
|
let danmaClient = new DanmaClient(roomId, {
|
|
257
267
|
auth: this.auth,
|
|
258
|
-
uid: this.uid,
|
|
268
|
+
uid: Number(this.uid),
|
|
259
269
|
useServerTimestamp: this.useServerTimestamp,
|
|
260
270
|
});
|
|
261
271
|
if (!this.disableProvideCommentsWhenRecording) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bililive-tools/bilibili-recorder",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "bililive-tools bilibili recorder implemention",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -39,7 +39,7 @@
|
|
|
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.6.1"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
45
|
"build": "tsc",
|