@bililive-tools/douyu-recorder 1.4.0 → 1.5.1

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
@@ -45,6 +45,7 @@ interface Options {
45
45
  disableProvideCommentsWhenRecording?: boolean; // 禁用弹幕录制
46
46
  saveGiftDanma?: boolean; // 保存礼物弹幕
47
47
  saveSCDanma?: boolean; // 保存高能弹幕
48
+ useServerTimestamp?: boolean; // 控制弹幕是否使用服务端时间戳,默认为true,斗鱼服务端时间戳只对文字弹幕生效,礼物等不生效
48
49
  saveCover?: boolean; // 保存封面
49
50
  videoFormat?: "auto"; // 视频格式: "auto", "ts", "mkv" ,auto模式下, 分段使用 "ts",不分段使用 "mp4"
50
51
  onlyAudio?: boolean; // 只录制音频,默认为否
package/lib/danma.js CHANGED
@@ -9,6 +9,7 @@ export const colorTab = {
9
9
  /**
10
10
  * from https://webconf.douyucdn.cn/resource/common/prop_gift_list/prop_gift_config.json
11
11
  */
12
+ // 粉丝荧光棒被手动置为0了
12
13
  export const giftMap = {
13
14
  "192": { name: "赞", pc: 10 },
14
15
  "193": { name: "弱鸡", pc: 20 },
@@ -39,7 +40,7 @@ export const giftMap = {
39
40
  "804": { name: "铜牌", pc: 10 },
40
41
  "805": { name: "银牌", pc: 30 },
41
42
  "806": { name: "金牌", pc: 60 },
42
- "824": { name: "粉丝荧光棒", pc: 10 },
43
+ "824": { name: "粉丝荧光棒", pc: 0 },
43
44
  "947": { name: "狼抓手", pc: 10 },
44
45
  "1005": { name: "超级火箭", pc: 200000 },
45
46
  "1075": { name: "这都不叫事", pc: 200000 },
@@ -253,13 +254,13 @@ export const giftMap = {
253
254
  "1800": { name: "69式饺子", pc: 200000 },
254
255
  "1804": { name: "帝国舰队", pc: 50100 },
255
256
  "1805": { name: "可爱羡羡火箭", pc: 50000 },
256
- "1806": { name: "粉丝荧光棒", pc: 10 },
257
+ "1806": { name: "粉丝荧光棒", pc: 0 },
257
258
  "1813": { name: "石西叽", pc: 200000 },
258
259
  "1814": { name: "一箭丹心", pc: 200000 },
259
260
  "1823": { name: "赞", pc: 10 },
260
261
  "1824": { name: "弱鸡", pc: 20 },
261
262
  "1828": { name: "帝国舰队", pc: 10100 },
262
- "1838": { name: "粉丝荧光棒", pc: 10 },
263
+ "1838": { name: "粉丝荧光棒", pc: 0 },
263
264
  "1844": { name: "英嘤英", pc: 200000 },
264
265
  "1850": { name: "一只狗", pc: 200000 },
265
266
  "1852": { name: "穷逼火箭", pc: 200000 },
@@ -280,7 +281,7 @@ export const giftMap = {
280
281
  "1897": { name: "大马猴火箭", pc: 50000 },
281
282
  "1912": { name: "岁月静好", pc: 200000 },
282
283
  "1913": { name: "吃鸡", pc: 10 },
283
- "1914": { name: "粉丝荧光棒", pc: 10 },
284
+ "1914": { name: "粉丝荧光棒", pc: 0 },
284
285
  "1923": { name: "伊C", pc: 200000 },
285
286
  "1924": { name: "装逼王超火", pc: 200000 },
286
287
  "1925": { name: "超级达克宁", pc: 200000 },
@@ -377,7 +378,7 @@ export const giftMap = {
377
378
  "20384": { name: "测试专用皮肤", pc: 10 },
378
379
  "20388": { name: "全民乐PK", pc: 10000 },
379
380
  "20389": { name: "挚爱超火", pc: 200000 },
380
- "20422": { name: "粉丝荧光棒", pc: 10 },
381
+ "20422": { name: "粉丝荧光棒", pc: 0 },
381
382
  "20426": { name: "不网恋超火", pc: 200000 },
382
383
  "20434": { name: "抢位道具卡", pc: 100 },
383
384
  "20435": { name: "普通家庭超火", pc: 200000 },
package/lib/index.js CHANGED
@@ -19,6 +19,7 @@ function createRecorder(opts) {
19
19
  availableSources: [],
20
20
  qualityMaxRetry: opts.qualityRetry ?? 0,
21
21
  qualityRetry: opts.qualityRetry ?? 0,
22
+ useServerTimestamp: opts.useServerTimestamp ?? true,
22
23
  state: "idle",
23
24
  getChannelURL() {
24
25
  return `https://www.douyu.com/${this.channelId}`;
@@ -248,9 +249,10 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, banLiveId, isMan
248
249
  return;
249
250
  switch (msg.type) {
250
251
  case "chatmsg": {
252
+ const timestamp = this.useServerTimestamp ? Number(msg.cst) : Date.now();
251
253
  const comment = {
252
254
  type: "comment",
253
- timestamp: Number(msg.cst),
255
+ timestamp: timestamp,
254
256
  text: msg.txt,
255
257
  color: colorTab[msg.col] ?? "#ffffff",
256
258
  sender: {
@@ -398,8 +400,8 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, banLiveId, isMan
398
400
  if (!this.recordHandle)
399
401
  return;
400
402
  this.state = "stopping-record";
401
- client.stop();
402
403
  try {
404
+ client.stop();
403
405
  await recorder.stop();
404
406
  }
405
407
  catch (err) {
@@ -443,14 +445,26 @@ export const provider = {
443
445
  const res = await requester.get(channelURL);
444
446
  const html = res.data;
445
447
  const matched = html.match(/\$ROOM\.room_id.?=(.*?);/);
446
- if (!matched)
448
+ let roomId = undefined;
449
+ if (matched) {
450
+ roomId = matched[1].trim();
451
+ }
452
+ else {
453
+ // 解析<link rel="canonical" href="xxxxxxx"/>中的href
454
+ const canonicalLink = html.match(/<link rel="canonical" href="(.*?)"/);
455
+ if (canonicalLink) {
456
+ const url = canonicalLink[1];
457
+ roomId = url.split("/").pop();
458
+ }
459
+ }
460
+ if (!roomId)
447
461
  return null;
448
- const room_id = matched[1].trim();
449
- const roomInfo = await getRoomInfo(Number(room_id));
462
+ const roomInfo = await getRoomInfo(Number(roomId));
450
463
  return {
451
- id: matched[1].trim(),
464
+ id: roomId,
452
465
  title: roomInfo.room.room_name,
453
466
  owner: roomInfo.room.nickname,
467
+ avatar: roomInfo.room.avatar?.big,
454
468
  };
455
469
  },
456
470
  createRecorder(opts) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bililive-tools/douyu-recorder",
3
- "version": "1.4.0",
3
+ "version": "1.5.1",
4
4
  "description": "bililive-tools douyu recorder implemention",
5
5
  "main": "./lib/index.js",
6
6
  "type": "module",
@@ -41,7 +41,7 @@
41
41
  "lodash-es": "^4.17.21",
42
42
  "axios": "^1.7.8",
43
43
  "douyu-api": "^0.1.0",
44
- "@bililive-tools/manager": "^1.3.0"
44
+ "@bililive-tools/manager": "^1.4.1"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@types/ws": "^8.5.13"