@bililive-tools/manager 1.6.1 → 1.9.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.
@@ -1,4 +1,7 @@
1
1
  import { EventEmitter } from "node:events";
2
+ import type { VideoFormat } from "../index.js";
3
+ import type { FormatName } from "./index.js";
4
+ import type { XmlStreamController } from "../xml_stream_controller.js";
2
5
  /**
3
6
  * 录制器构造函数选项的基础接口
4
7
  */
@@ -11,19 +14,21 @@ export interface BaseRecorderOptions {
11
14
  segment: number;
12
15
  inputOptions?: string[];
13
16
  disableDanma?: boolean;
14
- formatName?: "flv" | "ts" | "fmp4";
17
+ formatName: FormatName;
18
+ debugLevel?: "none" | "basic" | "verbose";
15
19
  headers?: {
16
20
  [key: string]: string | undefined;
17
21
  };
22
+ videoFormat?: VideoFormat;
18
23
  }
19
24
  /**
20
25
  * 录制器接口定义
21
26
  */
22
27
  export interface IRecorder extends EventEmitter {
28
+ type: "ffmpeg" | "mesio" | "bililive";
23
29
  readonly hasSegment: boolean;
24
30
  readonly segment: number;
25
31
  readonly inputOptions: string[];
26
- readonly isHls: boolean;
27
32
  readonly disableDanma: boolean;
28
33
  readonly url: string;
29
34
  readonly headers: {
@@ -36,11 +41,13 @@ export interface IRecorder extends EventEmitter {
36
41
  run(): void;
37
42
  stop(): Promise<void>;
38
43
  getArguments(): string[];
39
- getExtraDataController(): any;
44
+ getExtraDataController(): XmlStreamController | null;
40
45
  createCommand(): any;
41
46
  on(event: "videoFileCreated", listener: (data: {
42
47
  filename: string;
43
48
  cover?: string;
49
+ rawFilename?: string;
50
+ title?: string;
44
51
  }) => void): this;
45
52
  on(event: "videoFileCompleted", listener: (data: {
46
53
  filename: string;
@@ -54,6 +61,8 @@ export interface IRecorder extends EventEmitter {
54
61
  emit(event: "videoFileCreated", data: {
55
62
  filename: string;
56
63
  cover?: string;
64
+ rawFilename?: string;
65
+ title?: string;
57
66
  }): boolean;
58
67
  emit(event: "videoFileCompleted", data: {
59
68
  filename: string;
@@ -70,12 +79,16 @@ export interface IRecorder extends EventEmitter {
70
79
  */
71
80
  export interface FFMPEGRecorderOptions extends BaseRecorderOptions {
72
81
  outputOptions: string[];
73
- videoFormat?: "auto" | "ts" | "mkv" | "mp4";
74
82
  }
75
83
  /**
76
84
  * Mesio录制器特定选项
77
85
  */
78
86
  export interface MesioRecorderOptions extends BaseRecorderOptions {
79
87
  outputOptions?: string[];
80
- isHls?: boolean;
88
+ }
89
+ /**
90
+ * Bililive录制器特定选项
91
+ */
92
+ export interface BililiveRecorderOptions extends BaseRecorderOptions {
93
+ outputOptions?: string[];
81
94
  }
@@ -1,25 +1,47 @@
1
1
  import { FFMPEGRecorder } from "./FFMPEGRecorder.js";
2
- import { mesioRecorder } from "./mesioRecorder.js";
2
+ import { MesioRecorder } from "./mesioRecorder.js";
3
+ import { BililiveRecorder } from "./BililiveRecorder.js";
3
4
  export { FFMPEGRecorder } from "./FFMPEGRecorder.js";
4
- export { mesioRecorder } from "./mesioRecorder.js";
5
- import type { IRecorder, FFMPEGRecorderOptions, MesioRecorderOptions } from "./IRecorder.js";
5
+ export { MesioRecorder } from "./mesioRecorder.js";
6
+ export { BililiveRecorder } from "./BililiveRecorder.js";
7
+ import type { IRecorder, FFMPEGRecorderOptions, MesioRecorderOptions, BililiveRecorderOptions } from "./IRecorder.js";
6
8
  /**
7
9
  * 录制器类型
8
10
  */
9
- export type RecorderType = "ffmpeg" | "mesio";
11
+ export type RecorderType = "ffmpeg" | "mesio" | "bililive";
12
+ export type FormatName = "flv" | "ts" | "fmp4";
10
13
  /**
11
14
  * 根据录制器类型获取对应的配置选项类型
12
15
  */
13
- export type RecorderOptions<T extends RecorderType> = T extends "ffmpeg" ? FFMPEGRecorderOptions : MesioRecorderOptions;
16
+ export type RecorderOptions<T extends RecorderType> = T extends "ffmpeg" ? FFMPEGRecorderOptions : T extends "mesio" ? MesioRecorderOptions : BililiveRecorderOptions;
14
17
  /**
15
18
  * 根据录制器类型获取对应的录制器实例类型
16
19
  */
17
- export type RecorderInstance<T extends RecorderType> = T extends "ffmpeg" ? FFMPEGRecorder : mesioRecorder;
20
+ export type RecorderInstance<T extends RecorderType> = T extends "ffmpeg" ? FFMPEGRecorder : T extends "mesio" ? MesioRecorder : BililiveRecorder;
21
+ type RecorderOpts = FFMPEGRecorderOptions | MesioRecorderOptions | BililiveRecorderOptions;
18
22
  /**
19
23
  * 创建录制器的工厂函数
20
24
  */
21
- export declare function createBaseRecorder<T extends RecorderType>(type: T, opts: RecorderOptions<T> & {
22
- mesioOptions?: string[];
25
+ export declare function createRecorder<T extends RecorderType>(type: T, opts: RecorderOptions<T> & {
26
+ onlyAudio?: boolean;
27
+ }, onEnd: (...args: unknown[]) => void, onUpdateLiveInfo: () => Promise<{
28
+ title?: string;
29
+ cover?: string;
30
+ }>): IRecorder;
31
+ /**
32
+ * 选择录制器
33
+ */
34
+ export declare function selectRecorder(preferredRecorder: "auto" | RecorderType | undefined): RecorderType;
35
+ /**
36
+ * 判断原始录制流格式,flv, ts, m4s
37
+ */
38
+ export declare function getSourceFormatName(streamUrl: string, formatName: FormatName | undefined): FormatName;
39
+ type PickPartial<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>> & Partial<Pick<T, K>>;
40
+ /**
41
+ * 创建录制器的工厂函数
42
+ */
43
+ export declare function createBaseRecorder(type: "auto" | RecorderType | undefined, opts: PickPartial<RecorderOpts, "formatName"> & {
44
+ onlyAudio?: boolean;
23
45
  }, onEnd: (...args: unknown[]) => void, onUpdateLiveInfo: () => Promise<{
24
46
  title?: string;
25
47
  cover?: string;
@@ -1,18 +1,78 @@
1
1
  import { FFMPEGRecorder } from "./FFMPEGRecorder.js";
2
- import { mesioRecorder } from "./mesioRecorder.js";
2
+ import { MesioRecorder } from "./mesioRecorder.js";
3
+ import { BililiveRecorder } from "./BililiveRecorder.js";
3
4
  export { FFMPEGRecorder } from "./FFMPEGRecorder.js";
4
- export { mesioRecorder } from "./mesioRecorder.js";
5
+ export { MesioRecorder } from "./mesioRecorder.js";
6
+ export { BililiveRecorder } from "./BililiveRecorder.js";
5
7
  /**
6
8
  * 创建录制器的工厂函数
7
9
  */
8
- export function createBaseRecorder(type, opts, onEnd, onUpdateLiveInfo) {
10
+ export function createRecorder(type, opts, onEnd, onUpdateLiveInfo) {
9
11
  if (type === "ffmpeg") {
10
12
  return new FFMPEGRecorder(opts, onEnd, onUpdateLiveInfo);
11
13
  }
12
14
  else if (type === "mesio") {
13
- return new mesioRecorder({ ...opts, inputOptions: opts.mesioOptions ?? [] }, onEnd, onUpdateLiveInfo);
15
+ return new MesioRecorder(opts, onEnd, onUpdateLiveInfo);
16
+ }
17
+ else if (type === "bililive") {
18
+ if (opts.formatName === "flv") {
19
+ // 录播姬引擎不支持只录音频
20
+ if (!opts.onlyAudio) {
21
+ return new BililiveRecorder(opts, onEnd, onUpdateLiveInfo);
22
+ }
23
+ }
24
+ return new FFMPEGRecorder(opts, onEnd, onUpdateLiveInfo);
14
25
  }
15
26
  else {
16
27
  throw new Error(`Unsupported recorder type: ${type}`);
17
28
  }
18
29
  }
30
+ /**
31
+ * 选择录制器
32
+ */
33
+ export function selectRecorder(preferredRecorder) {
34
+ let recorderType;
35
+ if (preferredRecorder === "auto") {
36
+ // 默认优先使用ffmpeg录制器
37
+ recorderType = "ffmpeg";
38
+ }
39
+ else if (preferredRecorder === "ffmpeg") {
40
+ recorderType = "ffmpeg";
41
+ }
42
+ else if (preferredRecorder === "mesio") {
43
+ recorderType = "mesio";
44
+ }
45
+ else if (preferredRecorder === "bililive") {
46
+ recorderType = "bililive";
47
+ }
48
+ else {
49
+ recorderType = "ffmpeg";
50
+ }
51
+ return recorderType;
52
+ }
53
+ /**
54
+ * 判断原始录制流格式,flv, ts, m4s
55
+ */
56
+ export function getSourceFormatName(streamUrl, formatName) {
57
+ if (formatName) {
58
+ return formatName;
59
+ }
60
+ if (streamUrl.includes(".m3u8")) {
61
+ return "ts";
62
+ }
63
+ else if (streamUrl.includes(".m4s")) {
64
+ // TODO: 使用b站的流进行测试
65
+ return "fmp4";
66
+ }
67
+ else {
68
+ return "flv";
69
+ }
70
+ }
71
+ /**
72
+ * 创建录制器的工厂函数
73
+ */
74
+ export function createBaseRecorder(type, opts, onEnd, onUpdateLiveInfo) {
75
+ const recorderType = selectRecorder(type);
76
+ const sourceFormatName = getSourceFormatName(opts.url, opts.formatName);
77
+ return createRecorder(recorderType, { ...opts, formatName: sourceFormatName }, onEnd, onUpdateLiveInfo);
78
+ }
@@ -15,9 +15,10 @@ declare class MesioCommand extends EventEmitter {
15
15
  kill(signal?: NodeJS.Signals): void;
16
16
  }
17
17
  export declare const createMesioBuilder: () => MesioCommand;
18
- export declare class mesioRecorder extends EventEmitter implements IRecorder {
18
+ export declare class MesioRecorder extends EventEmitter implements IRecorder {
19
19
  private onEnd;
20
20
  private onUpdateLiveInfo;
21
+ type: "mesio";
21
22
  private command;
22
23
  private streamManager;
23
24
  readonly hasSegment: boolean;
@@ -27,9 +28,9 @@ export declare class mesioRecorder extends EventEmitter implements IRecorder {
27
28
  }) => string;
28
29
  readonly segment: number;
29
30
  readonly inputOptions: string[];
30
- readonly isHls: boolean;
31
31
  readonly disableDanma: boolean;
32
32
  readonly url: string;
33
+ readonly debugLevel: "none" | "basic" | "verbose";
33
34
  readonly headers: {
34
35
  [key: string]: string | undefined;
35
36
  } | undefined;
@@ -84,18 +84,19 @@ class MesioCommand extends EventEmitter {
84
84
  export const createMesioBuilder = () => {
85
85
  return new MesioCommand();
86
86
  };
87
- export class mesioRecorder extends EventEmitter {
87
+ export class MesioRecorder extends EventEmitter {
88
88
  onEnd;
89
89
  onUpdateLiveInfo;
90
+ type = "mesio";
90
91
  command;
91
92
  streamManager;
92
93
  hasSegment;
93
94
  getSavePath;
94
95
  segment;
95
96
  inputOptions = [];
96
- isHls;
97
97
  disableDanma = false;
98
98
  url;
99
+ debugLevel = "none";
99
100
  headers;
100
101
  constructor(opts, onEnd, onUpdateLiveInfo) {
101
102
  super();
@@ -103,39 +104,32 @@ export class mesioRecorder extends EventEmitter {
103
104
  this.onUpdateLiveInfo = onUpdateLiveInfo;
104
105
  const hasSegment = true;
105
106
  this.disableDanma = opts.disableDanma ?? false;
107
+ this.debugLevel = opts.debugLevel ?? "none";
106
108
  let videoFormat = "flv";
107
109
  if (opts.url.includes(".m3u8")) {
108
110
  videoFormat = "ts";
109
111
  }
110
- if (opts.formatName) {
111
- if (opts.formatName === "fmp4") {
112
- videoFormat = "m4s";
113
- }
114
- else if (opts.formatName === "ts") {
115
- videoFormat = "ts";
116
- }
117
- else if (opts.formatName === "flv") {
118
- videoFormat = "flv";
119
- }
112
+ if (opts.formatName === "fmp4") {
113
+ videoFormat = "m4s";
114
+ }
115
+ else if (opts.formatName === "ts") {
116
+ videoFormat = "ts";
117
+ }
118
+ else if (opts.formatName === "flv") {
119
+ videoFormat = "flv";
120
120
  }
121
121
  this.streamManager = new StreamManager(opts.getSavePath, hasSegment, this.disableDanma, "mesio", videoFormat, {
122
122
  onUpdateLiveInfo: this.onUpdateLiveInfo,
123
123
  });
124
124
  this.hasSegment = hasSegment;
125
125
  this.getSavePath = opts.getSavePath;
126
- this.inputOptions = opts.inputOptions ?? [];
126
+ this.inputOptions = [];
127
127
  this.url = opts.url;
128
128
  this.segment = opts.segment;
129
129
  this.headers = opts.headers;
130
- if (opts.isHls === undefined) {
131
- this.isHls = this.url.includes("m3u8");
132
- }
133
- else {
134
- this.isHls = opts.isHls;
135
- }
136
130
  this.command = this.createCommand();
137
- this.streamManager.on("videoFileCreated", ({ filename, cover }) => {
138
- this.emit("videoFileCreated", { filename, cover });
131
+ this.streamManager.on("videoFileCreated", ({ filename, cover, rawFilename, title }) => {
132
+ this.emit("videoFileCreated", { filename, cover, rawFilename, title });
139
133
  });
140
134
  this.streamManager.on("videoFileCompleted", ({ filename }) => {
141
135
  this.emit("videoFileCompleted", { filename });
@@ -150,7 +144,11 @@ export class mesioRecorder extends EventEmitter {
150
144
  "--fix",
151
145
  "-H",
152
146
  "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36",
147
+ "--no-proxy",
153
148
  ];
149
+ if (this.debugLevel === "verbose") {
150
+ inputOptions.push("-v");
151
+ }
154
152
  if (this.headers) {
155
153
  Object.entries(this.headers).forEach(([key, value]) => {
156
154
  if (!value)
@@ -168,8 +166,8 @@ export class mesioRecorder extends EventEmitter {
168
166
  .on("error", this.onEnd)
169
167
  .on("end", () => this.onEnd("finished"))
170
168
  .on("stderr", async (stderrLine) => {
171
- await this.streamManager.handleVideoStarted(stderrLine);
172
169
  this.emit("DebugLog", { type: "ffmpeg", text: stderrLine });
170
+ await this.streamManager.handleVideoStarted(stderrLine);
173
171
  });
174
172
  return command;
175
173
  }
@@ -1,12 +1,12 @@
1
1
  import EventEmitter from "node:events";
2
2
  import { createRecordExtraDataController } from "../xml_stream_controller.js";
3
3
  import type { RecorderCreateOpts } from "../recorder.js";
4
+ import type { VideoFormat } from "../index.js";
4
5
  export type GetSavePath = (data: {
5
6
  startTime: number;
6
7
  title?: string;
7
8
  }) => string;
8
9
  type RecorderType = Exclude<RecorderCreateOpts["recorderType"], undefined | "auto">;
9
- type VideoFormat = "auto" | "ts" | "mkv" | "flv" | "mp4" | "m4s";
10
10
  export declare class Segment extends EventEmitter {
11
11
  extraDataController: ReturnType<typeof createRecordExtraDataController> | null;
12
12
  init: boolean;
@@ -1,7 +1,7 @@
1
1
  import EventEmitter from "node:events";
2
2
  import fs from "fs/promises";
3
3
  import { createRecordExtraDataController } from "../xml_stream_controller.js";
4
- import { replaceExtName, ensureFolderExist, isFfmpegStartSegment, isMesioStartSegment, isFfmpegStart, retry, cleanTerminalText, } from "../utils.js";
4
+ import { replaceExtName, ensureFolderExist, isFfmpegStartSegment, isMesioStartSegment, isBililiveStartSegment, isFfmpegStart, retry, cleanTerminalText, } from "../utils.js";
5
5
  export class Segment extends EventEmitter {
6
6
  extraDataController = null;
7
7
  init = true;
@@ -27,8 +27,12 @@ export class Segment extends EventEmitter {
27
27
  return;
28
28
  }
29
29
  try {
30
+ this.emit("DebugLog", {
31
+ type: "info",
32
+ text: `Renaming segment file: ${this.rawRecordingVideoPath} -> ${this.outputFilePath}`,
33
+ });
30
34
  await Promise.all([
31
- retry(() => fs.rename(this.rawRecordingVideoPath, this.outputFilePath), 10, 2000),
35
+ retry(() => fs.rename(this.rawRecordingVideoPath, this.outputFilePath), 20, 1000),
32
36
  this.extraDataController?.flush(),
33
37
  ]);
34
38
  this.emit("videoFileCompleted", { filename: this.outputFilePath });
@@ -38,6 +42,8 @@ export class Segment extends EventEmitter {
38
42
  type: "error",
39
43
  text: "videoFileCompleted error " + String(err),
40
44
  });
45
+ // 虽然重命名失败了,但是也当作完成处理,避免卡住录制流程
46
+ this.emit("videoFileCompleted", { filename: this.outputFilePath });
41
47
  }
42
48
  }
43
49
  async onSegmentStart(stderrLine, callBack) {
@@ -75,14 +81,17 @@ export class Segment extends EventEmitter {
75
81
  if (!match) {
76
82
  match = cleanTerminalText(stderrLine).match(mesioRegex);
77
83
  }
84
+ this.emit("DebugLog", { type: "ffmpeg", text: `Segment start line: ${stderrLine}` });
78
85
  if (match) {
79
86
  const filename = match[1];
80
87
  this.rawRecordingVideoPath = filename;
81
88
  this.emit("videoFileCreated", {
89
+ rawFilename: filename,
82
90
  filename: this.outputFilePath,
83
91
  title: liveInfo?.title,
84
92
  cover: liveInfo?.cover,
85
93
  });
94
+ this.emit("DebugLog", { type: "ffmpeg", text: JSON.stringify(match, null, 2) });
86
95
  }
87
96
  else {
88
97
  this.emit("DebugLog", { type: "ffmpeg", text: "No match found" });
@@ -147,6 +156,15 @@ export class StreamManager extends EventEmitter {
147
156
  }
148
157
  else if (this.recorderType === "mesio") {
149
158
  if (this.segment && isMesioStartSegment(stderrLine)) {
159
+ for (let line of stderrLine.split("\n")) {
160
+ if (isMesioStartSegment(line)) {
161
+ await this.segment.onSegmentStart(line, this.callBack);
162
+ }
163
+ }
164
+ }
165
+ }
166
+ else if (this.recorderType === "bililive") {
167
+ if (this.segment && isBililiveStartSegment(stderrLine)) {
150
168
  await this.segment.onSegmentStart(stderrLine, this.callBack);
151
169
  }
152
170
  }
@@ -168,6 +186,11 @@ export class StreamManager extends EventEmitter {
168
186
  await this.segment.handleSegmentEnd();
169
187
  }
170
188
  }
189
+ else if (this.recorderType === "bililive") {
190
+ if (this.segment) {
191
+ await this.segment.handleSegmentEnd();
192
+ }
193
+ }
171
194
  }
172
195
  getExtraDataController() {
173
196
  return this.segment?.extraDataController || this.extraDataController;
@@ -179,6 +202,9 @@ export class StreamManager extends EventEmitter {
179
202
  else if (this.recorderType === "mesio") {
180
203
  return this.videoFormat;
181
204
  }
205
+ else if (this.recorderType === "bililive") {
206
+ return "flv";
207
+ }
182
208
  else {
183
209
  throw new Error("Unknown recorderType");
184
210
  }
@@ -192,6 +218,9 @@ export class StreamManager extends EventEmitter {
192
218
  else if (this.recorderType === "mesio") {
193
219
  return `${this.recordSavePath}-PART%i.${this.videoExt}`;
194
220
  }
221
+ else if (this.recorderType === "bililive") {
222
+ return `${this.recordSavePath}.${this.videoExt}`;
223
+ }
195
224
  return `${this.recordSavePath}.${this.videoExt}`;
196
225
  }
197
226
  }
package/lib/recorder.d.ts CHANGED
@@ -3,6 +3,7 @@ import { ChannelId, Message, Quality } from "./common.js";
3
3
  import { RecorderProvider } from "./manager.js";
4
4
  import { AnyObject, PickRequired, UnknownObject } from "./utils.js";
5
5
  import { Cache } from "./cache.js";
6
+ import type { RecorderType } from "./recorder/index.js";
6
7
  type FormatName = "auto" | "flv" | "hls" | "fmp4" | "flv_only" | "hls_only" | "fmp4_only";
7
8
  type CodecName = "auto" | "avc" | "hevc" | "avc_only" | "hevc_only";
8
9
  export interface RecorderCreateOpts<E extends AnyObject = UnknownObject> {
@@ -44,9 +45,9 @@ export interface RecorderCreateOpts<E extends AnyObject = UnknownObject> {
44
45
  /** 标题关键词,如果直播间标题包含这些关键词,则不会自动录制(仅对斗鱼有效),多个关键词用英文逗号分隔 */
45
46
  titleKeywords?: string;
46
47
  /** 用于指定录制文件格式,auto时,分段使用ts,不分段使用mp4 */
47
- videoFormat?: "auto" | "ts" | "mkv";
48
+ videoFormat?: "auto" | "ts" | "mkv" | "flv";
48
49
  /** 录制类型 */
49
- recorderType?: "auto" | "ffmpeg" | "mesio";
50
+ recorderType?: "auto" | "ffmpeg" | "mesio" | "bililive";
50
51
  /** 流格式优先级 */
51
52
  formatriorities?: Array<"flv" | "hls">;
52
53
  /** 只录制音频 */
@@ -56,10 +57,14 @@ export interface RecorderCreateOpts<E extends AnyObject = UnknownObject> {
56
57
  /** 控制弹幕是否使用服务端时间戳 */
57
58
  useServerTimestamp?: boolean;
58
59
  extra?: Partial<E>;
60
+ /** 调试等级 */
61
+ debugLevel?: "none" | "basic" | "verbose";
62
+ /** 缓存 */
59
63
  cache: Cache;
60
64
  }
61
65
  export type SerializedRecorder<E extends AnyObject> = PickRequired<RecorderCreateOpts<E>, "id"> & Pick<Recorder<E>, "id" | "channelId" | "remarks" | "disableAutoCheck" | "quality" | "streamPriorities" | "sourcePriorities" | "extra" | "segment" | "saveSCDanma" | "saveCover" | "saveGiftDanma" | "disableProvideCommentsWhenRecording" | "liveInfo" | "uid" | "titleKeywords">;
62
- export type RecorderState = "idle" | "recording" | "stopping-record" | "check-error";
66
+ /** 录制状态,idle: 空闲中,recording: 录制中,stopping-record: 停止录制中,check-error: 检查错误,title-blocked: 标题黑名单 */
67
+ export type RecorderState = "idle" | "recording" | "stopping-record" | "check-error" | "title-blocked";
63
68
  export type Progress = {
64
69
  time: string | null;
65
70
  };
@@ -67,6 +72,7 @@ export interface RecordHandle {
67
72
  id: string;
68
73
  stream: string;
69
74
  source: string;
75
+ recorderType?: RecorderType;
70
76
  url: string;
71
77
  ffmpegArgs?: string[];
72
78
  progress?: Progress;
@@ -81,7 +87,9 @@ export interface DebugLog {
81
87
  export type GetSavePath = (data: {
82
88
  owner: string;
83
89
  title: string;
84
- startTime?: number;
90
+ startTime: number;
91
+ liveStartTime: Date;
92
+ recordStartTime: Date;
85
93
  }) => string;
86
94
  export interface Recorder<E extends AnyObject = UnknownObject> extends Emitter<{
87
95
  RecordStart: RecordHandle;
@@ -89,6 +97,7 @@ export interface Recorder<E extends AnyObject = UnknownObject> extends Emitter<{
89
97
  videoFileCreated: {
90
98
  filename: string;
91
99
  cover?: string;
100
+ rawFilename?: string;
92
101
  };
93
102
  videoFileCompleted: {
94
103
  filename: string;
@@ -116,7 +125,7 @@ export interface Recorder<E extends AnyObject = UnknownObject> extends Emitter<{
116
125
  living: boolean;
117
126
  owner: string;
118
127
  title: string;
119
- startTime?: Date;
128
+ startTime: Date;
120
129
  avatar: string;
121
130
  cover: string;
122
131
  liveId?: string;
package/lib/utils.d.ts CHANGED
@@ -34,9 +34,10 @@ export declare function assertStringType(data: unknown, msg?: string): asserts d
34
34
  export declare function assertNumberType(data: unknown, msg?: string): asserts data is number;
35
35
  export declare function assertObjectType(data: unknown, msg?: string): asserts data is object;
36
36
  export declare function formatDate(date: Date, format: string): string;
37
- export declare function removeSystemReservedChars(filename: string): string;
37
+ export declare function removeSystemReservedChars(str: string): string;
38
38
  export declare function isFfmpegStartSegment(line: string): boolean;
39
39
  export declare function isMesioStartSegment(line: string): boolean;
40
+ export declare function isBililiveStartSegment(line: string): boolean;
40
41
  export declare function isFfmpegStart(line: string): boolean;
41
42
  export declare function cleanTerminalText(text: string): string;
42
43
  export declare const formatTemplate: (string: string, ...args: any[]) => string;
@@ -72,6 +73,15 @@ export declare function sortByKeyOrder<T, K extends keyof T>(objects: T[], order
72
73
  */
73
74
  export declare function retry<T>(fn: () => Promise<T>, retries?: number, delay?: number): Promise<T>;
74
75
  export declare const isBetweenTimeRange: (range: undefined | [] | [string | null, string | null]) => boolean;
76
+ export declare const sleep: (ms: number) => Promise<unknown>;
77
+ /**
78
+ * 检查标题是否包含黑名单关键词
79
+ */
80
+ declare function hasBlockedTitleKeywords(title: string, titleKeywords: string | undefined): boolean;
81
+ /**
82
+ * 检查是否需要进行标题关键词检查
83
+ */
84
+ declare function shouldCheckTitleKeywords(isManualStart: boolean | undefined, titleKeywords: string | undefined): boolean;
75
85
  declare const _default: {
76
86
  replaceExtName: typeof replaceExtName;
77
87
  singleton: typeof singleton;
@@ -91,5 +101,8 @@ declare const _default: {
91
101
  sortByKeyOrder: typeof sortByKeyOrder;
92
102
  retry: typeof retry;
93
103
  isBetweenTimeRange: (range: undefined | [] | [string | null, string | null]) => boolean;
104
+ hasBlockedTitleKeywords: typeof hasBlockedTitleKeywords;
105
+ shouldCheckTitleKeywords: typeof shouldCheckTitleKeywords;
106
+ sleep: (ms: number) => Promise<unknown>;
94
107
  };
95
108
  export default _default;
package/lib/utils.js CHANGED
@@ -120,14 +120,17 @@ export function formatDate(date, format) {
120
120
  };
121
121
  return format.replace(/yyyy|MM|dd|HH|mm|ss/g, (matched) => map[matched]);
122
122
  }
123
- export function removeSystemReservedChars(filename) {
124
- return filenamify(filename, { replacement: "_" });
123
+ export function removeSystemReservedChars(str) {
124
+ return filenamify(str, { replacement: "_" });
125
125
  }
126
126
  export function isFfmpegStartSegment(line) {
127
127
  return line.includes("Opening ") && line.includes("for writing");
128
128
  }
129
129
  export function isMesioStartSegment(line) {
130
- return line.includes("Opening ") && line.includes("Opening segment");
130
+ return line.includes("Opening segment");
131
+ }
132
+ export function isBililiveStartSegment(line) {
133
+ return line.includes("创建录制文件");
131
134
  }
132
135
  export function isFfmpegStart(line) {
133
136
  return ((line.includes("frame=") && line.includes("fps=")) ||
@@ -323,6 +326,23 @@ function isBetweenTime(currentTime, timeRange) {
323
326
  }
324
327
  return start <= current && current <= end;
325
328
  }
329
+ export const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
330
+ /**
331
+ * 检查标题是否包含黑名单关键词
332
+ */
333
+ function hasBlockedTitleKeywords(title, titleKeywords) {
334
+ const keywords = (titleKeywords ?? "")
335
+ .split(",")
336
+ .map((k) => k.trim())
337
+ .filter((k) => k);
338
+ return keywords.some((keyword) => title.toLowerCase().includes(keyword.toLowerCase()));
339
+ }
340
+ /**
341
+ * 检查是否需要进行标题关键词检查
342
+ */
343
+ function shouldCheckTitleKeywords(isManualStart, titleKeywords) {
344
+ return (!isManualStart && !!titleKeywords && typeof titleKeywords === "string" && !!titleKeywords.trim());
345
+ }
326
346
  export default {
327
347
  replaceExtName,
328
348
  singleton,
@@ -342,4 +362,7 @@ export default {
342
362
  sortByKeyOrder,
343
363
  retry,
344
364
  isBetweenTimeRange,
365
+ hasBlockedTitleKeywords,
366
+ shouldCheckTitleKeywords,
367
+ sleep,
345
368
  };
@@ -17,7 +17,7 @@ export interface XmlStreamController {
17
17
  /** 设计上来说,外部程序不应该能直接修改 data 上的东西 */
18
18
  readonly data: XmlStreamData;
19
19
  addMessage: (message: Message) => void;
20
- setMeta: (meta: Partial<XmlStreamData["meta"]>) => void;
20
+ setMeta: (meta: Partial<XmlStreamData["meta"]>) => Promise<void>;
21
21
  flush: () => Promise<void>;
22
22
  }
23
23
  export declare function createRecordExtraDataController(savePath: string): XmlStreamController;