@ikenxuan/amagi 4.5.1 → 5.0.0

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