@bililive-tools/bilibili-recorder 1.12.0 → 1.15.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
@@ -55,6 +55,7 @@ interface Options {
55
55
  onlyAudio?: boolean; // 只录制音频,默认为否
56
56
  recorderType?: "auto" | "ffmpeg" | "mesio" | "bililive"; // 底层录制器,使用mesio和bililive时videoFormat参数无效
57
57
  debugLevel?: `verbose` | "basic"; // verbose参数时,录制器会输出更加详细的log
58
+ customHost?: string; // 自定义host来替换直播流的host
58
59
  }
59
60
  ```
60
61
 
@@ -42,6 +42,7 @@ export declare function getStatusInfoByUIDs<UID extends number>(userIds: UID[]):
42
42
  online: number;
43
43
  room_id: number;
44
44
  short_id: number;
45
+ area_v2_parent_name: string;
45
46
  }>>;
46
47
  export declare function getRoomBaseInfo<RoomId extends number>(roomId: RoomId): Promise<Record<RoomId, {
47
48
  title: string;
@@ -8,6 +8,9 @@ const requester = axios.create({
8
8
  // axios 会自动读取环境变量中的 http_proxy 和 https_proxy 并应用,
9
9
  // 但会导致请求报错 "Client network socket disconnected before secure TLS connection was established"。
10
10
  proxy: false,
11
+ headers: {
12
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36",
13
+ },
11
14
  });
12
15
  export async function getRoomInit(roomIdOrShortId) {
13
16
  const res = await requester.get(`https://api.live.bilibili.com/room/v1/Room/room_init?id=${roomIdOrShortId}`);
package/lib/index.js CHANGED
@@ -19,6 +19,7 @@ function createRecorder(opts) {
19
19
  state: "idle",
20
20
  qualityRetry: opts.qualityRetry ?? 0,
21
21
  useM3U8Proxy: opts.useM3U8Proxy ?? false,
22
+ customHost: opts.customHost,
22
23
  useServerTimestamp: opts.useServerTimestamp ?? true,
23
24
  m3u8ProxyUrl: opts.m3u8ProxyUrl,
24
25
  formatName: opts.formatName ?? "auto",
@@ -121,6 +122,7 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, isManualStart, b
121
122
  formatName: this.formatName,
122
123
  codecName: this.codecName,
123
124
  onlyAudio: this.onlyAudio,
125
+ customHost: this.customHost,
124
126
  });
125
127
  }
126
128
  catch (err) {
package/lib/stream.d.ts CHANGED
@@ -25,6 +25,7 @@ export declare function getInfo(channelId: string): Promise<{
25
25
  liveId: string;
26
26
  liveStartTime: Date;
27
27
  recordStartTime: Date;
28
+ area: string;
28
29
  }>;
29
30
  export declare function getStream(opts: Pick<Recorder, "channelId" | "quality"> & {
30
31
  cookie?: string;
@@ -32,6 +33,7 @@ export declare function getStream(opts: Pick<Recorder, "channelId" | "quality">
32
33
  formatName: RecorderCreateOpts["formatName"];
33
34
  codecName: RecorderCreateOpts["codecName"];
34
35
  onlyAudio?: boolean;
36
+ customHost?: string;
35
37
  }): Promise<{
36
38
  currentStream: {
37
39
  name: string;
package/lib/stream.js CHANGED
@@ -55,6 +55,7 @@ export async function getInfo(channelId) {
55
55
  roomId: roomInit.room_id,
56
56
  liveId: utils.md5(`${roomInit.room_id}-${liveStartTime?.getTime()}`),
57
57
  recordStartTime,
58
+ area: status.parent_area_name,
58
59
  };
59
60
  }
60
61
  const liveStartTime = new Date(status.live_time * 1000);
@@ -69,6 +70,7 @@ export async function getInfo(channelId) {
69
70
  liveStartTime: liveStartTime,
70
71
  liveId: utils.md5(`${roomInit.room_id}-${liveStartTime.getTime()}`),
71
72
  recordStartTime,
73
+ area: status.area_v2_parent_name,
72
74
  };
73
75
  }
74
76
  async function getLiveInfo(roomIdOrShortId, opts) {
@@ -158,6 +160,7 @@ async function getLiveInfo(roomIdOrShortId, opts) {
158
160
  // console.log("conditons", opts.codecName, conditons);
159
161
  let streamInfo;
160
162
  let streamOptions;
163
+ // console.log("conditons", JSON.stringify(res.playurl_info.playurl.stream, null, 2));
161
164
  for (const condition of conditons) {
162
165
  const streamList = res.playurl_info.playurl.stream
163
166
  .find(({ protocol_name }) => protocol_name === condition.protocol_name)
@@ -236,12 +239,14 @@ export async function getStream(opts) {
236
239
  if (!expectSource) {
237
240
  throw new Error("Can not get expect source");
238
241
  }
242
+ const host = opts.customHost ? `https://${opts.customHost}` : expectSource.host;
243
+ const url = host + liveInfo.base_url + expectSource.extra;
239
244
  return {
240
245
  ...liveInfo,
241
246
  currentStream: {
242
247
  name: liveInfo.name,
243
248
  source: expectSource.name,
244
- url: expectSource.host + liveInfo.base_url + expectSource.extra,
249
+ url: url,
245
250
  },
246
251
  };
247
252
  }
package/lib/utils.d.ts CHANGED
@@ -20,4 +20,3 @@ export declare function assert(assertion: unknown, msg?: string): asserts assert
20
20
  export declare function assertStringType(data: unknown, msg?: string): asserts data is string;
21
21
  export declare function assertNumberType(data: unknown, msg?: string): asserts data is number;
22
22
  export declare function assertObjectType(data: unknown, msg?: string): asserts data is object;
23
- export declare function createInvalidStreamChecker(count?: number): (ffmpegLogLine: string) => boolean;
package/lib/utils.js CHANGED
@@ -59,25 +59,3 @@ export function assertNumberType(data, msg) {
59
59
  export function assertObjectType(data, msg) {
60
60
  assert(typeof data === "object", msg);
61
61
  }
62
- export function createInvalidStreamChecker(count = 10) {
63
- let prevFrame = 0;
64
- let frameUnchangedCount = 0;
65
- return (ffmpegLogLine) => {
66
- const streamInfo = ffmpegLogLine.match(/frame=\s*(\d+) fps=.*? q=.*? size=.*? time=.*? bitrate=.*? speed=.*?/);
67
- if (streamInfo != null) {
68
- const [, frameText] = streamInfo;
69
- const frame = Number(frameText);
70
- if (frame === prevFrame) {
71
- if (++frameUnchangedCount >= count) {
72
- return true;
73
- }
74
- }
75
- else {
76
- prevFrame = frame;
77
- frameUnchangedCount = 0;
78
- }
79
- return false;
80
- }
81
- return false;
82
- };
83
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bililive-tools/bilibili-recorder",
3
- "version": "1.12.0",
3
+ "version": "1.15.0",
4
4
  "description": "bililive-tools bilibili recorder implemention",
5
5
  "main": "./lib/index.js",
6
6
  "type": "module",
@@ -38,8 +38,8 @@
38
38
  "mitt": "^3.0.1",
39
39
  "tiny-bilibili-ws": "^1.0.2",
40
40
  "lodash-es": "^4.17.21",
41
- "axios": "^1.7.8",
42
- "@bililive-tools/manager": "^1.12.0"
41
+ "axios": "^1.15.0",
42
+ "@bililive-tools/manager": "^1.14.1"
43
43
  },
44
44
  "scripts": {
45
45
  "build": "tsc",