@bililive-tools/bilibili-recorder 1.18.2 → 1.19.2

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 CHANGED
@@ -56,6 +56,7 @@ interface Options {
56
56
  recorderType?: "auto" | "ffmpeg" | "mesio" | "bililive"; // 底层录制器,使用mesio和bililive时videoFormat参数无效
57
57
  debugLevel?: `verbose` | "basic"; // verbose参数时,录制器会输出更加详细的log
58
58
  customHost?: string; // 自定义host来替换直播流的host
59
+ segmentOnTitleChange?: boolean; // 标题变更时分段,默认为false;bililive引擎无损切段,其他引擎中断录制
59
60
  }
60
61
  ```
61
62
 
package/lib/index.js CHANGED
@@ -265,9 +265,11 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, isManualStart, b
265
265
  uid: Number(this.uid),
266
266
  useServerTimestamp: this.useServerTimestamp,
267
267
  });
268
- // 开启了禁止提供弹幕功能,并且也没有设置标题关键词,才完全禁止连接弹幕服务器,否则都连接弹幕服务器,前者不处理弹幕消息,后者根据标题关键词来判断是否停止录制
268
+ // 禁用弹幕且不需要监听标题时,才完全禁止连接弹幕服务器
269
269
  const enableDanmaListen = !this.disableProvideCommentsWhenRecording ||
270
- utils.shouldCheckTitleKeywords(isManualStart, this.titleKeywords);
270
+ utils.shouldCheckTitleKeywords(isManualStart, this.titleKeywords) ||
271
+ this.segmentOnTitleChange;
272
+ let currentTitle = title;
271
273
  danmaClient.on("Message", (msg) => {
272
274
  if (this.disableProvideCommentsWhenRecording)
273
275
  return;
@@ -281,9 +283,9 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, isManualStart, b
281
283
  this.emit("Message", msg);
282
284
  extraDataController.addMessage(msg);
283
285
  });
284
- danmaClient.on("onRoomInfoChange", (msg) => {
286
+ danmaClient.on("RoomInfoChange", (msg) => {
287
+ const title = msg?.body?.title?.trim() ?? "";
285
288
  if (utils.shouldCheckTitleKeywords(isManualStart, this.titleKeywords)) {
286
- const title = msg?.body?.title ?? "";
287
289
  const hasTitleKeyword = utils.hasBlockedTitleKeywords(title, this.titleKeywords);
288
290
  if (hasTitleKeyword) {
289
291
  this.emit("stateChange", {
@@ -296,8 +298,35 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, isManualStart, b
296
298
  });
297
299
  // 停止录制
298
300
  this.recordHandle && this.recordHandle.stop("直播间标题包含关键词");
301
+ return;
299
302
  }
300
303
  }
304
+ if (!this.segmentOnTitleChange || !title || title === currentTitle)
305
+ return;
306
+ const previousTitle = currentTitle;
307
+ currentTitle = title;
308
+ if (this.liveInfo) {
309
+ this.liveInfo.title = title;
310
+ }
311
+ if (downloader.type !== "bililive") {
312
+ this.emit("DebugLog", {
313
+ type: "common",
314
+ text: `检测到标题由 "${previousTitle}" 变更为 "${title}",中断录制以进行分段`,
315
+ });
316
+ this.appendTimeline({
317
+ text: `检测到标题由 "${previousTitle}" 变更为 "${title}",中断录制以进行分段`,
318
+ });
319
+ this.recordHandle && this.recordHandle.stop("标题变更分段");
320
+ return;
321
+ }
322
+ this.emit("DebugLog", {
323
+ type: "common",
324
+ text: `检测到标题由 "${previousTitle}" 变更为 "${title}",开始分段`,
325
+ });
326
+ this.appendTimeline({
327
+ text: `检测到标题由 "${previousTitle}" 变更为 "${title}",开始分段`,
328
+ });
329
+ downloader.cut();
301
330
  });
302
331
  danmaClient.on("open", () => {
303
332
  this.appendTimeline({
package/lib/stream.d.ts CHANGED
@@ -49,11 +49,11 @@ export declare function getStream(opts: Pick<Recorder, "channelId" | "quality">
49
49
  onlyAudio?: boolean;
50
50
  customHost?: string;
51
51
  }): Promise<{
52
- currentStream: {
53
- name: string;
54
- source: string;
55
- url: string;
56
- };
52
+ codec_name: string | "avc" | "hevc";
53
+ accept_qn: number[];
54
+ base_url: string;
55
+ current_qn: number;
56
+ url_info: Omit<SourceProfile, "name">[];
57
57
  streams: StreamProfile[];
58
58
  sources: SourceProfile[];
59
59
  name: string;
@@ -63,9 +63,9 @@ export declare function getStream(opts: Pick<Recorder, "channelId" | "quality">
63
63
  codec_name: string;
64
64
  qn: number;
65
65
  };
66
- codec_name: string | "avc" | "hevc";
67
- accept_qn: number[];
68
- base_url: string;
69
- current_qn: number;
70
- url_info: Omit<SourceProfile, "name">[];
66
+ currentStream: {
67
+ name: string;
68
+ source: string;
69
+ url: string;
70
+ };
71
71
  }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bililive-tools/bilibili-recorder",
3
- "version": "1.18.2",
3
+ "version": "1.19.2",
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.17.1"
42
+ "@bililive-tools/manager": "^1.17.2"
43
43
  },
44
44
  "scripts": {
45
45
  "build": "tsc",