@bililive-tools/douyin-recorder 1.16.1 → 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.
- package/lib/index.js +19 -10
- package/package.json +3 -3
package/lib/index.js
CHANGED
|
@@ -20,6 +20,7 @@ function createRecorder(opts) {
|
|
|
20
20
|
useServerTimestamp: opts.useServerTimestamp ?? true,
|
|
21
21
|
state: "idle",
|
|
22
22
|
cache: null,
|
|
23
|
+
appendTimeline: null,
|
|
23
24
|
getChannelURL() {
|
|
24
25
|
return `https://live.douyin.com/${this.channelId}`;
|
|
25
26
|
},
|
|
@@ -83,10 +84,13 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, banLiveId, isMan
|
|
|
83
84
|
uid: this.uid,
|
|
84
85
|
});
|
|
85
86
|
this.liveInfo = liveInfo;
|
|
86
|
-
this.state
|
|
87
|
+
this.emit("stateChange", { state: "idle" });
|
|
87
88
|
}
|
|
88
89
|
catch (error) {
|
|
89
|
-
this.
|
|
90
|
+
this.emit("stateChange", {
|
|
91
|
+
state: "check-error",
|
|
92
|
+
msg: `检查失败,` + (error instanceof Error ? error.message : String(error)),
|
|
93
|
+
});
|
|
90
94
|
throw error;
|
|
91
95
|
}
|
|
92
96
|
if (this.liveInfo.liveId && this.liveInfo.liveId === banLiveId) {
|
|
@@ -106,7 +110,6 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, banLiveId, isMan
|
|
|
106
110
|
const strictQuality = utils.shouldUseStrictQuality(qualityRetryLeft, this.qualityRetry, isManualStart);
|
|
107
111
|
let res;
|
|
108
112
|
try {
|
|
109
|
-
// TODO: 检查mobile接口处理双屏录播流
|
|
110
113
|
res = await getStream({
|
|
111
114
|
channelId: this.channelId,
|
|
112
115
|
quality: this.quality,
|
|
@@ -131,11 +134,14 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, banLiveId, isMan
|
|
|
131
134
|
catch (err) {
|
|
132
135
|
if (qualityRetryLeft > 0)
|
|
133
136
|
await this.cache.set("qualityRetryLeft", qualityRetryLeft - 1);
|
|
134
|
-
this.
|
|
137
|
+
this.emit("stateChange", {
|
|
138
|
+
state: "check-error",
|
|
139
|
+
msg: `检查失败,` + (err instanceof Error ? err.message : String(err)),
|
|
140
|
+
});
|
|
135
141
|
throw err;
|
|
136
142
|
}
|
|
137
143
|
const { owner, title, liveStartTime, recordStartTime } = this.liveInfo;
|
|
138
|
-
this.state
|
|
144
|
+
this.emit("stateChange", { state: "recording" });
|
|
139
145
|
const { currentStream: stream, sources: availableSources, streams: availableStreams } = res;
|
|
140
146
|
this.availableStreams = availableStreams.map((s) => s.desc);
|
|
141
147
|
this.availableSources = availableSources.map((s) => s.name);
|
|
@@ -173,6 +179,7 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, banLiveId, isMan
|
|
|
173
179
|
headers: {
|
|
174
180
|
Cookie: this.auth,
|
|
175
181
|
},
|
|
182
|
+
proxy: this.proxy,
|
|
176
183
|
}, onEnd, async () => {
|
|
177
184
|
const info = await getInfo(this.channelId, {
|
|
178
185
|
auth: this.auth,
|
|
@@ -324,24 +331,26 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, banLiveId, isMan
|
|
|
324
331
|
giftMessageCache.set(groupId, { gift, timer });
|
|
325
332
|
});
|
|
326
333
|
client.on("reconnect", (attempts) => {
|
|
334
|
+
this.appendTimeline({ text: `弹幕连接断开,正在重试: ${attempts}` });
|
|
327
335
|
this.emit("DebugLog", {
|
|
328
336
|
type: "common",
|
|
329
|
-
text: `douyin ${this.channelId}
|
|
337
|
+
text: `douyin ${this.channelId} danma has reconnect ${attempts}`,
|
|
330
338
|
});
|
|
331
339
|
});
|
|
332
340
|
client.on("error", (err) => {
|
|
333
341
|
this.emit("DebugLog", {
|
|
334
342
|
type: "common",
|
|
335
|
-
text: `douyin ${this.channelId}
|
|
343
|
+
text: `douyin ${this.channelId} danma error: ${String(err)}`,
|
|
336
344
|
});
|
|
337
345
|
});
|
|
338
346
|
client.on("init", (url) => {
|
|
339
347
|
this.emit("DebugLog", {
|
|
340
348
|
type: "common",
|
|
341
|
-
text: `douyin ${this.channelId}
|
|
349
|
+
text: `douyin ${this.channelId} danma init ${url}`,
|
|
342
350
|
});
|
|
343
351
|
});
|
|
344
352
|
client.on("open", () => {
|
|
353
|
+
this.appendTimeline({ text: `弹幕连接已建立` });
|
|
345
354
|
this.emit("DebugLog", {
|
|
346
355
|
type: "common",
|
|
347
356
|
text: `douyin ${this.channelId} danma open`,
|
|
@@ -378,7 +387,7 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, banLiveId, isMan
|
|
|
378
387
|
const stop = singleton(async (reason) => {
|
|
379
388
|
if (!this.recordHandle)
|
|
380
389
|
return;
|
|
381
|
-
this.state
|
|
390
|
+
this.emit("stateChange", { state: "stopping-record" });
|
|
382
391
|
try {
|
|
383
392
|
// 清理所有礼物缓存定时器
|
|
384
393
|
for (const [_groupId, cached] of giftMessageCache.entries()) {
|
|
@@ -405,7 +414,7 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, banLiveId, isMan
|
|
|
405
414
|
this.emit("RecordStop", { recordHandle: this.recordHandle, reason });
|
|
406
415
|
this.recordHandle = undefined;
|
|
407
416
|
this.liveInfo = undefined;
|
|
408
|
-
this.state
|
|
417
|
+
this.emit("stateChange", { state: "idle" });
|
|
409
418
|
this.cache.set("qualityRetryLeft", this.qualityRetry);
|
|
410
419
|
});
|
|
411
420
|
this.recordHandle = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bililive-tools/douyin-recorder",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.17.0",
|
|
4
4
|
"description": "@bililive-tools douyin recorder implemention",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"lodash-es": "^4.17.21",
|
|
39
39
|
"mitt": "^3.0.1",
|
|
40
40
|
"sm-crypto": "^0.3.13",
|
|
41
|
-
"
|
|
42
|
-
"
|
|
41
|
+
"@bililive-tools/manager": "^1.17.0",
|
|
42
|
+
"douyin-danma-listener": "0.4.1"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@types/node": "*"
|