@bililive-tools/douyin-recorder 1.17.3 → 1.17.4

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
@@ -68,7 +68,7 @@ function createRecorder(opts) {
68
68
  }
69
69
  const ffmpegOutputOptions = [];
70
70
  const ffmpegInputOptions = ["-rw_timeout", "10000000", "-timeout", "10000000"];
71
- const checkLiveStatusAndRecord = async function ({ getSavePath, banLiveId, isManualStart, }) {
71
+ const checkLiveStatusAndRecord = async function ({ getSavePath, banLiveId, isManualStart, streamRetryHint, }) {
72
72
  // 如果已经在录制中,只在需要检查标题关键词时才获取最新信息
73
73
  if (this.recordHandle != null) {
74
74
  const shouldStop = await utils.checkTitleKeywordsWhileRecording(this, isManualStart, (channelId) => getInfo(channelId, {
@@ -130,6 +130,8 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, banLiveId, isMan
130
130
  api: this.api,
131
131
  uid: this.uid,
132
132
  isLiveRadio: isLiveRadio,
133
+ preferAlternativeStream: streamRetryHint?.preferAlternativeStream === true &&
134
+ streamRetryHint.liveId === this.liveInfo.liveId,
133
135
  });
134
136
  this.liveInfo.owner = res.owner;
135
137
  this.liveInfo.title = res.title;
@@ -186,7 +188,9 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, banLiveId, isMan
186
188
  debugLevel: this.debugLevel ?? "none",
187
189
  onlyAudio: stream.onlyAudio,
188
190
  headers: {
189
- Cookie: this.auth,
191
+ Origin: "https://live.douyin.com",
192
+ Referer: "https://live.douyin.com/",
193
+ // Cookie: this.auth,
190
194
  },
191
195
  proxy: this.proxy,
192
196
  }, onEnd, async () => {
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.17.4",
4
4
  "description": "@bililive-tools douyin recorder implemention",
5
5
  "main": "./lib/index.js",
6
6
  "type": "module",
@@ -38,7 +38,7 @@
38
38
  "lodash-es": "^4.17.21",
39
39
  "mitt": "^3.0.1",
40
40
  "sm-crypto": "^0.3.13",
41
- "@bililive-tools/manager": "^1.17.1",
41
+ "@bililive-tools/manager": "^1.17.3",
42
42
  "douyin-danma-listener": "0.4.1"
43
43
  },
44
44
  "devDependencies": {