-
Notifications
You must be signed in to change notification settings - Fork 159
/
Copy pathgaze.js
601 lines (586 loc) · 17 KB
/
gaze.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
globalThis.window = globalThis.global = globalThis;
class Go {
constructor() {
let s = new TextEncoder("utf-8"),
i = new TextDecoder("utf-8"),
r = new DataView(new ArrayBuffer(8));
var o = [];
this._callbackTimeouts = new Map();
this._nextCallbackTimeoutID = 1;
let e = () => new DataView(this._inst.exports.m.buffer);
let t = (e) => {
r.setBigInt64(0, e, !0);
let t = r.getFloat64(0, !0);
if (0 === t) return;
if (!isNaN(t)) return t;
let n = 4294967295n & e;
return this._values[n];
};
let n = (n) => {
let s = e().getBigUint64(n, !0);
return t(s);
};
let l = (e) => {
if ("number" == typeof e)
return isNaN(e)
? 2146959360n << 32n
: 0 === e
? (2146959360n << 32n) | 1n
: (r.setFloat64(0, e, !0), r.getBigInt64(0, !0));
switch (e) {
case void 0:
return 0n;
case null:
return (2146959360n << 32n) | 2n;
case !0:
return (2146959360n << 32n) | 3n;
case !1:
return (2146959360n << 32n) | 4n;
}
let t = this._ids.get(e);
void 0 === t &&
(void 0 === (t = this._idPool.pop()) &&
(t = BigInt(this._values.length)),
(this._values[t] = e),
(this._goRefCounts[t] = 0),
this._ids.set(e, t)),
this._goRefCounts[t]++;
let n = 1n;
switch (typeof e) {
case "string":
n = 2n;
break;
case "symbol":
n = 3n;
break;
case "function":
n = 4n;
}
return t | ((2146959360n | n) << 32n);
};
let a = (t, n) => {
let s = l(n);
e().setBigUint64(t, s, !0);
};
let c = (e, t, n) => new Uint8Array(this._inst.exports.m.buffer, e, t);
let $ = (e, t, s) => {
let i = Array(t);
for (let r = 0; r < t; r++) i[r] = n(e + 8 * r);
return i;
};
let d = (e, t) => i.decode(new DataView(this._inst.exports.m.buffer, e, t));
let u = Date.now() - performance.now();
this.importObject = {
wasi_snapshot_preview1: {
fd_write: function (t, n, s, r) {
let l = 0;
if (1 == t)
for (let a = 0; a < s; a++) {
let c = n + 8 * a,
$ = e().getUint32(c + 0, !0),
d = e().getUint32(c + 4, !0);
l += d;
for (let u = 0; u < d; u++) {
let f = e().getUint8($ + u);
if (13 == f);
else if (10 == f) {
let h = i.decode(new Uint8Array(o));
(o = []), console.log(h);
} else o.push(f);
}
}
else console.error("invalid file descriptor:", t);
return e().setUint32(r, l, !0), 0;
},
fd_close: () => 0,
fd_fdstat_get: () => 0,
fd_seek: () => 0,
proc_exit(e) {
if (globalThis.process) process.exit(e);
else throw "trying to exit with code " + e;
},
random_get: (e, t) => (crypto.getRandomValues(c(e, t)), 0),
},
a: {
"runtime.ticks": () => u + performance.now(),
"runtime.sleepTicks": (e) => {
setTimeout(this._inst.exports.t, e);
},
d(e) {
console.error("d not implemented");
},
e(e, t) {
let n = d(e, t);
return l(n);
},
a(e, n, s) {
let i = d(n, s),
r = t(e),
o = Reflect.get(r, i);
return l(o);
},
f(e, n, s, i) {
let r = t(e),
o = d(n, s),
l = t(i);
Reflect.set(r, o, l);
},
"syscall/js.valueDelete"(e, n, s) {
let i = t(e),
r = d(n, s);
Reflect.deleteProperty(i, r);
},
i: (e, n) => l(Reflect.get(t(e), n)),
fIndex(e, n, s) {
Reflect.set(t(e), n, t(s));
},
j(n, s, i, r, o, l, c) {
let u = t(s),
f = d(i, r),
h = $(o, l, c);
try {
let g = Reflect.get(u, f);
a(n, Reflect.apply(g, u, h)), e().setUint8(n + 8, 1);
} catch (p) {
a(n, p), e().setUint8(n + 8, 0);
}
},
"syscall/js.valueInvoke"(n, s, i, r, o) {
try {
let l = t(s),
c = $(i, r, o);
a(n, Reflect.apply(l, void 0, c)), e().setUint8(n + 8, 1);
} catch (d) {
a(n, d), e().setUint8(n + 8, 0);
}
},
g(n, s, i, r, o) {
let l = t(s),
c = $(i, r, o);
try {
a(n, Reflect.construct(l, c)), e().setUint8(n + 8, 1);
} catch (d) {
a(n, d), e().setUint8(n + 8, 0);
}
},
h: (e) => t(e).length,
b(n, i) {
let r = String(t(i)),
o = s.encode(r);
a(n, o), e().setInt32(n + 8, o.length, !0);
},
c(e, n, s, i) {
let r = t(e);
c(n, s, i).set(r);
},
"syscall/js.valueInstanceOf": (e, n) => t(e) instanceof t(n),
k(n, s, i, r, o) {
let l = n + 4,
a = c(s, i),
$ = t(o);
if (!($ instanceof Uint8Array || $ instanceof Uint8ClampedArray)) {
e().setUint8(l, 0);
return;
}
let d = $.subarray(0, a.length);
a.set(d), e().setUint32(n, d.length, !0), e().setUint8(l, 1);
},
l(n, s, i, r, o) {
let l = n + 4,
a = t(s),
$ = c(i, r);
if (!(a instanceof Uint8Array || a instanceof Uint8ClampedArray)) {
e().setUint8(l, 0);
return;
}
let d = $.subarray(0, a.length);
a.set(d), e().setUint32(n, d.length, !0), e().setUint8(l, 1);
},
},
};
this.importObject.env = this.importObject.a;
}
async run(instance) {
this._inst = instance;
this._values = [NaN, 0, null, true, false, globalThis, this];
this._goRefCounts = [];
this._ids = new Map();
this._idPool = [];
this.exited = false;
while (true) {
const resumePromise = new Promise((resolve) => {
this._resolveCallbackPromise = () => {
if (this.exited) {
throw new Error("bad callback: Go program has already exited");
}
setTimeout(resolve, 0);
};
});
this._inst.exports.r();
if (this.exited) break;
await resumePromise;
}
}
_resume() {
if (this.exited) {
throw new Error("Go program has already exited");
}
this._inst.exports.s();
if (this.exited) {
this._resolveExitPromise();
}
}
_makeFuncWrapper(funcId) {
const self = this;
console.log("正在绑定函数id:", funcId);
return function () {
console.log("执行函数id:", funcId);
console.log("函数参数:", Array.from(arguments));
const event = {
id: funcId,
this: this,
args: arguments,
};
self._pendingEvent = event;
self._resume();
const result = event.result;
console.log("函数结果:", result);
return result;
};
}
}
const decryptor = (() => {
let wasmInstance = null;
let go = new Go();
const pedanticAe = function (buffer) {
const decompressedSync = zlib.brotliDecompressSync(buffer);
return decompressedSync;
};
const initWASM = async (func) => {
const wasmBuffer = await fetchWASM();
const { instance } = await WebAssembly.instantiate(
wasmBuffer,
go.importObject
);
wasmInstance = instance;
go.run(instance);
};
const fetchWASM = async () => {
const response = await axios.get(
"https://temp-rs-1257790209.cos.ap-chengdu.myqcloud.com/IceDespair-V2.6.svg",
{
responseType: "arraybuffer",
headers: {
"Content-Type": "application/wasm",
},
}
);
return pedanticAe(new Uint8Array(response.data));
};
const parseUrlParams = (url) => {
const params = {};
const queryString = url.split("?")[1];
if (!queryString) return params;
queryString.split("-").forEach((pair) => {
const [key, value] = pair.split("=");
if (key && value) params[key] = decodeURIComponent(value);
});
return params;
};
const getWasmFunc = (name, mid, key) => {
return window[
bytesToString(window["DimGive"](name, mid, decodeURIComponent(key)))
];
};
const decryptDataM3u = async (bytes, sign, mid, key) => {
if (!wasmInstance) await initWASM();
const result = getWasmFunc("nihilism", mid, key)(
bytes,
sign,
mid,
decodeURIComponent(key)
);
return bytesToString(pedanticAe(result));
};
const decryptData = async (data, mid, key) => {
if (!wasmInstance) await initWASM();
const result = getWasmFunc("8069", mid, key)(
data,
mid,
decodeURIComponent(key)
);
return bytesToString(result);
};
const decryptStream = async (data, mid, key, url) => {
const indexMa = url.split('/').at(-1);
if (!indexMa) return url;
const index = indexMa[1];
const istr = `${index}+gazes_v-@_info`;
console.log(istr);
const ungzipped = pako.ungzip(data, {
to: "string",
});
const bytes = processBytes(CryptoJS.enc.Base64.parse(ungzipped));
const sign = CryptoJS.MD5(
`${istr}- are we anti-socialists? against the government? spies? traitor? fresh blood? no, we are just weak, sick bystanders; we just need to rot little by little with formalism until we finally become food for new shoots. `
)
.toString()
.substring(8, 24);
return decryptDataM3u(bytes, sign, mid, key);
};
const processBytes = (base64Data) => {
return Uint8Array.from(
{
length: base64Data.sigBytes,
},
(_, i) => (base64Data.words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff
);
};
const bytesToString = (byteArray) => {
return String.fromCharCode.apply(null, byteArray);
};
const decryptPlay = async (playUrl, src) => {
const params = parseUrlParams(playUrl);
const encryptedSrc = src;
const decryptedLink = await decryptData(
Uint8Array.from(atob(encryptedSrc), (c) => c.charCodeAt(0)),
params.mid,
params[Object.keys(params).at(-1)]
);
return decryptedLink;
};
const decryptM3u8 = async (playUrl, src, decryptedLink) => {
const params = parseUrlParams(playUrl);
const encryptedSrc = src;
const { data } = await axios.get(decryptedLink, {
responseType: "arraybuffer",
});
const m3u8 = await decryptStream(
data,
params.mid,
params[Object.keys(params).at(-1)],
decryptedLink
);
return m3u8;
};
return {
decryptM3u8,
decryptPlay,
parseUrlParams,
};
})();
var rule = {
类型: "影视",
title: "GAZE",
desc: "源动力+L佬+秋秋+嗷呜 联合出品",
host: "https://gaze.run",
url: "/filter_movielist",
searchUrl: "/filter_movielist",
searchable: 2,
quickSearch: 0,
timeout: 5000,
play_parse: true,
filterable: 0,
class_name: "电影&剧集&番剧&国漫",
class_url: "1&2&bangumi&chinese_cartoon",
headers: {
"User-Agent": PC_UA,
Origin: "https://gaze.run",
},
预处理: async () => {
await rule.dealHeaders();
},
推荐: async function (tid, pg, filter, extend) {
const { input, pdfa, pdfh, pd } = this;
const html = await request(input);
const d = [];
const data = pdfa(html, ".row .card");
data.forEach((it) => {
d.push({
title: pdfh(it, ".card-body .card-title&&Text"),
pic_url: pdfh(it, ".view img.load-imgs&&data-src"),
desc: pdfh(it, ".view .dbadge-box .badge-default&&Text"),
url: pdfh(it, ".view a&&href").replace("play/", ""),
});
});
return setResult(d);
},
一级: async function (tid, pg, filter, extend) {
const { input } = this;
const html = await request(input, {
method: "POST",
headers: {
...this.headers,
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
},
data: {
mform: tid,
mcountry: "all",
"tag_arr[]": "all",
album: "all",
years: "all",
sort: "updatetime",
title: "",
page: pg,
},
});
const resp = JSON.parse(html);
const d = [];
resp.mlist.forEach((it) => {
d.push({
title: it.title,
pic_url: it.cover_img,
desc: `${it.grade}|${it.definition}`,
url: it.mid,
});
});
return setResult(d);
},
二级: async function (ids) {
const { input, pdfa, pdfh, pd } = this;
const html = await request(`${this.host}/play/${ids[0]}`, {
headers: this.headers,
});
const vod = {
vod_id: ids[0],
vod_name: pdfh(html, ".row.p-2 img&&alt"),
vod_pic: pdfh(html, ".row.p-2 img&&src"),
type_name: pdfa(html, ".row.p-2 a")
.map((it) => pdfh(it, "a&&Text"))
.join("/"),
vod_remarks: pdfh(html, ".row.p-2 h5:eq(-1)&&Text"),
vod_year: pdfh(html, ".row.p-2 a:eq(-1)&&Text"),
vod_area: pdfh(html, ".row.p-2 a:eq(-2)&&Text"),
vod_content: pdfh(html, ".row.p-2 p&&Text"),
vod_play_from: "源动力偷的线路",
vod_play_url: pdfa(html, ".col-md-12&&.sbtn-block")
.map(
(it) =>
`${pdfh(it, "button--i&&Text").trim()}$${ids[0]}|${pdfh(
it,
"button&&data-src"
)}`
)
.join("#"),
};
return vod;
},
搜索: async function (wd, quick, pg) {
const { input } = this;
const html = await request(input, {
method: "POST",
headers: {
...this.headers,
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
},
data: {
mform: "all",
mcountry: "all",
"tag_arr[]": "all",
album: "all",
years: "all",
sort: "updatetime",
title: wd,
page: pg,
},
});
const resp = JSON.parse(html);
const d = [];
resp.mlist.forEach((it) => {
d.push({
title: it.title,
pic_url: it.cover_img,
desc: `${it.grade}|${it.definition}`,
url: it.mid,
});
});
return setResult(d);
},
lazy: async function (flag, id, flags) {
const { pdfa, pdfh } = this;
const [data_id, data_src] = id.split("|");
const sourceReqUrl = `${this.host}/play/${data_id}`;
console.warn(data_id, data_src);
const source = await axios.get(sourceReqUrl, { headers: this.headers });
const script = pdfa(source.data, "script");
const scriptContent = script.filter((e) =>
e.includes("configs-n26.1.js")
)[0];
const sourceUrl = pdfh(scriptContent, "script&&src");
console.warn("sourceUrl", sourceUrl);
let play = await decryptor.decryptPlay(sourceUrl, data_src);
if (play.includes("gazes_v-@_info")) {
return {
parse: 0,
url:
getProxyUrl() +
"&playdata=" +
encodeURIComponent(JSON.stringify([sourceUrl, data_src, play])) +
"&t=0",
};
} else {
if (play.includes("cloud.189.cn")) {
let js_data = decryptor.parseUrlParams(sourceUrl);
const thirdKey = Object.keys(js_data)[2];
try {
const re_link = await axios.post(
`${this.host}/fetch_189c_murl`,
{
urls: play,
mid: js_data.mid,
},
{
headers: {
"Content-Type":
"application/x-www-form-urlencoded; charset=UTF-8",
Accept: "*/*",
Origin: this,
[thirdKey]: encodeURIComponent(js_data[thirdKey]),
Cookie: source.headers["set-cookie"]
.map((it) => it.split(";")[0])
.join(";"),
},
}
);
console.log("API Response:", re_link.data);
play = re_link.data?.url;
} catch (error) {
console.error("Request Failed:", error);
}
}
return {
parse: 0,
url: play,
};
}
},
proxy_rule: async function (params) {
try {
const segments = JSON.parse(decodeURIComponent(params.playdata));
let [sourceUrl, data_src, play] = segments;
console.log(segments);
let m3u8 = await decryptor.decryptM3u8(sourceUrl, data_src, play);
return [200, "text/text", m3u8];
} catch (e) {
console.log(e);
}
},
dealHeaders: async function () {
const resp = await axios.get(`${this.host}/filter`, {
headers: this.headers,
});
// cookie 处理
const headers = resp.headers;
const cookies = headers["set-cookie"];
const cookie = cookies.map((item) => item.split(";")[0]).join("; ");
this.headers.Cookie = cookie;
// 请求头处理
const html = resp.data;
const kv_macth = html.match(/'headers':({[^{}]*})/)[1];
const kv_headers = new Function(`return ${kv_macth}`)();
for (const key in kv_headers) {
this.headers[key] = kv_headers[key];
}
console.warn("headers", this.headers);
},
};