@ikenxuan/amagi 1.4.3

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.
Files changed (58) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +82 -0
  3. package/config/config.yaml +5 -0
  4. package/config/default_config.yaml +5 -0
  5. package/lib/app.d.ts +1 -0
  6. package/lib/app.js +2 -0
  7. package/lib/business/bilibili/API.d.ts +39 -0
  8. package/lib/business/bilibili/API.js +37 -0
  9. package/lib/business/bilibili/getdata.d.ts +9 -0
  10. package/lib/business/bilibili/getdata.js +169 -0
  11. package/lib/business/bilibili/getid.d.ts +26 -0
  12. package/lib/business/bilibili/getid.js +41 -0
  13. package/lib/business/bilibili/index.d.ts +7 -0
  14. package/lib/business/bilibili/index.js +7 -0
  15. package/lib/business/bilibili/qtparam.d.ts +13 -0
  16. package/lib/business/bilibili/qtparam.js +16 -0
  17. package/lib/business/bilibili/result.d.ts +6 -0
  18. package/lib/business/bilibili/result.js +36 -0
  19. package/lib/business/bilibili/sign/CorrespondPath.d.ts +1 -0
  20. package/lib/business/bilibili/sign/CorrespondPath.js +11 -0
  21. package/lib/business/bilibili/sign/wbi.d.ts +1 -0
  22. package/lib/business/bilibili/sign/wbi.js +56 -0
  23. package/lib/business/douyin/API.d.ts +37 -0
  24. package/lib/business/douyin/API.js +42 -0
  25. package/lib/business/douyin/getdata.d.ts +9 -0
  26. package/lib/business/douyin/getdata.js +119 -0
  27. package/lib/business/douyin/getid.d.ts +13 -0
  28. package/lib/business/douyin/getid.js +36 -0
  29. package/lib/business/douyin/index.d.ts +6 -0
  30. package/lib/business/douyin/index.js +6 -0
  31. package/lib/business/douyin/result.d.ts +6 -0
  32. package/lib/business/douyin/result.js +39 -0
  33. package/lib/business/douyin/sign/a_bougs.js +487 -0
  34. package/lib/business/douyin/sign/index.d.ts +8 -0
  35. package/lib/business/douyin/sign/index.js +29 -0
  36. package/lib/index.d.ts +30 -0
  37. package/lib/index.js +113 -0
  38. package/lib/model/config.d.ts +70 -0
  39. package/lib/model/config.js +173 -0
  40. package/lib/model/index.d.ts +4 -0
  41. package/lib/model/index.js +4 -0
  42. package/lib/model/logger.d.ts +3 -0
  43. package/lib/model/logger.js +28 -0
  44. package/lib/model/networks.d.ts +38 -0
  45. package/lib/model/networks.js +224 -0
  46. package/lib/types/ConfigType.d.ts +10 -0
  47. package/lib/types/ConfigType.js +1 -0
  48. package/lib/types/DataType.d.ts +32 -0
  49. package/lib/types/DataType.js +1 -0
  50. package/lib/types/GetDataResponseType.d.ts +17 -0
  51. package/lib/types/GetDataResponseType.js +1 -0
  52. package/lib/types/NetworksConfigType.d.ts +30 -0
  53. package/lib/types/NetworksConfigType.js +1 -0
  54. package/lib/types/OptionsType.d.ts +66 -0
  55. package/lib/types/OptionsType.js +1 -0
  56. package/lib/types/index.d.ts +6 -0
  57. package/lib/types/index.js +1 -0
  58. package/package.json +49 -0
