forked from qist/tvbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
drpy2.js
2808 lines (2677 loc) · 97.1 KB
/
drpy2.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
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import cheerio from 'assets://js/lib/cheerio.min.js';
import 'assets://js/lib/crypto-js.js';
import './jsencrypt.js';
import 模板 from "../js/模板.js"
import {gbkTool} from './gbk.js'
// import cheerio from "https://ghproxy.net/https://raw.githubusercontent.com/hjdhnx/dr_py/main/libs/cheerio.min.js";
// import "https://ghproxy.net/https://raw.githubusercontent.com/hjdhnx/dr_py/main/libs/crypto-js.js";
// import 模板 from"https://ghproxy.net/https://raw.githubusercontent.com/hjdhnx/dr_py/main/js/模板.js";
// import {gbkTool} from 'https://ghproxy.net/https://raw.githubusercontent.com/hjdhnx/dr_py/main/libs/gbk.js'
function init_test(){
// console.log(typeof(CryptoJS));
console.log("init_test_start");
// print(模板);
// print(typeof(模板.getMubans));
console.log("当前版本号:"+VERSION);
console.log(RKEY);
console.log(JSON.stringify(rule));
console.log("init_test_end");
// log('typeof (JSEncrypt):'+typeof (JSEncrypt));
// let publicKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwEc7wBMtYKkxvrQNI3+ITBZwAkPkGvsv4TsAHFskKGZWz9eYl3scivhmlEfWHlEkdyb0m82CmB1qAgef+pD4cZu+Cdmm2e9lnExhLwm8cBgpkAen9QRNdjojZgxM0W+JcReH4W6pw+uFXiLRn4AIQkDftWGNLg6wlNS+39Z/RvP9zyATJLZ9AKDdHp62XMxEK1KZvWBuIg+Oa5UzgA9jy+2XyIqwhBtO8tPbUl21t2pvTzHoLUjSkPNm2LurcUk6+jQ2r6aiS2CN1NXIucPJU6mkuIQ821SjvkYPtIdRMntW4y2u4cyiqVEEQwlzWVMHh+/vfrWAQr9fgjDuYYtvPQIDAQAB';
// let privateKey = 'MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDARzvAEy1gqTG+tA0jf4hMFnACQ+Qa+y/hOwAcWyQoZlbP15iXexyK+GaUR9YeUSR3JvSbzYKYHWoCB5/6kPhxm74J2abZ72WcTGEvCbxwGCmQB6f1BE12OiNmDEzRb4lxF4fhbqnD64VeItGfgAhCQN+1YY0uDrCU1L7f1n9G8/3PIBMktn0AoN0enrZczEQrUpm9YG4iD45rlTOAD2PL7ZfIirCEG07y09tSXbW3am9PMegtSNKQ82bYu6txSTr6NDavpqJLYI3U1ci5w8lTqaS4hDzbVKO+Rg+0h1Eye1bjLa7hzKKpUQRDCXNZUweH7+9+tYBCv1+CMO5hi289AgMBAAECggEBAIRbRJUWXmEwdq64kGbELlV6CIZ2p3mvOSlIjO34Cy7IK7AMz9xOgbpj/XDK9miOIJTouu7ZC7GcZdGZ4BUCYBMMS0fKjGFuurpZlXhkslNTPqEHtCUkXhIpOR7RDrwIlErGEOIsZC4aXQcM3tF1t7mroJLh4OY4dHMu82lv5NM4hhFMNvHzXVvrPXeTzw26gddHVG/ke0WUYOcB5j3cPp8xaVp7JV8bdxtGtkqIfBLY/dIczzJu/3F3cBpU2nNwt8uVUF/w/HKlr7j8FqqFHXWh182beU0n5AIdRyRJBrRUAEhdtsUnvJOVBDqzZa+9DJ5395F7V8KRlQptxETdhCECgYEA4x/2HM9fnVIhG6wTbEt1LhGTKYb/igMAHLqquEMfRsB44tobI8gVNwR3qJQY/nKXxcQemQV29PcdqpENCKyXUXGD8SI1UPg15rHFBI8CIqlCXfzJybdHjmzlhaA9I5lofIVh+5MW7WkvHZoRy7NeDMhHUuaiveuqC4OJ8n+dD2kCgYEA2LkmUVef3WkBBwUBRdkyoog3DMwR+/ubb0ncJVYy3ItYVJltQ4HqmrRiJc8xBAoFnG8rbiqDnmTnDR3WbuxU1G2hml09fqId+rQds2UfESswCXHU43A4f77m1XyA6PprBxpozVIcmK69N4rR9jOXflLWo3O+p2ipUbmNpId7+rUCgYBSpcbBJRT+AmzZzPwkZDD32p1ady114zGfQq3s7z/qVw+mPQezNZPCuXVxerK9pKVl6b/Ynwxyh5nb/3xms6c8k7oXfQM5u5ihof63cfKs+jqUSPCE3pTDVw0OWwjkc2Z6KW9GRHgLXEMw2mevYE3RCPArUpHV2nO+TNddzuIwQQKBgQDOZwdnUNygMfEYjlu3+jOPN8u2FGTMZ8SRKPbRWFb4VH27lKPLN2AIFuOivsEf56uQYRAry7GumMq0Y0ZmPg5Mglz2dvaqNBv5OLFQuW3tHAST+iWWtroYb+fISts7B8QG79AAO8OgZksvKrbslBYj6SEiaomZRsR7YQzVNXOOQQKBgQCovElZ50c8ZJ6m9D9fw3Nes7u9vshpyyac5tt4tZ7yfU4l5pWGrIUqCE703qZp4NAqEvlZUCJbj9kkysaj/2MfFb2b9jSvdNB+V/YW9Cwg+5TziYoOcQzN1z2u4p4goTAv0S+pTNSr3qWaTUI4TXUXQajif45Fexv+MrP5AAXQyw=='
// // let text = '你好';
// let text = '[{"vod_name":"兔小贝原创儿歌","vod_pic":"https://resource-cdn.tuxiaobei.com/video-album/FnQ8ieJHgsbgCKWXNBg4uoOmKgG5.jpg","vod_remarks":"共229首","vod_content":"","vod_id":"/subject/17@@兔小贝原创儿歌@@https://resource-cdn.tuxiaobei.com/video-album/FnQ8ieJHgsbgCKWXNBg4uoOmKgG5.jpg"},{"vod_name":"英文儿歌","vod_pic":"https://resource-cdn.tuxiaobei.com/video-album/Fqjpx2H_-QaYNAYn2MekRuDpeyUv.jpg","vod_remarks":"共10首","vod_content":"","vod_id":"/subject/23@@英文儿歌@@https://resource-cdn.tuxiaobei.com/video-album/Fqjpx2H_-QaYNAYn2MekRuDpeyUv.jpg"}]';
// let str = RSA.encode(text, publicKey);
// console.log("加密数据:" + str);
// let str1 = 'Wa2c/868VOm0PgpGG2s2aMrDbGOlJRdZXlSGswjFgywd3nZNB7ND8kVMdNB/OsNFoQXJXSJMvPaE73BH7rs8fz54JGdYQK+qTgfQRqQZvomCjbzseSR4bm4NOrtIOOslL3WqxlzOuU0M1P1eERmkLEVU2WSyc3RGtJro3b3MOWYCNdKMoZdncfOHJndkl4wm9V3GGc3uH98hs6OxLvBWgXoW9jZQ3n0vR2FtS2KYrPGuSuKGkxlt9Kw5TD6nri142NOimz05WK55Xe04YUQ1VZd51t0wzJGXolWgfzIQaK2zzhk5Zjlm+IQJxXqEWiJ2+O6TJ+lIttvsDSaUflcDXQ==';
// let str2 = 'R86mW9DzBw05pxBSh9ECh1stXxINmnudgZBbzU/cz1EcFgrEgdk0Zk4ruAiJZB2fP5c7d3gMmN8+Dv19IfARWSzw85xCEjUhpdcMJ0jn6ZE5H+muadND9LzjeVisojqwYxot3YVdKof7HMhPFN8QR0jfzqhjmnGFTlY1jMXzJK0MSOLNRLDar480CdKNb/cxALC8+xKIlhM9E4B31t8J4rNMUWSCAr49lbZ3jx3PxieBpTQUdDJz96AttR93Pc+c51wrxh0Ch/Mt4Rs09HGMXwIpNV+CxsGwSGRQUlyJo2k3d0WqsVzpz6S8A4VGEMTRLGI3IjEt+eWt7wM3nAXarg==';
// let str3 = 'D4eOsRqua+jYA5+ZOR9PLI2PExKjKfArQfv9/wGeG50bQSjWypShJPY6RQfO+rghyf0juzHIUSxqH91OxinhCFkONaF2Vod2QVyphyn9eh73dAcEFKIFFKGXoPCjbMWrr3p4d+hgVrHzrFeGqkRq8JFOvG2L5XDxVfWbV8KmUA0DKuz6QwWg7P4kesy+C7BbLALy5W/wfZchD3gnsBvx/pjFoe11VfAify9isLxg9a15jj52xr6lzQ9kge9C2JcV8yq85bFKaUpJWgobzz+BSIv3lVMU6vgcldmOrhkyiETpFGFGGF00DphGCEoK6uAyyNDh7+Jn8P17zf/DW1wV3A==';
// let uncrypted = RSA.decode(str, privateKey);
// log('解密数据:'+uncrypted);
// uncrypted = RSA.decode(str1, privateKey);
// log('解密数据1:'+uncrypted);
// uncrypted = RSA.decode(str2, privateKey);
// log('解密数据2:'+uncrypted);
// uncrypted = RSA.decode(str3, privateKey);
// log('解密数据3:'+uncrypted);
// log('rsax:'+typeof(rsax));
// log('rsaX:'+typeof(rsaX));
// let data = base64Encode('你好');
// let publicKey = 'dzyyds';
// console.log(typeof (RSA.encode));
// let encryptBase64Data = RSA.encode(data,publicKey);
// log('encryptBase64Data:'+encryptBase64Data);
// let str = RSA.decode(data,publicKey);
// log('str:'+str);
}
/**
* 执行预处理代码
*/
function pre(){
if(typeof(rule.预处理) === 'string' && rule.预处理 && rule.预处理.trim()){
let code = rule.预处理.trim();
console.log("执行预处理代码:"+code);
if(code.startsWith('js:')){
code = code.replace('js:','');
}
try {
// code里可以进行get 或者 post请求cookie并改变rule.headers 里的cookie
// 直接操作 rule_fetch_params 这个变量 .headers.Cookie
eval(code);
}catch (e) {
console.log('预处理执行失败:'+e.message);
}
}
}
let rule = {};
let vercode = typeof(pdfl) ==='function'?'drpy2.1':'drpy2';
const VERSION = vercode+' 3.9.49beta40 202400426';
/** 已知问题记录
* 1.影魔的jinjia2引擎不支持 {{fl}}对象直接渲染 (有能力解决的话尽量解决下,支持对象直接渲染字符串转义,如果加了|safe就不转义)[影魔牛逼,最新的文件发现这问题已经解决了]
* Array.prototype.append = Array.prototype.push; 这种js执行后有毛病,for in 循环列表会把属性给打印出来 (这个大毛病需要重点排除一下)
* 2.import es6py.js但是里面的函数没有被装载进来.比如drpy规则报错setResult2 is undefiend(合并文件了可以不管了)
* 3.无法重复导入cheerio(怎么解决drpy和parseTag里都需要导入cheerio的问题) 无法在副文件导入cheerio (现在是全部放在drpy一个文件里了,凑合解决?)
* 4.有个错误不知道哪儿来的 executeScript: com.quickjs.JSObject$Undefined cannot be cast to java.lang.String 在 点击选集播放打印init_test_end后面打印(貌似不影响使用)
* 5.需要实现 stringify 函数,比起JSON.strifngify函数,它会原封不动保留中文不会编码unicode
* 6.base64Encode,base64Decode,md5函数还没有实现 (抄影魔代码实现了)
* 7.eval(getCryptoJS());还没有实现 (可以空实现了,以后遇到能忽略)
* done: jsp:{pdfa,pdfh,pd},json:{pdfa,pdfh,pd},jq:{pdfa,pdfh,pd}
* 8.req函数不支持传递字符串的data参数 {'content-type':'text/plain'} 类型数据,因此无法直接调用alist的ocr接口
* * 电脑看日志调试
adb tcpip 5555
adb connect 192.168.10.192
adb devices -l
adb logcat -c
adb logcat | grep -i QuickJS
adb logcat -c -b events
adb logcat -c -b main -b events -b radio -b system
adb logcat > 2.log DRPY:E | grep -i QuickJS
* **/
/*** 以下是内置变量和解析方法 **/
const MOBILE_UA = 'Mozilla/5.0 (Linux; Android 11; M2007J3SC Build/RKQ1.200826.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.120 MQQBrowser/6.2 TBS/045714 Mobile Safari/537.36';
const PC_UA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36';
const UA = 'Mozilla/5.0';
const UC_UA = 'Mozilla/5.0 (Linux; U; Android 9; zh-CN; MI 9 Build/PKQ1.181121.001) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.108 UCBrowser/12.5.5.1035 Mobile Safari/537.36';
const IOS_UA = 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1';
const RULE_CK = 'cookie'; // 源cookie的key值
// const KEY = typeof(key)!=='undefined'&&key?key:'drpy_' + (rule.title || rule.host); // 源的唯一标识
const CATE_EXCLUDE = '首页|留言|APP|下载|资讯|新闻|动态';
const TAB_EXCLUDE = '猜你|喜欢|下载|剧情|热播';
const OCR_RETRY = 3;//ocr验证重试次数
// const OCR_API = 'http://dm.mudery.com:10000';//ocr在线识别接口
// const OCR_API = 'http://192.168.3.239:5705/parse/ocr';//ocr在线识别接口
// const OCR_API = 'http://cms.nokia.press/parse/ocr';//ocr在线识别接口
// const OCR_API = 'http://cms.nokia.press:5707/parse/ocr';//ocr在线识别接口
const OCR_API = 'http://drpy.nokia.press:8028/ocr/drpy/text';//ocr在线识别接口
if(typeof(MY_URL)==='undefined'){
var MY_URL; // 全局注入变量,pd函数需要
}
var HOST;
var RKEY; // 源的唯一标识
var fetch;
var print;
var log;
var rule_fetch_params;
var fetch_params; // 每个位置单独的
var oheaders;
// var play_url; // 二级详情页注入变量,为了适配js模式0 (不在这里定义了,直接二级里定义了个空字符串)
var _pdfh;
var _pdfa;
var _pd;
// const DOM_CHECK_ATTR = ['url', 'src', 'href', 'data-original', 'data-src'];
const DOM_CHECK_ATTR = /(url|src|href|-original|-src|-play|-url|style)$/;
// 过滤特殊链接,不走urlJoin
const SPECIAL_URL = /^(ftp|magnet|thunder|ws):/;
const NOADD_INDEX = /:eq|:lt|:gt|:first|:last|^body$|^#/; // 不自动加eq下标索引
const URLJOIN_ATTR = /(url|src|href|-original|-src|-play|-url|style)$/; // 需要自动urljoin的属性
const SELECT_REGEX = /:eq|:lt|:gt|#/g;
const SELECT_REGEX_A = /:eq|:lt|:gt/g;
/**
es6py扩展
*/
if (typeof Object.assign != 'function') {
Object.assign = function () {
let target = arguments[0];
for (let i = 1; i < arguments.length; i++) {
let source = arguments[i];
for (let key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
}
if (!String.prototype.includes) {
String.prototype.includes = function (search, start) {
if (typeof start !== 'number') {
start = 0;
}
if (start + search.length > this.length) {
return false;
} else {
return this.indexOf(search, start) !== -1;
}
};
}
if (!Array.prototype.includes) {
Object.defineProperty(Array.prototype, 'includes', {
value: function (searchElement, fromIndex) {
if (this == null) {//this是空或者未定义,抛出错误
throw new TypeError('"this" is null or not defined');
}
var o = Object(this);//将this转变成对象
var len = o.length >>> 0;//无符号右移0位,获取对象length属性,如果未定义就会变成0
if (len === 0) {//length为0直接返回false未找到目标值
return false;
}
var n = fromIndex | 0;//查找起始索引
var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);//计算正确起始索引,因为有可能是负值
while (k < len) {//从起始索引处开始循环
if (o[k] === searchElement) {//如果某一位置与寻找目标相等,返回true,找到了
return true;
}
k++;
}
return false;//未找到,返回false
}
});
}
if (typeof String.prototype.startsWith != 'function') {
String.prototype.startsWith = function (prefix){
return this.slice(0, prefix.length) === prefix;
};
}
if (typeof String.prototype.endsWith != 'function') {
String.prototype.endsWith = function(suffix) {
return this.indexOf(suffix, this.length - suffix.length) !== -1;
};
}
Object.prototype.myValues=function(obj){
if(obj ==null) {
throw new TypeError("Cannot convert undefined or null to object");
}
var res=[]
for(var k in obj){
if(obj.hasOwnProperty(k)){//需判断是否是本身的属性
res.push(obj[k]);
}
}
return res;
}
if (typeof Object.prototype.values != 'function') {
Object.prototype.values=function(obj){
if(obj ==null) {
throw new TypeError("Cannot convert undefined or null to object");
}
var res=[]
for(var k in obj){
if(obj.hasOwnProperty(k)){//需判断是否是本身的属性
res.push(obj[k]);
}
}
return res;
}
}
if (typeof Array.prototype.join != 'function') {
Array.prototype.join = function (emoji) {
// emoji = emoji||',';
emoji = emoji||'';
let self = this;
let str = "";
let i = 0;
if (!Array.isArray(self)) {throw String(self)+'is not Array'}
if(self.length===0){return ''}
if (self.length === 1){return String(self[0])}
i = 1;
str = this[0];
for (; i < self.length; i++) {
str += String(emoji)+String(self[i]);
}
return str;
};
}
if (typeof Array.prototype.toReversed != 'function') {
Array.prototype.toReversed = function () {
const clonedList = this.slice();
// 倒序新数组
const reversedList = clonedList.reverse();
return reversedList;
};
}
String.prototype.rstrip = function (chars) {
let regex = new RegExp(chars + "$");
return this.replace(regex, "");
};
Array.prototype.append = Array.prototype.push;
String.prototype.strip = String.prototype.trim;
function 是否正版(vipUrl){
let flag = new RegExp('qq\.com|iqiyi\.com|youku\.com|mgtv\.com|bilibili\.com|sohu\.com|ixigua\.com|pptv\.com|miguvideo\.com|le\.com|1905\.com|fun\.tv');
return flag.test(vipUrl);
}
function urlDeal(vipUrl){
if(!vipUrl){
return ''
}
if(!是否正版(vipUrl)){
return vipUrl
}
if(!/miguvideo/.test(vipUrl)){
vipUrl=vipUrl.split('#')[0].split('?')[0];
}
return vipUrl
}
function setResult(d){
if(!Array.isArray(d)){
return []
}
VODS = [];
// print(d);
d.forEach(function (it){
let obj = {
vod_id:it.url||'',
vod_name: it.title||'',
vod_remarks: it.desc||'',
vod_content: it.content||'',
vod_pic: it.pic_url||it.img||'',
};
let keys = Object.keys(it);
if(keys.includes('tname')){
obj.type_name = it.tname||'';
}
if(keys.includes('tid')){
obj.type_id = it.tid||'';
}
if(keys.includes('year')){
obj.vod_year = it.year||'';
}
if(keys.includes('actor')){
obj.vod_actor = it.actor||'';
}
if(keys.includes('director')){
obj.vod_director = it.director||'';
}
if(keys.includes('area')){
obj.vod_area = it.area||'';
}
VODS.push(obj);
});
return VODS
}
function setResult2(res){
VODS = res.list||[];
return VODS
}
function setHomeResult(res){
if(!res||typeof(res)!=='object'){
return []
}
return setResult(res.list);
}
// 猫了个咪
function rc(js) {
if (js === 'maomi_aes.js') {
var a = CryptoJS.enc.Utf8.parse("625222f9149e961d");
var t = CryptoJS.enc.Utf8.parse("5efdtf6060e2o330");
return {
De: function (word) {
word = CryptoJS.enc.Hex.parse(word)
return CryptoJS.AES.decrypt(CryptoJS.enc.Base64.stringify(word), a, {
iv: t,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7
}).toString(CryptoJS.enc.Utf8)
},
En: function (word) {
// print(a);
// print(word);
var Encrypted = CryptoJS.AES.encrypt(word, a, {
iv: t,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7
});
return Encrypted.ciphertext.toString();
}
};
}
return {};
}
// 千万不要用for in 推荐 forEach (for in 会打乱顺序)
//猫函数
function maoss(jxurl, ref, key) {
fetch_params = JSON.parse(JSON.stringify(rule_fetch_params));
eval(getCryptoJS());
try {
var getVideoInfo = function (text) {
return CryptoJS.AES.decrypt(text, key, {iv: iv, padding: CryptoJS.pad.Pkcs7}).toString(CryptoJS.enc.Utf8);
};
var token_key = key == undefined ? 'dvyYRQlnPRCMdQSe' : key;
if (ref) {
var html = request(jxurl, {
headers: {
'Referer': ref
}
});
} else {
var html = request(jxurl);
}
// print(html);
if (html.indexOf('&btwaf=') != -1) {
html = request(jxurl + '&btwaf' + html.match(/&btwaf(.*?)"/)[1], {
headers: {
'Referer': ref
}
})
}
var token_iv = html.split('_token = "')[1].split('"')[0];
var key = CryptoJS.enc.Utf8.parse(token_key);
var iv = CryptoJS.enc.Utf8.parse(token_iv);
// log("iv:"+iv);
// log(html);
// print(key);
// print(iv);
eval(html.match(/var config = {[\s\S]*?}/)[0] + '');
// config.url = config.url.replace(/,/g,'');
// print(config.url);
if (!config.url.startsWith('http')) {
//config.url = decodeURIComponent(AES(config.url, key, iv));
config.url = CryptoJS.AES.decrypt(config.url, key, {
iv: iv,
padding: CryptoJS.pad.Pkcs7
}).toString(CryptoJS.enc.Utf8)
}
return config.url;
} catch (e) {
return '';
}
}
function urlencode (str) {
str = (str + '').toString();
return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').
replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
}
function base64Encode(text){
return CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(text));
// return text
}
function base64Decode(text){
return CryptoJS.enc.Utf8.stringify(CryptoJS.enc.Base64.parse(text));
// return text
}
function md5(text) {
return CryptoJS.MD5(text).toString();
}
/**
* 字符串按指定编码
* @param input
* @param encoding
* @returns {*}
*/
function encodeStr(input,encoding){
encoding = encoding||'gbk';
if(encoding.startsWith('gb')){
const strTool = gbkTool();
input = strTool.encode(input);
}
return input
}
/**
* 字符串指定解码
* @param input
* @param encoding
* @returns {*}
*/
function decodeStr(input,encoding){
encoding = encoding||'gbk';
if(encoding.startsWith('gb')){
const strTool = gbkTool();
input = strTool.decode(input);
}
return input
}
function getCryptoJS(){
// return request('https://ghproxy.net/https://raw.githubusercontent.com/hjdhnx/dr_py/main/libs/crypto-hiker.js');
return 'console.log("CryptoJS已装载");'
}
// 封装的RSA加解密类
const RSA = {
decode: function (data, key, option) {
option = option || {};
if (typeof (JSEncrypt) === 'function') {
let chunkSize = option.chunkSize || 117; // 默认分段长度为117
let privateKey = this.getPrivateKey(key); // 获取私钥
const decryptor = new JSEncrypt(); //创建解密对象实例
decryptor.setPrivateKey(privateKey); //设置秘钥
let uncrypted = '';
// uncrypted = decryptor.decrypt(data);
uncrypted = decryptor.decryptUnicodeLong(data);
return uncrypted;
} else {
return false
}
},
encode: function (data, key, option) {
option = option || {};
if (typeof (JSEncrypt) === 'function') {
let chunkSize = option.chunkSize || 117; // 默认分段长度为117
let publicKey = this.getPublicKey(key); // 获取公钥
const encryptor = new JSEncrypt();
encryptor.setPublicKey(publicKey); // 设置公钥
let encrypted = ''; // 加密结果
// const textLen = data.length; // 待加密文本长度
// let offset = 0; // 分段偏移量
// // 分段加密
// while (offset < textLen) {
// let chunk = data.slice(offset, chunkSize); // 提取分段数据
// let enc = encryptor.encrypt(chunk); // 加密分段数据
// encrypted += enc; // 连接加密结果
// offset += chunkSize; // 更新偏移量
// }
encrypted = encryptor.encryptUnicodeLong(data);
return encrypted
} else {
return false
}
},
fixKey(key, prefix, endfix) {
if (!key.includes(prefix)) {
key = prefix + key;
}
if (!key.includes(endfix)) {
key += endfix
}
return key
},
getPrivateKey(key) {
let prefix = '-----BEGIN RSA PRIVATE KEY-----';
let endfix = '-----END RSA PRIVATE KEY-----';
return this.fixKey(key, prefix, endfix);
},
getPublicKey(key) {
let prefix = '-----BEGIN PUBLIC KEY-----';
let endfix = '-----END PUBLIC KEY-----';
return this.fixKey(key, prefix, endfix);
}
};
/**
* 获取壳子返回的代理地址
* @returns {string|*}
*/
function getProxyUrl(){
if(typeof(getProxy)==='function'){//判断壳子里有getProxy函数就执行取返回结果。否则取默认的本地
return getProxy(true)
}else{
return 'http://127.0.0.1:9978/proxy?do=js'
}
}
/**
* 根据正则处理原始m3u8里的广告ts片段,自动修复相对链接
* @param m3u8_text m3u8原始文本,里面是最末级的只含ts片段的。不支持嵌套m3u8链接
* @param m3u8_url m3u8原始地址
* @param ad_remove 正则表达式如: reg:/video/adjump(.*?)ts
* @returns {string|DocumentFragment|*|string}
*/
function fixAdM3u8(m3u8_text, m3u8_url, ad_remove) {
if ((!m3u8_text && !m3u8_url) || (!m3u8_text && m3u8_url && !m3u8_url.startsWith('http'))) {
return ''
}
if (!m3u8_text) {
log('m3u8_url:' + m3u8_url);
m3u8_text = request(m3u8_url);
}
log('len(m3u8_text):' + m3u8_text.length);
if (!ad_remove) {
return m3u8_text
}
if (ad_remove.startsWith('reg:')) {
ad_remove = ad_remove.slice(4)
} else if (ad_remove.startsWith('js:')) {
ad_remove = ad_remove.slice(3)
}
let m3u8_start = m3u8_text.slice(0, m3u8_text.indexOf('#EXTINF')).trim();
let m3u8_body = m3u8_text.slice(m3u8_text.indexOf('#EXTINF'), m3u8_text.indexOf('#EXT-X-ENDLIST')).trim();
let m3u8_end = m3u8_text.slice(m3u8_text.indexOf('#EXT-X-ENDLIST')).trim();
let murls = [];
let m3_body_list = m3u8_body.split('\n');
let m3_len = m3_body_list.length;
let i = 0;
while (i < m3_len) {
let mi = m3_body_list[i];
let mi_1 = m3_body_list[i + 1];
if (mi.startsWith('#EXTINF')) {
murls.push([mi, mi_1].join('&'));
i += 2
} else if (mi.startsWith('#EXT-X-DISCONTINUITY')) {
let mi_2 = m3_body_list[i + 2];
murls.push([mi, mi_1, mi_2].join('&'));
i += 3
} else {
break;
}
}
let new_m3u8_body = [];
for (let murl of murls) {
if (ad_remove && new RegExp(ad_remove).test(murl)) {
} else {
let murl_list = murl.split('&');
if (!murl_list[murl_list.length - 1].startsWith('http') && m3u8_url.startsWith('http')) {
murl_list[murl_list.length - 1] = urljoin(m3u8_url, murl_list[murl_list.length - 1]);
}
murl_list.forEach((it) => {
new_m3u8_body.push(it);
});
}
}
new_m3u8_body = new_m3u8_body.join('\n').trim();
m3u8_text = [m3u8_start, new_m3u8_body, m3u8_end].join('\n').trim();
return m3u8_text
}
/**
* 智能对比去除广告。支持嵌套m3u8。只需要传入播放地址
* @param m3u8_url m3u8播放地址
* @returns {string}
*/
function fixAdM3u8Ai(m3u8_url) {
let ts = new Date().getTime();
function b(s1, s2) {
let i = 0;
while (i < s1.length) {
if (s1[i] !== s2[i]) {
break
}
i++
}
return i;
}
function reverseString(str) {
return str.split('').reverse().join('');
}
//log('播放的地址:' + m3u8_url);
let m3u8 = request(m3u8_url);
//log('m3u8处理前:' + m3u8);
m3u8 = m3u8.trim().split('\n').map(it => it.startsWith('#') ? it : urljoin(m3u8_url, it)).join('\n');
//log('m3u8处理后:============:' + m3u8);
// 获取嵌套m3u8地址
let last_url = m3u8.split('\n').slice(-1)[0];
if (last_url.includes('.m3u8') && last_url !== m3u8_url) {
m3u8_url = last_url;
//log('嵌套的m3u8_url:' + m3u8_url);
m3u8 = request(m3u8_url);
}
//log('----处理有广告的地址----');
let s = m3u8.trim().split('\n').filter(it => it.trim()).join('\n');
let ss = s.split('\n')
//找出第一条播放地址
let firststr = ss.find(x => !x.startsWith('#'));
let maxl = 0;//最大相同字符
let firststrlen = firststr.length;
//log('字符串长度:' + firststrlen);
let ml = Math.round(ss.length / 2).toString().length;//取数据的长度的位数
//log('数据条数的长度:' + ml);
//找出最后一条播放地址
let laststr = ss.toReversed().find((x) => {
if (!x.startsWith('#')) {
let k = b(reverseString(firststr), reverseString(x));
maxl = b(firststr, x);
if (firststrlen - maxl <= ml + k) {
return true
}
}
return false
});
log('最后一条切片:' + laststr);
//log('最小相同字符长度:' + maxl);
let ad_urls = [];
for (let i = 0; i < ss.length; i++) {
let s = ss[i];
if (!s.startsWith('#')) {
if (b(firststr, s) < maxl) {
ad_urls.push(s); // 广告地址加入列表
ss.splice(i - 1, 2);
i = i - 2;
} else {
ss[i] = urljoin(m3u8_url, s);
}
} else {
ss[i] = s.replace(/URI=\"(.*)\"/, 'URI=\"' + urljoin(m3u8_url, '$1') + '\"');
}
}
log('处理的m3u8地址:' + m3u8_url);
log('----广告地址----');
log(ad_urls);
m3u8 = ss.join('\n');
//log('处理完成');
log('处理耗时:' + (new Date().getTime() - ts).toString());
return m3u8
}
/**
* 强制正序算法
* @param lists 待正序列表
* @param key 正序键
* @param option 单个元素处理函数
* @returns {*}
*/
function forceOrder(lists,key,option){
let start = Math.floor(lists.length/2);
let end = Math.min(lists.length-1,start+1);
if(start >= end){
return lists;
}
let first = lists[start];
let second = lists[end];
if(key){
try {
first = first[key];
second = second[key];
}catch (e) {}
}
if(option && typeof(option)==='function'){
try {
first = option(first);
second = option(second);
}catch (e) {}
}
first+='';
second+='';
// console.log(first,second);
if(first.match(/(\d+)/)&&second.match(/(\d+)/)){
let num1 = Number(first.match(/(\d+)/)[1]);
let num2 = Number(second.match(/(\d+)/)[1]);
if (num1 > num2){
lists.reverse();
}
}
return lists
}
let VODS = [];// 一级或者搜索需要的数据列表
let VOD = {};// 二级的单个数据
let TABS = [];// 二级的自定义线路列表 如: TABS=['道长在线','道长在线2']
let LISTS = [];// 二级的自定义选集播放列表 如: LISTS=[['第1集$http://1.mp4','第2集$http://2.mp4'],['第3集$http://1.mp4','第4集$http://2.mp4']]
globalThis.encodeUrl = urlencode;
globalThis.urlencode = urlencode;
/**
* url拼接
* @param fromPath 初始当前页面url
* @param nowPath 相对当前页面url
* @returns {*}
*/
function urljoin(fromPath, nowPath) {
fromPath = fromPath||'';
nowPath = nowPath||'';
return joinUrl(fromPath, nowPath);
// try {
// // import Uri from './uri.min.js';
// // var Uri = require('./uri.min.js');
// // eval(request('https://cdn.bootcdn.net/ajax/libs/URI.js/1.19.11/URI.min.js'));
// // let new_uri = URI(nowPath, fromPath);
// let new_uri = Uri(nowPath, fromPath);
// new_uri = new_uri.toString();
// // console.log(new_uri);
// // return fromPath + nowPath
// return new_uri
// }
// catch (e) {
// console.log('urljoin发生错误:'+e.message);
// if(nowPath.startsWith('http')){
// return nowPath
// }if(nowPath.startsWith('/')){
// return getHome(fromPath)+nowPath
// }
// return fromPath+nowPath
// }
}
var urljoin2 = urljoin;
// 内置 pdfh,pdfa,pd
const defaultParser = {
pdfh:pdfh,
pdfa:pdfa,
pd:pd,
};
/**
* pdfh原版优化,能取style属性里的图片链接
* @param html 源码
* @param parse 解析表达式
* @returns {string|*}
*/
function pdfh2(html,parse){
let html2 = html;
try {
if(typeof(html)!=='string'){
html2 = html.rr(html.ele).toString();
}
}catch (e) {
print('html对象转文本发生了错误:'+e.message);
}
let result = defaultParser.pdfh(html2,parse);
let option = parse.includes('&&')?parse.split('&&').slice(-1)[0]:parse.split(' ').slice(-1)[0];
if(/style/.test(option.toLowerCase())&&/url\(/.test(result)){
try {
result = result.match(/url\((.*?)\)/)[1];
// 2023/07/28新增 style取内部链接自动去除首尾单双引号
result = result.replace(/^['|"](.*)['|"]$/, "$1");
}catch (e) {}
}
return result
}
/**
* pdfa原版优化,可以转换jq的html对象
* @param html
* @param parse
* @returns {*}
*/
function pdfa2(html,parse){
let html2 = html;
try {
if(typeof(html)!=='string'){
html2 = html.rr(html.ele).toString();
}
}catch (e) {
print('html对象转文本发生了错误:'+e.message);
}
return defaultParser.pdfa(html2,parse);
}
/**
* pd原版方法重写-增加自动urljoin
* @param html
* @param parse
* @param uri
* @returns {*}
*/
function pd2(html,parse,uri){
let ret = pdfh2(html,parse);
if(typeof(uri)==='undefined'||!uri){
uri = '';
}
if(DOM_CHECK_ATTR.test(parse) && !SPECIAL_URL.test(ret)){
if(/http/.test(ret)){
ret = ret.slice(ret.indexOf('http'));
}else{
ret = urljoin(MY_URL,ret)
}
}
// MY_URL = getItem('MY_URL',MY_URL);
// console.log(`规则${RKEY}打印MY_URL:${MY_URL},uri:${uri}`);
return ret
}
const parseTags = {
jsp:{
pdfh:pdfh2,
pdfa:pdfa2,
pd:pd2,
},
json:{
pdfh(html, parse) {
if (!parse || !parse.trim()){
return '';
}
if (typeof(html) === 'string'){
// print('jsonpath:pdfh字符串转dict');
html = JSON.parse(html);
}
parse = parse.trim();
if (!parse.startsWith('$.')){
parse = '$.' + parse;
}
parse = parse.split('||');
for (let ps of parse) {
let ret = cheerio.jp(ps, html);
if (Array.isArray(ret)){
ret = ret[0] || '';
} else{
ret = ret || ''
}
if (ret && typeof (ret) !== 'string'){
ret = ret.toString();
}
if(ret){
return ret
}
}
return '';
},
pdfa(html, parse) {
if (!parse || !parse.trim()){
return '';
}
if (typeof(html) === 'string'){
// print('jsonpath:pdfa字符串转dict');
html = JSON.parse(html);
}
parse = parse.trim()
if (!parse.startsWith('$.')){
parse = '$.' + parse;
}
let ret = cheerio.jp(parse, html);
if (Array.isArray(ret) && Array.isArray(ret[0]) && ret.length === 1){
return ret[0] || []
}
return ret || []
},
pd(html,parse){
let ret = parseTags.json.pdfh(html,parse);
if(ret){
return urljoin(MY_URL,ret);
}
return ret
},
},
jq:{
pdfh(html, parse) {
if (!html||!parse || !parse.trim()) {
return ''
}
parse = parse.trim();
let result = defaultParser.pdfh(html,parse);
// print(`pdfh解析${parse}=>${result}`);
return result;
},
pdfa(html, parse) {
if (!html||!parse || !parse.trim()) {
return [];
}
parse = parse.trim();
let result = defaultParser.pdfa(html,parse);
// print(result);
print(`pdfa解析${parse}=>${result.length}`);
return result;
},
pd(html,parse,base_url){
if (!html||!parse || !parse.trim()) {
return ''
}
parse = parse.trim();
base_url = base_url||MY_URL;
return defaultParser.pd(html, parse, base_url);
},
},
getParse(p0){//非js开头的情况自动获取解析标签
if(p0.startsWith('jsp:')){
return this.jsp
}else if(p0.startsWith('json:')){
return this.json
}else if(p0.startsWith('jq:')){
return this.jq
}else {
return this.jq
}
}
};
const stringify = JSON.stringify;
const jsp = parseTags.jsp;
const jq = parseTags.jq;
/*** 后台需要实现的java方法并注入到js中 ***/
/**
* 读取本地文件->应用程序目录
* @param filePath
* @returns {string}
*/
function readFile(filePath){
filePath = filePath||'./uri.min.js';
var fd = os.open(filePath);
var buffer = new ArrayBuffer(1024);
var len = os.read(fd, buffer, 0, 1024);
console.log(len);
let text = String.fromCharCode.apply(null, new Uint8Array(buffer));
console.log(text);
return text
}
/**
* 处理返回的json数据
* @param html
* @returns {*}
*/
function dealJson(html) {
try {
// html = html.match(/[\w|\W|\s|\S]*?(\{[\w|\W|\s|\S]*\})/).group[1];
html = html.trim();
if(!((html.startsWith('{') && html.endsWith('}'))||(html.startsWith('[') && html.endsWith(']')))){
html = '{'+html.match(/.*?\{(.*)\}/m)[1]+'}';
}
} catch (e) {
}
try {
html = JSON.parse(html);
}catch (e) {}
// console.log(typeof(html));
return html;
}
/**
* 验证码识别逻辑,需要java实现(js没有bytes类型,无法调用后端的传递图片二进制获取验证码文本的接口)
* @type {{api: string, classification: (function(*=): string)}}
*/
var OcrApi={
api:OCR_API,
classification:function (img){ // img是byte类型,这里不方便搞啊
let code = '';
try {