@ikenxuan/amagi 4.5.0 → 4.5.2

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.
@@ -337,7 +337,20 @@ var BiLiBiLiAPI = class {
337
337
  }
338
338
  /** 评论区类型,type参数详见 [评论区类型代码](https://github.com/SocialSisterYi/bilibili-API-collect/blob/master/docs/comment/readme.md#评论区类型代码) */
339
339
  \u8BC4\u8BBA\u533A\u660E\u7EC6(data2) {
340
- return `https://api.bilibili.com/x/v2/reply?sort=1&ps=${data2.number ?? 20}&type=${data2.type}&oid=${data2.oid}&pn=${data2.pn}`;
340
+ const params = new URLSearchParams({
341
+ oid: data2.oid.toString(),
342
+ type: data2.type.toString(),
343
+ mode: (data2.mode ?? 3).toString(),
344
+ plat: "1",
345
+ seek_rpid: "",
346
+ web_location: "1315875"
347
+ });
348
+ if (data2.pagination_str) {
349
+ params.append("pagination_str", JSON.stringify({ offset: data2.pagination_str }));
350
+ } else {
351
+ params.append("pagination_str", JSON.stringify({ offset: "" }));
352
+ }
353
+ return `https://api.bilibili.com/x/v2/reply/wbi/main?${params.toString()}`;
341
354
  }