@@ -0,0 +1,487 @@
1
+ // All the content in this article is only for learning and communication use, not for any other purpose, strictly prohibited for commercial use and illegal use, otherwise all the consequences are irrelevant to the author!
2
+ function rc4_encrypt (plaintext, key) {
3
+ const s = []
4
+ for (var i = 0; i < 256; i++) {
5
+ s[i] = i
6
+ }
7
+ var j = 0
8
+ for (var i = 0; i < 256; i++) {
9
+ j = (j + s[i] + key.charCodeAt(i % key.length)) % 256
10
+ var temp = s[i]
11
+ s[i] = s[j]
12
+ s[j] = temp
13
+ }
14
+
15
+ var i = 0
16
+ var j = 0
17
+ const cipher = []
18
+ for (let k = 0; k < plaintext.length; k++) {
19
+ i = (i + 1) % 256
20
+ j = (j + s[i]) % 256
21
+ var temp = s[i]
22
+ s[i] = s[j]
23
+ s[j] = temp
24
+ const t = (s[i] + s[j]) % 256
25
+ cipher.push(String.fromCharCode(s[t] ^ plaintext.charCodeAt(k)))
26
+ }
27
+ return cipher.join('')
28
+ }
29
+
30
+ function le (e, r) {
31
+ return ((e << (r %= 32)) | (e >>> (32 - r))) >>> 0
32
+ }
33
+
34
+ function de (e) {
35
+ return e >= 0 && e < 16 ? 2043430169 : e >= 16 && e < 64 ? 2055708042 : void console.error('invalid j for constant Tj')
36
+ }
37
+
38
+ function pe (e, r, t, n) {
39
+ return e >= 0 && e < 16
40
+ ? (r ^ t ^ n) >>> 0
41
+ : e >= 16 && e < 64
42
+ ? ((r & t) | (r & n) | (t & n)) >>> 0
43
+ : (console.error('invalid j for bool function FF'), 0)
44
+ }
45
+
46
+ function he (e, r, t, n) {
47
+ 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)
48
+ }
49
+
50
+ function reset () {
51
+ (this.reg[0] = 1937774191),
52
+ (this.reg[1] = 1226093241),
53
+ (this.reg[2] = 388252375),
54
+ (this.reg[3] = 3666478592),
55
+ (this.reg[4] = 2842636476),
56
+ (this.reg[5] = 372324522),
57
+ (this.reg[6] = 3817729613),
58
+ (this.reg[7] = 2969243214),
59
+ (this.chunk = []),
60
+ (this.size = 0)
61
+ }
62
+
63
+ function write (e) {
64
+ let n
65
+ var a =
66
+ typeof e == 'string'
67
+ ? (function (e) {
68
+ ; (n = encodeURIComponent(e).replace(/%([0-9A-F]{2})/g, function (e, r) {
69
+ return String.fromCharCode('0x' + r)
70
+ })),
71
+ (a = new Array(n.length))
72
+ return (
73
+ Array.prototype.forEach.call(n, function (e, r) {
74
+ a[r] = e.charCodeAt(0)
75
+ }),
76
+ a
77
+ )
78
+ })(e)
79
+ : e
80
+ this.size += a.length
81
+ let f = 64 - this.chunk.length
82
+ if (a.length < f) this.chunk = this.chunk.concat(a)
83
+ else {
84
+ for (this.chunk = this.chunk.concat(a.slice(0, f)); this.chunk.length >= 64;) { this._compress(this.chunk), f < a.length ? (this.chunk = a.slice(f, Math.min(f + 64, a.length))) : (this.chunk = []), (f += 64) }
85
+ }
86
+ }
87
+
88
+ function sum (e, t) {
89
+ e && (this.reset(), this.write(e)), this._fill()
90
+ for (var f = 0; f < this.chunk.length; f += 64) this._compress(this.chunk.slice(f, f + 64))
91
+ let i = null
92
+ if (t == 'hex') {
93
+ i = ''
94
+ for (f = 0; f < 8; f++) i += se(this.reg[f].toString(16), 8, '0')
95
+ } else {
96
+ for (i = new Array(32), f = 0; f < 8; f++) {
97
+ let c = this.reg[f]
98
+ ; (i[4 * f + 3] = (255 & c) >>> 0),
99
+ (c >>>= 8),
100
+ (i[4 * f + 2] = (255 & c) >>> 0),
101
+ (c >>>= 8),
102
+ (i[4 * f + 1] = (255 & c) >>> 0),
103
+ (c >>>= 8),
104
+ (i[4 * f] = (255 & c) >>> 0)
105
+ }
106
+ }
107
+ return this.reset(), i
108
+ }
109
+
110
+ function _compress (t) {
111
+ if (t < 64) console.error('compress error: not enough data')
112
+ else {
113
+ for (
114
+ var f = (function (e) {
115
+ for (var r = new Array(132), t = 0; t < 16; t++) { (r[t] = e[4 * t] << 24), (r[t] |= e[4 * t + 1] << 16), (r[t] |= e[4 * t + 2] << 8), (r[t] |= e[4 * t + 3]), (r[t] >>>= 0) }
116
+ for (var n = 16; n < 68; n++) {
117
+ let a = r[n - 16] ^ r[n - 9] ^ le(r[n - 3], 15)
118
+ ; (a = a ^ le(a, 15) ^ le(a, 23)), (r[n] = (a ^ le(r[n - 13], 7) ^ r[n - 6]) >>> 0)
119
+ }
120
+ for (n = 0; n < 64; n++) r[n + 68] = (r[n] ^ r[n + 4]) >>> 0
121
+ return r
122
+ })(t),
123
+ i = this.reg.slice(0),
124
+ c = 0;
125
+ c < 64;
126
+ c++
127
+ ) {
128
+ let o = le(i[0], 12) + i[4] + le(de(c), c)
129
+ const s = ((o = le((o = (4294967295 & o) >>> 0), 7)) ^ le(i[0], 12)) >>> 0
130
+ let u = pe(c, i[0], i[1], i[2])
131
+ u = (4294967295 & (u = u + i[3] + s + f[c + 68])) >>> 0
132
+ let b = he(c, i[4], i[5], i[6])
133
+ ; (b = (4294967295 & (b = b + i[7] + o + f[c])) >>> 0),
134
+ (i[3] = i[2]),
135
+ (i[2] = le(i[1], 9)),
136
+ (i[1] = i[0]),
137
+ (i[0] = u),
138
+ (i[7] = i[6]),
139
+ (i[6] = le(i[5], 19)),
140
+ (i[5] = i[4]),
141
+ (i[4] = (b ^ le(b, 9) ^ le(b, 17)) >>> 0)
142
+ }
143
+ for (let l = 0; l < 8; l++) this.reg[l] = (this.reg[l] ^ i[l]) >>> 0
144
+ }
145
+ }
146
+
147
+ function _fill () {
148
+ const a = 8 * this.size
149
+ let f = this.chunk.push(128) % 64
150
+ for (64 - f < 8 && (f -= 64); f < 56; f++) this.chunk.push(0)
151
+ for (var i = 0; i < 4; i++) {
152
+ const c = Math.floor(a / 4294967296)
153
+ this.chunk.push((c >>> (8 * (3 - i))) & 255)
154
+ }
155
+ for (i = 0; i < 4; i++) this.chunk.push((a >>> (8 * (3 - i))) & 255)
156
+ }
157
+
158
+ function SM3 () {
159
+ this.reg = []
160
+ this.chunk = []
161
+ this.size = 0
162
+ this.reset()
163
+ }
164
+ SM3.prototype.reset = reset
165
+ SM3.prototype.write = write
166
+ SM3.prototype.sum = sum
167
+ SM3.prototype._compress = _compress
168
+ SM3.prototype._fill = _fill
169
+
170
+ function result_encrypt (long_str, num = null) {
171
+ const s_obj = {
172
+ s0: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=',
173
+ s1: 'Dkdpgh4ZKsQB80/Mfvw36XI1R25+WUAlEi7NLboqYTOPuzmFjJnryx9HVGcaStCe=',
174
+ s2: 'Dkdpgh4ZKsQB80/Mfvw36XI1R25-WUAlEi7NLboqYTOPuzmFjJnryx9HVGcaStCe=',
175
+ s3: 'ckdp1h4ZKsUB80/Mfvw36XIgR25+WQAlEi7NLboqYTOPuzmFjJnryx9HVGDaStCe',
176
+ s4: 'Dkdpgh2ZmsQB80/MfvV36XI1R45-WUAlEixNLwoqYTOPuzKFjJnry79HbGcaStCe'
177
+ }
178
+ const constant = {
179
+ 0: 16515072,
180
+ 1: 258048,
181
+ 2: 4032,
182
+ str: s_obj[num]
183
+ }
184
+
185
+ let result = ''
186
+ let lound = 0
187
+ let long_int = get_long_int(lound, long_str)
188
+ for (let i = 0; i < (long_str.length / 3) * 4; i++) {
189
+ if (Math.floor(i / 4) !== lound) {
190
+ lound += 1
191
+ long_int = get_long_int(lound, long_str)
192
+ }
193
+ const key = i % 4
194
+ let temp_int
195
+ switch (key) {
196
+ case 0:
197
+ temp_int = (long_int & constant['0']) >> 18
198
+ result += constant.str.charAt(temp_int)
199
+ break
200
+ case 1:
201
+ temp_int = (long_int & constant['1']) >> 12
202
+ result += constant.str.charAt(temp_int)
203
+ break
204
+ case 2:
205
+ temp_int = (long_int & constant['2']) >> 6
206
+ result += constant.str.charAt(temp_int)
207
+ break
208
+ case 3:
209
+ temp_int = long_int & 63
210
+ result += constant.str.charAt(temp_int)
211
+ break
212
+ default:
213
+ break
214
+ }
215
+ }
216
+ return result
217
+ }
218
+
219
+ function get_long_int (round, long_str) {
220
+ round = round * 3
221
+ return (long_str.charCodeAt(round) << 16) | (long_str.charCodeAt(round + 1) << 8) | long_str.charCodeAt(round + 2)
222
+ }
223
+
224
+ function gener_random (random, option) {
225
+ return [
226
+ (random & 255 & 170) | (option[0] & 85), // 163
227
+ (random & 255 & 85) | (option[0] & 170), // 87
228
+ ((random >> 8) & 255 & 170) | (option[1] & 85), // 37
229
+ ((random >> 8) & 255 & 85) | (option[1] & 170) // 41
230
+ ]
231
+ }
232
+
233
+ /// ///////////////////////////////////////////
234
+ function generate_rc4_bb_str (url_search_params, user_agent, window_env_str, suffix = 'cus', Arguments = [0, 1, 14]) {
235
+ const sm3 = new SM3()
236
+ const start_time = Date.now()
237
+ /**
238
+ * 进行3次加密处理
239
+ * 1: url_search_params两次sm3之的结果
240
+ * 2: 对后缀两次sm3之的结果
241
+ * 3: 对ua处理之后的结果
242
+ */
243
+ // url_search_params两次sm3之的结果
244
+ const url_search_params_list = sm3.sum(sm3.sum(url_search_params + suffix))
245
+ // 对后缀两次sm3之的结果
246
+ const cus = sm3.sum(sm3.sum(suffix))
247
+ // 对ua处理之后的结果
248
+ const ua = sm3.sum(result_encrypt(rc4_encrypt(user_agent, String.fromCharCode.apply(null, [0.00390625, 1, 14])), 's3'))
249
+ //
250
+ const end_time = Date.now()
251
+ // b
252
+ const b = {
253
+ 8: 3, // 固定
254
+ 10: end_time, // 3次加密结束时间
255
+ 15: {
256
+ aid: 6383,
257
+ pageId: 6241,
258
+ boe: false,
259
+ ddrt: 7,
260
+ paths: {
261
+ include: [{}, {}, {}, {}, {}, {}, {}],
262
+ exclude: []
263
+ },
264
+ track: {
265
+ mode: 0,
266
+ delay: 300,
267
+ paths: []
268
+ },
269
+ dump: true,
270
+ rpU: ''
271
+ },
272
+ 16: start_time, // 3次加密开始时间
273
+ 18: 44, // 固定
274
+ 19: [1, 0, 1, 5]
275
+ }
276
+
277
+ // 3次加密开始时间
278
+ b[20] = (b[16] >> 24) & 255
279
+ b[21] = (b[16] >> 16) & 255
280
+ b[22] = (b[16] >> 8) & 255
281
+ b[23] = b[16] & 255
282
+ b[24] = (b[16] / 256 / 256 / 256 / 256) >> 0
283
+ b[25] = (b[16] / 256 / 256 / 256 / 256 / 256) >> 0
284
+
285
+ // 参数Arguments [0, 1, 14, ...]
286
+ // let Arguments = [0, 1, 14]
287
+ b[26] = (Arguments[0] >> 24) & 255
288
+ b[27] = (Arguments[0] >> 16) & 255
289
+ b[28] = (Arguments[0] >> 8) & 255
290
+ b[29] = Arguments[0] & 255
291
+
292
+ b[30] = (Arguments[1] / 256) & 255
293
+ b[31] = Arguments[1] % 256 & 255
294
+ b[32] = (Arguments[1] >> 24) & 255
295
+ b[33] = (Arguments[1] >> 16) & 255
296
+
297
+ b[34] = (Arguments[2] >> 24) & 255
298
+ b[35] = (Arguments[2] >> 16) & 255
299
+ b[36] = (Arguments[2] >> 8) & 255
300
+ b[37] = Arguments[2] & 255
301
+
302
+ // (url_search_params + "cus") 两次sm3之的结果
303
+ /** let url_search_params_list = [
304
+ 91, 186, 35, 86, 143, 253, 6, 76,
305
+ 34, 21, 167, 148, 7, 42, 192, 219,
306
+ 188, 20, 182, 85, 213, 74, 213, 147,
307
+ 37, 155, 93, 139, 85, 118, 228, 213
308
+ ] */
309
+ b[38] = url_search_params_list[21]
310
+ b[39] = url_search_params_list[22]
311
+
312
+ // ("cus") 对后缀两次sm3之的结果
313
+ /**
314
+ * let cus = [
315
+ 136, 101, 114, 147, 58, 77, 207, 201,
316
+ 215, 162, 154, 93, 248, 13, 142, 160,
317
+ 105, 73, 215, 241, 83, 58, 51, 43,
318
+ 255, 38, 168, 141, 216, 194, 35, 236
319
+ ] */
320
+ b[40] = cus[21]
321
+ b[41] = cus[22]
322
+
323
+ // 对ua处理之后的结果
324
+ /**
325
+ * let ua = [
326
+ 129, 190, 70, 186, 86, 196, 199, 53,
327
+ 99, 38, 29, 209, 243, 17, 157, 69,
328
+ 147, 104, 53, 23, 114, 126, 66, 228,
329
+ 135, 30, 168, 185, 109, 156, 251, 88
330
+ ] */
331
+ b[42] = ua[23]
332
+ b[43] = ua[24]
333
+
334
+ // 3次加密结束时间
335
+ b[44] = (b[10] >> 24) & 255
336
+ b[45] = (b[10] >> 16) & 255
337
+ b[46] = (b[10] >> 8) & 255
338
+ b[47] = b[10] & 255
339
+ b[48] = b[8]
340
+ b[49] = (b[10] / 256 / 256 / 256 / 256) >> 0
341
+ b[50] = (b[10] / 256 / 256 / 256 / 256 / 256) >> 0
342
+
343
+ // object配置项
344
+ b[51] = b[15].pageId
345
+ b[52] = (b[15].pageId >> 24) & 255
346
+ b[53] = (b[15].pageId >> 16) & 255
347
+ b[54] = (b[15].pageId >> 8) & 255
348
+ b[55] = b[15].pageId & 255
349
+
350
+ b[56] = b[15].aid
351
+ b[57] = b[15].aid & 255
352
+ b[58] = (b[15].aid >> 8) & 255
353
+ b[59] = (b[15].aid >> 16) & 255
354
+ b[60] = (b[15].aid >> 24) & 255
355
+
356
+ // 中间进行了环境检测
357
+ // 代码索引: 2496 索引值: 17 (索引64关键条件)
358
+ // '1536|747|1536|834|0|30|0|0|1536|834|1536|864|1525|747|24|24|Win32'.charCodeAt()得到65位数组
359
+ /**
360
+ * let window_env_list = [49, 53, 51, 54, 124, 55, 52, 55, 124, 49, 53, 51, 54, 124, 56, 51, 52, 124, 48, 124, 51,
361
+ * 48, 124, 48, 124, 48, 124, 49, 53, 51, 54, 124, 56, 51, 52, 124, 49, 53, 51, 54, 124, 56,
362
+ * 54, 52, 124, 49, 53, 50, 53, 124, 55, 52, 55, 124, 50, 52, 124, 50, 52, 124, 87, 105, 110,
363
+ * 51, 50]
364
+ */
365
+ const window_env_list = []
366
+ for (let index = 0; index < window_env_str.length; index++) {
367
+ window_env_list.push(window_env_str.charCodeAt(index))
368
+ }
369
+ b[64] = window_env_list.length
370
+ b[65] = b[64] & 255
371
+ b[66] = (b[64] >> 8) & 255
372
+
373
+ b[69] = [].length
374
+ b[70] = b[69] & 255
375
+ b[71] = (b[69] >> 8) & 255
376
+
377
+ b[72] =
378
+ b[18] ^
379
+ b[20] ^
380
+ b[26] ^
381
+ b[30] ^
382
+ b[38] ^
383
+ b[40] ^
384
+ b[42] ^
385
+ b[21] ^
386
+ b[27] ^
387
+ b[31] ^
388
+ b[35] ^
389
+ b[39] ^
390
+ b[41] ^
391
+ b[43] ^
392
+ b[22] ^
393
+ b[28] ^
394
+ b[32] ^
395
+ b[36] ^
396
+ b[23] ^
397
+ b[29] ^
398
+ b[33] ^
399
+ b[37] ^
400
+ b[44] ^
401
+ b[45] ^
402
+ b[46] ^
403
+ b[47] ^
404
+ b[48] ^
405
+ b[49] ^
406
+ b[50] ^
407
+ b[24] ^
408
+ b[25] ^
409
+ b[52] ^
410
+ b[53] ^
411
+ b[54] ^
412
+ b[55] ^
413
+ b[57] ^
414
+ b[58] ^
415
+ b[59] ^
416
+ b[60] ^
417
+ b[65] ^
418
+ b[66] ^
419
+ b[70] ^
420
+ b[71]
421
+ let bb = [
422
+ b[18],
423
+ b[20],
424
+ b[52],
425
+ b[26],
426
+ b[30],
427
+ b[34],
428
+ b[58],
429
+ b[38],
430
+ b[40],
431
+ b[53],
432
+ b[42],
433
+ b[21],
434
+ b[27],
435
+ b[54],
436
+ b[55],
437
+ b[31],
438
+ b[35],
439
+ b[57],
440
+ b[39],
441
+ b[41],
442
+ b[43],
443
+ b[22],
444
+ b[28],
445
+ b[32],
446
+ b[60],
447
+ b[36],
448
+ b[23],
449
+ b[29],
450
+ b[33],
451
+ b[37],
452
+ b[44],
453
+ b[45],
454
+ b[59],
455
+ b[46],
456
+ b[47],
457
+ b[48],
458
+ b[49],
459
+ b[50],
460
+ b[24],
461
+ b[25],
462
+ b[65],
463
+ b[66],
464
+ b[70],
465
+ b[71]
466
+ ]
467
+ bb = bb.concat(window_env_list).concat(b[72])
468
+ return rc4_encrypt(String.fromCharCode.apply(null, bb), String.fromCharCode.apply(null, [121]))
469
+ }
470
+
471
+ function generate_random_str () {
472
+ let random_str_list = []
473
+ random_str_list = random_str_list.concat(gener_random(Math.random() * 10000, [3, 45]))
474
+ random_str_list = random_str_list.concat(gener_random(Math.random() * 10000, [1, 0]))
475
+ random_str_list = random_str_list.concat(gener_random(Math.random() * 10000, [1, 5]))
476
+ return String.fromCharCode.apply(null, random_str_list)
477
+ }
478
+
479
+ export function AB (url_search_params, user_agent) {
480
+ /**
481
+ * url_search_params:"device_platform=webapp&aid=6383&channel=channel_pc_web&update_version_code=170400&pc_client_type=1&version_code=170400&version_name=17.4.0&cookie_enabled=true&screen_width=1536&screen_height=864&browser_language=zh-CN&browser_platform=Win32&browser_name=Chrome&browser_version=123.0.0.0&browser_online=true&engine_name=Blink&engine_version=123.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=7362810250930783783&msToken=VkDUvz1y24CppXSl80iFPr6ez-3FiizcwD7fI1OqBt6IICq9RWG7nCvxKb8IVi55mFd-wnqoNkXGnxHrikQb4PuKob5Q-YhDp5Um215JzlBszkUyiEvR"
482
+ * user_agent:"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36"
483
+ */
484
+ const result_str =
485
+ generate_random_str() + generate_rc4_bb_str(url_search_params, user_agent, '1536|747|1536|834|0|30|0|0|1536|834|1536|864|1525|747|24|24|Win32')
486
+ return result_encrypt(result_str, 's4') + '='
487
+ }
@@ -0,0 +1,8 @@
1
+ export default class sign {
2
+ /** 生成一个指定长度的随机字符串 */
3
+ static Mstoken(length: number): string;
4
+ /** a_bougs 签名算法 */
5
+ static AB(url: string): string;
6
+ /** 生成一个唯一的验证字符串 */
7
+ static VerifyFpManager(): string;
8
+ }
@@ -0,0 +1,29 @@
1
+ // @ts-ignore
2
+ import { AB } from './a_bougs.js';
3
+ import crypto from 'crypto';
4
+ const headers = {
5
+ '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'
6
+ };
7
+ export default class sign {
8
+ /** 生成一个指定长度的随机字符串 */
9
+ static Mstoken(length) {
10
+ const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
11
+ const randomBytes = crypto.randomBytes(length);
12
+ return Array.from(randomBytes, (byte) => characters[byte % characters.length]).join('');
13
+ }
14
+ /** a_bougs 签名算法 */
15
+ static AB(url) {
16
+ return AB(new URLSearchParams(new URL(url).search).toString(), headers['User-Agent']);
17
+ }
18
+ /** 生成一个唯一的验证字符串 */
19
+ static VerifyFpManager() {
20
+ const e = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
21
+ const t = e.length;
22
+ const n = new Date().getTime().toString(36);
23
+ const r = [];
24
+ (r[8] = r[13] = r[18] = r[23] = '_'), (r[14] = '4');
25
+ for (var o, i = 0; i < 36; i++)
26
+ r[i] || ((o = 0 | (Math.random() * t)), (r[i] = e[i == 19 ? (3 & o) | 8 : o]));
27
+ return 'verify_' + n + '_' + r.join('');
28
+ }
29
+ }
package/lib/index.d.ts ADDED
@@ -0,0 +1,30 @@
1
+ import { FastifyInstance, RouteHandler, HTTPMethods } from 'fastify';
2
+ interface ServerOptions {
3
+ /**
4
+ * 端口
5
+ */
6
+ port?: number;
7
+ /**
8
+ * 是否启用日志
9
+ */
10
+ log?: boolean;
11
+ }
12
+ export declare const initServer: (client: FastifyInstance) => Promise<FastifyInstance>;
13
+ /**
14
+ * 添加路由
15
+ * @param client fastify实例
16
+ * @param routeOptions[] 路由参数,传递数组
17
+ * @param extend 是否继承 amagi 的默认路由
18
+ * @returns
19
+ */
20
+ export declare const AddRoute: (client: FastifyInstance, routeOptions?: RouteOptions[], extend?: boolean) => any;
21
+ /** 创建一个新的 fastify 实例 */
22
+ export declare const CreateNewClient: (options: ServerOptions) => FastifyInstance;
23
+ /** 启动监听 */
24
+ export declare const StartClient: (client: FastifyInstance, options: ServerOptions) => Promise<void>;
25
+ interface RouteOptions {
26
+ method: HTTPMethods;
27
+ url: string;
28
+ handler: RouteHandler;
29
+ }
30
+ export {};
package/lib/index.js ADDED
@@ -0,0 +1,113 @@
1
+ import fastify from 'fastify';
2
+ import { DouyinResult } from './business/douyin/index.js';
3
+ import { BilibiliResult } from './business/bilibili/index.js';
4
+ import { logger } from './model/index.js';
5
+ import chalk from 'chalk';
6
+ export const initServer = async (client) => {
7
+ client.get('/api/douyin/aweme', async (request, reply) => {
8
+ const url = request.query.url;
9
+ reply.type('application/json').send(await new DouyinResult("VideoData" /* DouyinDataType['单个视频作品数据'] */).result({ url }));
10
+ });
11
+ client.get('/api/douyin/comments', async (request, reply) => {
12
+ const url = request.query.url;
13
+ reply.type('application/json').send(await new DouyinResult("CommentData" /* DouyinDataType['评论数据'] */).result({ url }));
14
+ });
15
+ client.get('/api/douyin/comments/reply', async (request, reply) => {
16
+ const { aweme_id, comment_id } = request.query;
17
+ reply.type('application/json').send(await new DouyinResult("CommentReplyData" /* DouyinDataType['二级评论数据'] */).result({ aweme_id, comment_id }));
18
+ });
19
+ client.get('/api/douyin/userinfo', async (request, reply) => {
20
+ const sec_uid = request.query.sec_uid;
21
+ reply.type('application/json').send(await new DouyinResult("UserInfoData" /* DouyinDataType['用户主页数据'] */).result({ sec_uid }));
22
+ });
23
+ client.get('/api/douyin/uservideoslist', async (request, reply) => {
24
+ const sec_uid = request.query.sec_uid;
25
+ reply.type('application/json').send(await new DouyinResult("UserVideosListData" /* DouyinDataType['用户主页视频列表数据'] */).result({ sec_uid }));
26
+ });
27
+ client.get('/api/douyin/suggestwords', async (request, reply) => {
28
+ const query = request.query.query;
29
+ reply.type('application/json').send(await new DouyinResult("SuggestWordsData" /* DouyinDataType['热点词数据'] */).result({ query }));
30
+ });
31
+ client.get('/api/douyin/search', async (request, reply) => {
32
+ const query = request.query.query;
33
+ reply.type('application/json').send(await new DouyinResult("SearchData" /* DouyinDataType['搜索数据'] */).result({ query }));
34
+ });
35
+ client.get('/api/douyin/emoji', async (_request, reply) => {
36
+ reply.type('application/json').send(await new DouyinResult("EmojiData" /* DouyinDataType['官方emoji数据'] */).result());
37
+ });
38
+ client.get('/api/douyin/expressionplus', async (_request, reply) => {
39
+ reply.type('application/json').send(await new DouyinResult("ExpressionPlusData" /* DouyinDataType['动态表情数据'] */).result());
40
+ });
41
+ client.get('/api/douyin/music', async (request, reply) => {
42
+ const music_id = request.query.music_id;
43
+ reply.type('application/json').send(await new DouyinResult("MusicData" /* DouyinDataType['音乐数据'] */).result({ music_id }));
44
+ });
45
+ // bilibili
46
+ client.get('/api/bilibili/work', async (request, reply) => {
47
+ const url = request.query.url;
48
+ reply.type('application/json').send(await new BilibiliResult("VideoData" /* BilibiliDataType['单个视频作品数据'] */).result({ url }));
49
+ });
50
+ client.get('/api/bilibili/comment', async (request, reply) => {
51
+ const bvid = request.query.bvid;
52
+ reply.type('application/json').send(await new BilibiliResult("CommentData" /* BilibiliDataType['评论数据'] */).result({ bvid }));
53
+ });
54
+ client.get('/api/bilibili/emoji', async (_request, reply) => {
55
+ reply.type('application/json').send(await new BilibiliResult("EmojiData" /* BilibiliDataType['emoji数据'] */).result());
56
+ });
57
+ client.get('/api/bilibili/bangumivideoinfo', async (request, reply) => {
58
+ const url = request.query.url;
59
+ reply.type('application/json').send(await new BilibiliResult("BangumiVideoData" /* BilibiliDataType['番剧基本信息数据'] */).result({ url }));
60
+ });
61
+ client.get('/api/bilibili/bangumivideodownloadlink', async (request, reply) => {
62
+ const { cid, ep_id } = request.query;
63
+ reply.type('application/json').send(await new BilibiliResult("BangumiVideoDownloadLinkData" /* BilibiliDataType['番剧下载信息数据'] */).result({ cid, ep_id }));
64
+ });
65
+ client.get('/api/bilibili/dynamiclist', async (request, reply) => {
66
+ const host_mid = request.query.host_mid;
67
+ reply.type('application/json').send(await new BilibiliResult("UserDynamicListData" /* BilibiliDataType['用户主页动态列表数据'] */).result({ host_mid }));
68
+ });
69
+ client.get('/api/bilibili/dynamicinfo', async (request, reply) => {
70
+ const dynamic_id = request.query.dynamic_id;
71
+ reply.type('application/json').send(await new BilibiliResult("DynamicInfoData" /* BilibiliDataType['动态详情数据'] */).result({ dynamic_id }));
72
+ });
73
+ client.get('/api/bilibili/dynamicdard', async (request, reply) => {
74
+ const dynamic_id = request.query.dynamic_id;
75
+ reply.type('application/json').send(await new BilibiliResult("DynamicCardData" /* BilibiliDataType['动态卡片数据'] */).result({ dynamic_id }));
76
+ });
77
+ client.get('/api/bilibili/userinfo', async (request, reply) => {
78
+ const host_mid = request.query.host_mid;
79
+ reply.type('application/json').send(await new BilibiliResult("UserInfoData" /* BilibiliDataType['用户主页数据'] */).result({ host_mid }));
80
+ });
81
+ // 返回fastify实例
82
+ return client;
83
+ };
84
+ /**
85
+ * 添加路由
86
+ * @param client fastify实例
87
+ * @param routeOptions[] 路由参数,传递数组
88
+ * @param extend 是否继承 amagi 的默认路由
89
+ * @returns
90
+ */
91
+ export const AddRoute = (client, routeOptions = [], extend = false) => {
92
+ if (extend)
93
+ return client;
94
+ // 继承默认路由参数
95
+ initServer(client);
96
+ for (const item of routeOptions) {
97
+ client.route({ method: item.method, handler: item.handler, url: item.url });
98
+ }
99
+ return client;
100
+ };
101
+ /** 创建一个新的 fastify 实例 */
102
+ export const CreateNewClient = (options) => {
103
+ return fastify({ logger: options.log });
104
+ };
105
+ /** 启动监听 */
106
+ export const StartClient = async (client, options) => {
107
+ // 继承 amagi 路由规则
108
+ return client.listen({ port: options.port, host: '127.0.0.1' }, (_err, address) => {
109
+ if (_err)
110
+ logger.error(_err);
111
+ console.log(chalk.green(`服务监听于 ${address}`));
112
+ });
113
+ };