@bililive-tools/douyu-recorder 1.6.0 → 1.7.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.
@@ -18,6 +18,7 @@ export class BufferCoder {
18
18
  if (littleEndian == null) {
19
19
  littleEndian = this.littleEndian;
20
20
  }
21
+ // @ts-ignore
21
22
  this.buffer = this.concat(this.buffer, newBuffer).buffer;
22
23
  while (this.buffer && this.buffer.byteLength > 0) {
23
24
  if (this.readLength === 0) {
@@ -38,6 +39,7 @@ export class BufferCoder {
38
39
  if (littleEndian == null) {
39
40
  littleEndian = this.littleEndian;
40
41
  }
42
+ // @ts-ignore
41
43
  const out = this.concat(this.encoder.encode(msg), Uint8Array.of(0));
42
44
  const formatBodySize = 8 + out.length;
43
45
  const dv = new DataView(new ArrayBuffer(formatBodySize + 4));
package/lib/index.js CHANGED
@@ -106,10 +106,17 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, banLiveId, isMan
106
106
  return this.recordHandle;
107
107
  }
108
108
  // 获取直播间信息
109
- const liveInfo = await getInfo(this.channelId);
110
- const { living, owner, title } = liveInfo;
111
- this.liveInfo = liveInfo;
112
- if (liveInfo.liveId === banLiveId) {
109
+ try {
110
+ const liveInfo = await getInfo(this.channelId);
111
+ this.liveInfo = liveInfo;
112
+ this.state = "idle";
113
+ }
114
+ catch (error) {
115
+ this.state = "check-error";
116
+ throw error;
117
+ }
118
+ const { living, owner, title } = this.liveInfo;
119
+ if (this.liveInfo.liveId === banLiveId) {
113
120
  this.tempStopIntervalCheck = true;
114
121
  }
115
122
  else {
@@ -151,7 +158,6 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, banLiveId, isMan
151
158
  if (isManualStart) {
152
159
  strictQuality = false;
153
160
  }
154
- // TODO: 还需要测试仅音频流的情况,mesio可能并不支持
155
161
  res = await getStream({
156
162
  channelId: this.channelId,
157
163
  quality: this.quality,
@@ -164,7 +170,7 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, banLiveId, isMan
164
170
  catch (err) {
165
171
  if (this.qualityRetry > 0)
166
172
  this.qualityRetry -= 1;
167
- this.state = "idle";
173
+ this.state = "check-error";
168
174
  throw err;
169
175
  }
170
176
  this.state = "recording";
@@ -225,7 +231,7 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, banLiveId, isMan
225
231
  extraDataController?.setMeta({
226
232
  room_id: this.channelId,
227
233
  platform: provider?.id,
228
- liveStartTimestamp: liveInfo.startTime?.getTime(),
234
+ liveStartTimestamp: this?.liveInfo?.startTime?.getTime(),
229
235
  // recordStopTimestamp: Date.now(),
230
236
  title: title,
231
237
  user_name: owner,
@@ -453,11 +459,18 @@ export const provider = {
453
459
  roomId = matched[1].trim();
454
460
  }
455
461
  else {
456
- // 解析<link rel="canonical" href="xxxxxxx"/>中的href
457
- const canonicalLink = html.match(/<link rel="canonical" href="(.*?)"/);
458
- if (canonicalLink) {
459
- const url = canonicalLink[1];
460
- roomId = url.split("/").pop();
462
+ // 解析出query中的rid参数
463
+ const rid = new URL(channelURL).searchParams.get("rid");
464
+ if (rid) {
465
+ roomId = rid;
466
+ }
467
+ else {
468
+ // 解析<link rel="canonical" href="xxxxxxx"/>中的href
469
+ const canonicalLink = html.match(/<link rel="canonical" href="(.*?)"/);
470
+ if (canonicalLink) {
471
+ const url = canonicalLink[1];
472
+ roomId = url.split("/").pop();
473
+ }
461
474
  }
462
475
  }
463
476
  if (!roomId)
package/lib/stream.js CHANGED
@@ -46,6 +46,7 @@ export async function getStream(opts) {
46
46
  const qn = (DouyuQualities.includes(opts.quality) ? opts.quality : 0);
47
47
  let cdn = opts.source === "auto" ? undefined : opts.source;
48
48
  if (opts.source === "auto" && opts.avoidEdgeCDN) {
49
+ // TODO: 如果不存在 cdn=hw-h5 的源,那么还是可能默认到边缘节点,就先这样吧
49
50
  cdn = "hw-h5";
50
51
  }
51
52
  let liveInfo = await getLiveInfo({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bililive-tools/douyu-recorder",
3
- "version": "1.6.0",
3
+ "version": "1.7.1",
4
4
  "description": "bililive-tools douyu recorder implemention",
5
5
  "main": "./lib/index.js",
6
6
  "type": "module",
@@ -41,7 +41,7 @@
41
41
  "lodash-es": "^4.17.21",
42
42
  "axios": "^1.7.8",
43
43
  "douyu-api": "^0.1.0",
44
- "@bililive-tools/manager": "^1.6.0"
44
+ "@bililive-tools/manager": "^1.6.1"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@types/ws": "^8.5.13"