342
355
  \u8BC4\u8BBA\u533A\u72B6\u6001(data2) {
343
356
  return `https://api.bilibili.com/x/v2/reply/subject/description?type=${data2.type}&oid=${data2.oid}`;
@@ -393,6 +406,112 @@ var kuaishouAPIErrorCode = /* @__PURE__ */ ((kuaishouAPIErrorCode2) => {
393
406
  kuaishouAPIErrorCode2["UNKNOWN"] = "UNKNOWN_ERROR" /* UNKNOWN */;
394
407
  return kuaishouAPIErrorCode2;
395
408
  })(kuaishouAPIErrorCode || {});
409
+ var mixinKeyEncTab = [
410
+ 46,
411
+ 47,
412
+ 18,
413
+ 2,
414
+ 53,
415
+ 8,
416
+ 23,
417
+ 32,
418
+ 15,
419
+ 50,
420
+ 10,
421
+ 31,
422
+ 58,
423
+ 3,
424
+ 45,
425
+ 35,
426
+ 27,
427
+ 43,
428
+ 5,
429
+ 49,
430
+ 33,
431
+ 9,
432
+ 42,
433
+ 19,
434
+ 29,
435
+ 28,
436
+ 14,
437
+ 39,
438
+ 12,
439
+ 38,
440
+ 41,
441
+ 13,
442
+ 37,
443
+ 48,
444
+ 7,
445
+ 16,
446
+ 24,
447
+ 55,
448
+ 40,
449
+ 61,
450
+ 26,
451
+ 17,
452
+ 0,
453
+ 1,
454
+ 60,
455
+ 51,
456
+ 30,
457
+ 4,
458
+ 22,
459
+ 25,
460
+ 54,
461
+ 21,
462
+ 56,
463
+ 59,
464
+ 6,
465
+ 63,
466
+ 57,
467
+ 62,
468
+ 11,
469
+ 36,
470
+ 20,
471
+ 34,
472
+ 44,
473
+ 52
474
+ ];
475
+ var getMixinKey = (orig) => mixinKeyEncTab.map((n) => orig[n]).join("").slice(0, 32);
476
+ var encWbi = (params, img_key, sub_key) => {
477
+ const mixin_key = getMixinKey(img_key + sub_key);
478
+ const curr_time = Math.round(Date.now() / 1e3);
479
+ const chr_filter = /[!'()*]/g;
480
+ Object.assign(params, { wts: curr_time });
481
+ const query = Object.keys(params).sort().map((key) => {
482
+ const value = params[key].toString().replace(chr_filter, "");
483
+ return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
484
+ }).join("&");
485
+ const wbi_sign2 = crypto.createHash("md5").update(query + mixin_key).digest("hex");
486
+ return `&wts=${curr_time}&w_rid=${wbi_sign2}`;
487
+ };
488
+ var getWbiKeys = async (cookie) => {
489
+ const res = await axios("https://api.bilibili.com/x/web-interface/nav", {
490
+ headers: {
491
+ Cookie: cookie
492
+ }
493
+ });
494
+ const response = res.data;
495
+ const {
496
+ data: {
497
+ wbi_img: { img_url, sub_url }
498
+ }
499
+ } = response;
500
+ return {
501
+ img_key: img_url.slice(img_url.lastIndexOf("/") + 1, img_url.lastIndexOf(".")),
502
+ sub_key: sub_url.slice(sub_url.lastIndexOf("/") + 1, sub_url.lastIndexOf("."))
503
+ };
504
+ };
505
+ var wbi_sign = async (BASEURL, cookie) => {
506
+ const web_keys = await getWbiKeys(cookie);
507
+ const url = new URL(BASEURL);
508
+ const params = {};
509
+ for (const [key, value] of url.searchParams.entries()) {
510
+ params[key] = value;
511
+ }
512
+ const query = encWbi(params, web_keys.img_key, web_keys.sub_key);
513
+ return query;
514
+ };
396
515
 
397
516
  // src/platform/bilibili/getdata.ts
398
517
  var defheaders = {
@@ -411,6 +530,7 @@ var defheaders = {
411
530
  referer: "https://www.bilibili.com/"
412
531
  };
413
532
  var fetchBilibili = async (data2, cookie) => {
533
+ var _a, _b, _c;
414
534
  const headers2 = {
415
535
  ...defheaders,
416
536
  cookie: cookie ? cookie.replace(/\s+/g, "") : ""
@@ -434,67 +554,65 @@ var fetchBilibili = async (data2, cookie) => {
434
554
  return DATA;
435
555
  }
436
556
  case "\u8BC4\u8BBA\u6570\u636E": {
437
- let { oid, number, pn, type } = data2;
557
+ let { oid, number, type, mode, pagination_str, plat, seek_rpid, web_location } = data2;
438
558
  let fetchedComments = [];
439
- pn = pn ?? 1;
440
559
  const maxRequestCount = 100;
441
- const commentGrowthStabilized = 5;
442
- let lastFetchedCount = 0;
443
- let stabilizedCount = 0;
444
560
  let requestCount = 0;
445
561
  let tmpresp;
446
- while (fetchedComments.length < Number(number ?? 20) && requestCount < maxRequestCount) {
447
- if (number === 0 || number === void 0) {
448
- requestCount = 0;
449
- } else {
450
- requestCount = Math.min(20, Number(number) - fetchedComments.length);
451
- }
452
- const url = bilibiliApiUrls.\u8BC4\u8BBA\u533A\u660E\u7EC6({
562
+ let nextPaginationStr = pagination_str;
563
+ let isEnd = false;
564
+ const checkStatusUrl = bilibiliApiUrls.\u8BC4\u8BBA\u533A\u72B6\u6001({ oid, type });
565
+ const checkStatusRes = await GlobalGetData({
566
+ url: checkStatusUrl,
567
+ headers: headers2,
568
+ ...data2
569
+ });
570
+ if (checkStatusRes.data === null) {
571
+ logger.error("\u8BC4\u8BBA\u533A\u672A\u5F00\u653E");
572
+ return {
573
+ code: 404,
574
+ message: "\u8BC4\u8BBA\u533A\u672A\u5F00\u653E",
575
+ data: null
576
+ };
577
+ }
578
+ while (fetchedComments.length < Number(number ?? 20) && requestCount < maxRequestCount && !isEnd) {
579
+ const baseUrl = bilibiliApiUrls.\u8BC4\u8BBA\u533A\u660E\u7EC6({
453
580
  type,
454
581
  oid,
455
- number: requestCount,
456
- pn
457
- });
458
- const checkStatusUrl = bilibiliApiUrls.\u8BC4\u8BBA\u533A\u72B6\u6001({ oid, type });
459
- const checkStatusRes = await GlobalGetData({
460
- url: checkStatusUrl,
461
- headers: headers2,
462
- ...data2
582
+ mode: mode ?? 3,
583
+ pagination_str: nextPaginationStr,
584
+ plat: plat ?? 1,
585
+ seek_rpid,
586
+ web_location: web_location ?? "1315875"
463
587
  });
464
- if (checkStatusRes.data === null) {
465
- logger.error("\u8BC4\u8BBA\u533A\u672A\u5F00\u653E");
466
- return {
467
- code: 404,
468
- message: "\u8BC4\u8BBA\u533A\u672A\u5F00\u653E",
469
- data: null
470
- };
471
- }
588
+ const wbiSignQuery = await wbi_sign(baseUrl, headers2.cookie);
589
+ const finalUrl = baseUrl + wbiSignQuery;
472
590
  const response = await GlobalGetData({
473
- url,
591
+ url: finalUrl,
474
592
  headers: headers2,
475
593
  ...data2
476
594
  });
477
595
  tmpresp = response;
478
- const currentCount = response.data.replies ? response.data.replies.length : 0;
479
- fetchedComments.push(...response.data.replies || []);
480
- if (currentCount === lastFetchedCount) {
481
- stabilizedCount++;
596
+ const currentComments = ((_a = response.data) == null ? void 0 : _a.replies) || [];
597
+ fetchedComments.push(...currentComments);
598
+ if ((_b = response.data) == null ? void 0 : _b.cursor) {
599
+ nextPaginationStr = (_c = response.data.cursor.pagination_reply) == null ? void 0 : _c.next_offset;
600
+ isEnd = response.data.cursor.is_end;
482
601
  } else {
483
- stabilizedCount = 0;
602
+ isEnd = true;
484
603
  }
485
- lastFetchedCount = currentCount;
486
- if (stabilizedCount >= commentGrowthStabilized || requestCount >= maxRequestCount) {
604
+ requestCount++;
605
+ if (isEnd || currentComments.length === 0 || !nextPaginationStr) {
606
+ logger.info("\u5DF2\u5230\u8FBE\u8BC4\u8BBA\u672B\u5C3E\u6216\u65E0\u66F4\u591A\u8BC4\u8BBA");
487
607
  break;
488
608
  }
489
- pn++;
490
- requestCount++;
491
609
  }
492
610
  const finalResponse = {
493
611
  ...tmpresp,
494
612
  data: {
495
613
  ...tmpresp.data,
496
- // 去重
497
- replies: Array.from(new Map(fetchedComments.map((item) => [item.rpid, item])).values()).slice(0, Number(data2.number))
614
+ // 去重并限制数量
615
+ replies: Array.from(new Map(fetchedComments.map((item) => [item.rpid, item])).values()).slice(0, Number(data2.number || 20))
498
616
  }
499
617
  };
500
618
  return finalResponse;
@@ -751,112 +869,6 @@ var bilibiliErrorCodeMap = {
751
869
  "-799": "\u8BF7\u6C42\u8FC7\u4E8E\u9891\u7E41\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5",
752
870
  "-8888": "\u5BF9\u4E0D\u8D77\uFF0C\u670D\u52A1\u5668\u5F00\u5C0F\u5DEE\u4E86~ (\u0CA5\uFE4F\u0CA5)"
753
871
  };
754
- var mixinKeyEncTab = [
755
- 46,
756
- 47,
757
- 18,
758
- 2,
759
- 53,
760
- 8,
761
- 23,
762
- 32,
763
- 15,
764
- 50,
765
- 10,
766
- 31,
767
- 58,
768
- 3,
769
- 45,
770
- 35,
771
- 27,
772
- 43,
773
- 5,
774
- 49,
775
- 33,
776
- 9,
777
- 42,
778
- 19,
779
- 29,
780
- 28,
781
- 14,
782
- 39,
783
- 12,
784
- 38,
785
- 41,
786
- 13,
787
- 37,
788
- 48,
789
- 7,
790
- 16,
791
- 24,
792
- 55,
793
- 40,
794
- 61,
795
- 26,
796
- 17,
797
- 0,
798
- 1,
799
- 60,
800
- 51,
801
- 30,
802
- 4,
803
- 22,
804
- 25,
805
- 54,
806
- 21,
807
- 56,
808
- 59,
809
- 6,
810
- 63,
811
- 57,
812
- 62,
813
- 11,
814
- 36,
815
- 20,
816
- 34,
817
- 44,
818
- 52
819
- ];
820
- var getMixinKey = (orig) => mixinKeyEncTab.map((n) => orig[n]).join("").slice(0, 32);
821
- var encWbi = (params, img_key, sub_key) => {
822
- const mixin_key = getMixinKey(img_key + sub_key);
823
- const curr_time = Math.round(Date.now() / 1e3);
824
- const chr_filter = /[!'()*]/g;
825
- Object.assign(params, { wts: curr_time });
826
- const query = Object.keys(params).sort().map((key) => {
827
- const value = params[key].toString().replace(chr_filter, "");
828
- return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
829
- }).join("&");
830
- const wbi_sign2 = crypto.createHash("md5").update(query + mixin_key).digest("hex");
831
- return `&wts=${curr_time}&w_rid=${wbi_sign2}`;
832
- };
833
- var getWbiKeys = async (cookie) => {
834
- const res = await axios("https://api.bilibili.com/x/web-interface/nav", {
835
- headers: {
836
- Cookie: cookie
837
- }
838
- });
839
- const response = res.data;
840
- const {
841
- data: {
842
- wbi_img: { img_url, sub_url }
843
- }
844
- } = response;
845
- return {
846
- img_key: img_url.slice(img_url.lastIndexOf("/") + 1, img_url.lastIndexOf(".")),
847
- sub_key: sub_url.slice(sub_url.lastIndexOf("/") + 1, sub_url.lastIndexOf("."))
848
- };
849
- };
850
- var wbi_sign = async (BASEURL, cookie) => {
851
- const web_keys = await getWbiKeys(cookie);
852
- const url = new URL(BASEURL);
853
- const params = {};
854
- for (const [key, value] of url.searchParams.entries()) {
855
- params[key] = value;
856
- }
857
- const query = encWbi(params, web_keys.img_key, web_keys.sub_key);
858
- return query;
859
- };
860
872
 
861
873
  // src/platform/douyin/sign/a_bogus.ts
862
874
  var SM3 = class {
@@ -1805,11 +1817,6 @@ var DouyinMusicParamsSchema = z.object({
1805
1817
  methodType: z.literal("\u97F3\u4E50\u6570\u636E"),
1806
1818
  music_id: z.string({ required_error: "\u97F3\u4E50ID\u4E0D\u80FD\u4E3A\u7A7A" }).min(1, "\u97F3\u4E50ID\u4E0D\u80FD\u4E3A\u7A7A")
1807
1819
  });
1808
- var DouyinLiveRoomParamsSchema = z.object({
1809
- methodType: z.literal("\u76F4\u64AD\u95F4\u4FE1\u606F\u6570\u636E"),
1810
- room_id: z.string({ required_error: "\u76F4\u64AD\u95F4ID\u4E0D\u80FD\u4E3A\u7A7A" }).min(1, "\u76F4\u64AD\u95F4ID\u4E0D\u80FD\u4E3A\u7A7A"),
1811
- web_rid: z.string({ required_error: "\u76F4\u64AD\u95F4\u771F\u5B9E\u623F\u95F4\u53F7\u4E0D\u80FD\u4E3A\u7A7A" }).min(1, "\u76F4\u64AD\u95F4\u771F\u5B9E\u623F\u95F4\u53F7\u4E0D\u80FD\u4E3A\u7A7A")
1812
- });
1813
1820
  var DouyinQrcodeParamsSchema = z.object({
1814
1821
  methodType: z.literal("\u7533\u8BF7\u4E8C\u7EF4\u7801\u6570\u636E"),
1815
1822
  verify_fp: z.string({ required_error: "fp\u6307\u7EB9\u4E0D\u80FD\u4E3A\u7A7A" }).min(1, "fp\u6307\u7EB9\u4E0D\u80FD\u4E3A\u7A7A")
@@ -1831,7 +1838,7 @@ var DouyinValidationSchemas2 = {
1831
1838
  "\u70ED\u70B9\u8BCD\u6570\u636E": DouyinSearchParamsSchema,
1832
1839
  "\u641C\u7D22\u6570\u636E": DouyinSearchParamsSchema,
1833
1840
  "\u97F3\u4E50\u6570\u636E": DouyinMusicParamsSchema,
1834
- "\u76F4\u64AD\u95F4\u4FE1\u606F\u6570\u636E": DouyinLiveRoomParamsSchema,
1841
+ "\u76F4\u64AD\u95F4\u4FE1\u606F\u6570\u636E": DouyinUserParamsSchema,
1835
1842
  "\u7533\u8BF7\u4E8C\u7EF4\u7801\u6570\u636E": DouyinQrcodeParamsSchema,
1836
1843
  "Emoji\u6570\u636E": DouyinEmojiListParamsSchema,
1837
1844
  "\u52A8\u6001\u8868\u60C5\u6570\u636E": DouyinEmojiProParamsSchema,
@@ -1848,7 +1855,7 @@ var BilibiliVideoDownloadParamsSchema = z.object({
1848
1855
  });
1849
1856
  var BilibiliCommentParamsSchema = z.object({
1850
1857
  methodType: z.literal("\u8BC4\u8BBA\u6570\u636E"),
1851
- oid: smartNumber("OID\u4E0D\u80FD\u4E3A\u7A7A", 1, true),
1858
+ oid: z.string({ required_error: "OID\u4E0D\u80FD\u4E3A\u7A7A" }).min(1, "OID\u4E0D\u80FD\u4E3A\u7A7A"),
1852
1859
  type: smartNumber("\u8BC4\u8BBA\u7C7B\u578B\u4E0D\u80FD\u4E3A\u7A7A", 1, true).refine(
1853
1860
  (val) => [1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 33].includes(val),
1854
1861
  { message: "\u65E0\u6548\u7684\u8BC4\u8BBA\u533A\u7C7B\u578B" }
@@ -3010,4 +3017,4 @@ var v5_default = amagi;
3010
3017
  * GPL-3.0 Licensed
3011
3018
  */
3012
3019
 
3013
- export { ApiError, BilibiliAv2BvParamsSchema, BilibiliBangumiInfoParamsSchema, BilibiliBangumiStreamParamsSchema, BilibiliBv2AvParamsSchema, BilibiliCommentParamsSchema, BilibiliDynamicParamsSchema, BilibiliEmojiParamsSchema, BilibiliLiveParamsSchema, BilibiliLoginParamsSchema, BilibiliQrcodeParamsSchema, BilibiliQrcodeStatusParamsSchema, BilibiliUserParamsSchema, BilibiliValidationSchemas2 as BilibiliValidationSchemas, BilibiliVideoDownloadParamsSchema, BilibiliVideoParamsSchema, CreateApp as Client, CreateApp, DouyinCommentParamsSchema, DouyinCommentReplyParamsSchema, DouyinEmojiListParamsSchema, DouyinEmojiProParamsSchema, DouyinLiveRoomParamsSchema, DouyinMusicParamsSchema, DouyinQrcodeParamsSchema, DouyinSearchParamsSchema, DouyinUserParamsSchema, DouyinValidationSchemas2 as DouyinValidationSchemas, DouyinWorkParamsSchema, KuaishouCommentParamsSchema, KuaishouEmojiParamsSchema, KuaishouValidationSchemas2 as KuaishouValidationSchemas, KuaishouVideoParamsSchema, Networks, ValidationError, amagiClient, av2bv, bilibili, bilibiliApiUrls, bilibiliErrorCodeMap, bilibiliUtils, bv2av, createAmagiClient, createBilibiliRoutes, createBoundBilibiliApi, createBoundDouyinApi, createBoundKuaishouApi, createDouyinRoutes, createErrorResponse, createKuaishouRoutes, createSuccessResponse, v5_default as default, douyin, douyinApiUrls, douyinSign, douyinUtils, getBilibiliData, getDouyinData, getKuaishouData, handleError, httpLogger, kuaishou, kuaishouApiUrls, kuaishouUtils, logMiddleware, logger, qtparam, validateBilibiliParams, validateDouyinParams, validateKuaishouParams, wbi_sign };
3020
+ export { ApiError, BilibiliAv2BvParamsSchema, BilibiliBangumiInfoParamsSchema, BilibiliBangumiStreamParamsSchema, BilibiliBv2AvParamsSchema, BilibiliCommentParamsSchema, BilibiliDynamicParamsSchema, BilibiliEmojiParamsSchema, BilibiliLiveParamsSchema, BilibiliLoginParamsSchema, BilibiliQrcodeParamsSchema, BilibiliQrcodeStatusParamsSchema, BilibiliUserParamsSchema, BilibiliValidationSchemas2 as BilibiliValidationSchemas, BilibiliVideoDownloadParamsSchema, BilibiliVideoParamsSchema, CreateApp as Client, CreateApp, DouyinCommentParamsSchema, DouyinCommentReplyParamsSchema, DouyinEmojiListParamsSchema, DouyinEmojiProParamsSchema, DouyinMusicParamsSchema, DouyinQrcodeParamsSchema, DouyinSearchParamsSchema, DouyinUserParamsSchema, DouyinValidationSchemas2 as DouyinValidationSchemas, DouyinWorkParamsSchema, KuaishouCommentParamsSchema, KuaishouEmojiParamsSchema, KuaishouValidationSchemas2 as KuaishouValidationSchemas, KuaishouVideoParamsSchema, Networks, ValidationError, amagiClient, av2bv, bilibili, bilibiliApiUrls, bilibiliErrorCodeMap, bilibiliUtils, bv2av, createAmagiClient, createBilibiliRoutes, createBoundBilibiliApi, createBoundDouyinApi, createBoundKuaishouApi, createDouyinRoutes, createErrorResponse, createKuaishouRoutes, createSuccessResponse, v5_default as default, douyin, douyinApiUrls, douyinSign, douyinUtils, getBilibiliData, getDouyinData, getKuaishouData, handleError, httpLogger, kuaishou, kuaishouApiUrls, kuaishouUtils, logMiddleware, logger, qtparam, validateBilibiliParams, validateDouyinParams, validateKuaishouParams, wbi_sign };