@ikenxuan/amagi 5.12.3 → 5.13.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/dist/default/index.cjs +177 -8
- package/dist/default/index.d.cts +134 -17
- package/dist/default/index.d.cts.map +1 -1
- package/dist/default/index.d.ts +134 -17
- package/dist/default/index.d.ts.map +1 -1
- package/dist/default/index.js +173 -7
- package/dist/default/index.js.map +1 -1
- package/package.json +2 -1
package/dist/default/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
1
|
import path from "node:path";
|
|
3
2
|
import url from "node:url";
|
|
3
|
+
import fs from "node:fs";
|
|
4
4
|
import { Chalk } from "chalk";
|
|
5
5
|
import axios, { AxiosError } from "axios";
|
|
6
6
|
import zod from "zod";
|
|
7
7
|
import { Xhshow } from "@ikenxuan/xhshow-ts";
|
|
8
|
+
import protobuf from "protobufjs";
|
|
8
9
|
import crypto from "node:crypto";
|
|
9
10
|
import express from "express";
|
|
10
11
|
|
|
@@ -526,6 +527,11 @@ const BilibiliValidateCaptchaParamsSchema = zod.object({
|
|
|
526
527
|
validate: zod.string({ error: "验证码validate必须是字符串" }).min(1, { error: "验证码validate不能为空" }),
|
|
527
528
|
seccode: zod.string({ error: "验证码seccode必须是字符串" }).min(1, { error: "验证码seccode不能为空" })
|
|
528
529
|
});
|
|
530
|
+
const BilibiliDanmakuParamsSchema = zod.object({
|
|
531
|
+
methodType: zod.literal("实时弹幕", { error: "方法类型必须是\"实时弹幕\"" }),
|
|
532
|
+
cid: smartNumber("CID不能为空", 1, true),
|
|
533
|
+
segment_index: zod.coerce.number({ error: "分段序号必须是数字" }).int({ error: "分段序号必须是整数" }).positive({ error: "分段序号必须是正数" }).default(1).optional()
|
|
534
|
+
});
|
|
529
535
|
const BilibiliValidationSchemas = {
|
|
530
536
|
单个视频作品数据: BilibiliVideoParamsSchema,
|
|
531
537
|
单个视频下载信息数据: BilibiliVideoDownloadParamsSchema,
|
|
@@ -552,7 +558,8 @@ const BilibiliValidationSchemas = {
|
|
|
552
558
|
专栏文章基本信息: BilibiliArticleInfoParamsSchema,
|
|
553
559
|
文集基本信息: BilibiliColumnInfoParamsSchema,
|
|
554
560
|
从_v_voucher_申请_captcha: BilibiliApplyCaptchaParamsSchema,
|
|
555
|
-
验证验证码结果: BilibiliValidateCaptchaParamsSchema
|
|
561
|
+
验证验证码结果: BilibiliValidateCaptchaParamsSchema,
|
|
562
|
+
实时弹幕: BilibiliDanmakuParamsSchema
|
|
556
563
|
};
|
|
557
564
|
const BilibiliMethodRoutes = {
|
|
558
565
|
单个视频作品数据: "/fetch_one_video",
|
|
@@ -580,7 +587,8 @@ const BilibiliMethodRoutes = {
|
|
|
580
587
|
专栏文章基本信息: "/fetch_article_info",
|
|
581
588
|
文集基本信息: "/fetch_column_info",
|
|
582
589
|
从_v_voucher_申请_captcha: "/apply_captcha",
|
|
583
|
-
验证验证码结果: "/validate_captcha"
|
|
590
|
+
验证验证码结果: "/validate_captcha",
|
|
591
|
+
实时弹幕: "/fetch_danmaku"
|
|
584
592
|
};
|
|
585
593
|
|
|
586
594
|
//#endregion
|
|
@@ -1525,6 +1533,17 @@ var BiLiBiLiAPI = class {
|
|
|
1525
1533
|
}
|
|
1526
1534
|
};
|
|
1527
1535
|
}
|
|
1536
|
+
/**
|
|
1537
|
+
* 获取实时弹幕(web端 protobuf 接口)
|
|
1538
|
+
* @see https://github.com/SocialSisterYi/bilibili-API-collect/blob/master/docs/danmaku/danmaku_proto.md
|
|
1539
|
+
*/
|
|
1540
|
+
实时弹幕(data$1) {
|
|
1541
|
+
return `https://api.bilibili.com/x/v2/dm/web/seg.so?${new URLSearchParams({
|
|
1542
|
+
type: "1",
|
|
1543
|
+
oid: data$1.cid.toString(),
|
|
1544
|
+
segment_index: (data$1.segment_index ?? 1).toString()
|
|
1545
|
+
}).toString()}`;
|
|
1546
|
+
}
|
|
1528
1547
|
};
|
|
1529
1548
|
/** 该类下的所有方法只会返回拼接好参数后的 Url 地址,需要手动请求该地址以获取数据 */
|
|
1530
1549
|
const bilibiliApiUrls = new BiLiBiLiAPI();
|
|
@@ -1589,7 +1608,8 @@ const bilibili = {
|
|
|
1589
1608
|
getColumnInfo: createBilibiliApiMethod("文集基本信息"),
|
|
1590
1609
|
getUserProfileDetail: createBilibiliApiMethod("用户空间详细信息"),
|
|
1591
1610
|
applyVoucherCaptcha: createBilibiliApiMethod("从_v_voucher_申请_captcha"),
|
|
1592
|
-
validateCaptcha: createBilibiliApiMethod("验证验证码结果")
|
|
1611
|
+
validateCaptcha: createBilibiliApiMethod("验证验证码结果"),
|
|
1612
|
+
getDanmaku: createBilibiliApiMethod("实时弹幕")
|
|
1593
1613
|
};
|
|
1594
1614
|
/**
|
|
1595
1615
|
* 创建绑定了cookie的B站API对象
|
|
@@ -1623,7 +1643,8 @@ const createBoundBilibiliApi = (cookie, requestConfig) => {
|
|
|
1623
1643
|
getColumnInfo: createBoundBilibiliApiMethod("文集基本信息", cookie),
|
|
1624
1644
|
getUserProfileDetail: createBoundBilibiliApiMethod("用户空间详细信息", cookie),
|
|
1625
1645
|
applyVoucherCaptcha: createBoundBilibiliApiMethod("从_v_voucher_申请_captcha", cookie),
|
|
1626
|
-
validateCaptcha: createBoundBilibiliApiMethod("验证验证码结果", cookie)
|
|
1646
|
+
validateCaptcha: createBoundBilibiliApiMethod("验证验证码结果", cookie),
|
|
1647
|
+
getDanmaku: createBoundBilibiliApiMethod("实时弹幕", cookie)
|
|
1627
1648
|
};
|
|
1628
1649
|
};
|
|
1629
1650
|
|
|
@@ -1679,6 +1700,101 @@ const bv2av = (bvid) => {
|
|
|
1679
1700
|
return Number(tmp & MASK_CODE ^ XOR_CODE);
|
|
1680
1701
|
};
|
|
1681
1702
|
|
|
1703
|
+
//#endregion
|
|
1704
|
+
//#region src/platform/bilibili/sign/danmaku_proto.ts
|
|
1705
|
+
/**
|
|
1706
|
+
* B站弹幕 Protobuf 定义(内联)
|
|
1707
|
+
* @see https://github.com/SocialSisterYi/bilibili-API-collect/blob/master/docs/danmaku/danmaku_proto.md
|
|
1708
|
+
*/
|
|
1709
|
+
const DANMAKU_PROTO_JSON = { nested: { bilibili: { nested: { community: { nested: { service: { nested: { dm: { nested: { v1: { nested: {
|
|
1710
|
+
DmSegMobileReply: { fields: { elems: {
|
|
1711
|
+
rule: "repeated",
|
|
1712
|
+
type: "DanmakuElem",
|
|
1713
|
+
id: 1
|
|
1714
|
+
} } },
|
|
1715
|
+
DanmakuElem: { fields: {
|
|
1716
|
+
id: {
|
|
1717
|
+
type: "int64",
|
|
1718
|
+
id: 1
|
|
1719
|
+
},
|
|
1720
|
+
progress: {
|
|
1721
|
+
type: "int32",
|
|
1722
|
+
id: 2
|
|
1723
|
+
},
|
|
1724
|
+
mode: {
|
|
1725
|
+
type: "int32",
|
|
1726
|
+
id: 3
|
|
1727
|
+
},
|
|
1728
|
+
fontsize: {
|
|
1729
|
+
type: "int32",
|
|
1730
|
+
id: 4
|
|
1731
|
+
},
|
|
1732
|
+
color: {
|
|
1733
|
+
type: "uint32",
|
|
1734
|
+
id: 5
|
|
1735
|
+
},
|
|
1736
|
+
midHash: {
|
|
1737
|
+
type: "string",
|
|
1738
|
+
id: 6
|
|
1739
|
+
},
|
|
1740
|
+
content: {
|
|
1741
|
+
type: "string",
|
|
1742
|
+
id: 7
|
|
1743
|
+
},
|
|
1744
|
+
ctime: {
|
|
1745
|
+
type: "int64",
|
|
1746
|
+
id: 8
|
|
1747
|
+
},
|
|
1748
|
+
weight: {
|
|
1749
|
+
type: "int32",
|
|
1750
|
+
id: 9
|
|
1751
|
+
},
|
|
1752
|
+
action: {
|
|
1753
|
+
type: "string",
|
|
1754
|
+
id: 10
|
|
1755
|
+
},
|
|
1756
|
+
pool: {
|
|
1757
|
+
type: "int32",
|
|
1758
|
+
id: 11
|
|
1759
|
+
},
|
|
1760
|
+
idStr: {
|
|
1761
|
+
type: "string",
|
|
1762
|
+
id: 12
|
|
1763
|
+
},
|
|
1764
|
+
attr: {
|
|
1765
|
+
type: "int32",
|
|
1766
|
+
id: 13
|
|
1767
|
+
},
|
|
1768
|
+
animation: {
|
|
1769
|
+
type: "string",
|
|
1770
|
+
id: 22
|
|
1771
|
+
}
|
|
1772
|
+
} }
|
|
1773
|
+
} } } } } } } } } } } };
|
|
1774
|
+
let DmSegMobileReplyType = null;
|
|
1775
|
+
/**
|
|
1776
|
+
* 获取 protobuf 类型定义
|
|
1777
|
+
*/
|
|
1778
|
+
function getProtoType() {
|
|
1779
|
+
if (DmSegMobileReplyType) return DmSegMobileReplyType;
|
|
1780
|
+
DmSegMobileReplyType = protobuf.Root.fromJSON(DANMAKU_PROTO_JSON).lookupType("bilibili.community.service.dm.v1.DmSegMobileReply");
|
|
1781
|
+
return DmSegMobileReplyType;
|
|
1782
|
+
}
|
|
1783
|
+
/**
|
|
1784
|
+
* 解析弹幕分段响应
|
|
1785
|
+
* @param data - 二进制 protobuf 数据
|
|
1786
|
+
* @returns 解析后的弹幕数据
|
|
1787
|
+
*/
|
|
1788
|
+
function parseDmSegMobileReply(data$1) {
|
|
1789
|
+
const messageType = getProtoType();
|
|
1790
|
+
const buffer = data$1 instanceof Uint8Array ? data$1 : new Uint8Array(data$1);
|
|
1791
|
+
const message = messageType.decode(buffer);
|
|
1792
|
+
return messageType.toObject(message, {
|
|
1793
|
+
longs: String,
|
|
1794
|
+
defaults: true
|
|
1795
|
+
});
|
|
1796
|
+
}
|
|
1797
|
+
|
|
1682
1798
|
//#endregion
|
|
1683
1799
|
//#region src/platform/bilibili/sign/wbi.ts
|
|
1684
1800
|
/**
|
|
@@ -1978,6 +2094,7 @@ const bilibiliUtils = {
|
|
|
1978
2094
|
av2bv,
|
|
1979
2095
|
bv2av
|
|
1980
2096
|
},
|
|
2097
|
+
danmaku: { parseDmSegMobileReply },
|
|
1981
2098
|
bilibiliApiUrls,
|
|
1982
2099
|
api: bilibili
|
|
1983
2100
|
};
|
|
@@ -2317,6 +2434,48 @@ const fetchBilibili = async (data$1, cookie, requestConfig) => {
|
|
|
2317
2434
|
url: bilibiliApiUrls.验证验证码结果(data$1).Url,
|
|
2318
2435
|
data: bilibiliApiUrls.验证验证码结果(data$1).Body
|
|
2319
2436
|
});
|
|
2437
|
+
case "实时弹幕": {
|
|
2438
|
+
const url$1 = bilibiliApiUrls.实时弹幕({
|
|
2439
|
+
cid: data$1.cid,
|
|
2440
|
+
segment_index: data$1.segment_index
|
|
2441
|
+
});
|
|
2442
|
+
try {
|
|
2443
|
+
const response = await fetchData({
|
|
2444
|
+
...baseRequestConfig,
|
|
2445
|
+
url: url$1,
|
|
2446
|
+
responseType: "arraybuffer"
|
|
2447
|
+
});
|
|
2448
|
+
if (isNetworkErrorResult(response)) {
|
|
2449
|
+
const networkError = new Error(response.error.amagiError.errorDescription);
|
|
2450
|
+
Object.assign(networkError, {
|
|
2451
|
+
code: response.error.code,
|
|
2452
|
+
data: null,
|
|
2453
|
+
amagiError: {
|
|
2454
|
+
...response.error.amagiError,
|
|
2455
|
+
requestType: data$1.methodType
|
|
2456
|
+
}
|
|
2457
|
+
});
|
|
2458
|
+
throw networkError;
|
|
2459
|
+
}
|
|
2460
|
+
return {
|
|
2461
|
+
code: 0,
|
|
2462
|
+
message: "success",
|
|
2463
|
+
data: { elems: parseDmSegMobileReply(response).elems }
|
|
2464
|
+
};
|
|
2465
|
+
} catch (error) {
|
|
2466
|
+
if (error && typeof error === "object" && "code" in error) return error;
|
|
2467
|
+
const Err = {
|
|
2468
|
+
errorDescription: `获取弹幕数据失败:${error instanceof Error ? error.message : "未知错误"}`,
|
|
2469
|
+
requestType: data$1.methodType,
|
|
2470
|
+
requestUrl: url$1
|
|
2471
|
+
};
|
|
2472
|
+
return {
|
|
2473
|
+
code: amagiAPIErrorCode.UNKNOWN,
|
|
2474
|
+
data: null,
|
|
2475
|
+
amagiError: Err
|
|
2476
|
+
};
|
|
2477
|
+
}
|
|
2478
|
+
}
|
|
2320
2479
|
default:
|
|
2321
2480
|
logger.warn(`未知的B站数据接口:「${logger.red(data$1.methodType)}」`);
|
|
2322
2481
|
return null;
|
|
@@ -5171,7 +5330,14 @@ let DynamicType = /* @__PURE__ */ function(DynamicType$1) {
|
|
|
5171
5330
|
|
|
5172
5331
|
//#endregion
|
|
5173
5332
|
//#region src/index.ts
|
|
5174
|
-
|
|
5333
|
+
/**
|
|
5334
|
+
* 获取版本号
|
|
5335
|
+
* 构建后使用 __VERSION__,开发环境从 package.json 读取
|
|
5336
|
+
*/
|
|
5337
|
+
const getVersion = () => {
|
|
5338
|
+
return "5.13.0";
|
|
5339
|
+
};
|
|
5340
|
+
const VERSION = getVersion();
|
|
5175
5341
|
/**
|
|
5176
5342
|
* @deprecated 请使用 createAmagiClient 替代
|
|
5177
5343
|
*/
|
|
@@ -5207,5 +5373,5 @@ const Client = CreateApp;
|
|
|
5207
5373
|
const amagi = Client;
|
|
5208
5374
|
|
|
5209
5375
|
//#endregion
|
|
5210
|
-
export { AdditionalType, ApiError, BilibiliApplyCaptchaParamsSchema, BilibiliArticleCardParamsSchema, BilibiliArticleInfoParamsSchema, BilibiliArticleParamsSchema, BilibiliAv2BvParamsSchema, BilibiliBangumiInfoParamsSchema, BilibiliBangumiStreamParamsSchema, BilibiliBv2AvParamsSchema, BilibiliColumnInfoParamsSchema, BilibiliCommentParamsSchema, BilibiliCommentReplyParamsSchema, BilibiliDynamicParamsSchema, BilibiliEmojiParamsSchema, BilibiliLiveParamsSchema, BilibiliLoginParamsSchema, BilibiliMethodRoutes, BilibiliQrcodeParamsSchema, BilibiliQrcodeStatusParamsSchema, BilibiliUserParamsSchema, BilibiliValidateCaptchaParamsSchema, BilibiliValidationSchemas, BilibiliVideoDownloadParamsSchema, BilibiliVideoParamsSchema, CommentType, CreateApp, DouyinCommentParamsSchema, DouyinCommentReplyParamsSchema, DouyinDanmakuParamsSchema, DouyinEmojiListParamsSchema, DouyinEmojiProParamsSchema, DouyinHotWordsParamsSchema, DouyinLiveRoomParamsSchema, DouyinMethodRoutes, DouyinMusicParamsSchema, DouyinQrcodeParamsSchema, DouyinSearchParamsSchema, DouyinUserParamsSchema, DouyinValidationSchemas, DouyinWorkParamsSchema, DynamicType, KuaishouCommentParamsSchema, KuaishouEmojiParamsSchema, KuaishouMethodRoutes, KuaishouValidationSchemas, KuaishouVideoParamsSchema, MajorType, ValidationError, XiaohongshuMethodRoutes, XiaohongshuValidationSchemas, amagi, amagiClient, av2bv, bilibili, bilibiliApiUrls, bilibiliErrorCodeMap, bilibiliUtils, bv2av, createAmagiClient, createBilibiliRoutes, createBilibiliRoutes as registerBilibiliRoutes, createBoundBilibiliApi, createBoundDouyinApi, createBoundKuaishouApi, createBoundXiaohongshuApi, createDouyinRoutes, createDouyinRoutes as registerDouyinRoutes, createErrorResponse, createKuaishouRoutes, createKuaishouRoutes as registerKuaishouRoutes, createSuccessResponse, createXiaohongshuRoutes, createXiaohongshuRoutes as registerXiaohongshuRoutes, Client as default, douyin, douyinApiUrls, douyinSign, douyinUtils, fetchData, fetchResponse, getBilibiliData, getDouyinData, getHeadersAndData, getKuaishouData, handleError, httpLogger, initLogger, isNetworkErrorResult, kuaishou, kuaishouApiUrls, kuaishouUtils, logMiddleware, logger, qtparam, validateBilibiliParams, validateDouyinParams, validateKuaishouParams, validateXiaohongshuParams, wbi_sign, xiaohongshu, xiaohongshuApiUrls, xiaohongshuSign, xiaohongshuUtils };
|
|
5376
|
+
export { AdditionalType, ApiError, BilibiliApplyCaptchaParamsSchema, BilibiliArticleCardParamsSchema, BilibiliArticleInfoParamsSchema, BilibiliArticleParamsSchema, BilibiliAv2BvParamsSchema, BilibiliBangumiInfoParamsSchema, BilibiliBangumiStreamParamsSchema, BilibiliBv2AvParamsSchema, BilibiliColumnInfoParamsSchema, BilibiliCommentParamsSchema, BilibiliCommentReplyParamsSchema, BilibiliDanmakuParamsSchema, BilibiliDynamicParamsSchema, BilibiliEmojiParamsSchema, BilibiliLiveParamsSchema, BilibiliLoginParamsSchema, BilibiliMethodRoutes, BilibiliQrcodeParamsSchema, BilibiliQrcodeStatusParamsSchema, BilibiliUserParamsSchema, BilibiliValidateCaptchaParamsSchema, BilibiliValidationSchemas, BilibiliVideoDownloadParamsSchema, BilibiliVideoParamsSchema, CommentType, CreateApp, DouyinCommentParamsSchema, DouyinCommentReplyParamsSchema, DouyinDanmakuParamsSchema, DouyinEmojiListParamsSchema, DouyinEmojiProParamsSchema, DouyinHotWordsParamsSchema, DouyinLiveRoomParamsSchema, DouyinMethodRoutes, DouyinMusicParamsSchema, DouyinQrcodeParamsSchema, DouyinSearchParamsSchema, DouyinUserParamsSchema, DouyinValidationSchemas, DouyinWorkParamsSchema, DynamicType, KuaishouCommentParamsSchema, KuaishouEmojiParamsSchema, KuaishouMethodRoutes, KuaishouValidationSchemas, KuaishouVideoParamsSchema, MajorType, ValidationError, XiaohongshuMethodRoutes, XiaohongshuValidationSchemas, amagi, amagiClient, av2bv, bilibili, bilibiliApiUrls, bilibiliErrorCodeMap, bilibiliUtils, bv2av, createAmagiClient, createBilibiliRoutes, createBilibiliRoutes as registerBilibiliRoutes, createBoundBilibiliApi, createBoundDouyinApi, createBoundKuaishouApi, createBoundXiaohongshuApi, createDouyinRoutes, createDouyinRoutes as registerDouyinRoutes, createErrorResponse, createKuaishouRoutes, createKuaishouRoutes as registerKuaishouRoutes, createSuccessResponse, createXiaohongshuRoutes, createXiaohongshuRoutes as registerXiaohongshuRoutes, Client as default, douyin, douyinApiUrls, douyinSign, douyinUtils, fetchData, fetchResponse, getBilibiliData, getDouyinData, getHeadersAndData, getKuaishouData, handleError, httpLogger, initLogger, isNetworkErrorResult, kuaishou, kuaishouApiUrls, kuaishouUtils, logMiddleware, logger, parseDmSegMobileReply, qtparam, validateBilibiliParams, validateDouyinParams, validateKuaishouParams, validateXiaohongshuParams, wbi_sign, xiaohongshu, xiaohongshuApiUrls, xiaohongshuSign, xiaohongshuUtils };
|
|
5211
5377
|
//# sourceMappingURL=index.js.map
|