@bililive-tools/bilibili-recorder 1.15.0 → 1.16.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/lib/index.js +44 -45
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -2,7 +2,6 @@ import path from "node:path";
|
|
|
2
2
|
import mitt from "mitt";
|
|
3
3
|
import { defaultFromJSON, defaultToJSON, genRecorderUUID, genRecordUUID, utils, createDownloader, } from "@bililive-tools/manager";
|
|
4
4
|
import { getInfo, getStream, getLiveStatus, getStrictStream } from "./stream.js";
|
|
5
|
-
import { ensureFolderExist } from "./utils.js";
|
|
6
5
|
import DanmaClient from "./danma.js";
|
|
7
6
|
function createRecorder(opts) {
|
|
8
7
|
// 内部实现时,应该只有 proxy 包裹的那一层会使用这个 recorder 标识符,不应该有直接通过
|
|
@@ -185,6 +184,7 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, isManualStart, b
|
|
|
185
184
|
startTime: opts.startTime,
|
|
186
185
|
liveStartTime: liveStartTime,
|
|
187
186
|
recordStartTime,
|
|
187
|
+
extraMs: opts.extraMs,
|
|
188
188
|
}),
|
|
189
189
|
formatName: streamOptions.format_name,
|
|
190
190
|
disableDanma: this.disableProvideCommentsWhenRecording,
|
|
@@ -197,20 +197,6 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, isManualStart, b
|
|
|
197
197
|
const info = await getInfo(this.channelId);
|
|
198
198
|
return info;
|
|
199
199
|
});
|
|
200
|
-
const savePath = getSavePath({
|
|
201
|
-
owner,
|
|
202
|
-
title,
|
|
203
|
-
startTime: Date.now(),
|
|
204
|
-
liveStartTime: liveStartTime,
|
|
205
|
-
recordStartTime,
|
|
206
|
-
});
|
|
207
|
-
try {
|
|
208
|
-
ensureFolderExist(savePath);
|
|
209
|
-
}
|
|
210
|
-
catch (err) {
|
|
211
|
-
this.state = "idle";
|
|
212
|
-
throw err;
|
|
213
|
-
}
|
|
214
200
|
const handleVideoCreated = async ({ filename, title, cover, rawFilename }) => {
|
|
215
201
|
this.emit("videoFileCreated", { filename, cover, rawFilename });
|
|
216
202
|
if (title && this?.liveInfo) {
|
|
@@ -230,8 +216,8 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, isManualStart, b
|
|
|
230
216
|
});
|
|
231
217
|
};
|
|
232
218
|
downloader.on("videoFileCreated", handleVideoCreated);
|
|
233
|
-
downloader.on("videoFileCompleted", (
|
|
234
|
-
this.emit("videoFileCompleted",
|
|
219
|
+
downloader.on("videoFileCompleted", (data) => {
|
|
220
|
+
this.emit("videoFileCompleted", data);
|
|
235
221
|
});
|
|
236
222
|
downloader.on("DebugLog", (data) => {
|
|
237
223
|
this.emit("DebugLog", data);
|
|
@@ -247,34 +233,47 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, isManualStart, b
|
|
|
247
233
|
uid: Number(this.uid),
|
|
248
234
|
useServerTimestamp: this.useServerTimestamp,
|
|
249
235
|
});
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
236
|
+
// 开启了禁止提供弹幕功能,并且也没有设置标题关键词,才完全禁止连接弹幕服务器,否则都连接弹幕服务器,前者不处理弹幕消息,后者根据标题关键词来判断是否停止录制
|
|
237
|
+
const enableDanmaListen = !this.disableProvideCommentsWhenRecording ||
|
|
238
|
+
utils.shouldCheckTitleKeywords(isManualStart, this.titleKeywords);
|
|
239
|
+
danmaClient.on("Message", (msg) => {
|
|
240
|
+
if (this.disableProvideCommentsWhenRecording)
|
|
241
|
+
return;
|
|
242
|
+
const extraDataController = downloader.getExtraDataController();
|
|
243
|
+
if (!extraDataController)
|
|
244
|
+
return;
|
|
245
|
+
if (msg.type === "super_chat" && this.saveSCDanma === false)
|
|
246
|
+
return;
|
|
247
|
+
if ((msg.type === "give_gift" || msg.type === "guard") && this.saveGiftDanma === false)
|
|
248
|
+
return;
|
|
249
|
+
this.emit("Message", msg);
|
|
250
|
+
extraDataController.addMessage(msg);
|
|
251
|
+
});
|
|
252
|
+
danmaClient.on("onRoomInfoChange", (msg) => {
|
|
253
|
+
if (utils.shouldCheckTitleKeywords(isManualStart, this.titleKeywords)) {
|
|
254
|
+
const title = msg?.body?.title ?? "";
|
|
255
|
+
const hasTitleKeyword = utils.hasBlockedTitleKeywords(title, this.titleKeywords);
|
|
256
|
+
if (hasTitleKeyword) {
|
|
257
|
+
this.state = "title-blocked";
|
|
258
|
+
this.emit("DebugLog", {
|
|
259
|
+
type: "common",
|
|
260
|
+
text: `检测到标题包含关键词,停止录制:直播间标题 "${title}" 包含关键词 "${this.titleKeywords}"`,
|
|
261
|
+
});
|
|
262
|
+
// 停止录制
|
|
263
|
+
this.recordHandle && this.recordHandle.stop("直播间标题包含关键词");
|
|
275
264
|
}
|
|
276
|
-
}
|
|
277
|
-
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
if (enableDanmaListen) {
|
|
268
|
+
try {
|
|
269
|
+
danmaClient.start();
|
|
270
|
+
}
|
|
271
|
+
catch (err) {
|
|
272
|
+
this.emit("DebugLog", {
|
|
273
|
+
type: "error",
|
|
274
|
+
text: `弹幕连接失败,错误信息: ${String(err)}`,
|
|
275
|
+
});
|
|
276
|
+
}
|
|
278
277
|
}
|
|
279
278
|
const downloaderArgs = downloader.getArguments();
|
|
280
279
|
downloader.run();
|
|
@@ -313,7 +312,7 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, isManualStart, b
|
|
|
313
312
|
recorderType: downloader.type,
|
|
314
313
|
url: stream.url,
|
|
315
314
|
downloaderArgs,
|
|
316
|
-
savePath:
|
|
315
|
+
savePath: downloader.videoFilePath,
|
|
317
316
|
stop,
|
|
318
317
|
cut,
|
|
319
318
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bililive-tools/bilibili-recorder",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.16.1",
|
|
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.15.0",
|
|
42
|
-
"@bililive-tools/manager": "^1.
|
|
42
|
+
"@bililive-tools/manager": "^1.16.2"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
45
|
"build": "tsc",
|