@bililive-tools/huya-recorder 1.15.0 → 1.17.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.
Files changed (2) hide show
  1. package/lib/index.js +22 -24
  2. 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 } from "./stream.js";
5
- import { ensureFolderExist } from "./utils.js";
6
5
  import HuYaDanMu from "huya-danma-listener";
7
6
  function createRecorder(opts) {
8
7
  // 内部实现时,应该只有 proxy 包裹的那一层会使用这个 recorder 标识符,不应该有直接通过
@@ -14,6 +13,7 @@ function createRecorder(opts) {
14
13
  ...mitt(),
15
14
  ...opts,
16
15
  cache: null,
16
+ appendTimeline: null,
17
17
  availableStreams: [],
18
18
  availableSources: [],
19
19
  qualityRetry: opts.qualityRetry ?? 0,
@@ -72,10 +72,13 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, banLiveId, isMan
72
72
  try {
73
73
  const liveInfo = await getInfo(this.channelId);
74
74
  this.liveInfo = liveInfo;
75
- this.state = "idle";
75
+ this.emit("stateChange", { state: "idle" });
76
76
  }
77
77
  catch (error) {
78
- this.state = "check-error";
78
+ this.emit("stateChange", {
79
+ state: "check-error",
80
+ msg: `检查失败,` + (error instanceof Error ? error.message : String(error)),
81
+ });
79
82
  throw error;
80
83
  }
81
84
  const { living, owner, title, liveStartTime, recordStartTime } = this.liveInfo;
@@ -109,10 +112,13 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, banLiveId, isMan
109
112
  catch (err) {
110
113
  if (qualityRetryLeft > 0)
111
114
  await this.cache.set("qualityRetryLeft", qualityRetryLeft - 1);
112
- this.state = "check-error";
115
+ this.emit("stateChange", {
116
+ state: "check-error",
117
+ msg: `检查失败,` + (err instanceof Error ? err.message : String(err)),
118
+ });
113
119
  throw err;
114
120
  }
115
- this.state = "recording";
121
+ this.emit("stateChange", { state: "recording" });
116
122
  const { currentStream: stream, sources: availableSources, streams: availableStreams } = res;
117
123
  this.availableStreams = availableStreams.map((s) => s.desc);
118
124
  this.availableSources = availableSources.map((s) => s.name);
@@ -146,6 +152,7 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, banLiveId, isMan
146
152
  startTime: opts.startTime,
147
153
  liveStartTime,
148
154
  recordStartTime,
155
+ extraMs: opts.extraMs,
149
156
  }),
150
157
  disableDanma: this.disableProvideCommentsWhenRecording,
151
158
  videoFormat: this.videoFormat ?? "auto",
@@ -153,24 +160,11 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, banLiveId, isMan
153
160
  headers: {
154
161
  "User-Agent": stream.ua,
155
162
  },
163
+ proxy: this.proxy,
156
164
  }, onEnd, async () => {
157
165
  const info = await getInfo(this.channelId);
158
166
  return info;
159
167
  });
160
- const savePath = getSavePath({
161
- owner,
162
- title,
163
- startTime: Date.now(),
164
- liveStartTime,
165
- recordStartTime,
166
- });
167
- try {
168
- ensureFolderExist(savePath);
169
- }
170
- catch (err) {
171
- this.state = "idle";
172
- throw err;
173
- }
174
168
  const handleVideoCreated = async ({ filename, title, cover, rawFilename }) => {
175
169
  this.emit("videoFileCreated", { filename, cover, rawFilename });
176
170
  if (title && this?.liveInfo) {
@@ -190,8 +184,8 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, banLiveId, isMan
190
184
  });
191
185
  };
192
186
  downloader.on("videoFileCreated", handleVideoCreated);
193
- downloader.on("videoFileCompleted", ({ filename }) => {
194
- this.emit("videoFileCompleted", { filename });
187
+ downloader.on("videoFileCompleted", (data) => {
188
+ this.emit("videoFileCompleted", data);
195
189
  });
196
190
  downloader.on("DebugLog", (data) => {
197
191
  this.emit("DebugLog", data);
@@ -255,7 +249,11 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, banLiveId, isMan
255
249
  client.on("error", (e) => {
256
250
  this.emit("DebugLog", { type: "common", text: String(e) });
257
251
  });
252
+ client.on("connect", () => {
253
+ this.appendTimeline({ text: `弹幕连接已建立` });
254
+ });
258
255
  client.on("retry", (e) => {
256
+ this.appendTimeline({ text: `弹幕连接断开,正在重试: ${e.count}/${e.max}` });
259
257
  this.emit("DebugLog", {
260
258
  type: "common",
261
259
  text: `${this?.liveInfo?.owner}:${this.channelId} huya danmu retry: ${e.count}/${e.max}`,
@@ -273,7 +271,7 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, banLiveId, isMan
273
271
  const stop = utils.singleton(async (reason) => {
274
272
  if (!this.recordHandle)
275
273
  return;
276
- this.state = "stopping-record";
274
+ this.emit("stateChange", { state: "stopping-record" });
277
275
  try {
278
276
  client?.stop();
279
277
  await downloader.stop();
@@ -289,7 +287,7 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, banLiveId, isMan
289
287
  this.emit("RecordStop", { recordHandle: this.recordHandle, reason });
290
288
  this.recordHandle = undefined;
291
289
  this.liveInfo = undefined;
292
- this.state = "idle";
290
+ this.emit("stateChange", { state: "idle" });
293
291
  this.cache.set("qualityRetryLeft", this.qualityRetry);
294
292
  });
295
293
  this.recordHandle = {
@@ -299,7 +297,7 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, banLiveId, isMan
299
297
  recorderType: downloader.type,
300
298
  url: stream.url,
301
299
  downloaderArgs,
302
- savePath: savePath,
300
+ savePath: downloader.videoFilePath,
303
301
  stop,
304
302
  cut,
305
303
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bililive-tools/huya-recorder",
3
- "version": "1.15.0",
3
+ "version": "1.17.0",
4
4
  "description": "bililive-tools huya recorder implemention",
5
5
  "main": "./lib/index.js",
6
6
  "type": "module",
@@ -38,7 +38,7 @@
38
38
  "axios": "^1.15.0",
39
39
  "lodash-es": "^4.17.21",
40
40
  "mitt": "^3.0.1",
41
- "@bililive-tools/manager": "^1.14.1",
41
+ "@bililive-tools/manager": "^1.17.0",
42
42
  "huya-danma-listener": "0.1.4"
43
43
  },
44
44
  "scripts": {