@bililive-tools/douyin-recorder 1.3.0 → 1.4.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/README.md CHANGED
@@ -43,6 +43,7 @@ interface Options {
43
43
  saveGiftDanma?: boolean; // 保存礼物弹幕
44
44
  saveCover?: boolean; // 保存封面
45
45
  videoFormat?: "auto"; // 视频格式: "auto", "ts", "mkv" ,auto模式下, 分段使用 "ts",不分段使用 "mp4"
46
+ doubleScreen?: boolean; // 是否使用双屏直播流,开启后如果是双屏直播,那么就使用拼接的流,默认为true
46
47
  auth?: string; // 传递cookie,用于录制会员视频
47
48
  }
48
49
  ```
@@ -5,7 +5,11 @@
5
5
  */
6
6
  export declare function resolveShortURL(shortURL: string): Promise<string>;
7
7
  export declare const getCookie: () => Promise<string>;
8
- export declare function getRoomInfo(webRoomId: string, retryOnSpecialCode?: boolean, auth?: string): Promise<{
8
+ export declare function getRoomInfo(webRoomId: string, opts?: {
9
+ retryOnSpecialCode?: boolean;
10
+ auth?: string;
11
+ doubleScreen?: boolean;
12
+ }): Promise<{
9
13
  living: boolean;
10
14
  roomId: string;
11
15
  owner: string;
package/lib/douyin_api.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import axios from "axios";
2
+ import { isEmpty } from "lodash-es";
2
3
  import { assert } from "./utils.js";
3
4
  const requester = axios.create({
4
5
  timeout: 10e3,
@@ -76,10 +77,10 @@ export const getCookie = async () => {
76
77
  };
77
78
  return cookies;
78
79
  };
79
- export async function getRoomInfo(webRoomId, retryOnSpecialCode = true, auth) {
80
+ export async function getRoomInfo(webRoomId, opts = {}) {
80
81
  let cookies = undefined;
81
- if (auth) {
82
- cookies = auth;
82
+ if (opts.auth) {
83
+ cookies = opts.auth;
83
84
  }
84
85
  else {
85
86
  // 抖音的 'webcast/room/web/enter' api 会需要 ttwid 的 cookie,这个 cookie 是由这个请求的响应头设置的,
@@ -110,7 +111,7 @@ export async function getRoomInfo(webRoomId, retryOnSpecialCode = true, auth) {
110
111
  },
111
112
  });
112
113
  // 无 cookie 时 code 为 10037
113
- if (res.data.status_code === 10037 && retryOnSpecialCode) {
114
+ if (res.data.status_code === 10037 && opts.retryOnSpecialCode) {
114
115
  // resp 自动设置 cookie
115
116
  // const cookieRes = await requester.get("https://live.douyin.com/favicon.ico");
116
117
  // const cookies = cookieRes.headers["set-cookie"]
@@ -119,7 +120,10 @@ export async function getRoomInfo(webRoomId, retryOnSpecialCode = true, auth) {
119
120
  // })
120
121
  // .join("; ");
121
122
  // console.log("cookies", cookies);
122
- return getRoomInfo(webRoomId, false);
123
+ return getRoomInfo(webRoomId, {
124
+ retryOnSpecialCode: false,
125
+ doubleScreen: opts.doubleScreen,
126
+ });
123
127
  }
124
128
  assert(res.data.status_code === 0, `Unexpected resp, code ${res.data.status_code}, msg ${JSON.stringify(res.data.data)}, id ${webRoomId}`);
125
129
  const data = res.data.data;
@@ -138,7 +142,22 @@ export async function getRoomInfo(webRoomId, retryOnSpecialCode = true, auth) {
138
142
  liveId: room.id_str,
139
143
  };
140
144
  }
141
- const { options: { qualities }, stream_data, } = room.stream_url.live_core_sdk_data.pull_data;
145
+ let qualities = [];
146
+ let stream_data = "";
147
+ if (opts.doubleScreen && !isEmpty(room.stream_url.pull_datas)) {
148
+ const pull_data = Object.values(room.stream_url.pull_datas)[0] ?? {
149
+ options: {
150
+ qualities: [],
151
+ },
152
+ stream_data: "",
153
+ };
154
+ qualities = pull_data.options.qualities;
155
+ stream_data = pull_data.stream_data;
156
+ }
157
+ if (!stream_data) {
158
+ qualities = room.stream_url.live_core_sdk_data.pull_data.options.qualities;
159
+ stream_data = room.stream_url.live_core_sdk_data.pull_data.stream_data;
160
+ }
142
161
  const streamData = JSON.parse(stream_data).data;
143
162
  const streams = qualities.map((info) => ({
144
163
  desc: info.name,
package/lib/index.js CHANGED
@@ -109,6 +109,7 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, banLiveId, isMan
109
109
  strictQuality: strictQuality,
110
110
  cookie: this.auth,
111
111
  formatPriorities: this.formatPriorities,
112
+ doubleScreen: this.doubleScreen,
112
113
  });
113
114
  }
114
115
  catch (err) {
package/lib/stream.d.ts CHANGED
@@ -14,6 +14,7 @@ export declare function getStream(opts: Pick<Recorder, "channelId" | "quality" |
14
14
  strictQuality?: boolean;
15
15
  cookie?: string;
16
16
  formatPriorities?: Array<"flv" | "hls">;
17
+ doubleScreen?: boolean;
17
18
  }): Promise<{
18
19
  currentStream: {
19
20
  name: string;
package/lib/stream.js CHANGED
@@ -13,7 +13,11 @@ export async function getInfo(channelId) {
13
13
  };
14
14
  }
15
15
  export async function getStream(opts) {
16
- const info = await getRoomInfo(opts.channelId, true, opts.cookie);
16
+ const info = await getRoomInfo(opts.channelId, {
17
+ retryOnSpecialCode: true,
18
+ doubleScreen: opts.doubleScreen ?? true,
19
+ auth: opts.cookie,
20
+ });
17
21
  if (!info.living) {
18
22
  throw new Error("It must be called getStream when living");
19
23
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bililive-tools/douyin-recorder",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "@bililive-tools douyin recorder implemention",
5
5
  "main": "./lib/index.js",
6
6
  "type": "module",
@@ -37,8 +37,8 @@
37
37
  "axios": "^1.7.8",
38
38
  "lodash-es": "^4.17.21",
39
39
  "mitt": "^3.0.1",
40
- "@bililive-tools/manager": "^1.3.0",
41
- "douyin-danma-listener": "0.2.0"
40
+ "douyin-danma-listener": "0.2.0",
41
+ "@bililive-tools/manager": "^1.3.0"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@types/node": "*"