@ikenxuan/amagi 4.5.1 → 5.0.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.
@@ -1,3093 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var chalk = require('chalk');
6
- var log4js = require('log4js');
7
- var path = require('path');
8
- var url = require('url');
9
- var fs = require('fs');
10
- var axios = require('axios');
11
- var crypto = require('crypto');
12
- var zod = require('zod');
13
- var express = require('express');
14
-
15
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
16
-
17
- var log4js__default = /*#__PURE__*/_interopDefault(log4js);
18
- var path__default = /*#__PURE__*/_interopDefault(path);
19
- var fs__default = /*#__PURE__*/_interopDefault(fs);
20
- var axios__default = /*#__PURE__*/_interopDefault(axios);
21
- var crypto__default = /*#__PURE__*/_interopDefault(crypto);
22
- var express__default = /*#__PURE__*/_interopDefault(express);
23
-
24
- /*!
25
- * @ikenxuan/amagi
26
- * Copyright(c) 2023 ikenxuan
27
- * GPL-3.0 Licensed
28
- */
29
-
30
- // node_modules/.pnpm/tsup@8.5.0_@swc+core@1.12.9_tsx@4.20.3_typescript@5.8.3/node_modules/tsup/assets/cjs_shims.js
31
- var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
32
- var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
33
- var getPackageLogsPath = () => {
34
- const currentFileUrl = importMetaUrl;
35
- const currentFilePath = url.fileURLToPath(currentFileUrl);
36
- const currentDir = path__default.default.dirname(currentFilePath);
37
- let packageRoot = currentDir;
38
- while (packageRoot !== path__default.default.dirname(packageRoot)) {
39
- if (fs__default.default.existsSync(path__default.default.join(packageRoot, "package.json"))) {
40
- break;
41
- }
42
- packageRoot = path__default.default.dirname(packageRoot);
43
- }
44
- return path__default.default.join(packageRoot, "logs");
45
- };
46
- var logsPath = getPackageLogsPath();
47
- log4js__default.default.configure({
48
- appenders: {
49
- console: {
50
- type: "stdout",
51
- layout: {
52
- type: "pattern",
53
- pattern: "%[[amagi][%d{hh:mm:ss.SSS}][%4.4p]%] %m"
54
- }
55
- },
56
- command: {
57
- type: "dateFile",
58
- filename: path__default.default.join(logsPath, "application", "command"),
59
- pattern: "yyyy-MM-dd.log",
60
- numBackups: 15,
61
- alwaysIncludePattern: true,
62
- layout: {
63
- type: "pattern",
64
- pattern: "[%d{hh:mm:ss.SSS}][%4.4p] %m"
65
- }
66
- },
67
- httpConsole: {
68
- type: "stdout",
69
- layout: {
70
- type: "pattern",
71
- pattern: "%[[amagi][%d{hh:mm:ss.SSS}][HTTP]%] %m"
72
- }
73
- },
74
- httpRequest: {
75
- type: "dateFile",
76
- filename: path__default.default.join(logsPath, "http", "requests"),
77
- pattern: "yyyy-MM-dd.log",
78
- numBackups: 30,
79
- alwaysIncludePattern: true,
80
- layout: {
81
- type: "pattern",
82
- pattern: "[%d{hh:mm:ss.SSS}][%4.4p] %m"
83
- }
84
- }
85
- },
86
- categories: {
87
- default: { appenders: ["console", "command"], level: "info" },
88
- http: { appenders: ["httpConsole", "httpRequest"], level: "debug" }
89
- },
90
- pm2: true
91
- });
92
- var CustomLogger = class {
93
- logger;
94
- chalk;
95
- red;
96
- green;
97
- yellow;
98
- blue;
99
- magenta;
100
- cyan;
101
- white;
102
- gray;
103
- constructor(name) {
104
- this.logger = log4js__default.default.getLogger(name);
105
- this.chalk = new chalk.Chalk();
106
- this.red = this.chalk.red;
107
- this.green = this.chalk.green;
108
- this.yellow = this.chalk.yellow;
109
- this.blue = this.chalk.blue;
110
- this.magenta = this.chalk.magenta;
111
- this.cyan = this.chalk.cyan;
112
- this.white = this.chalk.white;
113
- this.gray = this.chalk.gray;
114
- }
115
- // 代理 log4js.Logger 的方法
116
- info(message, ...args) {
117
- this.logger.info(message, ...args);
118
- }
119
- warn(message, ...args) {
120
- this.logger.warn(message, ...args);
121
- }
122
- error(message, ...args) {
123
- this.logger.error(message, ...args);
124
- }
125
- mark(message, ...args) {
126
- this.logger.mark(message, ...args);
127
- }
128
- debug(message, ...args) {
129
- this.logger.debug(message, ...args);
130
- }
131
- };
132
- var logger = new CustomLogger("default");
133
- var httpLogger = new CustomLogger("http");
134
- var logMiddleware = (pathsToLog) => {
135
- return (req, res, next) => {
136
- if (!pathsToLog || pathsToLog.some((path2) => req.url.startsWith(path2))) {
137
- const startTime = Date.now();
138
- const url = req.url;
139
- const method = req.method;
140
- const clientIP = req.headers["x-forwarded-for"] || req.socket.remoteAddress;
141
- const referer = req.headers["referer"] || req.headers["referrer"] || "-";
142
- const contentType = req.headers["content-type"] || "-";
143
- const requestSize = req.headers["content-length"] || "0";
144
- const protocol = req.protocol;
145
- const httpVersion = req.httpVersion;
146
- res.on("finish", () => {
147
- const responseTime = Date.now() - startTime;
148
- const statusCode = res.statusCode;
149
- const responseSize = res.get("content-length") || "0";
150
- const logData = {
151
- method,
152
- url,
153
- statusCode,
154
- responseTime: `${responseTime}ms`,
155
- clientIP,
156
- referer,
157
- contentType,
158
- requestSize: `${requestSize}B`,
159
- responseSize: `${responseSize}B`,
160
- protocol,
161
- httpVersion,
162
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
163
- };
164
- httpLogger.debug(JSON.stringify(logData));
165
- });
166
- }
167
- next();
168
- };
169
- };
170
- var Networks = class {
171
- url;
172
- method;
173
- headers;
174
- type;
175
- body;
176
- axiosInstance;
177
- isGetResult;
178
- timeout;
179
- timer;
180
- data;
181
- constructor(data2) {
182
- this.headers = data2.headers ?? {};
183
- this.url = data2.url ?? "";
184
- this.type = data2.responseType ?? "json";
185
- this.method = data2.method ?? "GET";
186
- this.body = data2.body ?? null;
187
- this.data = {};
188
- this.timeout = data2.timeout ?? 15e3;
189
- this.isGetResult = false;
190
- this.timer = void 0;
191
- this.axiosInstance = axios__default.default.create({
192
- timeout: this.timeout,
193
- headers: this.headers,
194
- maxRedirects: 5,
195
- validateStatus: (status) => {
196
- return status >= 200 && status < 600;
197
- }
198
- });
199
- }
200
- get config() {
201
- let config = {
202
- url: this.url,
203
- method: this.method,
204
- headers: this.headers
205
- };
206
- if (this.method === "POST" && this.body) {
207
- config.data = this.body;
208
- }
209
- return config;
210
- }
211
- async getfetch() {
212
- try {
213
- const result = await this.returnResult();
214
- if (result.status === 504) {
215
- return result;
216
- }
217
- this.isGetResult = true;
218
- return result;
219
- } catch (error) {
220
- logger.info(error);
221
- return false;
222
- }
223
- }
224
- async returnResult() {
225
- return await this.axiosInstance(this.config);
226
- }
227
- /** 最终地址(跟随重定向) */
228
- async getLongLink() {
229
- try {
230
- const response = await this.axiosInstance({
231
- method: "GET",
232
- url: this.url
233
- });
234
- return response.request.res.responseUrl;
235
- } catch (error) {
236
- if (error instanceof axios.AxiosError) {
237
- throw new Error(error.stack);
238
- }
239
- return "";
240
- }
241
- }
242
- /** 获取首个302 */
243
- async getLocation() {
244
- try {
245
- const response = await this.axiosInstance({
246
- method: "GET",
247
- url: this.url,
248
- maxRedirects: 0,
249
- // 禁止跟随重定向
250
- validateStatus: (status) => status >= 300 && status < 400
251
- // 仅处理3xx响应
252
- });
253
- return response.headers["location"];
254
- } catch (error) {
255
- if (error instanceof axios.AxiosError) {
256
- throw new Error(error.stack);
257
- }
258
- return "";
259
- }
260
- }
261
- /** 获取数据并处理数据的格式化,默认json */
262
- async getData(new_fetch = "") {
263
- try {
264
- if (!new_fetch) {
265
- const result = await this.returnResult();
266
- if (result.status === 504) {
267
- return result;
268
- }
269
- if (result.status === 429) {
270
- logger.error("HTTP \u54CD\u5E94\u72B6\u6001\u7801: 429");
271
- throw new Error("ratelimit triggered, \u89E6\u53D1 https://www.douyin.com/ \u7684\u901F\u7387\u9650\u5236\uFF01\uFF01\uFF01");
272
- }
273
- this.axiosInstance = result;
274
- this.isGetResult = true;
275
- } else {
276
- this.axiosInstance = new_fetch;
277
- }
278
- return this.axiosInstance.data;
279
- } catch (error) {
280
- if (error instanceof axios.AxiosError) {
281
- throw new Error(error.stack);
282
- }
283
- return false;
284
- }
285
- }
286
- async getHeadersAndData() {
287
- try {
288
- const result = await this.axiosInstance(this.config);
289
- let headers2 = {};
290
- const fetchHeaders = result.headers;
291
- for (const [key, value] of Object.entries(fetchHeaders)) {
292
- headers2[key] = value;
293
- }
294
- return { headers: headers2, data: result.data };
295
- } catch (error) {
296
- console.error("\u83B7\u53D6\u54CD\u5E94\u5934\u548C\u6570\u636E\u5931\u8D25:", error);
297
- return { headers: null, data: null };
298
- }
299
- }
300
- };
301
-
302
- // src/platform/bilibili/qtparam.ts
303
- var qtparam = async (BASEURL, cookie) => {
304
- if (cookie === "") return { QUERY: "&platform=html5", STATUS: "!isLogin" };
305
- const logininfo = await new Networks({ url: bilibiliApiUrls.\u767B\u5F55\u57FA\u672C\u4FE1\u606F(), headers: { Cookie: cookie } }).getData();
306
- const sign = await wbi_sign(BASEURL, cookie);
307
- const qn = [6, 16, 32, 64, 74, 80, 112, 116, 120, 125, 126, 127];
308
- let isvip;
309
- logininfo.data.vipStatus === 1 ? isvip = true : isvip = false;
310
- if (isvip) {
311
- return { QUERY: `&fnval=16&fourk=1&${sign}`, STATUS: "isLogin", isvip };
312
- } else return { QUERY: `&qn=${qn[3]}&fnval=16`, STATUS: "isLogin", isvip };
313
- };
314
-
315
- // src/platform/bilibili/sign/bv2av.ts
316
- var XOR_CODE = 23442827791579n;
317
- var MASK_CODE = 2251799813685247n;
318
- var MAX_AID = 1n << 51n;
319
- var BASE = 58n;
320
- var data = "FcwAPNKTMug3GV5Lj7EJnHpWsx4tb8haYeviqBz6rkCy12mUSDQX9RdoZf";
321
- var av2bv = (aid) => {
322
- const bytes = ["B", "V", "1", "0", "0", "0", "0", "0", "0", "0", "0", "0"];
323
- let bvIndex = bytes.length - 1;
324
- let tmp = (MAX_AID | BigInt(aid)) ^ XOR_CODE;
325
- while (tmp > 0) {
326
- bytes[bvIndex] = data[Number(tmp % BigInt(BASE))];
327
- tmp = tmp / BASE;
328
- bvIndex -= 1;
329
- }
330
- [bytes[3], bytes[9]] = [bytes[9], bytes[3]];
331
- [bytes[4], bytes[7]] = [bytes[7], bytes[4]];
332
- return bytes.join("");
333
- };
334
- var bv2av = (bvid) => {
335
- const bvidArr = Array.from(bvid);
336
- [bvidArr[3], bvidArr[9]] = [bvidArr[9], bvidArr[3]];
337
- [bvidArr[4], bvidArr[7]] = [bvidArr[7], bvidArr[4]];
338
- bvidArr.splice(0, 3);
339
- const tmp = bvidArr.reduce((pre, bvidChar) => pre * BASE + BigInt(data.indexOf(bvidChar)), 0n);
340
- return Number(tmp & MASK_CODE ^ XOR_CODE);
341
- };
342
-
343
- // src/platform/bilibili/API.ts
344
- var BiLiBiLiAPI = class {
345
- \u767B\u5F55\u57FA\u672C\u4FE1\u606F() {
346
- return "https://api.bilibili.com/x/web-interface/nav";
347
- }
348
- \u89C6\u9891\u8BE6\u7EC6\u4FE1\u606F(data2) {
349
- return `https://api.bilibili.com/x/web-interface/view?bvid=${data2.bvid}`;
350
- }
351
- \u89C6\u9891\u6D41\u4FE1\u606F(data2) {
352
- return `https://api.bilibili.com/x/player/playurl?avid=${data2.avid}&cid=${data2.cid}`;
353
- }
354
- /** 评论区类型,type参数详见 [评论区类型代码](https://github.com/SocialSisterYi/bilibili-API-collect/blob/master/docs/comment/readme.md#评论区类型代码) */
355
- \u8BC4\u8BBA\u533A\u660E\u7EC6(data2) {
356
- return `https://api.bilibili.com/x/v2/reply?sort=1&ps=${data2.number ?? 20}&type=${data2.type}&oid=${data2.oid}&pn=${data2.pn}`;
357
- }
358
- \u8BC4\u8BBA\u533A\u72B6\u6001(data2) {
359
- return `https://api.bilibili.com/x/v2/reply/subject/description?type=${data2.type}&oid=${data2.oid}`;
360
- }
361
- \u8868\u60C5\u5217\u8868() {
362
- return "https://api.bilibili.com/x/emote/user/panel/web?business=reply&web_location=0.0";
363
- }
364
- \u756A\u5267\u660E\u7EC6(data2) {
365
- if (data2.ep_id) {
366
- return `https://api.bilibili.com/pgc/view/web/season?ep_id=${data2.ep_id}`;
367
- } else if (data2.season_id) {
368
- return `https://api.bilibili.com/pgc/view/web/season?season_id=${data2.season_id}`;
369
- } else {
370
- throw new Error("\u62DF\u9020\u63A5\u53E3\u5730\u5740\u51FA\u9519\uFF0C\u7F3A\u5C11 ep_id \u6216 season_id \u53C2\u6570");
371
- }
372
- }
373
- \u756A\u5267\u89C6\u9891\u6D41\u4FE1\u606F(data2) {
374
- return `https://api.bilibili.com/pgc/player/web/playurl?cid=${data2.cid}&ep_id=${data2.ep_id}`;
375
- }
376
- \u7528\u6237\u7A7A\u95F4\u52A8\u6001(data2) {
377
- return `https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/space?host_mid=${data2.host_mid}`;
378
- }
379
- \u52A8\u6001\u8BE6\u60C5(data2) {
380
- return `https://api.bilibili.com/x/polymer/web-dynamic/v1/detail?id=${data2.dynamic_id}`;
381
- }
382
- \u52A8\u6001\u5361\u7247\u4FE1\u606F(data2) {
383
- return `https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/get_dynamic_detail?dynamic_id=${data2.dynamic_id}`;
384
- }
385
- \u7528\u6237\u540D\u7247\u4FE1\u606F(data2) {
386
- return `https://api.bilibili.com/x/web-interface/card?mid=${data2.host_mid}&photo=true`;
387
- }
388
- \u76F4\u64AD\u95F4\u4FE1\u606F(data2) {
389
- return `https://api.live.bilibili.com/room/v1/Room/get_info?room_id=${data2.room_id}`;
390
- }
391
- \u76F4\u64AD\u95F4\u521D\u59CB\u5316\u4FE1\u606F(data2) {
392
- return `https://api.live.bilibili.com/room/v1/Room/room_init?id=${data2.room_id}`;
393
- }
394
- \u7533\u8BF7\u4E8C\u7EF4\u7801() {
395
- return "https://passport.bilibili.com/x/passport-login/web/qrcode/generate";
396
- }
397
- \u4E8C\u7EF4\u7801\u72B6\u6001(data2) {
398
- return `https://passport.bilibili.com/x/passport-login/web/qrcode/poll?qrcode_key=${data2.qrcode_key}`;
399
- }
400
- \u83B7\u53D6UP\u4E3B\u603B\u64AD\u653E\u91CF(data2) {
401
- return `https://api.bilibili.com/x/space/upstat?mid=${data2.host_mid}`;
402
- }
403
- };
404
- var bilibiliApiUrls = new BiLiBiLiAPI();
405
-
406
- // src/types/NetworksConfigType.ts
407
- var kuaishouAPIErrorCode = /* @__PURE__ */ ((kuaishouAPIErrorCode2) => {
408
- kuaishouAPIErrorCode2["COOKIE"] = "INVALID_COOKIE";
409
- kuaishouAPIErrorCode2["UNKNOWN"] = "UNKNOWN_ERROR" /* UNKNOWN */;
410
- return kuaishouAPIErrorCode2;
411
- })(kuaishouAPIErrorCode || {});
412
-
413
- // src/platform/bilibili/getdata.ts
414
- var defheaders = {
415
- accept: "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
416
- "accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
417
- "cache-control": "max-age=0",
418
- priority: "u=0, i",
419
- "sec-ch-ua": "'Microsoft Edge';v='131', 'Chromium';v='131', 'Not_A Brand';v='24'",
420
- "sec-ch-ua-mobile": "?0",
421
- "sec-ch-ua-platform": "'Windows'",
422
- "sec-fetch-dest": "document",
423
- "sec-fetch-mode": "navigate",
424
- "sec-fetch-site": "none",
425
- "sec-fetch-user": "?1",
426
- "upgrade-insecure-requests": "1",
427
- referer: "https://www.bilibili.com/"
428
- };
429
- var fetchBilibili = async (data2, cookie) => {
430
- const headers2 = {
431
- ...defheaders,
432
- cookie: cookie ? cookie.replace(/\s+/g, "") : ""
433
- };
434
- switch (data2.methodType) {
435
- case "\u5355\u4E2A\u89C6\u9891\u4F5C\u54C1\u6570\u636E": {
436
- const INFODATA = await GlobalGetData({
437
- url: bilibiliApiUrls.\u89C6\u9891\u8BE6\u7EC6\u4FE1\u606F({ bvid: data2.bvid }),
438
- ...data2
439
- });
440
- return INFODATA;
441
- }
442
- case "\u5355\u4E2A\u89C6\u9891\u4E0B\u8F7D\u4FE1\u606F\u6570\u636E": {
443
- const BASEURL = bilibiliApiUrls.\u89C6\u9891\u6D41\u4FE1\u606F({ avid: data2.avid, cid: data2.cid });
444
- const SIGN = await qtparam(BASEURL, headers2.cookie);
445
- const DATA = await GlobalGetData({
446
- url: bilibiliApiUrls.\u89C6\u9891\u6D41\u4FE1\u606F({ avid: data2.avid, cid: data2.cid }) + SIGN.QUERY,
447
- headers: headers2,
448
- ...data2
449
- });
450
- return DATA;
451
- }
452
- case "\u8BC4\u8BBA\u6570\u636E": {
453
- let { oid, number, pn, type } = data2;
454
- let fetchedComments = [];
455
- pn = pn ?? 1;
456
- const maxRequestCount = 100;
457
- const commentGrowthStabilized = 5;
458
- let lastFetchedCount = 0;
459
- let stabilizedCount = 0;
460
- let requestCount = 0;
461
- let tmpresp;
462
- while (fetchedComments.length < Number(number ?? 20) && requestCount < maxRequestCount) {
463
- if (number === 0 || number === void 0) {
464
- requestCount = 0;
465
- } else {
466
- requestCount = Math.min(20, Number(number) - fetchedComments.length);
467
- }
468
- const url = bilibiliApiUrls.\u8BC4\u8BBA\u533A\u660E\u7EC6({
469
- type,
470
- oid,
471
- number: requestCount,
472
- pn
473
- });
474
- const checkStatusUrl = bilibiliApiUrls.\u8BC4\u8BBA\u533A\u72B6\u6001({ oid, type });
475
- const checkStatusRes = await GlobalGetData({
476
- url: checkStatusUrl,
477
- headers: headers2,
478
- ...data2
479
- });
480
- if (checkStatusRes.data === null) {
481
- logger.error("\u8BC4\u8BBA\u533A\u672A\u5F00\u653E");
482
- return {
483
- code: 404,
484
- message: "\u8BC4\u8BBA\u533A\u672A\u5F00\u653E",
485
- data: null
486
- };
487
- }
488
- const response = await GlobalGetData({
489
- url,
490
- headers: headers2,
491
- ...data2
492
- });
493
- tmpresp = response;
494
- const currentCount = response.data.replies ? response.data.replies.length : 0;
495
- fetchedComments.push(...response.data.replies || []);
496
- if (currentCount === lastFetchedCount) {
497
- stabilizedCount++;
498
- } else {
499
- stabilizedCount = 0;
500
- }
501
- lastFetchedCount = currentCount;
502
- if (stabilizedCount >= commentGrowthStabilized || requestCount >= maxRequestCount) {
503
- break;
504
- }
505
- pn++;
506
- requestCount++;
507
- }
508
- const finalResponse = {
509
- ...tmpresp,
510
- data: {
511
- ...tmpresp.data,
512
- // 去重
513
- replies: Array.from(new Map(fetchedComments.map((item) => [item.rpid, item])).values()).slice(0, Number(data2.number))
514
- }
515
- };
516
- return finalResponse;
517
- }
518
- case "Emoji\u6570\u636E": {
519
- return await GlobalGetData({
520
- url: bilibiliApiUrls.\u8868\u60C5\u5217\u8868(),
521
- ...data2
522
- });
523
- }
524
- case "\u756A\u5267\u57FA\u672C\u4FE1\u606F\u6570\u636E": {
525
- let id = data2.ep_id ? data2.ep_id : data2.season_id;
526
- if (!id) {
527
- return false;
528
- }
529
- const idType = id ? id.startsWith("ep") ? "ep_id" : "season_id" : "ep_id";
530
- const newId = idType === "ep_id" ? id.replace("ep", "") : id.replace("ss", "");
531
- const INFO = await GlobalGetData({
532
- url: bilibiliApiUrls.\u756A\u5267\u660E\u7EC6({ [idType]: newId }),
533
- headers: headers2,
534
- ...data2
535
- });
536
- return INFO;
537
- }
538
- case "\u756A\u5267\u4E0B\u8F7D\u4FE1\u606F\u6570\u636E": {
539
- const BASEURL = bilibiliApiUrls.\u756A\u5267\u89C6\u9891\u6D41\u4FE1\u606F({ cid: data2.cid, ep_id: data2.ep_id.replace("ep", "") });
540
- const SIGN = await qtparam(BASEURL, headers2.cookie);
541
- const DATA = await GlobalGetData({
542
- url: bilibiliApiUrls.\u756A\u5267\u89C6\u9891\u6D41\u4FE1\u606F({ cid: data2.cid, ep_id: data2.ep_id.replace("ep", "") }) + SIGN.QUERY,
543
- headers: headers2,
544
- ...data2
545
- });
546
- return DATA;
547
- }
548
- case "\u7528\u6237\u4E3B\u9875\u52A8\u6001\u5217\u8868\u6570\u636E": {
549
- delete headers2.referer;
550
- const { host_mid } = data2;
551
- const result = await GlobalGetData({
552
- url: bilibiliApiUrls.\u7528\u6237\u7A7A\u95F4\u52A8\u6001({ host_mid }),
553
- headers: headers2,
554
- ...data2
555
- });
556
- return result;
557
- }
558
- case "\u52A8\u6001\u8BE6\u60C5\u6570\u636E": {
559
- delete headers2.referer;
560
- const dynamicINFO = await GlobalGetData({
561
- url: bilibiliApiUrls.\u52A8\u6001\u8BE6\u60C5({ dynamic_id: data2.dynamic_id }),
562
- headers: headers2,
563
- ...data2
564
- });
565
- return dynamicINFO;
566
- }
567
- case "\u52A8\u6001\u5361\u7247\u6570\u636E": {
568
- delete headers2.referer;
569
- const { dynamic_id } = data2;
570
- const dynamicINFO_CARD = await GlobalGetData({
571
- url: bilibiliApiUrls.\u52A8\u6001\u5361\u7247\u4FE1\u606F({ dynamic_id }),
572
- headers: headers2,
573
- ...data2
574
- });
575
- return dynamicINFO_CARD;
576
- }
577
- case "\u7528\u6237\u4E3B\u9875\u6570\u636E": {
578
- const { host_mid } = data2;
579
- const result = await GlobalGetData({
580
- url: bilibiliApiUrls.\u7528\u6237\u540D\u7247\u4FE1\u606F({ host_mid }),
581
- headers: headers2,
582
- ...data2
583
- });
584
- return result;
585
- }
586
- case "\u76F4\u64AD\u95F4\u4FE1\u606F": {
587
- const result = await GlobalGetData({
588
- url: bilibiliApiUrls.\u76F4\u64AD\u95F4\u4FE1\u606F({ room_id: data2.room_id }),
589
- headers: headers2,
590
- ...data2
591
- });
592
- return result;
593
- }
594
- case "\u76F4\u64AD\u95F4\u521D\u59CB\u5316\u4FE1\u606F": {
595
- const result = await GlobalGetData({
596
- url: bilibiliApiUrls.\u76F4\u64AD\u95F4\u521D\u59CB\u5316\u4FE1\u606F({ room_id: data2.room_id }),
597
- headers: headers2,
598
- ...data2
599
- });
600
- return result;
601
- }
602
- case "\u7533\u8BF7\u4E8C\u7EF4\u7801": {
603
- const result = await GlobalGetData({
604
- url: bilibiliApiUrls.\u7533\u8BF7\u4E8C\u7EF4\u7801(),
605
- headers: headers2,
606
- ...data2
607
- });
608
- return result;
609
- }
610
- case "\u4E8C\u7EF4\u7801\u72B6\u6001": {
611
- const result = await new Networks({
612
- url: bilibiliApiUrls.\u4E8C\u7EF4\u7801\u72B6\u6001({ qrcode_key: data2.qrcode_key }),
613
- headers: headers2,
614
- ...data2
615
- }).getHeadersAndData();
616
- return result;
617
- }
618
- case "\u767B\u5F55\u57FA\u672C\u4FE1\u606F": {
619
- const result = await GlobalGetData({
620
- url: bilibiliApiUrls.\u767B\u5F55\u57FA\u672C\u4FE1\u606F(),
621
- headers: headers2,
622
- ...data2
623
- });
624
- return result;
625
- }
626
- case "\u83B7\u53D6UP\u4E3B\u603B\u64AD\u653E\u91CF": {
627
- const result = await GlobalGetData({
628
- url: bilibiliApiUrls.\u83B7\u53D6UP\u4E3B\u603B\u64AD\u653E\u91CF({ host_mid: data2.host_mid }),
629
- headers: headers2,
630
- ...data2
631
- });
632
- return result;
633
- }
634
- case "AV\u8F6CBV": {
635
- const result = av2bv(Number(data2.avid.toString().replace(/^av/i, "")));
636
- return {
637
- code: 0,
638
- message: "success",
639
- data: {
640
- bvid: result
641
- }
642
- };
643
- }
644
- case "BV\u8F6CAV": {
645
- const result = "av" + bv2av(data2.bvid);
646
- return {
647
- code: 0,
648
- message: "success",
649
- data: {
650
- aid: result
651
- }
652
- };
653
- }
654
- default:
655
- logger.warn(`\u672A\u77E5\u7684B\u7AD9\u6570\u636E\u63A5\u53E3\uFF1A\u300C${logger.red(data2.methodType)}\u300D`);
656
- return null;
657
- }
658
- };
659
- var GlobalGetData = async (options) => {
660
- let warningMessage = "";
661
- try {
662
- const result = await new Networks(options).getData();
663
- if (!result || result === "") {
664
- const Err = {
665
- errorDescription: "\u83B7\u53D6\u54CD\u5E94\u6570\u636E\u5931\u8D25\uFF01\u63A5\u53E3\u8FD4\u56DE\u5185\u5BB9\u4E3A\u7A7A\uFF0C\u4F60\u7684B\u7AD9ck\u53EF\u80FD\u5DF2\u7ECF\u5931\u6548\uFF01",
666
- requestType: options.methodType ?? "\u672A\u77E5\u8BF7\u6C42\u7C7B\u578B",
667
- requestUrl: options.url
668
- };
669
- warningMessage = `
670
- \u83B7\u53D6\u54CD\u5E94\u6570\u636E\u5931\u8D25\uFF01\u539F\u56E0\uFF1A${logger.yellow("\u63A5\u53E3\u8FD4\u56DE\u5185\u5BB9\u4E3A\u7A7A\uFF0C\u4F60\u7684B\u7AD9ck\u53EF\u80FD\u5DF2\u7ECF\u5931\u6548\uFF01")}
671
- \u8BF7\u6C42\u7C7B\u578B\uFF1A\u300C${options.methodType}\u300D
672
- \u8BF7\u6C42URL\uFF1A${options.url}
673
- `;
674
- logger.warn(warningMessage);
675
- throw {
676
- code: "-352" /* RISK_CONTROL_FAILED */,
677
- data: result,
678
- amagiError: Err
679
- };
680
- }
681
- if (result.code !== 0) {
682
- const errorMessage = bilibiliErrorCodeMap[result.code] || result.message || "\u672A\u77E5\u9519\u8BEF";
683
- const Err = {
684
- errorDescription: `\u83B7\u53D6\u54CD\u5E94\u6570\u636E\u5931\u8D25\uFF01\u539F\u56E0\uFF1A${errorMessage}\uFF01`,
685
- requestType: options.methodType ?? "\u672A\u77E5\u8BF7\u6C42\u7C7B\u578B",
686
- requestUrl: options.url
687
- };
688
- warningMessage = `
689
- \u83B7\u53D6\u54CD\u5E94\u6570\u636E\u5931\u8D25\uFF01\u539F\u56E0\uFF1A${logger.yellow(errorMessage)}
690
- \u9519\u8BEF\u4EE3\u7801\uFF1A${result.code}
691
- \u8BF7\u6C42\u7C7B\u578B\uFF1A\u300C${options.methodType}\u300D
692
- \u8BF7\u6C42URL\uFF1A${options.url}
693
- `;
694
- logger.warn(warningMessage);
695
- throw {
696
- code: result.code,
697
- data: result,
698
- amagiError: Err
699
- };
700
- }
701
- return result;
702
- } catch (error) {
703
- if (error && typeof error === "object") {
704
- const err = error;
705
- return { ...err, amagiMessage: warningMessage };
706
- }
707
- return {
708
- code: "UNKNOWN_ERROR" /* UNKNOWN */,
709
- data: error.data,
710
- amagiError: {
711
- errorDescription: "\u672A\u77E5\u9519\u8BEF",
712
- requestType: options.methodType,
713
- requestUrl: options.url
714
- },
715
- amagiMessage: warningMessage
716
- };
717
- }
718
- };
719
- var bilibiliErrorCodeMap = {
720
- "-1": "\u5E94\u7528\u7A0B\u5E8F\u4E0D\u5B58\u5728\u6216\u5DF2\u88AB\u5C01\u7981",
721
- "-2": "Access Key \u9519\u8BEF",
722
- "-3": "API \u6821\u9A8C\u5BC6\u5319\u9519\u8BEF",
723
- "-4": "\u8C03\u7528\u65B9\u5BF9\u8BE5 Method \u6CA1\u6709\u6743\u9650",
724
- "-101": "\u8D26\u53F7\u672A\u767B\u5F55",
725
- "-102": "\u8D26\u53F7\u88AB\u5C01\u505C",
726
- "-103": "\u79EF\u5206\u4E0D\u8DB3",
727
- "-104": "\u786C\u5E01\u4E0D\u8DB3",
728
- "-105": "\u9A8C\u8BC1\u7801\u9519\u8BEF",
729
- "-106": "\u8D26\u53F7\u975E\u6B63\u5F0F\u4F1A\u5458\u6216\u5728\u9002\u5E94\u671F",
730
- "-107": "\u5E94\u7528\u4E0D\u5B58\u5728\u6216\u8005\u88AB\u5C01\u7981",
731
- "-108": "\u672A\u7ED1\u5B9A\u624B\u673A",
732
- "-110": "\u672A\u7ED1\u5B9A\u624B\u673A",
733
- "-111": "csrf \u6821\u9A8C\u5931\u8D25",
734
- "-112": "\u7CFB\u7EDF\u5347\u7EA7\u4E2D",
735
- "-113": "\u8D26\u53F7\u5C1A\u672A\u5B9E\u540D\u8BA4\u8BC1",
736
- "-114": "\u8BF7\u5148\u7ED1\u5B9A\u624B\u673A",
737
- "-115": "\u8BF7\u5148\u5B8C\u6210\u5B9E\u540D\u8BA4\u8BC1",
738
- "-304": "\u6728\u6709\u6539\u52A8",
739
- "-307": "\u649E\u8F66\u8DF3\u8F6C",
740
- "-352": "\u98CE\u63A7\u6821\u9A8C\u5931\u8D25 (UA \u6216 wbi \u53C2\u6570\u4E0D\u5408\u6CD5)",
741
- "-400": "\u8BF7\u6C42\u9519\u8BEF",
742
- "-401": "\u672A\u8BA4\u8BC1 (\u6216\u975E\u6CD5\u8BF7\u6C42)",
743
- "-403": "\u8BBF\u95EE\u6743\u9650\u4E0D\u8DB3",
744
- "-404": "\u5565\u90FD\u6728\u6709",
745
- "-405": "\u4E0D\u652F\u6301\u8BE5\u65B9\u6CD5",
746
- "-409": "\u51B2\u7A81",
747
- "-412": "\u8BF7\u6C42\u88AB\u62E6\u622A (\u5BA2\u6237\u7AEF ip \u88AB\u670D\u52A1\u7AEF\u98CE\u63A7)",
748
- "-500": "\u670D\u52A1\u5668\u9519\u8BEF",
749
- "-503": "\u8FC7\u8F7D\u4FDD\u62A4,\u670D\u52A1\u6682\u4E0D\u53EF\u7528",
750
- "-504": "\u670D\u52A1\u8C03\u7528\u8D85\u65F6",
751
- "-509": "\u8D85\u51FA\u9650\u5236",
752
- "-616": "\u4E0A\u4F20\u6587\u4EF6\u4E0D\u5B58\u5728",
753
- "-617": "\u4E0A\u4F20\u6587\u4EF6\u592A\u5927",
754
- "-625": "\u767B\u5F55\u5931\u8D25\u6B21\u6570\u592A\u591A",
755
- "-626": "\u7528\u6237\u4E0D\u5B58\u5728",
756
- "-628": "\u5BC6\u7801\u592A\u5F31",
757
- "-629": "\u7528\u6237\u540D\u6216\u5BC6\u7801\u9519\u8BEF",
758
- "-632": "\u64CD\u4F5C\u5BF9\u8C61\u6570\u91CF\u9650\u5236",
759
- "-643": "\u88AB\u9501\u5B9A",
760
- "-650": "\u7528\u6237\u7B49\u7EA7\u592A\u4F4E",
761
- "-652": "\u91CD\u590D\u7684\u7528\u6237",
762
- "-658": "Token \u8FC7\u671F",
763
- "-662": "\u5BC6\u7801\u65F6\u95F4\u6233\u8FC7\u671F",
764
- "-688": "\u5730\u7406\u533A\u57DF\u9650\u5236",
765
- "-689": "\u7248\u6743\u9650\u5236",
766
- "-701": "\u6263\u8282\u64CD\u5931\u8D25",
767
- "-799": "\u8BF7\u6C42\u8FC7\u4E8E\u9891\u7E41\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5",
768
- "-8888": "\u5BF9\u4E0D\u8D77\uFF0C\u670D\u52A1\u5668\u5F00\u5C0F\u5DEE\u4E86~ (\u0CA5\uFE4F\u0CA5)"
769
- };
770
- var mixinKeyEncTab = [
771
- 46,
772
- 47,
773
- 18,
774
- 2,
775
- 53,
776
- 8,
777
- 23,
778
- 32,
779
- 15,
780
- 50,
781
- 10,
782
- 31,
783
- 58,
784
- 3,
785
- 45,
786
- 35,
787
- 27,
788
- 43,
789
- 5,
790
- 49,
791
- 33,
792
- 9,
793
- 42,
794
- 19,
795
- 29,
796
- 28,
797
- 14,
798
- 39,
799
- 12,
800
- 38,
801
- 41,
802
- 13,
803
- 37,
804
- 48,
805
- 7,
806
- 16,
807
- 24,
808
- 55,
809
- 40,
810
- 61,
811
- 26,
812
- 17,
813
- 0,
814
- 1,
815
- 60,
816
- 51,
817
- 30,
818
- 4,
819
- 22,
820
- 25,
821
- 54,
822
- 21,
823
- 56,
824
- 59,
825
- 6,
826
- 63,
827
- 57,
828
- 62,
829
- 11,
830
- 36,
831
- 20,
832
- 34,
833
- 44,
834
- 52
835
- ];
836
- var getMixinKey = (orig) => mixinKeyEncTab.map((n) => orig[n]).join("").slice(0, 32);
837
- var encWbi = (params, img_key, sub_key) => {
838
- const mixin_key = getMixinKey(img_key + sub_key);
839
- const curr_time = Math.round(Date.now() / 1e3);
840
- const chr_filter = /[!'()*]/g;
841
- Object.assign(params, { wts: curr_time });
842
- const query = Object.keys(params).sort().map((key) => {
843
- const value = params[key].toString().replace(chr_filter, "");
844
- return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
845
- }).join("&");
846
- const wbi_sign2 = crypto__default.default.createHash("md5").update(query + mixin_key).digest("hex");
847
- return `&wts=${curr_time}&w_rid=${wbi_sign2}`;
848
- };
849
- var getWbiKeys = async (cookie) => {
850
- const res = await axios__default.default("https://api.bilibili.com/x/web-interface/nav", {
851
- headers: {
852
- Cookie: cookie
853
- }
854
- });
855
- const response = res.data;
856
- const {
857
- data: {
858
- wbi_img: { img_url, sub_url }
859
- }
860
- } = response;
861
- return {
862
- img_key: img_url.slice(img_url.lastIndexOf("/") + 1, img_url.lastIndexOf(".")),
863
- sub_key: sub_url.slice(sub_url.lastIndexOf("/") + 1, sub_url.lastIndexOf("."))
864
- };
865
- };
866
- var wbi_sign = async (BASEURL, cookie) => {
867
- const web_keys = await getWbiKeys(cookie);
868
- const url = new URL(BASEURL);
869
- const params = {};
870
- for (const [key, value] of url.searchParams.entries()) {
871
- params[key] = value;
872
- }
873
- const query = encWbi(params, web_keys.img_key, web_keys.sub_key);
874
- return query;
875
- };
876
-
877
- // src/platform/douyin/sign/a_bogus.ts
878
- var SM3 = class {
879
- reg;
880
- chunk;
881
- size;
882
- constructor() {
883
- this.reg = [];
884
- this.chunk = [];
885
- this.size = 0;
886
- this.reset();
887
- }
888
- reset() {
889
- this.reg[0] = 1937774191;
890
- this.reg[1] = 1226093241;
891
- this.reg[2] = 388252375;
892
- this.reg[3] = 3666478592;
893
- this.reg[4] = 2842636476;
894
- this.reg[5] = 372324522;
895
- this.reg[6] = 3817729613;
896
- this.reg[7] = 2969243214;
897
- this.chunk = [];
898
- this.size = 0;
899
- }
900
- write(e) {
901
- const a = typeof e === "string" ? this.stringToBytes(e) : e;
902
- this.size += a.length;
903
- let f = 64 - this.chunk.length;
904
- if (a.length < f) {
905
- this.chunk = this.chunk.concat(a);
906
- } else {
907
- this.chunk = this.chunk.concat(a.slice(0, f));
908
- while (this.chunk.length >= 64) {
909
- this._compress(this.chunk);
910
- f < a.length ? this.chunk = a.slice(f, Math.min(f + 64, a.length)) : this.chunk = [];
911
- f += 64;
912
- }
913
- }
914
- }
915
- sum(e, t) {
916
- if (e) {
917
- this.reset();
918
- this.write(e);
919
- }
920
- this._fill();
921
- for (let f = 0; f < this.chunk.length; f += 64) {
922
- this._compress(this.chunk.slice(f, f + 64));
923
- }
924
- let i = null;
925
- if (t === "hex") {
926
- i = "";
927
- for (let f = 0; f < 8; f++) {
928
- i += this.padHex(this.reg[f].toString(16), 8);
929
- }
930
- } else {
931
- i = new Array(32);
932
- for (let f = 0; f < 8; f++) {
933
- let c = this.reg[f];
934
- i[4 * f + 3] = (255 & c) >>> 0;
935
- c >>>= 8;
936
- i[4 * f + 2] = (255 & c) >>> 0;
937
- c >>>= 8;
938
- i[4 * f + 1] = (255 & c) >>> 0;
939
- c >>>= 8;
940
- i[4 * f] = (255 & c) >>> 0;
941
- }
942
- }
943
- this.reset();
944
- return i;
945
- }
946
- _compress(t) {
947
- if (t.length < 64) {
948
- console.error("compress error: not enough data");
949
- } else {
950
- for (var f = ((e) => {
951
- for (var r = new Array(132), t2 = 0; t2 < 16; t2++) {
952
- r[t2] = e[4 * t2] << 24, r[t2] |= e[4 * t2 + 1] << 16, r[t2] |= e[4 * t2 + 2] << 8, r[t2] |= e[4 * t2 + 3], r[t2] >>>= 0;
953
- }
954
- for (var n = 16; n < 68; n++) {
955
- let a = r[n - 16] ^ r[n - 9] ^ this.le(r[n - 3], 15);
956
- a = a ^ this.le(a, 15) ^ this.le(a, 23), r[n] = (a ^ this.le(r[n - 13], 7) ^ r[n - 6]) >>> 0;
957
- }
958
- for (n = 0; n < 64; n++) r[n + 68] = (r[n] ^ r[n + 4]) >>> 0;
959
- return r;
960
- })(t), i = this.reg.slice(0), c = 0; c < 64; c++) {
961
- let o = this.le(i[0], 12) + i[4] + this.le(this.de(c), c);
962
- const s = ((o = this.le(o = (4294967295 & o) >>> 0, 7)) ^ this.le(i[0], 12)) >>> 0;
963
- let u = this.pe(c, i[0], i[1], i[2]);
964
- u = (4294967295 & (u = u + i[3] + s + f[c + 68])) >>> 0;
965
- let b = this.he(c, i[4], i[5], i[6]);
966
- b = (4294967295 & (b = b + i[7] + o + f[c])) >>> 0, i[3] = i[2], i[2] = this.le(i[1], 9), i[1] = i[0], i[0] = u, i[7] = i[6], i[6] = this.le(i[5], 19), i[5] = i[4], i[4] = (b ^ this.le(b, 9) ^ this.le(b, 17)) >>> 0;
967
- }
968
- for (let l = 0; l < 8; l++) this.reg[l] = (this.reg[l] ^ i[l]) >>> 0;
969
- }
970
- }
971
- _fill() {
972
- let a = 8 * this.size;
973
- let f = this.chunk.push(128) % 64;
974
- while (64 - f < 8) {
975
- f -= 64;
976
- }
977
- while (f < 56) {
978
- this.chunk.push(0);
979
- f++;
980
- }
981
- for (let i = 0; i < 4; i++) {
982
- const c = Math.floor(a / 4294967296);
983
- this.chunk.push(c >>> 8 * (3 - i) & 255);
984
- }
985
- for (let i = 0; i < 4; i++) {
986
- this.chunk.push(a >>> 8 * (3 - i) & 255);
987
- }
988
- }
989
- de(e) {
990
- return e >= 0 && e < 16 ? 2043430169 : e >= 16 && e < 64 ? 2055708042 : (console.error("invalid j for constant Tj"), 0);
991
- }
992
- pe(e, r, t, n) {
993
- return e >= 0 && e < 16 ? (r ^ t ^ n) >>> 0 : e >= 16 && e < 64 ? (r & t | r & n | t & n) >>> 0 : (console.error("invalid j for bool function FF"), 0);
994
- }
995
- he(e, r, t, n) {
996
- return e >= 0 && e < 16 ? (r ^ t ^ n) >>> 0 : e >= 16 && e < 64 ? (r & t | ~r & n) >>> 0 : (console.error("invalid j for bool function GG"), 0);
997
- }
998
- le(e, r) {
999
- return (e << (r %= 32) | e >>> 32 - r) >>> 0;
1000
- }
1001
- stringToBytes(str) {
1002
- const n = encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, (_, r) => String.fromCharCode(parseInt(r, 16)));
1003
- const a = new Array(n.length);
1004
- for (let i = 0; i < n.length; i++) {
1005
- a[i] = n.charCodeAt(i);
1006
- }
1007
- return a;
1008
- }
1009
- padHex(num, size) {
1010
- return num.padStart(size, "0");
1011
- }
1012
- };
1013
- function rc4_encrypt(plaintext, key) {
1014
- const s = [];
1015
- for (var i = 0; i < 256; i++) {
1016
- s[i] = i;
1017
- }
1018
- var j = 0;
1019
- for (var i = 0; i < 256; i++) {
1020
- j = (j + s[i] + key.charCodeAt(i % key.length)) % 256;
1021
- var temp = s[i];
1022
- s[i] = s[j];
1023
- s[j] = temp;
1024
- }
1025
- var i = 0;
1026
- var j = 0;
1027
- const cipher = [];
1028
- for (let k = 0; k < plaintext.length; k++) {
1029
- i = (i + 1) % 256;
1030
- j = (j + s[i]) % 256;
1031
- var temp = s[i];
1032
- s[i] = s[j];
1033
- s[j] = temp;
1034
- const t = (s[i] + s[j]) % 256;
1035
- cipher.push(String.fromCharCode(s[t] ^ plaintext.charCodeAt(k)));
1036
- }
1037
- return cipher.join("");
1038
- }
1039
- function result_encrypt(long_str, num) {
1040
- const s_obj = {
1041
- s0: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
1042
- s1: "Dkdpgh4ZKsQB80/Mfvw36XI1R25+WUAlEi7NLboqYTOPuzmFjJnryx9HVGcaStCe=",
1043
- s2: "Dkdpgh4ZKsQB80/Mfvw36XI1R25-WUAlEi7NLboqYTOPuzmFjJnryx9HVGcaStCe=",
1044
- s3: "ckdp1h4ZKsUB80/Mfvw36XIgR25+WQAlEi7NLboqYTOPuzmFjJnryx9HVGDaStCe",
1045
- s4: "Dkdpgh2ZmsQB80/MfvV36XI1R45-WUAlEixNLwoqYTOPuzKFjJnry79HbGcaStCe"
1046
- };
1047
- const constant = {
1048
- 0: 16515072,
1049
- 1: 258048,
1050
- 2: 4032,
1051
- str: s_obj[num]
1052
- };
1053
- let result = "";
1054
- let lound = 0;
1055
- let long_int = get_long_int(lound, long_str);
1056
- for (let i = 0; i < long_str.length / 3 * 4; i++) {
1057
- if (Math.floor(i / 4) !== lound) {
1058
- lound += 1;
1059
- long_int = get_long_int(lound, long_str);
1060
- }
1061
- let key = i % 4;
1062
- let temp_int;
1063
- switch (key) {
1064
- case 0:
1065
- temp_int = (long_int & constant["0"]) >> 18;
1066
- result += constant["str"].charAt(temp_int);
1067
- break;
1068
- case 1:
1069
- temp_int = (long_int & constant["1"]) >> 12;
1070
- result += constant["str"].charAt(temp_int);
1071
- break;
1072
- case 2:
1073
- temp_int = (long_int & constant["2"]) >> 6;
1074
- result += constant["str"].charAt(temp_int);
1075
- break;
1076
- case 3:
1077
- temp_int = long_int & 63;
1078
- result += constant["str"].charAt(temp_int);
1079
- break;
1080
- }
1081
- }
1082
- return result;
1083
- }
1084
- function get_long_int(round, long_str) {
1085
- round = round * 3;
1086
- return long_str.charCodeAt(round) << 16 | long_str.charCodeAt(round + 1) << 8 | long_str.charCodeAt(round + 2);
1087
- }
1088
- function gener_random(random, option) {
1089
- return [
1090
- random & 255 & 170 | option[0] & 85,
1091
- // 163
1092
- random & 255 & 85 | option[0] & 170,
1093
- // 87
1094
- random >> 8 & 255 & 170 | option[1] & 85,
1095
- // 37
1096
- random >> 8 & 255 & 85 | option[1] & 170
1097
- // 41
1098
- ];
1099
- }
1100
- function generate_rc4_bb_str(url_search_params, user_agent, window_env_str, suffix = "cus", Arguments = [0, 1, 14]) {
1101
- let sm3 = new SM3();
1102
- let start_time = Date.now();
1103
- const url_search_params_list = sm3.sum(sm3.sum(url_search_params + suffix));
1104
- const cus = sm3.sum(sm3.sum(suffix));
1105
- const ua = sm3.sum(result_encrypt(rc4_encrypt(user_agent, String.fromCharCode.apply(null, [390625e-8, 1, 14])), "s3"));
1106
- const end_time = Date.now();
1107
- let b = {
1108
- 8: 3,
1109
- // 固定
1110
- 10: end_time,
1111
- // 3次加密结束时间
1112
- 15: {
1113
- aid: 6383,
1114
- pageId: 6241},
1115
- 16: start_time,
1116
- // 3次加密开始时间
1117
- 18: 44};
1118
- b[20] = b[16] >> 24 & 255;
1119
- b[21] = b[16] >> 16 & 255;
1120
- b[22] = b[16] >> 8 & 255;
1121
- b[23] = b[16] & 255;
1122
- b[24] = b[16] / 256 / 256 / 256 / 256 >> 0;
1123
- b[25] = b[16] / 256 / 256 / 256 / 256 / 256 >> 0;
1124
- b[26] = Arguments[0] >> 24 & 255;
1125
- b[27] = Arguments[0] >> 16 & 255;
1126
- b[28] = Arguments[0] >> 8 & 255;
1127
- b[29] = Arguments[0] & 255;
1128
- b[30] = Arguments[1] / 256 & 255;
1129
- b[31] = Arguments[1] % 256 & 255;
1130
- b[32] = Arguments[1] >> 24 & 255;
1131
- b[33] = Arguments[1] >> 16 & 255;
1132
- b[34] = Arguments[2] >> 24 & 255;
1133
- b[35] = Arguments[2] >> 16 & 255;
1134
- b[36] = Arguments[2] >> 8 & 255;
1135
- b[37] = Arguments[2] & 255;
1136
- b[38] = url_search_params_list[21];
1137
- b[39] = url_search_params_list[22];
1138
- b[40] = cus[21];
1139
- b[41] = cus[22];
1140
- b[42] = ua[23];
1141
- b[43] = ua[24];
1142
- b[44] = b[10] >> 24 & 255;
1143
- b[45] = b[10] >> 16 & 255;
1144
- b[46] = b[10] >> 8 & 255;
1145
- b[47] = b[10] & 255;
1146
- b[48] = b[8];
1147
- b[49] = b[10] / 256 / 256 / 256 / 256 >> 0;
1148
- b[50] = b[10] / 256 / 256 / 256 / 256 / 256 >> 0;
1149
- b[51] = b[15].pageId;
1150
- b[52] = b[15].pageId >> 24 & 255;
1151
- b[53] = b[15].pageId >> 16 & 255;
1152
- b[54] = b[15].pageId >> 8 & 255;
1153
- b[55] = b[15].pageId & 255;
1154
- b[56] = b[15].aid;
1155
- b[57] = b[15].aid & 255;
1156
- b[58] = b[15].aid >> 8 & 255;
1157
- b[59] = b[15].aid >> 16 & 255;
1158
- b[60] = b[15].aid >> 24 & 255;
1159
- const window_env_list = [];
1160
- for (let index = 0; index < window_env_str.length; index++) {
1161
- window_env_list.push(window_env_str.charCodeAt(index));
1162
- }
1163
- b[64] = window_env_list.length;
1164
- b[65] = b[64] & 255;
1165
- b[66] = b[64] >> 8 & 255;
1166
- b[69] = [].length;
1167
- b[70] = b[69] & 255;
1168
- b[71] = b[69] >> 8 & 255;
1169
- b[72] = b[18] ^ b[20] ^ b[26] ^ b[30] ^ b[38] ^ b[40] ^ b[42] ^ b[21] ^ b[27] ^ b[31] ^ b[35] ^ b[39] ^ b[41] ^ b[43] ^ b[22] ^ b[28] ^ b[32] ^ b[36] ^ b[23] ^ b[29] ^ b[33] ^ b[37] ^ b[44] ^ b[45] ^ b[46] ^ b[47] ^ b[48] ^ b[49] ^ b[50] ^ b[24] ^ b[25] ^ b[52] ^ b[53] ^ b[54] ^ b[55] ^ b[57] ^ b[58] ^ b[59] ^ b[60] ^ b[65] ^ b[66] ^ b[70] ^ b[71];
1170
- let bb = [
1171
- b[18],
1172
- b[20],
1173
- b[52],
1174
- b[26],
1175
- b[30],
1176
- b[34],
1177
- b[58],
1178
- b[38],
1179
- b[40],
1180
- b[53],
1181
- b[42],
1182
- b[21],
1183
- b[27],
1184
- b[54],
1185
- b[55],
1186
- b[31],
1187
- b[35],
1188
- b[57],
1189
- b[39],
1190
- b[41],
1191
- b[43],
1192
- b[22],
1193
- b[28],
1194
- b[32],
1195
- b[60],
1196
- b[36],
1197
- b[23],
1198
- b[29],
1199
- b[33],
1200
- b[37],
1201
- b[44],
1202
- b[45],
1203
- b[59],
1204
- b[46],
1205
- b[47],
1206
- b[48],
1207
- b[49],
1208
- b[50],
1209
- b[24],
1210
- b[25],
1211
- b[65],
1212
- b[66],
1213
- b[70],
1214
- b[71]
1215
- ];
1216
- bb = bb.concat(window_env_list).concat(b[72]);
1217
- return rc4_encrypt(String.fromCharCode.apply(null, bb), String.fromCharCode.apply(null, [121]));
1218
- }
1219
- function generate_random_str() {
1220
- let random_str_list = [];
1221
- random_str_list = random_str_list.concat(gener_random(Math.random() * 1e4, [3, 45]));
1222
- random_str_list = random_str_list.concat(gener_random(Math.random() * 1e4, [1, 0]));
1223
- random_str_list = random_str_list.concat(gener_random(Math.random() * 1e4, [1, 5]));
1224
- return String.fromCharCode.apply(null, random_str_list);
1225
- }
1226
- var a_bogus_default = (url, user_agent) => {
1227
- let result_str = generate_random_str() + generate_rc4_bb_str(new URLSearchParams(new URL(url).search).toString(), user_agent, "1536|747|1536|834|0|30|0|0|1536|834|1536|864|1525|747|24|24|Win32");
1228
- return result_encrypt(result_str, "s4") + "=";
1229
- };
1230
-
1231
- // src/platform/douyin/sign/index.ts
1232
- var headers = {
1233
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36"
1234
- };
1235
- var douyinSign = class {
1236
- /**
1237
- * 生成一个指定长度的随机字符串
1238
- * @param length 字符串长度,默认为116
1239
- * @returns
1240
- */
1241
- static Mstoken(length) {
1242
- const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
1243
- const randomBytes = crypto__default.default.randomBytes(length ?? 116);
1244
- return Array.from(randomBytes, (byte) => characters[byte % characters.length]).join("");
1245
- }
1246
- /**
1247
- * a_bogus 签名算法
1248
- * @param url 需要签名的地址
1249
- * @returns 对此地址签名后的URL查询参数
1250
- */
1251
- static AB(url) {
1252
- return a_bogus_default(url, headers["User-Agent"]);
1253
- }
1254
- /** 生成一个唯一的验证字符串 */
1255
- static VerifyFpManager() {
1256
- const e = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split("");
1257
- const t = e.length;
1258
- const n = (/* @__PURE__ */ new Date()).getTime().toString(36);
1259
- const r = [];
1260
- r[8] = "_";
1261
- r[13] = "_";
1262
- r[18] = "_";
1263
- r[23] = "_";
1264
- r[14] = "4";
1265
- for (let o, i = 0; i < 36; i++) {
1266
- if (!r[i]) {
1267
- o = 0 | Math.random() * t;
1268
- r[i] = e[i === 19 ? 3 & o | 8 : o];
1269
- }
1270
- }
1271
- return "verify_" + n + "_" + r.join("");
1272
- }
1273
- };
1274
-
1275
- // src/platform/douyin/API.ts
1276
- var fp = douyinSign.VerifyFpManager();
1277
- var DouyinAPI = class {
1278
- \u89C6\u9891\u6216\u56FE\u96C6(data2) {
1279
- return `https://www.douyin.com/aweme/v1/web/aweme/detail/?device_platform=webapp&aid=6383&channel=channel_pc_web&aweme_id=${data2.aweme_id}&update_version_code=170400&pc_client_type=1&version_code=190500&version_name=19.5.0&cookie_enabled=true&screen_width=2328&screen_height=1310&browser_language=zh-CN&browser_platform=Win32&browser_name=Chrome&browser_version=125.0.0.0&browser_online=true&engine_name=Blink&engine_version=125.0.0.0&os_name=Windows&os_version=10&cpu_core_num=16&device_memory=8&platform=PC&downlink=10&effective_type=4g&round_trip_time=150&webid=7351848354471872041&msToken=${douyinSign.Mstoken(
1280
- 116
1281
- )}&verifyFp=${fp}&fp=${fp}`;
1282
- }
1283
- \u8BC4\u8BBA(data2) {
1284
- return `https://www.douyin.com/aweme/v1/web/comment/list/?device_platform=webapp&aid=6383&channel=channel_pc_web&aweme_id=${data2.aweme_id}&cursor=${data2.cursor ?? 0}&count=${data2.number ?? 50}&item_type=0&insert_ids=&whale_cut_token=&cut_version=1&rcFT=&pc_client_type=1&version_code=170400&version_name=17.4.0&cookie_enabled=true&screen_width=1552&screen_height=970&browser_language=zh-CN&browser_platform=Win32&browser_name=Chrome&browser_version=125.0.0.0&browser_online=true&engine_name=Blink&engine_version=125.0.0.0&os_name=Windows&os_version=10&cpu_core_num=16&device_memory=8&platform=PC&downlink=10&effective_type=4g&msToken=${douyinSign.Mstoken(
1285
- 116
1286
- )}&verifyFp=${fp}&fp=${fp}`;
1287
- }
1288
- \u4E8C\u7EA7\u8BC4\u8BBA(data2) {
1289
- return `https://www.douyin.com/aweme/v1/web/comment/list/reply/?device_platform=webapp&aid=6383&channel=channel_pc_web&item_id=${data2.aweme_id}&comment_id=${data2.comment_id}&cut_version=1&cursor=${data2.cursor}&count=${data2.number}&item_type=0&update_version_code=170400&pc_client_type=1&pc_libra_divert=Windows&support_h265=1&support_dash=1&version_code=170400&version_name=17.4.0&cookie_enabled=true&screen_width=1552&screen_height=970&browser_language=zh-CN&browser_platform=Win32&browser_name=Edge&browser_version=132.0.0.0&browser_online=true&engine_name=Blink&engine_version=132.0.0.0&os_name=Windows&os_version=10&cpu_core_num=16&device_memory=8&platform=PC&downlink=10&effective_type=4g&round_trip_time=50&webid=7386217876267796006&verifyFp=${fp}&fp=${fp}`;
1290
- }
1291
- \u52A8\u56FE(data2) {
1292
- return `https://www.iesdouyin.com/web/api/v2/aweme/slidesinfo/?reflow_source=reflow_page&web_id=7326472315356857893&device_id=7326472315356857893&aweme_ids=[${data2.aweme_id}]&request_source=200&msToken=${douyinSign.Mstoken(
1293
- 116
1294
- )}&verifyFp=${fp}&fp=${fp}`;
1295
- }
1296
- \u8868\u60C5() {
1297
- return "https://www.douyin.com/aweme/v1/web/emoji/list";
1298
- }
1299
- \u7528\u6237\u4E3B\u9875\u89C6\u9891(data2) {
1300
- return `https://www.douyin.com/aweme/v1/web/aweme/post/?device_platform=webapp&aid=6383&channel=channel_pc_web&sec_user_id=${data2.sec_uid}&max_cursor=0&locate_query=false&show_live_replay_strategy=1&need_time_list=1&time_list_query=0&whale_cut_token=&cut_version=1&count=18&publish_video_strategy_type=2&pc_client_type=1&version_code=170400&version_name=17.4.0&cookie_enabled=true&screen_width=1552&screen_height=970&browser_language=zh-CN&browser_platform=Win32&browser_name=Chrome&browser_version=125.0.0.0&browser_online=true&engine_name=Blink&engine_version=125.0.0.0&os_name=Windows&os_version=10&cpu_core_num=16&device_memory=8&platform=PC&downlink=10&effective_type=4g&round_trip_time=50&webid=7338423850134226495&msToken=${douyinSign.Mstoken(
1301
- 116
1302
- )}&verifyFp=${fp}&fp=${fp}`;
1303
- }
1304
- \u7528\u6237\u4E3B\u9875\u4FE1\u606F(data2) {
1305
- return `https://www.douyin.com/aweme/v1/web/user/profile/other/?device_platform=webapp&aid=6383&channel=channel_pc_web&publish_video_strategy_type=2&source=channel_pc_web&sec_user_id=${data2.sec_uid}&personal_center_strategy=1&pc_client_type=1&version_code=170400&version_name=17.4.0&cookie_enabled=true&screen_width=1552&screen_height=970&browser_language=zh-CN&browser_platform=Win32&browser_name=Chrome&browser_version=125.0.0.0&browser_online=true&engine_name=Blink&engine_version=125.0.0.0&os_name=Windows&os_version=10&cpu_core_num=16&device_memory=8&platform=PC&downlink=10&effective_type=4g&round_trip_time=0&webid=7327957959955580467&msToken=${douyinSign.Mstoken(
1306
- 116
1307
- )}&verifyFp=${fp}&fp=${fp}`;
1308
- }
1309
- \u70ED\u70B9\u8BCD(data2) {
1310
- return `https://www.douyin.com/aweme/v1/web/api/suggest_words/?device_platform=webapp&aid=6383&channel=channel_pc_web&query=${data2.query}&business_id=30088&from_group_id=7129543174929812767&pc_client_type=1&version_code=170400&version_name=17.4.0&cookie_enabled=true&screen_width=1552&screen_height=970&browser_language=zh - CN&browser_platform=Win32&browser_name=Chrome&browser_version=125.0.0.0&browser_online=true&engine_name=Blink&engine_version=125.0.0.0&os_name=Windows&os_version=10&cpu_core_num=16&device_memory=8&platform=PC&downlink=10&effective_type=4g&round_trip_time=50&webid=7327957959955580467&msToken=${douyinSign.Mstoken(
1311
- 116
1312
- )}&verifyFp=${fp}&fp=${fp}`;
1313
- }
1314
- \u641C\u7D22(data2) {
1315
- return `https://www.douyin.com/aweme/v1/web/general/search/single/?device_platform=webapp&aid=6383&channel=channel_pc_web&search_channel=aweme_general&sort_type=0&publish_time=0&keyword=${data2.query}&search_source=normal_search&query_correct_type=1&is_filter_search=0&from_group_id=&offset=0&count=15&pc_client_type=1&version_code=190600&version_name=19.6.0&cookie_enabled=true&screen_width=1552&screen_height=970&browser_language=zh-CN&browser_platform=Win32&browser_name=Chrome&browser_version=125.0.0.0&browser_online=true&engine_name=Blink&engine_version=125.0.0.0&os_name=Windows&os_version=10&cpu_core_num=16&device_memory=8&platform=PC&downlink=10&effective_type=4g&round_trip_time=50&webid=7338423850134226495&msToken=${douyinSign.Mstoken(
1316
- 116
1317
- )}&verifyFp=${fp}&fp=${fp}&search_id=${data2.search_id ?? ""}&count=${data2.number ?? 10}`;
1318
- }
1319
- \u4E92\u52A8\u8868\u60C5() {
1320
- return `https://www.douyin.com/aweme/v1/web/im/strategy/config?device_platform=webapp&aid=1128&channel=channel_pc_web&publish_video_strategy_type=2&app_id=1128&scenes=[%22interactive_resources%22]&pc_client_type=1&version_code=170400&version_name=17.4.0&cookie_enabled=true&screen_width=2328&screen_height=1310&browser_language=zh-CN&browser_platform=Win32&browser_name=Chrome&browser_version=126.0.0.0&browser_online=true&engine_name=Blink&engine_version=126.0.0.0&os_name=Windows&os_version=10&cpu_core_num=16&device_memory=8&platform=PC&downlink=1.5&effective_type=4g&round_trip_time=350&webid=7347329698282833447&msToken=${douyinSign.Mstoken(
1321
- 116
1322
- )}&verifyFp=${fp}&fp=${fp}`;
1323
- }
1324
- \u80CC\u666F\u97F3\u4E50(data2) {
1325
- return `https://www.douyin.com/aweme/v1/web/music/detail/?device_platform=webapp&aid=6383&channel=channel_pc_web&music_id=${data2.music_id}&scene=1&pc_client_type=1&version_code=170400&version_name=17.4.0&cookie_enabled=true&screen_width=2328&screen_height=1310&browser_language=zh-CN&browser_platform=Win32&browser_name=Chrome&browser_version=126.0.0.0&browser_online=true&engine_name=Blink&engine_version=126.0.0.0&os_name=Windows&os_version=10&cpu_core_num=16&device_memory=8&platform=PC&downlink=1.5&effective_type=4g&round_trip_time=350&webid=7347329698282833447&msToken=${douyinSign.Mstoken(
1326
- 116
1327
- )}&verifyFp=${fp}&fp=${fp}`;
1328
- }
1329
- \u76F4\u64AD\u95F4\u4FE1\u606F(data2) {
1330
- return `https://live.douyin.com/webcast/room/web/enter/?aid=6383&app_name=douyin_web&live_id=1&device_platform=web&language=zh-CN&enter_from=web_share_link&cookie_enabled=true&screen_width=2048&screen_height=1152&browser_language=zh-CN&browser_platform=Win32&browser_name=Chrome&browser_version=125.0.0.0&web_rid=${data2.web_rid}&room_id_str=${data2.room_id}&enter_source=&is_need_double_stream=false&insert_task_id=&live_reason=&msToken=${douyinSign.Mstoken(
1331
- 116
1332
- )}&verifyFp=${fp}&fp=${fp}`;
1333
- }
1334
- \u7533\u8BF7\u4E8C\u7EF4\u7801(data2) {
1335
- return `https://sso.douyin.com/get_qrcode/?verifyFp=${data2.verify_fp}&fp=${data2.verify_fp}`;
1336
- }
1337
- };
1338
- var douyinApiUrls = new DouyinAPI();
1339
-
1340
- // src/platform/douyin/getdata.ts
1341
- var defheaders2 = {
1342
- accept: "*/*",
1343
- priority: "u=0, i",
1344
- "content-type": "application/json; charset=utf-8",
1345
- "accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
1346
- "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36",
1347
- referer: "https://www.douyin.com/",
1348
- "accept-encoding": "gzip, deflate, br",
1349
- connection: "keep-alive"
1350
- };
1351
- var DouyinData = async (data2, cookie) => {
1352
- var _a, _b;
1353
- const headers2 = {
1354
- ...defheaders2,
1355
- cookie: cookie ? cookie.replace(/\s+/g, "") : ""
1356
- };
1357
- switch (data2.methodType) {
1358
- case "\u805A\u5408\u89E3\u6790":
1359
- case "\u89C6\u9891\u4F5C\u54C1\u6570\u636E":
1360
- case "\u56FE\u96C6\u4F5C\u54C1\u6570\u636E":
1361
- case "\u5408\u8F91\u4F5C\u54C1\u6570\u636E": {
1362
- const url = douyinApiUrls.\u89C6\u9891\u6216\u56FE\u96C6({ aweme_id: data2.aweme_id });
1363
- const VideoData = await GlobalGetData2({
1364
- url: `${url}&a_bogus=${douyinSign.AB(url)}`,
1365
- headers: headers2,
1366
- ...data2
1367
- });
1368
- return VideoData;
1369
- }
1370
- case "\u8BC4\u8BBA\u6570\u636E": {
1371
- const urlGenerator = (params) => douyinApiUrls.\u8BC4\u8BBA(params);
1372
- const response = await fetchPaginatedData(urlGenerator, data2, 50, headers2);
1373
- return response;
1374
- }
1375
- case "\u6307\u5B9A\u8BC4\u8BBA\u56DE\u590D\u6570\u636E": {
1376
- const urlGenerator = (params) => douyinApiUrls.\u4E8C\u7EA7\u8BC4\u8BBA(params);
1377
- const response = await fetchPaginatedData(
1378
- urlGenerator,
1379
- data2,
1380
- 3,
1381
- {
1382
- ...headers2,
1383
- referer: `https://www.douyin.com/note/${data2.aweme_id}`
1384
- }
1385
- );
1386
- return response;
1387
- }
1388
- case "\u7528\u6237\u4E3B\u9875\u6570\u636E": {
1389
- const url = douyinApiUrls.\u7528\u6237\u4E3B\u9875\u4FE1\u606F({ sec_uid: data2.sec_uid });
1390
- const UserInfoData = await GlobalGetData2({
1391
- url: `${url}&a_bogus=${douyinSign.AB(url)}`,
1392
- headers: {
1393
- ...headers2,
1394
- Referer: `https://www.douyin.com/user/${data2.sec_uid}`
1395
- },
1396
- ...data2
1397
- });
1398
- return UserInfoData;
1399
- }
1400
- case "Emoji\u6570\u636E": {
1401
- const url = douyinApiUrls.\u8868\u60C5();
1402
- const EmojiData = await GlobalGetData2({
1403
- url,
1404
- headers: headers2,
1405
- ...data2
1406
- });
1407
- return EmojiData;
1408
- }
1409
- case "\u7528\u6237\u4E3B\u9875\u89C6\u9891\u5217\u8868\u6570\u636E": {
1410
- const url = douyinApiUrls.\u7528\u6237\u4E3B\u9875\u89C6\u9891({ sec_uid: data2.sec_uid });
1411
- const UserVideoListData = await GlobalGetData2({
1412
- url: `${url}&a_bogus=${douyinSign.AB(url)}`,
1413
- headers: {
1414
- ...headers2,
1415
- Referer: `https://www.douyin.com/user/${data2.sec_uid}`
1416
- },
1417
- ...data2
1418
- });
1419
- return UserVideoListData;
1420
- }
1421
- case "\u70ED\u70B9\u8BCD\u6570\u636E": {
1422
- const url = douyinApiUrls.\u70ED\u70B9\u8BCD({ query: data2.query, number: data2.number ?? 10 });
1423
- const SuggestWordsData = await GlobalGetData2({
1424
- url: `${url}&a_bogus=${douyinSign.AB(url)}`,
1425
- headers: {
1426
- ...headers2,
1427
- Referer: `https://www.douyin.com/search/${encodeURIComponent(String(data2.query))}`
1428
- },
1429
- ...data2
1430
- });
1431
- return SuggestWordsData;
1432
- }
1433
- case "\u641C\u7D22\u6570\u636E": {
1434
- let search_id = "";
1435
- const maxPageSize = 15;
1436
- let fetchedSearchList = [];
1437
- let tmpresp = {};
1438
- while (fetchedSearchList.length < Number(data2.number ?? 10)) {
1439
- const requestCount = Math.min(Number(data2.number ?? 50) - fetchedSearchList.length, maxPageSize);
1440
- const url = douyinApiUrls.\u641C\u7D22({
1441
- query: data2.query,
1442
- number: requestCount,
1443
- search_id: search_id === "" ? void 0 : search_id
1444
- });
1445
- const response = await GlobalGetData2({
1446
- url: `${url}&a_bogus=${douyinSign.AB(url)}`,
1447
- headers: {
1448
- ...headers2,
1449
- Referer: `https://www.douyin.com/search/${encodeURIComponent(String(data2.query))}`
1450
- },
1451
- ...data2
1452
- });
1453
- if (response.data.length === 0) {
1454
- logger.warn("\u83B7\u53D6\u641C\u7D22\u6570\u636E\u5931\u8D25\uFF01\u8BF7\u6C42\u6210\u529F\u4F46\u63A5\u53E3\u8FD4\u56DE\u5185\u5BB9\u4E3A\u7A7A\n\u4F60\u7684\u6296\u97F3ck\u53EF\u80FD\u5DF2\u7ECF\u5931\u6548\uFF01\n\u8BF7\u6C42\u7C7B\u578B\uFF1A" + data2.methodType);
1455
- return false;
1456
- }
1457
- if (!response.data) {
1458
- response.data = [];
1459
- }
1460
- fetchedSearchList.push(...response.data);
1461
- tmpresp = response;
1462
- search_id = response.log_pb.impr_id;
1463
- }
1464
- const finalResponse = {
1465
- ...tmpresp,
1466
- data: data2.number === 0 ? [] : fetchedSearchList.slice(0, Number(data2.number ?? 10))
1467
- };
1468
- return finalResponse;
1469
- }
1470
- case "\u52A8\u6001\u8868\u60C5\u6570\u636E": {
1471
- const url = douyinApiUrls.\u4E92\u52A8\u8868\u60C5();
1472
- const ExpressionPlusData = await GlobalGetData2({
1473
- url: `${url}&a_bogus=${douyinSign.AB(url)}`,
1474
- headers: headers2,
1475
- ...data2
1476
- });
1477
- return ExpressionPlusData;
1478
- }
1479
- case "\u97F3\u4E50\u6570\u636E": {
1480
- const url = douyinApiUrls.\u80CC\u666F\u97F3\u4E50({ music_id: data2.music_id });
1481
- const MusicData = await GlobalGetData2({
1482
- url: `${url}&a_bogus=${douyinSign.AB(url)}`,
1483
- headers: headers2,
1484
- ...data2
1485
- });
1486
- return MusicData;
1487
- }
1488
- case "\u76F4\u64AD\u95F4\u4FE1\u606F\u6570\u636E": {
1489
- let url = douyinApiUrls.\u7528\u6237\u4E3B\u9875\u4FE1\u606F({ sec_uid: data2.sec_uid });
1490
- const fetchUrl = `${url}&a_bogus=${douyinSign.AB(url)}`;
1491
- const UserInfoData = await GlobalGetData2({
1492
- url: fetchUrl,
1493
- headers: {
1494
- ...headers2,
1495
- Referer: `https://www.douyin.com/user/${data2.sec_uid}`
1496
- },
1497
- ...data2
1498
- });
1499
- if (!((_a = UserInfoData == null ? void 0 : UserInfoData.user) == null ? void 0 : _a.live_status) || UserInfoData.user.live_status !== 1) {
1500
- logger.error((((_b = UserInfoData == null ? void 0 : UserInfoData.user) == null ? void 0 : _b.nickname) || "\u7528\u6237") + "\u5F53\u524D\u672A\u5728\u76F4\u64AD");
1501
- const Err = {
1502
- errorDescription: "\u68C0\u67E5\u5931\u8D25\uFF01\u8BE5\u7528\u6237\u5F53\u524D\u672A\u5728\u76F4\u64AD\uFF01 TypeError: Cannot read properties of undefined (reading 'live_status')",
1503
- requestType: data2.methodType ?? "\u672A\u77E5\u8BF7\u6C42\u7C7B\u578B",
1504
- requestUrl: fetchUrl
1505
- };
1506
- return {
1507
- code: "USER_NOT_LIVE" /* NOT_LIVE */,
1508
- data: UserInfoData,
1509
- amagiError: Err,
1510
- amagiMessage: Err.errorDescription
1511
- };
1512
- }
1513
- if (!UserInfoData.user.room_data) {
1514
- logger.error("\u672A\u83B7\u53D6\u5230\u76F4\u64AD\u95F4\u4FE1\u606F\uFF01");
1515
- return {
1516
- code: 500,
1517
- message: "\u672A\u83B7\u53D6\u5230\u76F4\u64AD\u95F4\u4FE1\u606F\uFF01",
1518
- data: null
1519
- };
1520
- }
1521
- const room_data = JSON.parse(UserInfoData.user.room_data);
1522
- url = douyinApiUrls.\u76F4\u64AD\u95F4\u4FE1\u606F({ room_id: UserInfoData.user.room_id_str, web_rid: room_data.owner.web_rid });
1523
- const LiveRoomData = await GlobalGetData2({
1524
- url: `${url}&a_bogus=${douyinSign.AB(url)}`,
1525
- headers: {
1526
- ...headers2,
1527
- Referer: `https://live.douyin.com/${room_data.owner.web_rid}`
1528
- },
1529
- ...data2
1530
- });
1531
- return LiveRoomData;
1532
- }
1533
- case "\u7533\u8BF7\u4E8C\u7EF4\u7801\u6570\u636E": {
1534
- const url = douyinApiUrls.\u7533\u8BF7\u4E8C\u7EF4\u7801({ verify_fp: data2.verify_fp });
1535
- const LoginQrcodeStatusData = await GlobalGetData2({
1536
- url: `${url}&a_bogus=${douyinSign.AB(url)}`,
1537
- headers: headers2,
1538
- ...data2
1539
- });
1540
- return LoginQrcodeStatusData;
1541
- }
1542
- default:
1543
- logger.warn(`\u672A\u77E5\u7684B\u7AD9\u6570\u636E\u63A5\u53E3\uFF1A\u300C${logger.red(data2.methodType)}\u300D`);
1544
- return null;
1545
- }
1546
- };
1547
- var fetchPaginatedData = async (apiUrlGenerator, params, maxPageSize, headers2) => {
1548
- let cursor = params.cursor ?? 0;
1549
- let fetchedData = [];
1550
- let tmpresp = {};
1551
- while (fetchedData.length < Number(params.number ?? maxPageSize)) {
1552
- const requestCount = Math.min(Number(params.number ?? maxPageSize) - fetchedData.length, maxPageSize);
1553
- const url = apiUrlGenerator({
1554
- ...params,
1555
- number: requestCount,
1556
- cursor
1557
- });
1558
- const response = await GlobalGetData2({
1559
- url: `${url}&a_bogus=${douyinSign.AB(url)}`,
1560
- headers: headers2,
1561
- ...params
1562
- });
1563
- fetchedData.push(...response.comments || response.data || []);
1564
- tmpresp = response;
1565
- if ((response.comments || response.data || []).length < requestCount) {
1566
- break;
1567
- }
1568
- cursor = response.cursor;
1569
- }
1570
- const finalResponse = {
1571
- ...tmpresp,
1572
- comments: params.number === 0 ? [] : fetchedData.slice(0, Number(params.number ?? maxPageSize)),
1573
- cursor: params.number === 0 ? 0 : fetchedData.length
1574
- };
1575
- return finalResponse;
1576
- };
1577
- var GlobalGetData2 = async (options) => {
1578
- let warningMessage = "";
1579
- try {
1580
- const result = await new Networks(options).getData();
1581
- if (!result || result === "") {
1582
- const Err = {
1583
- errorDescription: "\u83B7\u53D6\u54CD\u5E94\u6570\u636E\u5931\u8D25\uFF01\u63A5\u53E3\u8FD4\u56DE\u5185\u5BB9\u4E3A\u7A7A\uFF0C\u4F60\u7684\u6296\u97F3ck\u53EF\u80FD\u5DF2\u7ECF\u5931\u6548\uFF01",
1584
- requestType: options.methodType ?? "\u672A\u77E5\u8BF7\u6C42\u7C7B\u578B",
1585
- requestUrl: options.url
1586
- };
1587
- warningMessage = `
1588
- \u83B7\u53D6\u54CD\u5E94\u6570\u636E\u5931\u8D25\uFF01\u539F\u56E0\uFF1A${logger.yellow("\u63A5\u53E3\u8FD4\u56DE\u5185\u5BB9\u4E3A\u7A7A\uFF0C\u4F60\u7684\u6296\u97F3ck\u53EF\u80FD\u5DF2\u7ECF\u5931\u6548\uFF01")}
1589
- \u8BF7\u6C42\u7C7B\u578B\uFF1A\u300C${options.methodType}\u300D
1590
- \u8BF7\u6C42URL\uFF1A${options.url}
1591
- `;
1592
- logger.warn(warningMessage);
1593
- throw {
1594
- code: "INVALID_COOKIE" /* COOKIE */,
1595
- data: result,
1596
- amagiError: Err
1597
- };
1598
- }
1599
- if (result.filter_detail && result.filter_detail.filter_reason) {
1600
- const filterReason = result.filter_detail.filter_reason;
1601
- const Err = {
1602
- errorDescription: `\u83B7\u53D6\u54CD\u5E94\u6570\u636E\u5931\u8D25\uFF01\u539F\u56E0\uFF1A${filterReason}\uFF01`,
1603
- requestType: options.methodType ?? "\u672A\u77E5\u8BF7\u6C42\u7C7B\u578B",
1604
- requestUrl: options.url
1605
- };
1606
- warningMessage = `
1607
- \u83B7\u53D6\u54CD\u5E94\u6570\u636E\u5931\u8D25\uFF01\u539F\u56E0\uFF1A${logger.yellow(filterReason)}
1608
- \u8BF7\u6C42\u7C7B\u578B\uFF1A\u300C${options.methodType}\u300D
1609
- \u8BF7\u6C42URL\uFF1A${options.url}
1610
- `;
1611
- logger.warn(warningMessage);
1612
- throw {
1613
- code: "CONTENT_FILTERED" /* FILTER */,
1614
- data: result,
1615
- amagiError: Err
1616
- };
1617
- }
1618
- return result;
1619
- } catch (error) {
1620
- if (error && typeof error === "object") {
1621
- const err = error;
1622
- return { ...err, amagiMessage: warningMessage };
1623
- }
1624
- return {
1625
- code: "UNKNOWN_ERROR" /* UNKNOWN */,
1626
- data: null,
1627
- amagiError: {
1628
- errorDescription: "\u672A\u77E5\u9519\u8BEF",
1629
- requestType: options.methodType,
1630
- requestUrl: options.url
1631
- },
1632
- amagiMessage: warningMessage
1633
- };
1634
- }
1635
- };
1636
-
1637
- // src/platform/kuaishou/API.ts
1638
- var API = class {
1639
- \u5355\u4E2A\u4F5C\u54C1\u4FE1\u606F(data2) {
1640
- return {
1641
- /** 接口类型 */
1642
- type: "visionVideoDetail",
1643
- /** 请求url */
1644
- url: "https://www.kuaishou.com/graphql",
1645
- /** 请求参数 */
1646
- body: {
1647
- /** 接口类型 */
1648
- operationName: "visionVideoDetail",
1649
- variables: {
1650
- /** 作品ID */
1651
- photoId: data2.photoId,
1652
- page: "detail"
1653
- },
1654
- query: "query visionVideoDetail($photoId: String, $type: String, $page: String, $webPageArea: String) {\n visionVideoDetail(photoId: $photoId, type: $type, page: $page, webPageArea: $webPageArea) {\n status\n type\n author {\n id\n name\n following\n headerUrl\n __typename\n }\n photo {\n id\n duration\n caption\n likeCount\n realLikeCount\n coverUrl\n photoUrl\n liked\n timestamp\n expTag\n llsid\n viewCount\n videoRatio\n stereoType\n musicBlocked\n manifest {\n mediaType\n businessType\n version\n adaptationSet {\n id\n duration\n representation {\n id\n defaultSelect\n backupUrl\n codecs\n url\n height\n width\n avgBitrate\n maxBitrate\n m3u8Slice\n qualityType\n qualityLabel\n frameRate\n featureP2sp\n hidden\n disableAdaptive\n __typename\n }\n __typename\n }\n __typename\n }\n manifestH265\n photoH265Url\n coronaCropManifest\n coronaCropManifestH265\n croppedPhotoH265Url\n croppedPhotoUrl\n videoResource\n __typename\n }\n tags {\n type\n name\n __typename\n }\n commentLimit {\n canAddComment\n __typename\n }\n llsid\n danmakuSwitch\n __typename\n }\n}\n"
1655
- }
1656
- };
1657
- }
1658
- \u4F5C\u54C1\u8BC4\u8BBA\u4FE1\u606F(data2) {
1659
- return {
1660
- type: "commentListQuery",
1661
- url: "https://www.kuaishou.com/graphql",
1662
- body: {
1663
- operationName: "commentListQuery",
1664
- variables: {
1665
- photoId: data2.photoId,
1666
- pcursor: ""
1667
- },
1668
- query: "query commentListQuery($photoId: String, $pcursor: String) {\n visionCommentList(photoId: $photoId, pcursor: $pcursor) {\n commentCount\n pcursor\n rootComments {\n commentId\n authorId\n authorName\n content\n headurl\n timestamp\n likedCount\n realLikedCount\n liked\n status\n authorLiked\n subCommentCount\n subCommentsPcursor\n subComments {\n commentId\n authorId\n authorName\n content\n headurl\n timestamp\n likedCount\n realLikedCount\n liked\n status\n authorLiked\n replyToUserName\n replyTo\n __typename\n }\n __typename\n }\n __typename\n }\n}\n"
1669
- }
1670
- };
1671
- }
1672
- \u8868\u60C5() {
1673
- return {
1674
- type: "visionBaseEmoticons",
1675
- url: "https://www.kuaishou.com/graphql",
1676
- body: {
1677
- operationName: "visionBaseEmoticons",
1678
- variables: {},
1679
- query: "query visionBaseEmoticons {\n visionBaseEmoticons {\n iconUrls\n __typename\n }\n}\n"
1680
- }
1681
- };
1682
- }
1683
- };
1684
- var kuaishouApiUrls = new API();
1685
-
1686
- // src/platform/kuaishou/getdata.ts
1687
- var defheaders3 = {
1688
- referer: "https://www.kuaishou.com/new-reco",
1689
- origin: "https://www.kuaishou.com",
1690
- accept: "*/*",
1691
- "content-type": "application/json",
1692
- "accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
1693
- "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 Edg/130.0.0.0"
1694
- };
1695
- var KuaishouData = async (data2, cookie) => {
1696
- const headers2 = {
1697
- ...defheaders3,
1698
- cookie: cookie ? cookie.replace(/\s+/g, "") : ""
1699
- };
1700
- switch (data2.methodType) {
1701
- case "\u5355\u4E2A\u89C6\u9891\u4F5C\u54C1\u6570\u636E": {
1702
- const body = kuaishouApiUrls.\u5355\u4E2A\u4F5C\u54C1\u4FE1\u606F({ photoId: data2.photoId });
1703
- const VideoData = await GlobalGetData3({
1704
- url: body.url,
1705
- method: "POST",
1706
- headers: headers2,
1707
- body: body.body,
1708
- ...data2
1709
- });
1710
- return VideoData;
1711
- }
1712
- case "\u8BC4\u8BBA\u6570\u636E": {
1713
- const body = kuaishouApiUrls.\u4F5C\u54C1\u8BC4\u8BBA\u4FE1\u606F({ photoId: data2.photoId });
1714
- const VideoData = await GlobalGetData3({
1715
- url: body.url,
1716
- method: "POST",
1717
- headers: headers2,
1718
- body: body.body,
1719
- ...data2
1720
- });
1721
- return VideoData;
1722
- }
1723
- case "Emoji\u6570\u636E": {
1724
- const body = kuaishouApiUrls.\u8868\u60C5();
1725
- const EmojiData = await GlobalGetData3({
1726
- url: body.url,
1727
- method: "POST",
1728
- headers: headers2,
1729
- body: body.body,
1730
- ...data2
1731
- });
1732
- return EmojiData;
1733
- }
1734
- default:
1735
- logger.warn(`\u672A\u77E5\u7684\u5FEB\u624B\u6570\u636E\u63A5\u53E3\uFF1A\u300C${logger.red(data2.methodType)}\u300D`);
1736
- return null;
1737
- }
1738
- };
1739
- var GlobalGetData3 = async (options) => {
1740
- let warningMessage = "";
1741
- try {
1742
- const result = await new Networks(options).getData();
1743
- if (result === "" || !result || result.result === 2) {
1744
- const Err = {
1745
- errorDescription: `\u83B7\u53D6\u54CD\u5E94\u6570\u636E\u5931\u8D25\uFF01\u63A5\u53E3\u8FD4\u56DE\u5185\u5BB9\u4E3A\u7A7A\uFF01`,
1746
- requestType: options.methodType ?? "\u672A\u77E5\u8BF7\u6C42\u7C7B\u578B",
1747
- requestUrl: options.url,
1748
- requestBody: JSON.stringify(options.body)
1749
- };
1750
- warningMessage = `
1751
- \u83B7\u53D6\u54CD\u5E94\u6570\u636E\u5931\u8D25\uFF01\u539F\u56E0\uFF1A${logger.yellow("\u63A5\u53E3\u8FD4\u56DE\u5185\u5BB9\u4E3A\u7A7A\uFF0C\u4F60\u7684\u5FEB\u624Bck\u53EF\u80FD\u5DF2\u7ECF\u5931\u6548\uFF01")}
1752
- \u8BF7\u6C42\u7C7B\u578B\uFF1A\u300C${options.methodType}\u300D
1753
- \u8BF7\u6C42URL\uFF1A${options.url}
1754
- \u8BF7\u6C42\u53C2\u6570\uFF1A${JSON.stringify(options.body, null, 2)}
1755
- `;
1756
- logger.warn(warningMessage);
1757
- throw {
1758
- code: "INVALID_COOKIE" /* COOKIE */,
1759
- data: result,
1760
- amagiError: Err
1761
- };
1762
- }
1763
- return result;
1764
- } catch (error) {
1765
- if (error && typeof error === "object") {
1766
- const err = error;
1767
- return { ...err, amagiMessage: warningMessage };
1768
- }
1769
- return {
1770
- code: "UNKNOWN_ERROR" /* UNKNOWN */,
1771
- data: null,
1772
- amagiError: {
1773
- errorDescription: "\u672A\u77E5\u9519\u8BEF",
1774
- requestType: options.methodType,
1775
- requestUrl: options.url
1776
- },
1777
- amagiMessage: warningMessage
1778
- };
1779
- }
1780
- };
1781
- function smartNumber(errorMessage, minValue = 1, isInteger = false) {
1782
- if (isInteger) {
1783
- return zod.z.coerce.number({ required_error: errorMessage }).int(`${errorMessage.replace("\u4E0D\u80FD\u4E3A\u7A7A", "")}\u5FC5\u987B\u662F\u6574\u6570\uFF0C\u4E0D\u80FD\u5305\u542B\u5C0F\u6570`).min(minValue, `${errorMessage.replace("\u4E0D\u80FD\u4E3A\u7A7A", "")}\u5FC5\u987B\u5927\u4E8E\u7B49\u4E8E${minValue}`);
1784
- } else {
1785
- return zod.z.coerce.number({ required_error: errorMessage }).min(minValue, `${errorMessage.replace("\u4E0D\u80FD\u4E3A\u7A7A", "")}\u5FC5\u987B\u5927\u4E8E\u7B49\u4E8E${minValue}`);
1786
- }
1787
- }
1788
- var smartPositiveInteger = (errorMessage) => {
1789
- return smartNumber(errorMessage, 1, true);
1790
- };
1791
-
1792
- // src/validation/douyin.ts
1793
- var DouyinWorkParamsSchema = zod.z.object({
1794
- methodType: zod.z.enum(["\u89C6\u9891\u4F5C\u54C1\u6570\u636E", "\u56FE\u96C6\u4F5C\u54C1\u6570\u636E", "\u5408\u8F91\u4F5C\u54C1\u6570\u636E", "\u805A\u5408\u89E3\u6790"]),
1795
- aweme_id: zod.z.string({ required_error: "\u89C6\u9891ID\u4E0D\u80FD\u4E3A\u7A7A" }).min(1, "\u89C6\u9891ID\u4E0D\u80FD\u4E3A\u7A7A")
1796
- });
1797
- var DouyinCommentParamsSchema = zod.z.object({
1798
- methodType: zod.z.literal("\u8BC4\u8BBA\u6570\u636E"),
1799
- aweme_id: zod.z.string({ required_error: "\u89C6\u9891ID\u4E0D\u80FD\u4E3A\u7A7A" }).min(1, "\u89C6\u9891ID\u4E0D\u80FD\u4E3A\u7A7A"),
1800
- number: smartPositiveInteger("\u8BC4\u8BBA\u6570\u91CF\u5FC5\u987B\u662F\u6B63\u6574\u6570").optional().default(50),
1801
- cursor: zod.z.coerce.number().int().min(0).default(0).optional()
1802
- });
1803
- var DouyinSearchParamsSchema = zod.z.object({
1804
- methodType: zod.z.enum(["\u70ED\u70B9\u8BCD\u6570\u636E", "\u641C\u7D22\u6570\u636E"]),
1805
- query: zod.z.string({ required_error: "\u641C\u7D22\u8BCD\u4E0D\u80FD\u4E3A\u7A7A" }).min(1, "\u641C\u7D22\u8BCD\u4E0D\u80FD\u4E3A\u7A7A"),
1806
- number: smartPositiveInteger("\u641C\u7D22\u6570\u91CF\u5FC5\u987B\u662F\u6B63\u6574\u6570").optional().default(10),
1807
- search_id: zod.z.string().optional()
1808
- });
1809
- var DouyinCommentReplyParamsSchema = zod.z.object({
1810
- methodType: zod.z.literal("\u6307\u5B9A\u8BC4\u8BBA\u56DE\u590D\u6570\u636E"),
1811
- aweme_id: zod.z.string({ required_error: "\u89C6\u9891ID\u4E0D\u80FD\u4E3A\u7A7A" }).min(1, "\u89C6\u9891ID\u4E0D\u80FD\u4E3A\u7A7A"),
1812
- comment_id: zod.z.string({ required_error: "\u8BC4\u8BBAID\u4E0D\u80FD\u4E3A\u7A7A" }).min(1, "\u8BC4\u8BBAID\u4E0D\u80FD\u4E3A\u7A7A"),
1813
- number: smartPositiveInteger("\u8BC4\u8BBA\u6570\u91CF\u5FC5\u987B\u662F\u6B63\u6574\u6570").optional().default(5),
1814
- cursor: zod.z.coerce.number().int().min(0).default(0).optional()
1815
- });
1816
- var DouyinUserParamsSchema = zod.z.object({
1817
- methodType: zod.z.enum(["\u7528\u6237\u4E3B\u9875\u6570\u636E", "\u7528\u6237\u4E3B\u9875\u89C6\u9891\u5217\u8868\u6570\u636E", "\u76F4\u64AD\u95F4\u4FE1\u606F\u6570\u636E"]),
1818
- sec_uid: zod.z.string({ required_error: "\u7528\u6237ID\u4E0D\u80FD\u4E3A\u7A7A" }).min(1, "\u7528\u6237ID\u4E0D\u80FD\u4E3A\u7A7A")
1819
- });
1820
- var DouyinMusicParamsSchema = zod.z.object({
1821
- methodType: zod.z.literal("\u97F3\u4E50\u6570\u636E"),
1822
- music_id: zod.z.string({ required_error: "\u97F3\u4E50ID\u4E0D\u80FD\u4E3A\u7A7A" }).min(1, "\u97F3\u4E50ID\u4E0D\u80FD\u4E3A\u7A7A")
1823
- });
1824
- var DouyinQrcodeParamsSchema = zod.z.object({
1825
- methodType: zod.z.literal("\u7533\u8BF7\u4E8C\u7EF4\u7801\u6570\u636E"),
1826
- verify_fp: zod.z.string({ required_error: "fp\u6307\u7EB9\u4E0D\u80FD\u4E3A\u7A7A" }).min(1, "fp\u6307\u7EB9\u4E0D\u80FD\u4E3A\u7A7A")
1827
- });
1828
- var DouyinEmojiListParamsSchema = zod.z.object({
1829
- methodType: zod.z.literal("Emoji\u6570\u636E")
1830
- });
1831
- var DouyinEmojiProParamsSchema = zod.z.object({
1832
- methodType: zod.z.literal("\u52A8\u6001\u8868\u60C5\u6570\u636E")
1833
- });
1834
- var DouyinValidationSchemas2 = {
1835
- "\u805A\u5408\u89E3\u6790": DouyinWorkParamsSchema,
1836
- "\u89C6\u9891\u4F5C\u54C1\u6570\u636E": DouyinWorkParamsSchema,
1837
- "\u56FE\u96C6\u4F5C\u54C1\u6570\u636E": DouyinWorkParamsSchema,
1838
- "\u5408\u8F91\u4F5C\u54C1\u6570\u636E": DouyinWorkParamsSchema,
1839
- "\u8BC4\u8BBA\u6570\u636E": DouyinCommentParamsSchema,
1840
- "\u7528\u6237\u4E3B\u9875\u6570\u636E": DouyinUserParamsSchema,
1841
- "\u7528\u6237\u4E3B\u9875\u89C6\u9891\u5217\u8868\u6570\u636E": DouyinUserParamsSchema,
1842
- "\u70ED\u70B9\u8BCD\u6570\u636E": DouyinSearchParamsSchema,
1843
- "\u641C\u7D22\u6570\u636E": DouyinSearchParamsSchema,
1844
- "\u97F3\u4E50\u6570\u636E": DouyinMusicParamsSchema,
1845
- "\u76F4\u64AD\u95F4\u4FE1\u606F\u6570\u636E": DouyinUserParamsSchema,
1846
- "\u7533\u8BF7\u4E8C\u7EF4\u7801\u6570\u636E": DouyinQrcodeParamsSchema,
1847
- "Emoji\u6570\u636E": DouyinEmojiListParamsSchema,
1848
- "\u52A8\u6001\u8868\u60C5\u6570\u636E": DouyinEmojiProParamsSchema,
1849
- "\u6307\u5B9A\u8BC4\u8BBA\u56DE\u590D\u6570\u636E": DouyinCommentReplyParamsSchema
1850
- };
1851
- var BilibiliVideoParamsSchema = zod.z.object({
1852
- methodType: zod.z.literal("\u5355\u4E2A\u89C6\u9891\u4F5C\u54C1\u6570\u636E"),
1853
- bvid: zod.z.string({ required_error: "BVID\u4E0D\u80FD\u4E3A\u7A7A" }).min(1, "BVID\u4E0D\u80FD\u4E3A\u7A7A")
1854
- });
1855
- var BilibiliVideoDownloadParamsSchema = zod.z.object({
1856
- methodType: zod.z.literal("\u5355\u4E2A\u89C6\u9891\u4E0B\u8F7D\u4FE1\u606F\u6570\u636E"),
1857
- avid: smartNumber("AVID\u4E0D\u80FD\u4E3A\u7A7A", 1, true),
1858
- cid: smartNumber("CID\u4E0D\u80FD\u4E3A\u7A7A", 1, true)
1859
- });
1860
- var BilibiliCommentParamsSchema = zod.z.object({
1861
- methodType: zod.z.literal("\u8BC4\u8BBA\u6570\u636E"),
1862
- oid: smartNumber("OID\u4E0D\u80FD\u4E3A\u7A7A", 1, true),
1863
- type: smartNumber("\u8BC4\u8BBA\u7C7B\u578B\u4E0D\u80FD\u4E3A\u7A7A", 1, true).refine(
1864
- (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),
1865
- { message: "\u65E0\u6548\u7684\u8BC4\u8BBA\u533A\u7C7B\u578B" }
1866
- ),
1867
- number: zod.z.coerce.number().int().positive().default(20).optional(),
1868
- pn: zod.z.coerce.number().int().positive().default(1).optional()
1869
- });
1870
- var BilibiliUserParamsSchema = zod.z.object({
1871
- methodType: zod.z.enum(["\u7528\u6237\u4E3B\u9875\u6570\u636E", "\u7528\u6237\u4E3B\u9875\u52A8\u6001\u5217\u8868\u6570\u636E", "\u83B7\u53D6UP\u4E3B\u603B\u64AD\u653E\u91CF"]),
1872
- host_mid: smartNumber("UP\u4E3BUID\u4E0D\u80FD\u4E3A\u7A7A", 1, true)
1873
- });
1874
- var BilibiliEmojiParamsSchema = zod.z.object({
1875
- methodType: zod.z.literal("Emoji\u6570\u636E")
1876
- });
1877
- var BilibiliBangumiInfoParamsSchema = zod.z.object({
1878
- methodType: zod.z.literal("\u756A\u5267\u57FA\u672C\u4FE1\u606F\u6570\u636E"),
1879
- ep_id: zod.z.string().min(1, "\u756A\u5267EP ID\u4E0D\u80FD\u4E3A\u7A7A").optional(),
1880
- season_id: zod.z.string().optional()
1881
- }).refine(
1882
- (data2) => data2.ep_id || data2.season_id,
1883
- {
1884
- message: "ep_id \u548C season_id \u81F3\u5C11\u9700\u8981\u63D0\u4F9B\u4E00\u4E2A",
1885
- path: ["ep_id"]
1886
- }
1887
- );
1888
- var BilibiliBangumiStreamParamsSchema = zod.z.object({
1889
- methodType: zod.z.literal("\u756A\u5267\u4E0B\u8F7D\u4FE1\u606F\u6570\u636E"),
1890
- cid: smartNumber("CID\u4E0D\u80FD\u4E3A\u7A7A", 1, true),
1891
- ep_id: zod.z.string({ required_error: "\u756A\u5267EP ID\u4E0D\u80FD\u4E3A\u7A7A" }).min(1, "\u756A\u5267EP ID\u4E0D\u80FD\u4E3A\u7A7A")
1892
- });
1893
- var BilibiliDynamicParamsSchema = zod.z.object({
1894
- methodType: zod.z.enum(["\u52A8\u6001\u8BE6\u60C5\u6570\u636E", "\u52A8\u6001\u5361\u7247\u6570\u636E"]),
1895
- dynamic_id: zod.z.string({ required_error: "\u52A8\u6001ID\u4E0D\u80FD\u4E3A\u7A7A" }).min(1, "\u52A8\u6001ID\u4E0D\u80FD\u4E3A\u7A7A")
1896
- });
1897
- var BilibiliLiveParamsSchema = zod.z.object({
1898
- methodType: zod.z.enum(["\u76F4\u64AD\u95F4\u4FE1\u606F", "\u76F4\u64AD\u95F4\u521D\u59CB\u5316\u4FE1\u606F"]),
1899
- room_id: zod.z.string({ required_error: "\u76F4\u64AD\u95F4ID\u4E0D\u80FD\u4E3A\u7A7A" }).min(1, "\u76F4\u64AD\u95F4ID\u4E0D\u80FD\u4E3A\u7A7A")
1900
- });
1901
- var BilibiliLoginParamsSchema = zod.z.object({
1902
- methodType: zod.z.literal("\u767B\u5F55\u57FA\u672C\u4FE1\u606F")
1903
- });
1904
- var BilibiliQrcodeParamsSchema = zod.z.object({
1905
- methodType: zod.z.literal("\u7533\u8BF7\u4E8C\u7EF4\u7801")
1906
- });
1907
- var BilibiliQrcodeStatusParamsSchema = zod.z.object({
1908
- methodType: zod.z.literal("\u4E8C\u7EF4\u7801\u72B6\u6001"),
1909
- qrcode_key: zod.z.string({ required_error: "\u4E8C\u7EF4\u7801key\u4E0D\u80FD\u4E3A\u7A7A" }).min(1, "\u4E8C\u7EF4\u7801key\u4E0D\u80FD\u4E3A\u7A7A")
1910
- });
1911
- var BilibiliAv2BvParamsSchema = zod.z.object({
1912
- methodType: zod.z.literal("AV\u8F6CBV"),
1913
- avid: zod.z.coerce.number({ required_error: "AVID\u4E0D\u80FD\u4E3A\u7A7A" }).int().positive()
1914
- });
1915
- var BilibiliBv2AvParamsSchema = zod.z.object({
1916
- methodType: zod.z.literal("BV\u8F6CAV"),
1917
- bvid: zod.z.string({ required_error: "BVID\u4E0D\u80FD\u4E3A\u7A7A" }).min(1, "BVID\u4E0D\u80FD\u4E3A\u7A7A")
1918
- });
1919
- var BilibiliValidationSchemas2 = {
1920
- "\u5355\u4E2A\u89C6\u9891\u4F5C\u54C1\u6570\u636E": BilibiliVideoParamsSchema,
1921
- "\u5355\u4E2A\u89C6\u9891\u4E0B\u8F7D\u4FE1\u606F\u6570\u636E": BilibiliVideoDownloadParamsSchema,
1922
- "\u8BC4\u8BBA\u6570\u636E": BilibiliCommentParamsSchema,
1923
- "\u7528\u6237\u4E3B\u9875\u6570\u636E": BilibiliUserParamsSchema,
1924
- "\u7528\u6237\u4E3B\u9875\u52A8\u6001\u5217\u8868\u6570\u636E": BilibiliUserParamsSchema,
1925
- "Emoji\u6570\u636E": BilibiliEmojiParamsSchema,
1926
- "\u756A\u5267\u57FA\u672C\u4FE1\u606F\u6570\u636E": BilibiliBangumiInfoParamsSchema,
1927
- "\u756A\u5267\u4E0B\u8F7D\u4FE1\u606F\u6570\u636E": BilibiliBangumiStreamParamsSchema,
1928
- "\u52A8\u6001\u8BE6\u60C5\u6570\u636E": BilibiliDynamicParamsSchema,
1929
- "\u52A8\u6001\u5361\u7247\u6570\u636E": BilibiliDynamicParamsSchema,
1930
- "\u76F4\u64AD\u95F4\u4FE1\u606F": BilibiliLiveParamsSchema,
1931
- "\u76F4\u64AD\u95F4\u521D\u59CB\u5316\u4FE1\u606F": BilibiliLiveParamsSchema,
1932
- "\u767B\u5F55\u57FA\u672C\u4FE1\u606F": BilibiliLoginParamsSchema,
1933
- "\u7533\u8BF7\u4E8C\u7EF4\u7801": BilibiliQrcodeParamsSchema,
1934
- "\u4E8C\u7EF4\u7801\u72B6\u6001": BilibiliQrcodeStatusParamsSchema,
1935
- "\u83B7\u53D6UP\u4E3B\u603B\u64AD\u653E\u91CF": BilibiliUserParamsSchema,
1936
- "AV\u8F6CBV": BilibiliAv2BvParamsSchema,
1937
- "BV\u8F6CAV": BilibiliBv2AvParamsSchema
1938
- };
1939
- var KuaishouVideoParamsSchema = zod.z.object({
1940
- methodType: zod.z.literal("\u5355\u4E2A\u89C6\u9891\u4F5C\u54C1\u6570\u636E"),
1941
- photoId: zod.z.string({ required_error: "\u89C6\u9891ID\u4E0D\u80FD\u4E3A\u7A7A" }).min(1, "\u89C6\u9891ID\u4E0D\u80FD\u4E3A\u7A7A")
1942
- });
1943
- var KuaishouCommentParamsSchema = zod.z.object({
1944
- methodType: zod.z.literal("\u8BC4\u8BBA\u6570\u636E"),
1945
- photoId: zod.z.string({ required_error: "\u89C6\u9891ID\u4E0D\u80FD\u4E3A\u7A7A" }).min(1, "\u89C6\u9891ID\u4E0D\u80FD\u4E3A\u7A7A")
1946
- });
1947
- var KuaishouEmojiParamsSchema = zod.z.object({
1948
- methodType: zod.z.literal("Emoji\u6570\u636E")
1949
- });
1950
- var KuaishouValidationSchemas2 = {
1951
- "\u5355\u4E2A\u89C6\u9891\u4F5C\u54C1\u6570\u636E": KuaishouVideoParamsSchema,
1952
- "\u8BC4\u8BBA\u6570\u636E": KuaishouCommentParamsSchema,
1953
- "Emoji\u6570\u636E": KuaishouEmojiParamsSchema
1954
- };
1955
-
1956
- // src/validation/index.ts
1957
- var validateDouyinParams = (methodType, params) => {
1958
- const schema = DouyinValidationSchemas2[methodType];
1959
- const validated = schema.parse(
1960
- typeof params === "object" && params !== null ? { methodType, ...params } : { methodType, params }
1961
- );
1962
- return validated;
1963
- };
1964
- var validateBilibiliParams = (methodType, params) => {
1965
- const schema = BilibiliValidationSchemas2[methodType];
1966
- const validated = schema.parse(
1967
- typeof params === "object" && params !== null ? { methodType, ...params } : { methodType, params }
1968
- );
1969
- return validated;
1970
- };
1971
- var validateKuaishouParams = (methodType, params) => {
1972
- const schema = KuaishouValidationSchemas2[methodType];
1973
- const validated = schema.parse(
1974
- typeof params === "object" && params !== null ? { methodType, ...params } : { methodType, params }
1975
- );
1976
- return validated;
1977
- };
1978
- var createSuccessResponse = (data2, message, code = 200) => {
1979
- return {
1980
- success: true,
1981
- data: data2,
1982
- message,
1983
- code,
1984
- error: void 0
1985
- };
1986
- };
1987
- var createErrorResponse = (error, message, code = 500) => {
1988
- return {
1989
- success: false,
1990
- error,
1991
- message,
1992
- code,
1993
- data: void 0
1994
- };
1995
- };
1996
-
1997
- // src/model/DataFetchers.ts
1998
- async function getDouyinData(methodType, optionsOrCookie, cookieOrOptions) {
1999
- try {
2000
- let options;
2001
- let cookie;
2002
- if (typeof optionsOrCookie === "string") {
2003
- cookie = optionsOrCookie;
2004
- options = cookieOrOptions;
2005
- } else {
2006
- options = optionsOrCookie;
2007
- cookie = cookieOrOptions;
2008
- }
2009
- const { typeMode: _, ...validationOptions } = options || {};
2010
- const validatedParams = validateDouyinParams(methodType, validationOptions);
2011
- const apiParams = {
2012
- ...validatedParams
2013
- };
2014
- const rawData = await DouyinData(apiParams, cookie);
2015
- if (rawData.data === "") {
2016
- return createErrorResponse(rawData.amagiError, "\u6296\u97F3\u6570\u636E\u83B7\u53D6\u5931\u8D25");
2017
- }
2018
- return createSuccessResponse(rawData, "\u83B7\u53D6\u6210\u529F", 200);
2019
- } catch (error) {
2020
- const errorMessage = error instanceof Error ? error.message : "\u672A\u77E5\u9519\u8BEF";
2021
- throw new Error(`\u6296\u97F3\u6570\u636E\u83B7\u53D6\u5931\u8D25: ${errorMessage}`);
2022
- }
2023
- }
2024
- async function getBilibiliData(methodType, optionsOrCookie, cookieOrOptions) {
2025
- try {
2026
- let options;
2027
- let cookie;
2028
- if (typeof optionsOrCookie === "string") {
2029
- cookie = optionsOrCookie;
2030
- options = cookieOrOptions;
2031
- } else {
2032
- options = optionsOrCookie;
2033
- cookie = cookieOrOptions;
2034
- }
2035
- const { typeMode: _, ...validationOptions } = options || {};
2036
- const validatedParams = validateBilibiliParams(methodType, validationOptions);
2037
- const apiParams = {
2038
- ...validatedParams
2039
- };
2040
- const rawData = await fetchBilibili(apiParams, cookie);
2041
- if (rawData.code !== 0) {
2042
- return createErrorResponse(rawData.amagiError, "B\u7AD9\u6570\u636E\u83B7\u53D6\u5931\u8D25");
2043
- }
2044
- return createSuccessResponse(rawData, "\u83B7\u53D6\u6210\u529F", 200);
2045
- } catch (error) {
2046
- const errorMessage = error instanceof Error ? error.message : "\u672A\u77E5\u9519\u8BEF";
2047
- throw new Error(`B\u7AD9\u6570\u636E\u83B7\u53D6\u5931\u8D25: ${errorMessage}`);
2048
- }
2049
- }
2050
- async function getKuaishouData(methodType, optionsOrCookie, cookieOrOptions) {
2051
- try {
2052
- let options;
2053
- let cookie;
2054
- if (typeof optionsOrCookie === "string") {
2055
- cookie = optionsOrCookie;
2056
- options = cookieOrOptions;
2057
- } else {
2058
- options = optionsOrCookie;
2059
- cookie = cookieOrOptions;
2060
- }
2061
- const { typeMode: _, ...validationOptions } = options || {};
2062
- const validatedParams = validateKuaishouParams(methodType, validationOptions);
2063
- const apiParams = {
2064
- ...validatedParams
2065
- };
2066
- const rawData = await KuaishouData(apiParams, cookie);
2067
- if (rawData.code && Object.values(kuaishouAPIErrorCode).includes(rawData.code)) {
2068
- return createErrorResponse(rawData.amagiError, "\u5FEB\u624B\u6570\u636E\u83B7\u53D6\u5931\u8D25");
2069
- }
2070
- return createSuccessResponse(rawData, "\u83B7\u53D6\u6210\u529F", 200);
2071
- } catch (error) {
2072
- const errorMessage = error instanceof Error ? error.message : "\u672A\u77E5\u9519\u8BEF";
2073
- throw new Error(`\u5FEB\u624B\u6570\u636E\u83B7\u53D6\u5931\u8D25: ${errorMessage}`);
2074
- }
2075
- }
2076
-
2077
- // src/platform/bilibili/BilibiliApi.ts
2078
- var createBilibiliApiMethod = (methodType) => {
2079
- return async (options, cookie) => {
2080
- return await getBilibiliData(methodType, options, cookie);
2081
- };
2082
- };
2083
- var createBoundBilibiliApiMethod = (methodType, cookie) => {
2084
- return async (options) => {
2085
- return await getBilibiliData(methodType, options, cookie);
2086
- };
2087
- };
2088
- var bilibili = {
2089
- /**
2090
- * 获取单个视频作品数据
2091
- * @param options 请求参数,包含 bvid 和可选的 typeMode
2092
- * @param cookie 有效的用户 Cookie
2093
- * @returns 统一格式的API响应
2094
- */
2095
- getVideoInfo: createBilibiliApiMethod("\u5355\u4E2A\u89C6\u9891\u4F5C\u54C1\u6570\u636E"),
2096
- /**
2097
- * 获取单个视频下载信息数据
2098
- * @param options 请求参数,包含 avid, cid 和可选的 typeMode
2099
- * @param cookie 有效的用户 Cookie
2100
- * @returns 统一格式的API响应
2101
- */
2102
- getVideoStream: createBilibiliApiMethod("\u5355\u4E2A\u89C6\u9891\u4E0B\u8F7D\u4FE1\u606F\u6570\u636E"),
2103
- /**
2104
- * 获取评论数据
2105
- * @param options 请求参数,包含 type, oid, 可选的 number, pn 和 typeMode
2106
- * @param cookie 有效的用户 Cookie
2107
- * @returns 统一格式的API响应
2108
- */
2109
- getComments: createBilibiliApiMethod("\u8BC4\u8BBA\u6570\u636E"),
2110
- /**
2111
- * 获取用户主页数据
2112
- * @param options 请求参数,包含 host_mid 和可选的 typeMode
2113
- * @param cookie 有效的用户 Cookie
2114
- * @returns 统一格式的API响应
2115
- */
2116
- getUserProfile: createBilibiliApiMethod("\u7528\u6237\u4E3B\u9875\u6570\u636E"),
2117
- /**
2118
- * 获取用户主页动态列表数据
2119
- * @param options 请求参数,包含 host_mid 和可选的 typeMode
2120
- * @param cookie 有效的用户 Cookie
2121
- * @returns 统一格式的API响应
2122
- */
2123
- getUserDynamic: createBilibiliApiMethod("\u7528\u6237\u4E3B\u9875\u52A8\u6001\u5217\u8868\u6570\u636E"),
2124
- /**
2125
- * 获取 Emoji 数据
2126
- * @param options 可选的请求参数 (主要用于 typeMode)
2127
- * @param cookie 有效的用户 Cookie
2128
- * @returns 统一格式的API响应
2129
- */
2130
- getEmojiList: createBilibiliApiMethod("Emoji\u6570\u636E"),
2131
- /**
2132
- * 获取番剧基本信息数据
2133
- * @param options 请求参数,包含可选的 season_id, ep_id 和 typeMode
2134
- * @param cookie 有效的用户 Cookie
2135
- * @returns 统一格式的API响应
2136
- */
2137
- getBangumiInfo: createBilibiliApiMethod("\u756A\u5267\u57FA\u672C\u4FE1\u606F\u6570\u636E"),
2138
- /**
2139
- * 获取番剧下载信息数据
2140
- * @param options 请求参数,包含 cid, ep_id 和可选的 typeMode
2141
- * @param cookie 有效的用户 Cookie
2142
- * @returns 统一格式的API响应
2143
- */
2144
- getBangumiStream: createBilibiliApiMethod("\u756A\u5267\u4E0B\u8F7D\u4FE1\u606F\u6570\u636E"),
2145
- /**
2146
- * 获取动态详情数据
2147
- * @param options 请求参数,包含 dynamic_id 和可选的 typeMode
2148
- * @param cookie 有效的用户 Cookie
2149
- * @returns 统一格式的API响应
2150
- */
2151
- getDynamicInfo: createBilibiliApiMethod("\u52A8\u6001\u8BE6\u60C5\u6570\u636E"),
2152
- /**
2153
- * 获取动态卡片数据
2154
- * @param options 请求参数,包含 dynamic_id 和可选的 typeMode
2155
- * @param cookie 有效的用户 Cookie
2156
- * @returns 统一格式的API响应
2157
- */
2158
- getDynamicCard: createBilibiliApiMethod("\u52A8\u6001\u5361\u7247\u6570\u636E"),
2159
- /**
2160
- * 获取直播间信息
2161
- * @param options 请求参数,包含 room_id 和可选的 typeMode
2162
- * @param cookie 有效的用户 Cookie
2163
- * @returns 统一格式的API响应
2164
- */
2165
- getLiveRoomDetail: createBilibiliApiMethod("\u76F4\u64AD\u95F4\u4FE1\u606F"),
2166
- /**
2167
- * 获取直播间初始化信息
2168
- * @param options 请求参数,包含 room_id 和可选的 typeMode
2169
- * @param cookie 有效的用户 Cookie
2170
- * @returns 统一格式的API响应
2171
- */
2172
- getLiveRoomInitInfo: createBilibiliApiMethod("\u76F4\u64AD\u95F4\u521D\u59CB\u5316\u4FE1\u606F"),
2173
- /**
2174
- * 获取登录基本信息
2175
- * @param options 可选的请求参数 (主要用于 typeMode)
2176
- * @param cookie 有效的用户 Cookie
2177
- * @returns 统一格式的API响应
2178
- */
2179
- getLoginBasicInfo: createBilibiliApiMethod("\u767B\u5F55\u57FA\u672C\u4FE1\u606F"),
2180
- /**
2181
- * 申请登录二维码
2182
- * @param options 可选的请求参数 (主要用于 typeMode)
2183
- * @param cookie 有效的用户 Cookie
2184
- * @returns 统一格式的API响应
2185
- */
2186
- getLoginQrcode: createBilibiliApiMethod("\u7533\u8BF7\u4E8C\u7EF4\u7801"),
2187
- /**
2188
- * 检查二维码状态
2189
- * @param options 请求参数,包含 qrcode_key 和可选的 typeMode
2190
- * @param cookie 有效的用户 Cookie
2191
- * @returns 统一格式的API响应
2192
- */
2193
- checkQrcodeStatus: createBilibiliApiMethod("\u4E8C\u7EF4\u7801\u72B6\u6001"),
2194
- /**
2195
- * 获取 UP 主总播放量
2196
- * @param options 请求参数,包含 host_mid 和可选的 typeMode
2197
- * @param cookie 有效的用户 Cookie
2198
- * @returns 统一格式的API响应
2199
- */
2200
- getUserTotalPlayCount: createBilibiliApiMethod("\u83B7\u53D6UP\u4E3B\u603B\u64AD\u653E\u91CF"),
2201
- /**
2202
- * 将 AV 号转换为 BV 号
2203
- * @param options 请求参数,包含 avid 和可选的 typeMode
2204
- * @param cookie 有效的用户 Cookie (此接口通常不需要)
2205
- * @returns 统一格式的API响应
2206
- */
2207
- convertAvToBv: createBilibiliApiMethod("AV\u8F6CBV"),
2208
- /**
2209
- * 将 BV 号转换为 AV 号
2210
- * @param options 请求参数,包含 bvid 和可选的 typeMode
2211
- * @param cookie 有效的用户 Cookie (此接口通常不需要)
2212
- * @returns 统一格式的API响应
2213
- */
2214
- convertBvToAv: createBilibiliApiMethod("BV\u8F6CAV")
2215
- };
2216
- var createBoundBilibiliApi = (cookie) => {
2217
- return {
2218
- /**
2219
- * 获取单个视频作品数据
2220
- * @param options 请求参数,包含 bvid 和可选的 typeMode
2221
- * @returns 统一格式的API响应
2222
- */
2223
- getVideoInfo: createBoundBilibiliApiMethod("\u5355\u4E2A\u89C6\u9891\u4F5C\u54C1\u6570\u636E", cookie),
2224
- /**
2225
- * 获取单个视频下载信息数据
2226
- * @param options 请求参数,包含 avid, cid 和可选的 typeMode
2227
- * @returns 统一格式的API响应
2228
- */
2229
- getVideoStream: createBoundBilibiliApiMethod("\u5355\u4E2A\u89C6\u9891\u4E0B\u8F7D\u4FE1\u606F\u6570\u636E", cookie),
2230
- /**
2231
- * 获取评论数据
2232
- * @param options 请求参数,包含 type, oid, 可选的 number, pn 和 typeMode
2233
- * @returns 统一格式的API响应
2234
- */
2235
- getComments: createBoundBilibiliApiMethod("\u8BC4\u8BBA\u6570\u636E", cookie),
2236
- /**
2237
- * 获取用户主页数据
2238
- * @param options 请求参数,包含 host_mid 和可选的 typeMode
2239
- * @returns 统一格式的API响应
2240
- */
2241
- getUserProfile: createBoundBilibiliApiMethod("\u7528\u6237\u4E3B\u9875\u6570\u636E", cookie),
2242
- /**
2243
- * 获取用户主页动态列表数据
2244
- * @param options 请求参数,包含 host_mid 和可选的 typeMode
2245
- * @returns 统一格式的API响应
2246
- */
2247
- getUserDynamic: createBoundBilibiliApiMethod("\u7528\u6237\u4E3B\u9875\u52A8\u6001\u5217\u8868\u6570\u636E", cookie),
2248
- /**
2249
- * 获取 Emoji 数据
2250
- * @param options 可选的请求参数 (主要用于 typeMode)
2251
- * @returns 统一格式的API响应
2252
- */
2253
- getEmojiList: createBoundBilibiliApiMethod("Emoji\u6570\u636E", cookie),
2254
- /**
2255
- * 获取番剧基本信息数据
2256
- * @param options 请求参数,包含可选的 season_id, ep_id 和 typeMode
2257
- * @returns 统一格式的API响应
2258
- */
2259
- getBangumiInfo: createBoundBilibiliApiMethod("\u756A\u5267\u57FA\u672C\u4FE1\u606F\u6570\u636E", cookie),
2260
- /**
2261
- * 获取番剧下载信息数据
2262
- * @param options 请求参数,包含 cid, ep_id 和可选的 typeMode
2263
- * @returns 统一格式的API响应
2264
- */
2265
- getBangumiStream: createBoundBilibiliApiMethod("\u756A\u5267\u4E0B\u8F7D\u4FE1\u606F\u6570\u636E", cookie),
2266
- /**
2267
- * 获取动态详情数据
2268
- * @param options 请求参数,包含 dynamic_id 和可选的 typeMode
2269
- * @returns 统一格式的API响应
2270
- */
2271
- getDynamicInfo: createBoundBilibiliApiMethod("\u52A8\u6001\u8BE6\u60C5\u6570\u636E", cookie),
2272
- /**
2273
- * 获取动态卡片数据
2274
- * @param options 请求参数,包含 dynamic_id 和可选的 typeMode
2275
- * @returns 统一格式的API响应
2276
- */
2277
- getDynamicCard: createBoundBilibiliApiMethod("\u52A8\u6001\u5361\u7247\u6570\u636E", cookie),
2278
- /**
2279
- * 获取直播间信息
2280
- * @param options 请求参数,包含 room_id 和可选的 typeMode
2281
- * @returns 统一格式的API响应
2282
- */
2283
- getLiveRoomDetail: createBoundBilibiliApiMethod("\u76F4\u64AD\u95F4\u4FE1\u606F", cookie),
2284
- /**
2285
- * 获取直播间初始化信息
2286
- * @param options 请求参数,包含 room_id 和可选的 typeMode
2287
- * @returns 统一格式的API响应
2288
- */
2289
- getLiveRoomInitInfo: createBoundBilibiliApiMethod("\u76F4\u64AD\u95F4\u521D\u59CB\u5316\u4FE1\u606F", cookie),
2290
- /**
2291
- * 获取登录基本信息
2292
- * @param options 可选的请求参数 (主要用于 typeMode)
2293
- * @returns 统一格式的API响应
2294
- */
2295
- getLoginBasicInfo: createBoundBilibiliApiMethod("\u767B\u5F55\u57FA\u672C\u4FE1\u606F", cookie),
2296
- /**
2297
- * 申请登录二维码
2298
- * @param options 可选的请求参数 (主要用于 typeMode)
2299
- * @returns 统一格式的API响应
2300
- */
2301
- getLoginQrcode: createBoundBilibiliApiMethod("\u7533\u8BF7\u4E8C\u7EF4\u7801", cookie),
2302
- /**
2303
- * 检查二维码状态
2304
- * @param options 请求参数,包含 qrcode_key 和可选的 typeMode
2305
- * @returns 统一格式的API响应
2306
- */
2307
- checkQrcodeStatus: createBoundBilibiliApiMethod("\u4E8C\u7EF4\u7801\u72B6\u6001", cookie),
2308
- /**
2309
- * 获取 UP 主总播放量
2310
- * @param options 请求参数,包含 host_mid 和可选的 typeMode
2311
- * @returns 统一格式的API响应
2312
- */
2313
- getUserTotalPlayCount: createBoundBilibiliApiMethod("\u83B7\u53D6UP\u4E3B\u603B\u64AD\u653E\u91CF", cookie),
2314
- /**
2315
- * 将 AV 号转换为 BV 号
2316
- * @param options 请求参数,包含 avid 和可选的 typeMode
2317
- * @returns 统一格式的API响应
2318
- */
2319
- convertAvToBv: createBoundBilibiliApiMethod("AV\u8F6CBV", cookie),
2320
- /**
2321
- * 将 BV 号转换为 AV 号
2322
- * @param options 请求参数,包含 bvid 和可选的 typeMode
2323
- * @returns 统一格式的API响应
2324
- */
2325
- convertBvToAv: createBoundBilibiliApiMethod("BV\u8F6CAV", cookie)
2326
- };
2327
- };
2328
- var ApiError = class extends Error {
2329
- code;
2330
- platform;
2331
- /**
2332
- * 构造API错误
2333
- * @param message - 错误消息
2334
- * @param code - 错误代码
2335
- * @param platform - 平台名称
2336
- */
2337
- constructor(message, code = 500, platform = "unknown") {
2338
- super(message);
2339
- this.name = "ApiError";
2340
- this.code = code;
2341
- this.platform = platform;
2342
- }
2343
- };
2344
- var ValidationError = class _ValidationError extends Error {
2345
- errors;
2346
- requestPath;
2347
- /**
2348
- * 构造参数验证错误
2349
- * @param message - 错误消息
2350
- * @param errors - 详细错误信息
2351
- * @param requestPath - HTTP请求路径
2352
- */
2353
- constructor(message, errors, requestPath) {
2354
- super(message);
2355
- this.name = "ValidationError";
2356
- this.errors = errors;
2357
- this.requestPath = requestPath;
2358
- }
2359
- /**
2360
- * 从Zod错误创建验证错误
2361
- * @param zodError - Zod验证错误
2362
- * @param requestPath - HTTP请求路径
2363
- * @returns 验证错误实例
2364
- */
2365
- static fromZodError(zodError, requestPath) {
2366
- const errors = zodError.errors.map((err) => ({
2367
- field: err.path.join("."),
2368
- message: err.message
2369
- }));
2370
- return new _ValidationError("\u53C2\u6570\u9A8C\u8BC1\u5931\u8D25", errors, requestPath);
2371
- }
2372
- };
2373
- var handleError = (error, requestPath) => {
2374
- if (error instanceof ValidationError) {
2375
- return {
2376
- code: 400,
2377
- message: error.message,
2378
- data: null,
2379
- errors: error.errors,
2380
- requestPath: error.requestPath || requestPath
2381
- };
2382
- }
2383
- if (error instanceof ApiError) {
2384
- return {
2385
- code: error.code,
2386
- message: error.message,
2387
- data: null,
2388
- platform: error.platform,
2389
- requestPath
2390
- };
2391
- }
2392
- if (error instanceof zod.z.ZodError) {
2393
- const validationError = ValidationError.fromZodError(error, requestPath);
2394
- return handleError(validationError, requestPath);
2395
- }
2396
- const errorMessage = error instanceof Error ? error.message : "\u672A\u77E5\u9519\u8BEF";
2397
- return {
2398
- code: 500,
2399
- message: errorMessage,
2400
- data: null,
2401
- requestPath
2402
- };
2403
- };
2404
-
2405
- // src/middleware/validation.ts
2406
- var createValidationMiddleware = (validateFn, methodType) => {
2407
- return (req, res, next) => {
2408
- try {
2409
- const params = { ...req.query, ...req.body };
2410
- const validatedParams = validateFn(methodType, params);
2411
- req.validatedParams = validatedParams;
2412
- next();
2413
- } catch (error) {
2414
- const errorResponse = handleError(error, req.originalUrl);
2415
- res.status(errorResponse.code || 500).json(errorResponse);
2416
- }
2417
- };
2418
- };
2419
- var createDouyinValidationMiddleware = (methodType) => createValidationMiddleware(validateDouyinParams, methodType);
2420
- var createBilibiliValidationMiddleware = (methodType) => createValidationMiddleware(validateBilibiliParams, methodType);
2421
- var createKuaishouValidationMiddleware = (methodType) => createValidationMiddleware(validateKuaishouParams, methodType);
2422
- var createBilibiliRouteHandler = (dataFetcher, methodType, cookie) => {
2423
- return async (req, res) => {
2424
- try {
2425
- const result = await dataFetcher(methodType, req.validatedParams, cookie);
2426
- res.json({
2427
- ...result,
2428
- requestPath: req.originalUrl
2429
- });
2430
- } catch (error) {
2431
- const errorResponse = handleError(error);
2432
- res.status(errorResponse.code || 500).json({
2433
- ...errorResponse,
2434
- requestPath: req.originalUrl
2435
- });
2436
- }
2437
- };
2438
- };
2439
- var createBilibiliRoutes = (cookie) => {
2440
- const router = express.Router();
2441
- router.get(
2442
- "/fetch_one_video",
2443
- createBilibiliValidationMiddleware("\u5355\u4E2A\u89C6\u9891\u4F5C\u54C1\u6570\u636E"),
2444
- createBilibiliRouteHandler(getBilibiliData, "\u5355\u4E2A\u89C6\u9891\u4F5C\u54C1\u6570\u636E", cookie)
2445
- );
2446
- router.get(
2447
- "/fetch_video_playurl",
2448
- createBilibiliValidationMiddleware("\u5355\u4E2A\u89C6\u9891\u4E0B\u8F7D\u4FE1\u606F\u6570\u636E"),
2449
- createBilibiliRouteHandler(getBilibiliData, "\u5355\u4E2A\u89C6\u9891\u4E0B\u8F7D\u4FE1\u606F\u6570\u636E", cookie)
2450
- );
2451
- router.get(
2452
- "/fetch_work_comments",
2453
- createBilibiliValidationMiddleware("\u8BC4\u8BBA\u6570\u636E"),
2454
- createBilibiliRouteHandler(getBilibiliData, "\u8BC4\u8BBA\u6570\u636E", cookie)
2455
- );
2456
- router.get(
2457
- "/fetch_user_profile",
2458
- createBilibiliValidationMiddleware("\u7528\u6237\u4E3B\u9875\u6570\u636E"),
2459
- createBilibiliRouteHandler(getBilibiliData, "\u7528\u6237\u4E3B\u9875\u6570\u636E", cookie)
2460
- );
2461
- router.get(
2462
- "/fetch_user_dynamic",
2463
- createBilibiliValidationMiddleware("\u7528\u6237\u4E3B\u9875\u52A8\u6001\u5217\u8868\u6570\u636E"),
2464
- createBilibiliRouteHandler(getBilibiliData, "\u7528\u6237\u4E3B\u9875\u52A8\u6001\u5217\u8868\u6570\u636E", cookie)
2465
- );
2466
- router.get(
2467
- "/fetch_emoji_list",
2468
- createBilibiliValidationMiddleware("Emoji\u6570\u636E"),
2469
- createBilibiliRouteHandler(getBilibiliData, "Emoji\u6570\u636E", cookie)
2470
- );
2471
- router.get(
2472
- "/fetch_bangumi_video_info",
2473
- createBilibiliValidationMiddleware("\u756A\u5267\u57FA\u672C\u4FE1\u606F\u6570\u636E"),
2474
- createBilibiliRouteHandler(getBilibiliData, "\u756A\u5267\u57FA\u672C\u4FE1\u606F\u6570\u636E", cookie)
2475
- );
2476
- router.get(
2477
- "/fetch_bangumi_video_playurl",
2478
- createBilibiliValidationMiddleware("\u756A\u5267\u4E0B\u8F7D\u4FE1\u606F\u6570\u636E"),
2479
- createBilibiliRouteHandler(getBilibiliData, "\u756A\u5267\u4E0B\u8F7D\u4FE1\u606F\u6570\u636E", cookie)
2480
- );
2481
- router.get(
2482
- "/fetch_dynamic_info",
2483
- createBilibiliValidationMiddleware("\u52A8\u6001\u8BE6\u60C5\u6570\u636E"),
2484
- createBilibiliRouteHandler(getBilibiliData, "\u52A8\u6001\u8BE6\u60C5\u6570\u636E", cookie)
2485
- );
2486
- router.get(
2487
- "/fetch_dynamic_card",
2488
- createBilibiliValidationMiddleware("\u52A8\u6001\u5361\u7247\u6570\u636E"),
2489
- createBilibiliRouteHandler(getBilibiliData, "\u52A8\u6001\u5361\u7247\u6570\u636E", cookie)
2490
- );
2491
- router.get(
2492
- "/fetch_live_room_detail",
2493
- createBilibiliValidationMiddleware("\u76F4\u64AD\u95F4\u4FE1\u606F"),
2494
- createBilibiliRouteHandler(getBilibiliData, "\u76F4\u64AD\u95F4\u4FE1\u606F", cookie)
2495
- );
2496
- router.get(
2497
- "/fetch_liveroom_def",
2498
- createBilibiliValidationMiddleware("\u76F4\u64AD\u95F4\u521D\u59CB\u5316\u4FE1\u606F"),
2499
- createBilibiliRouteHandler(getBilibiliData, "\u76F4\u64AD\u95F4\u521D\u59CB\u5316\u4FE1\u606F", cookie)
2500
- );
2501
- router.get(
2502
- "/login_basic_info",
2503
- createBilibiliValidationMiddleware("\u767B\u5F55\u57FA\u672C\u4FE1\u606F"),
2504
- createBilibiliRouteHandler(getBilibiliData, "\u767B\u5F55\u57FA\u672C\u4FE1\u606F", cookie)
2505
- );
2506
- router.get(
2507
- "/new_login_qrcode",
2508
- createBilibiliValidationMiddleware("\u7533\u8BF7\u4E8C\u7EF4\u7801"),
2509
- createBilibiliRouteHandler(getBilibiliData, "\u7533\u8BF7\u4E8C\u7EF4\u7801", cookie)
2510
- );
2511
- router.get(
2512
- "/check_qrcode",
2513
- createBilibiliValidationMiddleware("\u4E8C\u7EF4\u7801\u72B6\u6001"),
2514
- createBilibiliRouteHandler(getBilibiliData, "\u4E8C\u7EF4\u7801\u72B6\u6001", cookie)
2515
- );
2516
- router.get(
2517
- "/fetch_user_full_view",
2518
- createBilibiliValidationMiddleware("\u83B7\u53D6UP\u4E3B\u603B\u64AD\u653E\u91CF"),
2519
- createBilibiliRouteHandler(getBilibiliData, "\u83B7\u53D6UP\u4E3B\u603B\u64AD\u653E\u91CF", cookie)
2520
- );
2521
- router.get(
2522
- "/av_to_bv",
2523
- createBilibiliValidationMiddleware("AV\u8F6CBV"),
2524
- createBilibiliRouteHandler(getBilibiliData, "AV\u8F6CBV", cookie)
2525
- );
2526
- router.get(
2527
- "/bv_to_av",
2528
- createBilibiliValidationMiddleware("BV\u8F6CAV"),
2529
- createBilibiliRouteHandler(getBilibiliData, "BV\u8F6CAV", cookie)
2530
- );
2531
- return router;
2532
- };
2533
-
2534
- // src/platform/bilibili/index.ts
2535
- var bilibiliUtils = {
2536
- sign: {
2537
- wbi_sign,
2538
- av2bv,
2539
- bv2av
2540
- },
2541
- bilibiliApiUrls,
2542
- api: bilibili
2543
- };
2544
-
2545
- // src/platform/douyin/DouyinApi.ts
2546
- var createDouyinApiMethod = (methodType) => {
2547
- return async (options, cookie) => {
2548
- return await getDouyinData(methodType, options, cookie);
2549
- };
2550
- };
2551
- var createBoundDouyinApiMethod = (methodType, cookie) => {
2552
- return async (options) => {
2553
- return await getDouyinData(methodType, options, cookie);
2554
- };
2555
- };
2556
- var douyin = {
2557
- /**
2558
- * 聚合解析 (视频/图集/合辑)
2559
- * @param options 请求参数,包含 aweme_id 和可选的 typeMode
2560
- * @param cookie 有效的用户 Cookie
2561
- * @returns 统一格式的API响应,包含视频、图集或合辑数据
2562
- */
2563
- getWorkInfo: createDouyinApiMethod("\u805A\u5408\u89E3\u6790"),
2564
- /**
2565
- * 获取视频作品数据
2566
- * @param options 请求参数,包含 aweme_id 和可选的 typeMode
2567
- * @param cookie 有效的用户 Cookie
2568
- * @returns 统一格式的API响应,包含视频作品详细信息
2569
- */
2570
- getVideoWorkInfo: createDouyinApiMethod("\u89C6\u9891\u4F5C\u54C1\u6570\u636E"),
2571
- /**
2572
- * 获取图集作品数据
2573
- * @param options 请求参数,包含 aweme_id 和可选的 typeMode
2574
- * @param cookie 有效的用户 Cookie
2575
- * @returns 统一格式的API响应,包含图集作品详细信息
2576
- */
2577
- getImageAlbumWorkInfo: createDouyinApiMethod("\u56FE\u96C6\u4F5C\u54C1\u6570\u636E"),
2578
- /**
2579
- * 获取合辑作品数据
2580
- * @param options 请求参数,包含 aweme_id 和可选的 typeMode
2581
- * @param cookie 有效的用户 Cookie
2582
- * @returns 统一格式的API响应,包含合辑作品详细信息
2583
- */
2584
- getSlidesWorkInfo: createDouyinApiMethod("\u5408\u8F91\u4F5C\u54C1\u6570\u636E"),
2585
- /**
2586
- * 获取评论数据
2587
- * @param options 请求参数,包含 aweme_id, 可选的 number, cursor 和 typeMode
2588
- * @param cookie 有效的用户 Cookie
2589
- * @returns 统一格式的API响应,包含评论列表数据
2590
- */
2591
- getComments: createDouyinApiMethod("\u8BC4\u8BBA\u6570\u636E"),
2592
- /**
2593
- * 获取指定评论回复数据
2594
- * @param options 请求参数,包含 aweme_id, comment_id, 可选的 number, cursor 和 typeMode
2595
- * @param cookie 有效的用户 Cookie
2596
- * @returns 统一格式的API响应,包含评论回复数据
2597
- */
2598
- getCommentReplies: createDouyinApiMethod("\u6307\u5B9A\u8BC4\u8BBA\u56DE\u590D\u6570\u636E"),
2599
- /**
2600
- * 获取用户主页数据
2601
- * @param options 请求参数,包含 sec_uid 和可选的 typeMode
2602
- * @param cookie 有效的用户 Cookie
2603
- * @returns 统一格式的API响应,包含用户详细信息
2604
- */
2605
- getUserProfile: createDouyinApiMethod("\u7528\u6237\u4E3B\u9875\u6570\u636E"),
2606
- /**
2607
- * 获取 Emoji 数据
2608
- * @param options 可选的请求参数 (主要用于 typeMode)
2609
- * @param cookie 可选的用户 Cookie
2610
- * @returns 统一格式的API响应,包含Emoji列表数据
2611
- */
2612
- getEmojiList: createDouyinApiMethod("Emoji\u6570\u636E"),
2613
- /**
2614
- * 获取动态表情数据
2615
- * @param options 可选的请求参数 (主要用于 typeMode)
2616
- * @param cookie 有效的用户 Cookie
2617
- * @returns 统一格式的API响应,包含动态表情数据
2618
- */
2619
- getEmojiProList: createDouyinApiMethod("\u52A8\u6001\u8868\u60C5\u6570\u636E"),
2620
- /**
2621
- * 获取用户主页视频列表数据
2622
- * @param options 请求参数,包含 sec_uid, 可选的 number, max_cursor 和 typeMode
2623
- * @param cookie 有效的用户 Cookie
2624
- * @returns 统一格式的API响应,包含用户发布的视频列表
2625
- */
2626
- getUserVideos: createDouyinApiMethod("\u7528\u6237\u4E3B\u9875\u89C6\u9891\u5217\u8868\u6570\u636E"),
2627
- /**
2628
- * 获取音乐数据
2629
- * @param options 请求参数,包含 music_id 和可选的 typeMode
2630
- * @param cookie 有效的用户 Cookie
2631
- * @returns 统一格式的API响应,包含音乐详细信息
2632
- */
2633
- getMusicInfo: createDouyinApiMethod("\u97F3\u4E50\u6570\u636E"),
2634
- /**
2635
- * 获取热点词数据
2636
- * @param options 请求参数,包含 query, 可选的 number 和 typeMode
2637
- * @param cookie 有效的用户 Cookie
2638
- * @returns 统一格式的API响应,包含热点搜索词列表
2639
- */
2640
- getSuggestWords: createDouyinApiMethod("\u70ED\u70B9\u8BCD\u6570\u636E"),
2641
- /**
2642
- * 获取搜索数据
2643
- * @param options 请求参数,包含 query, 可选的 number, search_id, cursor 和 typeMode
2644
- * @param cookie 有效的用户 Cookie
2645
- * @returns 统一格式的API响应,包含搜索结果数据
2646
- */
2647
- search: createDouyinApiMethod("\u641C\u7D22\u6570\u636E"),
2648
- /**
2649
- * 获取直播间信息
2650
- * @param options 请求参数,包含 sec_uid 和可选的 typeMode
2651
- * @param cookie 有效的用户 Cookie
2652
- * @returns 统一格式的API响应,包含直播间详细信息
2653
- */
2654
- getLiveRoomInfo: createDouyinApiMethod("\u76F4\u64AD\u95F4\u4FE1\u606F\u6570\u636E")
2655
- };
2656
- var createBoundDouyinApi = (cookie) => {
2657
- return {
2658
- /**
2659
- * 聚合解析 (视频/图集/合辑)
2660
- * @param options 请求参数,包含 aweme_id 和可选的 typeMode
2661
- * @returns 统一格式的API响应,包含视频、图集或合辑数据
2662
- */
2663
- getWorkInfo: createBoundDouyinApiMethod("\u805A\u5408\u89E3\u6790", cookie),
2664
- /**
2665
- * 获取视频作品数据
2666
- * @param options 请求参数,包含 aweme_id 和可选的 typeMode
2667
- * @returns 统一格式的API响应,包含视频作品详细信息
2668
- */
2669
- getVideoWorkInfo: createBoundDouyinApiMethod("\u89C6\u9891\u4F5C\u54C1\u6570\u636E", cookie),
2670
- /**
2671
- * 获取图集作品数据
2672
- * @param options 请求参数,包含 aweme_id 和可选的 typeMode
2673
- * @returns 统一格式的API响应,包含图集作品详细信息
2674
- */
2675
- getImageAlbumWorkInfo: createBoundDouyinApiMethod("\u56FE\u96C6\u4F5C\u54C1\u6570\u636E", cookie),
2676
- /**
2677
- * 获取合辑作品数据
2678
- * @param options 请求参数,包含 aweme_id 和可选的 typeMode
2679
- * @returns 统一格式的API响应,包含合辑作品详细信息
2680
- */
2681
- getSlidesWorkInfo: createBoundDouyinApiMethod("\u5408\u8F91\u4F5C\u54C1\u6570\u636E", cookie),
2682
- /**
2683
- * 获取评论数据
2684
- * @param options 请求参数,包含 aweme_id, 可选的 number, cursor 和 typeMode
2685
- * @returns 统一格式的API响应,包含评论列表数据
2686
- */
2687
- getComments: createBoundDouyinApiMethod("\u8BC4\u8BBA\u6570\u636E", cookie),
2688
- /**
2689
- * 获取指定评论回复数据
2690
- * @param options 请求参数,包含 aweme_id, comment_id, 可选的 number, cursor 和 typeMode
2691
- * @returns 统一格式的API响应,包含评论回复数据
2692
- */
2693
- getCommentReplies: createBoundDouyinApiMethod("\u6307\u5B9A\u8BC4\u8BBA\u56DE\u590D\u6570\u636E", cookie),
2694
- /**
2695
- * 获取用户主页数据
2696
- * @param options 请求参数,包含 sec_uid 和可选的 typeMode
2697
- * @returns 统一格式的API响应,包含用户详细信息
2698
- */
2699
- getUserProfile: createBoundDouyinApiMethod("\u7528\u6237\u4E3B\u9875\u6570\u636E", cookie),
2700
- /**
2701
- * 获取 Emoji 数据
2702
- * @param options 可选的请求参数 (主要用于 typeMode)
2703
- * @returns 统一格式的API响应,包含Emoji列表数据
2704
- */
2705
- getEmojiList: createBoundDouyinApiMethod("Emoji\u6570\u636E", cookie),
2706
- /**
2707
- * 获取动态表情数据
2708
- * @param options 可选的请求参数 (主要用于 typeMode)
2709
- * @returns 统一格式的API响应,包含动态表情数据
2710
- */
2711
- getEmojiProList: createBoundDouyinApiMethod("\u52A8\u6001\u8868\u60C5\u6570\u636E", cookie),
2712
- /**
2713
- * 获取用户主页视频列表数据
2714
- * @param options 请求参数,包含 sec_uid, 可选的 number, max_cursor 和 typeMode
2715
- * @returns 统一格式的API响应,包含用户发布的视频列表
2716
- */
2717
- getUserVideos: createBoundDouyinApiMethod("\u7528\u6237\u4E3B\u9875\u89C6\u9891\u5217\u8868\u6570\u636E", cookie),
2718
- /**
2719
- * 获取音乐数据
2720
- * @param options 请求参数,包含 music_id 和可选的 typeMode
2721
- * @returns 统一格式的API响应,包含音乐详细信息
2722
- */
2723
- getMusicInfo: createBoundDouyinApiMethod("\u97F3\u4E50\u6570\u636E", cookie),
2724
- /**
2725
- * 获取热点词数据
2726
- * @param options 请求参数,包含 query, 可选的 number 和 typeMode
2727
- * @returns 统一格式的API响应,包含热点搜索词列表
2728
- */
2729
- getSuggestWords: createBoundDouyinApiMethod("\u70ED\u70B9\u8BCD\u6570\u636E", cookie),
2730
- /**
2731
- * 获取搜索数据
2732
- * @param options 请求参数,包含 query, 可选的 number, search_id, cursor 和 typeMode
2733
- * @returns 统一格式的API响应,包含搜索结果数据
2734
- */
2735
- search: createBoundDouyinApiMethod("\u641C\u7D22\u6570\u636E", cookie),
2736
- /**
2737
- * 获取直播间信息
2738
- * @param options 请求参数,包含 sec_uid 和可选的 typeMode
2739
- * @returns 统一格式的API响应,包含直播间详细信息
2740
- */
2741
- getLiveRoomInfo: createBoundDouyinApiMethod("\u76F4\u64AD\u95F4\u4FE1\u606F\u6570\u636E", cookie)
2742
- };
2743
- };
2744
- var createDouyinRouteHandler = (dataFetcher, methodType, cookie) => {
2745
- return async (req, res) => {
2746
- try {
2747
- const result = await dataFetcher(methodType, req.validatedParams, cookie);
2748
- res.json({
2749
- ...result,
2750
- requestPath: req.originalUrl
2751
- });
2752
- } catch (error) {
2753
- const errorResponse = handleError(error);
2754
- res.status(errorResponse.code || 500).json({
2755
- ...errorResponse,
2756
- requestPath: req.originalUrl
2757
- });
2758
- }
2759
- };
2760
- };
2761
- var createDouyinRoutes = (cookie) => {
2762
- const router = express.Router();
2763
- router.get(
2764
- "/fetch_one_work",
2765
- createDouyinValidationMiddleware("\u805A\u5408\u89E3\u6790"),
2766
- createDouyinRouteHandler(getDouyinData, "\u805A\u5408\u89E3\u6790", cookie)
2767
- );
2768
- router.get(
2769
- "/fetch_one_work",
2770
- createDouyinValidationMiddleware("\u89C6\u9891\u4F5C\u54C1\u6570\u636E"),
2771
- createDouyinRouteHandler(getDouyinData, "\u89C6\u9891\u4F5C\u54C1\u6570\u636E", cookie)
2772
- );
2773
- router.get(
2774
- "/fetch_one_work",
2775
- createDouyinValidationMiddleware("\u56FE\u96C6\u4F5C\u54C1\u6570\u636E"),
2776
- createDouyinRouteHandler(getDouyinData, "\u56FE\u96C6\u4F5C\u54C1\u6570\u636E", cookie)
2777
- );
2778
- router.get(
2779
- "/fetch_one_work",
2780
- createDouyinValidationMiddleware("\u5408\u8F91\u4F5C\u54C1\u6570\u636E"),
2781
- createDouyinRouteHandler(getDouyinData, "\u5408\u8F91\u4F5C\u54C1\u6570\u636E", cookie)
2782
- );
2783
- router.get(
2784
- "/fetch_work_comments",
2785
- createDouyinValidationMiddleware("\u8BC4\u8BBA\u6570\u636E"),
2786
- createDouyinRouteHandler(getDouyinData, "\u8BC4\u8BBA\u6570\u636E", cookie)
2787
- );
2788
- router.get(
2789
- "/fetch_user_info",
2790
- createDouyinValidationMiddleware("\u7528\u6237\u4E3B\u9875\u6570\u636E"),
2791
- createDouyinRouteHandler(getDouyinData, "\u7528\u6237\u4E3B\u9875\u6570\u636E", cookie)
2792
- );
2793
- router.get(
2794
- "/fetch_user_post_videos",
2795
- createDouyinValidationMiddleware("\u7528\u6237\u4E3B\u9875\u89C6\u9891\u5217\u8868\u6570\u636E"),
2796
- createDouyinRouteHandler(getDouyinData, "\u7528\u6237\u4E3B\u9875\u89C6\u9891\u5217\u8868\u6570\u636E", cookie)
2797
- );
2798
- router.get(
2799
- "/fetch_search_info",
2800
- createDouyinValidationMiddleware("\u641C\u7D22\u6570\u636E"),
2801
- createDouyinRouteHandler(getDouyinData, "\u641C\u7D22\u6570\u636E", cookie)
2802
- );
2803
- router.get(
2804
- "/fetch_suggest_words",
2805
- createDouyinValidationMiddleware("\u70ED\u70B9\u8BCD\u6570\u636E"),
2806
- createDouyinRouteHandler(getDouyinData, "\u70ED\u70B9\u8BCD\u6570\u636E", cookie)
2807
- );
2808
- router.get(
2809
- "/fetch_music_work",
2810
- createDouyinValidationMiddleware("\u97F3\u4E50\u6570\u636E"),
2811
- createDouyinRouteHandler(getDouyinData, "\u97F3\u4E50\u6570\u636E", cookie)
2812
- );
2813
- router.get(
2814
- "/fetch_emoji_list",
2815
- createDouyinValidationMiddleware("Emoji\u6570\u636E"),
2816
- createDouyinRouteHandler(getDouyinData, "Emoji\u6570\u636E", cookie)
2817
- );
2818
- router.get(
2819
- "/fetch_emoji_pro_list",
2820
- createDouyinValidationMiddleware("\u52A8\u6001\u8868\u60C5\u6570\u636E"),
2821
- createDouyinRouteHandler(getDouyinData, "\u52A8\u6001\u8868\u60C5\u6570\u636E", cookie)
2822
- );
2823
- router.get(
2824
- "/fetch_user_live_videos",
2825
- createDouyinValidationMiddleware("\u76F4\u64AD\u95F4\u4FE1\u606F\u6570\u636E"),
2826
- createDouyinRouteHandler(getDouyinData, "\u76F4\u64AD\u95F4\u4FE1\u606F\u6570\u636E", cookie)
2827
- );
2828
- router.get(
2829
- "/fetch_video_comment_replies",
2830
- createDouyinValidationMiddleware("\u6307\u5B9A\u8BC4\u8BBA\u56DE\u590D\u6570\u636E"),
2831
- createDouyinRouteHandler(getDouyinData, "\u6307\u5B9A\u8BC4\u8BBA\u56DE\u590D\u6570\u636E", cookie)
2832
- );
2833
- return router;
2834
- };
2835
-
2836
- // src/platform/douyin/index.ts
2837
- var douyinUtils = {
2838
- sign: douyinSign,
2839
- douyinApiUrls,
2840
- api: douyin
2841
- };
2842
- var createKuaishouRouteHandler = (dataFetcher, methodType, cookie) => {
2843
- return async (req, res) => {
2844
- try {
2845
- const result = await dataFetcher(methodType, req.validatedParams, cookie);
2846
- res.json({
2847
- ...result,
2848
- requestPath: req.originalUrl
2849
- });
2850
- } catch (error) {
2851
- const errorResponse = handleError(error);
2852
- res.status(errorResponse.code || 500).json({
2853
- ...errorResponse,
2854
- requestPath: req.originalUrl
2855
- });
2856
- }
2857
- };
2858
- };
2859
- var createKuaishouRoutes = (cookie) => {
2860
- const router = express.Router();
2861
- router.get(
2862
- "/fetch_one_work",
2863
- createKuaishouValidationMiddleware("\u5355\u4E2A\u89C6\u9891\u4F5C\u54C1\u6570\u636E"),
2864
- createKuaishouRouteHandler(getKuaishouData, "\u5355\u4E2A\u89C6\u9891\u4F5C\u54C1\u6570\u636E", cookie)
2865
- );
2866
- router.get(
2867
- "/fetch_work_comments",
2868
- createKuaishouValidationMiddleware("\u8BC4\u8BBA\u6570\u636E"),
2869
- createKuaishouRouteHandler(getKuaishouData, "\u8BC4\u8BBA\u6570\u636E", cookie)
2870
- );
2871
- router.get(
2872
- "/fetch_emoji_list",
2873
- createKuaishouValidationMiddleware("Emoji\u6570\u636E"),
2874
- createKuaishouRouteHandler(getKuaishouData, "Emoji\u6570\u636E", cookie)
2875
- );
2876
- return router;
2877
- };
2878
-
2879
- // src/platform/kuaishou/KuaishouApi.ts
2880
- var createKuaishouApiMethod = (methodType) => {
2881
- return async (options, cookie) => {
2882
- return await getKuaishouData(methodType, options, cookie);
2883
- };
2884
- };
2885
- var createBoundKuaishouApiMethod = (methodType, cookie) => {
2886
- return async (options) => {
2887
- return await getKuaishouData(methodType, options, cookie);
2888
- };
2889
- };
2890
- var kuaishou = {
2891
- /**
2892
- * 获取单个视频作品数据
2893
- * @param options 请求参数,包含 photoId 和可选的 typeMode
2894
- * @param cookie 可选的用户 Cookie
2895
- * @returns 统一格式的API响应
2896
- */
2897
- getWorkInfo: createKuaishouApiMethod("\u5355\u4E2A\u89C6\u9891\u4F5C\u54C1\u6570\u636E"),
2898
- /**
2899
- * 获取评论数据
2900
- * @param options 请求参数,包含 photoId 和可选的 typeMode
2901
- * @param cookie 可选的用户 Cookie
2902
- * @returns 统一格式的API响应
2903
- */
2904
- getComments: createKuaishouApiMethod("\u8BC4\u8BBA\u6570\u636E"),
2905
- /**
2906
- * 获取 Emoji 数据
2907
- * @param options 可选的请求参数 (主要用于 typeMode)
2908
- * @param cookie 可选的用户 Cookie
2909
- * @returns 统一格式的API响应
2910
- */
2911
- getEmojiList: createKuaishouApiMethod("Emoji\u6570\u636E")
2912
- };
2913
- var createBoundKuaishouApi = (cookie) => {
2914
- return {
2915
- /**
2916
- * 获取单个视频作品数据
2917
- * @param options 请求参数,包含 photoId 和可选的 typeMode
2918
- * @returns 统一格式的API响应
2919
- */
2920
- getWorkInfo: createBoundKuaishouApiMethod("\u5355\u4E2A\u89C6\u9891\u4F5C\u54C1\u6570\u636E", cookie),
2921
- /**
2922
- * 获取评论数据
2923
- * @param options 请求参数,包含 photoId 和可选的 typeMode
2924
- * @returns 统一格式的API响应
2925
- */
2926
- getComments: createBoundKuaishouApiMethod("\u8BC4\u8BBA\u6570\u636E", cookie),
2927
- /**
2928
- * 获取 Emoji 数据
2929
- * @param options 可选的请求参数 (主要用于 typeMode)
2930
- * @returns 统一格式的API响应
2931
- */
2932
- getEmojiList: createBoundKuaishouApiMethod("Emoji\u6570\u636E", cookie)
2933
- };
2934
- };
2935
-
2936
- // src/platform/kuaishou/index.ts
2937
- var kuaishouUtils = {
2938
- kuaishouApiUrls,
2939
- api: kuaishou
2940
- };
2941
- var createAmagiClient = (options) => {
2942
- const douyinCookie = (options == null ? void 0 : options.douyin) ?? "";
2943
- const bilibiliCookie = (options == null ? void 0 : options.bilibili) ?? "";
2944
- const kuaishouCookie = (options == null ? void 0 : options.kuaishou) ?? "";
2945
- const startServer = (port = 4567) => {
2946
- const app = express__default.default();
2947
- app.use(express__default.default.json());
2948
- app.use(express__default.default.urlencoded({ extended: true }));
2949
- app.get("/", (_req, res) => {
2950
- res.redirect(301, "https://amagi.apifox.cn");
2951
- });
2952
- app.get("/docs", (_req, res) => {
2953
- res.redirect(301, "https://amagi.apifox.cn");
2954
- });
2955
- app.use("/api/douyin", createDouyinRoutes(douyinCookie));
2956
- app.use("/api/bilibili", createBilibiliRoutes(bilibiliCookie));
2957
- app.use("/api/kuaishou", createKuaishouRoutes(kuaishouCookie));
2958
- app.listen(port, "::", () => {
2959
- logger.mark(`Amagi server listening on ${logger.green(`http://localhost:${port}`)} ${logger.yellow("API docs: https://amagi.apifox.cn ")}`);
2960
- });
2961
- return app;
2962
- };
2963
- const startClient = (port = 4567) => {
2964
- return startServer(port);
2965
- };
2966
- const getDouyinDataWithCookie = async (methodType, options2) => {
2967
- return await getDouyinData(methodType, options2, douyinCookie);
2968
- };
2969
- const getBilibiliDataWithCookie = async (methodType, options2) => {
2970
- return await getBilibiliData(methodType, options2, bilibiliCookie);
2971
- };
2972
- const getKuaishouDataWithCookie = async (methodType, options2) => {
2973
- return await getKuaishouData(methodType, options2, kuaishouCookie);
2974
- };
2975
- return {
2976
- /** 启动本地HTTP服务 */
2977
- startServer,
2978
- /** @deprecated 此方法已废弃,请使用 startServer 方法代替 */
2979
- startClient,
2980
- getDouyinData: getDouyinDataWithCookie,
2981
- getBilibiliData: getBilibiliDataWithCookie,
2982
- getKuaishouData: getKuaishouDataWithCookie,
2983
- douyin: {
2984
- ...douyinUtils,
2985
- /** 绑定了cookie的抖音API对象,调用时不需要传递cookie */
2986
- api: createBoundDouyinApi(douyinCookie)
2987
- },
2988
- bilibili: {
2989
- ...bilibiliUtils,
2990
- /** 绑定了cookie的B站API对象,调用时不需要传递cookie */
2991
- api: createBoundBilibiliApi(bilibiliCookie)
2992
- },
2993
- kuaishou: {
2994
- ...kuaishouUtils,
2995
- /** 绑定了cookie的快手API对象,调用时不需要传递cookie */
2996
- api: createBoundKuaishouApi(kuaishouCookie)
2997
- }
2998
- };
2999
- };
3000
-
3001
- // src/v5.ts
3002
- var amagiClient = createAmagiClient;
3003
- function CreateAmagiApp(options = {}) {
3004
- if (!(this instanceof CreateAmagiApp)) {
3005
- return createAmagiClient(options);
3006
- }
3007
- return createAmagiClient(options);
3008
- }
3009
- CreateAmagiApp.douyin = douyinUtils;
3010
- CreateAmagiApp.bilibili = bilibiliUtils;
3011
- CreateAmagiApp.kuaishou = kuaishouUtils;
3012
- CreateAmagiApp.getDouyinData = getDouyinData;
3013
- CreateAmagiApp.getBilibiliData = getBilibiliData;
3014
- CreateAmagiApp.getKuaishouData = getKuaishouData;
3015
- var CreateApp = CreateAmagiApp;
3016
- var amagi = CreateApp;
3017
- var v5_default = amagi;
3018
- /*!
3019
- * @ikenxuan/amagi
3020
- * Copyright(c) 2023 ikenxuan
3021
- * GPL-3.0 Licensed
3022
- */
3023
-
3024
- exports.ApiError = ApiError;
3025
- exports.BilibiliAv2BvParamsSchema = BilibiliAv2BvParamsSchema;
3026
- exports.BilibiliBangumiInfoParamsSchema = BilibiliBangumiInfoParamsSchema;
3027
- exports.BilibiliBangumiStreamParamsSchema = BilibiliBangumiStreamParamsSchema;
3028
- exports.BilibiliBv2AvParamsSchema = BilibiliBv2AvParamsSchema;
3029
- exports.BilibiliCommentParamsSchema = BilibiliCommentParamsSchema;
3030
- exports.BilibiliDynamicParamsSchema = BilibiliDynamicParamsSchema;
3031
- exports.BilibiliEmojiParamsSchema = BilibiliEmojiParamsSchema;
3032
- exports.BilibiliLiveParamsSchema = BilibiliLiveParamsSchema;
3033
- exports.BilibiliLoginParamsSchema = BilibiliLoginParamsSchema;
3034
- exports.BilibiliQrcodeParamsSchema = BilibiliQrcodeParamsSchema;
3035
- exports.BilibiliQrcodeStatusParamsSchema = BilibiliQrcodeStatusParamsSchema;
3036
- exports.BilibiliUserParamsSchema = BilibiliUserParamsSchema;
3037
- exports.BilibiliValidationSchemas = BilibiliValidationSchemas2;
3038
- exports.BilibiliVideoDownloadParamsSchema = BilibiliVideoDownloadParamsSchema;
3039
- exports.BilibiliVideoParamsSchema = BilibiliVideoParamsSchema;
3040
- exports.Client = CreateApp;
3041
- exports.CreateApp = CreateApp;
3042
- exports.DouyinCommentParamsSchema = DouyinCommentParamsSchema;
3043
- exports.DouyinCommentReplyParamsSchema = DouyinCommentReplyParamsSchema;
3044
- exports.DouyinEmojiListParamsSchema = DouyinEmojiListParamsSchema;
3045
- exports.DouyinEmojiProParamsSchema = DouyinEmojiProParamsSchema;
3046
- exports.DouyinMusicParamsSchema = DouyinMusicParamsSchema;
3047
- exports.DouyinQrcodeParamsSchema = DouyinQrcodeParamsSchema;
3048
- exports.DouyinSearchParamsSchema = DouyinSearchParamsSchema;
3049
- exports.DouyinUserParamsSchema = DouyinUserParamsSchema;
3050
- exports.DouyinValidationSchemas = DouyinValidationSchemas2;
3051
- exports.DouyinWorkParamsSchema = DouyinWorkParamsSchema;
3052
- exports.KuaishouCommentParamsSchema = KuaishouCommentParamsSchema;
3053
- exports.KuaishouEmojiParamsSchema = KuaishouEmojiParamsSchema;
3054
- exports.KuaishouValidationSchemas = KuaishouValidationSchemas2;
3055
- exports.KuaishouVideoParamsSchema = KuaishouVideoParamsSchema;
3056
- exports.Networks = Networks;
3057
- exports.ValidationError = ValidationError;
3058
- exports.amagiClient = amagiClient;
3059
- exports.av2bv = av2bv;
3060
- exports.bilibili = bilibili;
3061
- exports.bilibiliApiUrls = bilibiliApiUrls;
3062
- exports.bilibiliErrorCodeMap = bilibiliErrorCodeMap;
3063
- exports.bilibiliUtils = bilibiliUtils;
3064
- exports.bv2av = bv2av;
3065
- exports.createAmagiClient = createAmagiClient;
3066
- exports.createBilibiliRoutes = createBilibiliRoutes;
3067
- exports.createBoundBilibiliApi = createBoundBilibiliApi;
3068
- exports.createBoundDouyinApi = createBoundDouyinApi;
3069
- exports.createBoundKuaishouApi = createBoundKuaishouApi;
3070
- exports.createDouyinRoutes = createDouyinRoutes;
3071
- exports.createErrorResponse = createErrorResponse;
3072
- exports.createKuaishouRoutes = createKuaishouRoutes;
3073
- exports.createSuccessResponse = createSuccessResponse;
3074
- exports.default = v5_default;
3075
- exports.douyin = douyin;
3076
- exports.douyinApiUrls = douyinApiUrls;
3077
- exports.douyinSign = douyinSign;
3078
- exports.douyinUtils = douyinUtils;
3079
- exports.getBilibiliData = getBilibiliData;
3080
- exports.getDouyinData = getDouyinData;
3081
- exports.getKuaishouData = getKuaishouData;
3082
- exports.handleError = handleError;
3083
- exports.httpLogger = httpLogger;
3084
- exports.kuaishou = kuaishou;
3085
- exports.kuaishouApiUrls = kuaishouApiUrls;
3086
- exports.kuaishouUtils = kuaishouUtils;
3087
- exports.logMiddleware = logMiddleware;
3088
- exports.logger = logger;
3089
- exports.qtparam = qtparam;
3090
- exports.validateBilibiliParams = validateBilibiliParams;
3091
- exports.validateDouyinParams = validateDouyinParams;
3092
- exports.validateKuaishouParams = validateKuaishouParams;
3093
- exports.wbi_sign = wbi_sign;