@ikenxuan/amagi 4.5.2 → 5.0.1

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