@bililive-tools/douyin-recorder 1.17.2 → 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
@@ -45,6 +45,12 @@ function createRecorder(opts) {
45
45
  quality: this.quality,
46
46
  streamPriorities: this.streamPriorities,
47
47
  sourcePriorities: this.sourcePriorities,
48
+ strictQuality: false,
49
+ auth: this.auth,
50
+ formatPriorities: this.formatPriorities,
51
+ doubleScreen: this.doubleScreen,
52
+ api: this.api,
53
+ uid: this.uid,
48
54
  });
49
55
  return res.currentStream;
50
56
  },
@@ -62,7 +68,7 @@ function createRecorder(opts) {
62
68
  }
63
69
  const ffmpegOutputOptions = [];
64
70
  const ffmpegInputOptions = ["-rw_timeout", "10000000", "-timeout", "10000000"];
65
- const checkLiveStatusAndRecord = async function ({ getSavePath, banLiveId, isManualStart, }) {
71
+ const checkLiveStatusAndRecord = async function ({ getSavePath, banLiveId, isManualStart, streamRetryHint, }) {
66
72
  // 如果已经在录制中,只在需要检查标题关键词时才获取最新信息
67
73
  if (this.recordHandle != null) {
68
74
  const shouldStop = await utils.checkTitleKeywordsWhileRecording(this, isManualStart, (channelId) => getInfo(channelId, {
@@ -124,6 +130,8 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, banLiveId, isMan
124
130
  api: this.api,
125
131
  uid: this.uid,
126
132
  isLiveRadio: isLiveRadio,
133
+ preferAlternativeStream: streamRetryHint?.preferAlternativeStream === true &&
134
+ streamRetryHint.liveId === this.liveInfo.liveId,
127
135
  });
128
136
  this.liveInfo.owner = res.owner;
129
137
  this.liveInfo.title = res.title;
@@ -180,7 +188,9 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, banLiveId, isMan
180
188
  debugLevel: this.debugLevel ?? "none",
181
189
  onlyAudio: stream.onlyAudio,
182
190
  headers: {
183
- Cookie: this.auth,
191
+ Origin: "https://live.douyin.com",
192
+ Referer: "https://live.douyin.com/",
193
+ // Cookie: this.auth,
184
194
  },
185
195
  proxy: this.proxy,
186
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.2",
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.0",
41
+ "@bililive-tools/manager": "^1.17.3",
42
42
  "douyin-danma-listener": "0.4.1"
43
43
  },
44
44
  "devDependencies": {