@bililive-tools/douyin-recorder 1.17.3 → 1.18.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 CHANGED
@@ -18,6 +18,7 @@ function createRecorder(opts) {
18
18
  availableSources: [],
19
19
  qualityRetry: opts.qualityRetry ?? 0,
20
20
  useServerTimestamp: opts.useServerTimestamp ?? true,
21
+ cookieMode: opts.cookieMode ?? "all",
21
22
  state: "idle",
22
23
  cache: null,
23
24
  appendTimeline: null,
@@ -31,7 +32,7 @@ function createRecorder(opts) {
31
32
  async getLiveInfo() {
32
33
  const channelId = this.channelId;
33
34
  const info = await getInfo(channelId, {
34
- auth: this.auth,
35
+ auth: this.cookieMode === "danma" ? undefined : this.auth,
35
36
  uid: this.uid,
36
37
  });
37
38
  return {
@@ -46,7 +47,7 @@ function createRecorder(opts) {
46
47
  streamPriorities: this.streamPriorities,
47
48
  sourcePriorities: this.sourcePriorities,
48
49
  strictQuality: false,
49
- auth: this.auth,
50
+ auth: this.cookieMode === "danma" ? undefined : this.auth,
50
51
  formatPriorities: this.formatPriorities,
51
52
  doubleScreen: this.doubleScreen,
52
53
  api: this.api,
@@ -68,11 +69,11 @@ function createRecorder(opts) {
68
69
  }
69
70
  const ffmpegOutputOptions = [];
70
71
  const ffmpegInputOptions = ["-rw_timeout", "10000000", "-timeout", "10000000"];
71
- const checkLiveStatusAndRecord = async function ({ getSavePath, banLiveId, isManualStart, }) {
72
+ const checkLiveStatusAndRecord = async function ({ getSavePath, banLiveId, isManualStart, streamRetryHint, }) {
72
73
  // 如果已经在录制中,只在需要检查标题关键词时才获取最新信息
73
74
  if (this.recordHandle != null) {
74
75
  const shouldStop = await utils.checkTitleKeywordsWhileRecording(this, isManualStart, (channelId) => getInfo(channelId, {
75
- auth: this.auth,
76
+ auth: this.cookieMode === "danma" ? undefined : this.auth,
76
77
  api: this.api,
77
78
  uid: this.uid,
78
79
  }));
@@ -86,7 +87,7 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, banLiveId, isMan
86
87
  let isLiveRadio = false;
87
88
  try {
88
89
  const liveInfo = await getInfo(this.channelId, {
89
- auth: this.auth,
90
+ auth: this.cookieMode === "danma" ? undefined : this.auth,
90
91
  api: this.api,
91
92
  uid: this.uid,
92
93
  });
@@ -124,12 +125,14 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, banLiveId, isMan
124
125
  streamPriorities: this.streamPriorities,
125
126
  sourcePriorities: this.sourcePriorities,
126
127
  strictQuality: strictQuality,
127
- auth: this.auth,
128
+ auth: this.cookieMode === "danma" ? undefined : this.auth,
128
129
  formatPriorities: this.formatPriorities,
129
130
  doubleScreen: this.doubleScreen,
130
131
  api: this.api,
131
132
  uid: this.uid,
132
133
  isLiveRadio: isLiveRadio,
134
+ preferAlternativeStream: streamRetryHint?.preferAlternativeStream === true &&
135
+ streamRetryHint.liveId === this.liveInfo.liveId,
133
136
  });
134
137
  this.liveInfo.owner = res.owner;
135
138
  this.liveInfo.title = res.title;
@@ -186,12 +189,14 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, banLiveId, isMan
186
189
  debugLevel: this.debugLevel ?? "none",
187
190
  onlyAudio: stream.onlyAudio,
188
191
  headers: {
189
- Cookie: this.auth,
192
+ Origin: "https://live.douyin.com",
193
+ Referer: "https://live.douyin.com/",
194
+ // Cookie: this.auth,
190
195
  },
191
196
  proxy: this.proxy,
192
197
  }, onEnd, async () => {
193
198
  const info = await getInfo(this.channelId, {
194
- auth: this.auth,
199
+ auth: this.cookieMode === "danma" ? undefined : this.auth,
195
200
  });
196
201
  return info;
197
202
  });
@@ -231,8 +236,9 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, banLiveId, isMan
231
236
  // 礼物延迟处理时间(毫秒),可根据实际情况调整
232
237
  const GIFT_DELAY = 5000;
233
238
  const client = new DouYinDanmaClient(this?.liveInfo?.liveId, {
234
- cookie: this.auth,
239
+ cookie: this.cookieMode === "stream" ? undefined : this.auth,
235
240
  });
241
+ console.log("DouYinDanmaClient", this?.liveInfo?.liveId, this.cookieMode, this.auth);
236
242
  client.on("chat", (msg) => {
237
243
  const extraDataController = downloader.getExtraDataController();
238
244
  if (!extraDataController)
package/lib/stream.d.ts CHANGED
@@ -28,13 +28,9 @@ export declare function getStream(opts: Pick<Recorder, "channelId" | "quality" |
28
28
  api?: APIType;
29
29
  uid?: string | number;
30
30
  isLiveRadio?: boolean;
31
+ /** 优先尝试用户格式优先级中的备用格式 */
32
+ preferAlternativeStream?: boolean;
31
33
  }): Promise<{
32
- currentStream: {
33
- name: string;
34
- source: string;
35
- url: string;
36
- onlyAudio: boolean;
37
- };
38
34
  living: boolean;
39
35
  isLiveRadio?: boolean;
40
36
  roomId: string;
@@ -47,4 +43,11 @@ export declare function getStream(opts: Pick<Recorder, "channelId" | "quality" |
47
43
  liveId: string;
48
44
  uid: string;
49
45
  api: RealAPIType;
46
+ currentStream: {
47
+ name: string;
48
+ source: string;
49
+ url: string;
50
+ onlyAudio: boolean;
51
+ };
50
52
  }>;
53
+ export declare function getFormatPriorities(formatPriorities: Array<"flv" | "hls">, preferAlternativeStream?: boolean): Array<"flv" | "hls">;
package/lib/stream.js CHANGED
@@ -57,7 +57,7 @@ export async function getStream(opts) {
57
57
  }
58
58
  // 抖音为自动cdn,所以指定选择第一个
59
59
  const sources = info.sources[0];
60
- const formatPriorities = opts.formatPriorities || ["flv", "hls"];
60
+ const formatPriorities = getFormatPriorities(opts.formatPriorities || ["flv", "hls"], opts.preferAlternativeStream);
61
61
  // 查找指定质量的流
62
62
  let targetStream = sources.streams.find((s) => s.quality === opts.quality);
63
63
  let qualityName = targetStream?.name ?? "未知";
@@ -104,3 +104,9 @@ export async function getStream(opts) {
104
104
  },
105
105
  };
106
106
  }
107
+ export function getFormatPriorities(formatPriorities, preferAlternativeStream = false) {
108
+ if (!preferAlternativeStream || formatPriorities.length < 2) {
109
+ return [...formatPriorities];
110
+ }
111
+ return [formatPriorities[1], formatPriorities[0]];
112
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bililive-tools/douyin-recorder",
3
- "version": "1.17.3",
3
+ "version": "1.18.0",
4
4
  "description": "@bililive-tools douyin recorder implemention",
5
5
  "main": "./lib/index.js",
6
6
  "type": "module",
@@ -30,7 +30,11 @@
30
30
  "录制",
31
31
  "抖音"
32
32
  ],
33
- "repository": "https://github.com/renmu123/biliLive-tools/tree/master/packages/DouYinRecorder",
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "https://github.com/renmu123/biliLive-tools",
36
+ "directory": "packages/DouYinRecorder"
37
+ },
34
38
  "author": "WhiteMind",
35
39
  "license": "LGPL",
36
40
  "dependencies": {
@@ -38,8 +42,8 @@
38
42
  "lodash-es": "^4.17.21",
39
43
  "mitt": "^3.0.1",
40
44
  "sm-crypto": "^0.3.13",
41
- "@bililive-tools/manager": "^1.17.1",
42
- "douyin-danma-listener": "0.4.1"
45
+ "@bililive-tools/manager": "^1.18.0",
46
+ "douyin-danma-listener": "0.4.2"
43
47
  },
44
48
  "devDependencies": {
45
49
  "@types/node": "*"