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