forked from tomorrow505/auto_feed_js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auto_feed_v1.3.js
3831 lines (3376 loc) · 160 KB
/
auto_feed_v1.3.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
// ==UserScript==
// @name auto_feed_v1.3
// @author tomorrow505
// @contributor daoshuailx/hollips/PatrickCao
// @description 一键克隆种子信息
// @namespace Violentmonkey Scripts
// @include http*://*/details.php*
// @include http*://*/upload.*php*
// @include http*://totheglory.im/t/*
// @include https://api.douban.com/v2/movie/*
// @include http*://privatehd.to/torrent/*
// @include http*://avistaz.to/torrent/*
// @include http*://www.morethan.tv/torrents.php?id*
// @include http*://www.bfdz.ink/tools/ptgen*
// @icon https://pt.m-team.cc//favicon.ico
// @run-at document-end
// @version v1.3
// @grant GM_xmlhttpRequest
// ==/UserScript==
//获取网页地址,有两种可能,一种匹配上发布页面,一种匹配上源页面,源页面进行解析,跳转发布页面进行填写
var site_url = decodeURI(location.href);
var seperator = '#seperator#'; //用来拼接发布站点的url和字符串,也可用于识别发布页和源页面
//添加一下ptgen跳转
if (site_url.match('ptgen')){
url = site_url.split('?')[1];
document.getElementById('input_value').value = url;
document.getElementById('query_btn').click();
}
/*
-----------------------------part 1 用户变量层-------------------------------------------------------
*/
/*
支持发布的站点信息,使用字典的数据结构 1、只写域名也可做match用; 2、键值统一并且尽量简明
*/
var site_info = {
'MTeam': "https://pt.m-team.cc/",
'CMCT': "https://springsunday.net/",
'HDSky': "https://hdsky.me/",
'CHDBits': "https://chdbits.co/",
'OurBits': "https://ourbits.club/",
'TTG': "https://totheglory.im/",
'HDChina': "https://hdchina.org/",
'PTer': "https://pterclub.com/",
'LeagueHD': "https://leaguehd.com/",
'HDHome': "https://hdhome.org/",
'PThome': "https://www.pthome.net/",
'PuTao': "https://pt.sjtu.edu.cn/",
'NanYang': "https://nanyangpt.com/",
'TJUPT': 'https://www.tjupt.org/',
'TLFbits': "http://pt.eastgame.org/",
'HDDolby': 'https://www.hddolby.com/',
'Moecat': 'https://moecat.best/',
'HDstreet': 'https://hdstreet.club/',
'BTSchool': 'https://pt.btschool.club/',
'HDArea': 'https://www.hdarea.co/',
'ptsbao': 'https://ptsbao.club/'
};
//常用站点列表,可以自行更换
var common_sites = ['MTeam', 'PTer', 'CMCT'];
//部分站点加载图标会有问题
var site_img_info = {
'HDHome': 'https://img.pterclub.com/images/2020/04/21/hdhfavicon.png',
'TJUPT': 'https://img.pterclub.com/images/2020/04/21/hdhfavicon.png',
'HDChina': 'https://img.pterclub.com/images/2020/04/21/hdcfavicon.png',
'HDArea': 'https://img.pterclub.com/images/2020/04/21/hdafavicon.png',
'BTSchool': 'https://img.pterclub.com/images/2020/05/05/bts.png',
'Moecat': 'https://img.pterclub.com/images/2020/05/05/moe.png'
};
//用于作为源站点但是不是转发站点的字典包含特殊的朋友和外站
var o_site_info = {
'FRDS': 'https://pt.keepfrds.com/',
'BeiTai': 'https://www.beitai.pt/',
'avz': 'https://avistaz.to/',
'PHD': 'https://privatehd.to/',
'hdt': 'https://hd-torrents.org/',
'MTV': 'https://www.morethan.tv/'
};
//官种匹配,可以自行增减
reg_team_name = {
'MTeam': /-(.*mteam|mpad|tnp|BMDru)/i,
'CMCT': /-(CMCT|cmctv)/i,
'HDSky': /-(hds|.*@HDSky)/i,
'CHDBits': /-(CHD|.*@CHDBits)/i,
'OurBits': /(-Ao|-.*OurBits|-FLTTH|-IloveTV)/i,
'TTG': /-(WiKi|DoA|.*TTG|NGB|ARiN)/i,
'HDChina': /-(HDC)/i,
'PTer': /-(Pter|.*Pter)/i,
'LeagueHD': /-(LHD|i18n|League.*)/i,
'HDHome': /-hdh/i,
'PThome': /-pthome/i,
'PuTao': /-putao/i,
'NanYang': /-nytv/i,
'TLFbits': /-tlf/i,
'HDDolby': /-DBTV/i,
'FRDS': /-FRDS|@FRDS/i,
'BeiTai': /-BeiTai/i
};
/*
-------------------------------------part 2 函数定义层-----------------------------------------------------
*/
//第一第二个函数用来豆瓣信息搜索时候进行处理
var numToChn = function(num) {
var chnNumChar = ["零", "一", "二", "三", "四", "五", "六", "七", "八", "九"];
var index = num.toString().indexOf(".");
if (index != -1) {
var str = num.toString().slice(index);
var a = "点";
for (var i = 1; i < str.length; i++) {
a += chnNumChar[parseInt(str[i])];
}
return a;
} else {
return;
}
};
function numToChinese(num) { //定义在每个小节的内部进行转化的方法,其他部分则与小节内部转化方法相同
var chnNumChar = ["零", "一", "二", "三", "四", "五", "六", "七", "八", "九"];
var chnUnitChar = ["", "十", "百", "千"];
var str = '',
chnstr = '',
zero = false,
count = 0; //zero为是否进行补零, 第一次进行取余由于为个位数,默认不补零
if (num > 0 && num < 100) {
var v = num % 10;
var q = Math.floor(num / 10);
if (num < 10) { //如果数字为零,则对字符串进行补零
chnstr = chnNumChar[v] + chnstr;
} else if (num == 10) chnstr = chnUnitChar[1];
else if (num > 10 && num < 20) chnstr = "十" + chnNumChar[v];
else {
if (v == 0) chnstr = chnNumChar[q] + "十";
else chnstr = chnNumChar[q] + "十" + chnNumChar[v];
}
}
return chnstr;
}
//用来判断地址属于哪个站点(国内发布站点,国外源站点,或其他)
function find_origin_site(url){
var domain; //域名
var reg; //正则匹配表达式
var key;
//先从发布站点找
for (key in site_info){
//获取域名
domain = site_info[key].split('//')[1].replace('/', '');
reg = new RegExp(domain, 'i');
if (url.match(reg)){
return key;
}
}
//再从特殊源站点找
for (key in o_site_info){
//获取域名
domain = o_site_info[key].split('//')[1].replace('/', '');
reg = new RegExp(domain, 'i');
if (url.match(reg)){
return key;
}
}
return 'other';
}
//标签及其字标签转换为字符串,主要用于获取简介等等
function walkDOM(n) {
do {
// alert(n.nodeName)
if (n.nodeName == 'FONT') {
if (n.color != '') {
n.innerHTML = '[color=' + n.color + ']' + n.innerHTML + '[/color]';
}
if (n.size != '') {
n.innerHTML = '[size=' + n.size + ']' + n.innerHTML + '[/size]';
}
if (n.face != '') {
n.innerHTML = '[font=' + n.face + ']' + n.innerHTML + '[/font]';
}
}
if (n.nodeName == 'SPAN') {
if (n.style.color != '') {
n.innerHTML = '[color=' + n.style.color + ']' + n.innerHTML + '[/color]';
}
}
if (n.nodeName == 'U'){
n.innerHTML = '[u]' + n.innerHTML + '[/u]';
}
if (n.nodeName == 'A') {
if (n.innerHTML != "") {
if (site_url.match(/http(s*):\/\/chdbits.co\/details.php.*/i)) {
if (n.innerHTML.match(/pic\/hdl\.gif/g)) {
} else {
n.innerHTML = '[url=' + n.href + ']' + n.innerHTML + '[/url]';
}
} else {
n.innerHTML = '[url=' + n.href + ']' + n.innerHTML + '[/url]';
}
}
}
if (n.nodeName == 'TABLE') {
if (n.innerHTML != "") {
if (site_url.match(/http(s*):\/\/totheglory.im.*/i)) {
n.innerHTML = '[quote]' + n.innerHTML + '[/quote]';
}
}
}
if (n.nodeName == 'P') {
// alert(n.innerHTML)
if (n.innerHTML != "") {
if (site_url.match(/http(s*):\/\/totheglory.im.*/i)) {
n.innerHTML = '';
}
}
}
if (n.nodeName == 'FIELDSET' || n.nodeName == 'BLOCKQUOTE') {
n.innerHTML = '[quote]' + n.innerHTML + '[/quote]';
}
if (n.nodeName == 'DIV' && n.innerHTML == '代码') {
n.innerHTML = '';
n.nextSibling.innerHTML = '[code]' + n.nextSibling.innerHTML + '[/code]';
}
if (n.nodeName == 'BR') {
if (site_url.match(/http(s*):\/\/ourbits.club\/details.php.*/i) || site_url.match(/http(s*):\/\/totheglory.im.*/i)) {
n.innerHTML = '\r\n';
}
}
if (n.nodeName == 'LEGEND') {
n.innerHTML = '';
}
if (n.nodeName == 'FIELDSET' && n.textContent.match(/(温馨提示|郑重声明|您的保种|商业盈利)/g)) {
n.innerHTML = '';
} else {
if (n.hasChildNodes()) {
walkDOM(n.firstChild);
} else {
if (n.nodeType == 1) {
if (n.nodeName == 'IMG') {
// alert(n.src)
if (site_url.match(/http(s*):\/\/chdbits.co\/details.php.*/i)) {
if (n.src.match(/pic\/hdl\.gif/g)) {
} else {
raw_info.descr = raw_info.descr + '[img]' + n.src + '[/img]';
}
} else {
raw_info.descr = raw_info.descr + '[img]' + n.src + '[/img]';
}
}
} else {
raw_info.descr = raw_info.descr + n.textContent;
}
}
}
n = n.nextSibling;
} while (n);
return raw_info.descr;
}
//为了春天获取简介而写的定制节点转文本
function walk_cmct(n) {
do {
if (n.nodeName == 'SPAN') {
if (n.style.color != '') {
n.innerHTML = '[color=' + n.style.color + ']' + n.innerHTML + '[/color]';
}
}
if (n.nodeName == 'A') {
if (n.innerHTML != "") {
n.innerHTML = n.innerHTML;
}
}
if (n.nodeName == 'BR') {
n.innerHTML = '\r\n';
}
if (n.hasChildNodes()) {
walk_cmct(n.firstChild);
} else {
if (n.nodeType !=1){
raw_info.descr = raw_info.descr + n.textContent;
}
}
n = n.nextSibling;
} while (n);
return raw_info.descr;
}
//标签节点连带转换成字符串
function domToString (node) {
var tmpNode = document.createElement('div');
tmpNode.appendChild(node);
var str = tmpNode.innerHTML;
tmpNode = node = null; // 解除引用,以便于垃圾回收
return str;
}
//方便进行判断是否是源站点,不然太长了,属于源站点进入逻辑业务层
function judge_if_the_site_as_source() {
if (site_url.match(/http(s*):\/\/.*\/(upload|offer).*php#seperator#/i)) {
return 0;
}
if (site_url.match(/http(s*):\/\/.*\/details.php.*/i)) {
return 1;
}
if (site_url.match(/http(s*):\/\/totheglory.im\/t\/.*/i)) {
return 1;
}
if (site_url.match(/http(s*):\/\/privatehd.to\/torrent/i)) {
return 1;
}
if (site_url.match(/http(s*):\/\/avistaz.to\/torrent/i)) {
return 1;
}
if (site_url.match(/http(s*):\/\/www.morethan.tv\/torrents.php\?id/i)) {
return 1;
}
}
//判断是否是国内的站点,国内站点架构基本一致且不需要额外获取豆瓣信息
function judge_if_the_site_in_domestic() {
var domain; //域名
var reg; //正则匹配表达式
var key;
for (key in o_site_info){
if (key != 'FRDS' && key != 'BeiTai'){
domain = o_site_info[key].split('//')[1].replace('/', '');
reg = new RegExp(domain, 'i');
if (site_url.match(reg)){
return 0;
}
}
}
return 1;
}
//处理标题业务封装进函数
function deal_with_title(title){
title = title.replace(/\./g, ' ');
if (title.match(/[^\d](2 0|5 1|7 1|1 0)/)) {
title = title.replace(/[^\d](2 0|5 1|7 1|1 0)/, function(data){
return data.slice(0,2)+'.'+ data.slice(3,data.length);
});
}
if (title.match(/H 264/)) {
title = title.replace("H 264", "H.264");
}
if (title.match(/H264/)) {
title = title.replace("H264", "H.264");
}
title = title.replace(/x265[.-]10bit/i, 'x265 10bit');
//处理免费后缀等等写在后边
title = title.replace(/\s+\[2?x?(免费|free)\].*$|\(限时.*\)|\(限時.*\)/ig, '');
title = title.replace(/\[.*\]/i, '');
title = title.replace(/剩余时间.*/i, '');
title = title.replace(/\(|\)/i, '');
title = title.trim();
return title;
}
//处理副标题逻辑业务封装进函数
function deal_with_subtitle(subtitle){
//去除中括号等等
subtitle = subtitle.replace(/(\[|\])/g, "");
subtitle = subtitle.replace(/autoup/i, '');
return subtitle;
}
//字典转成字符串传达到跳转页面
function dictToString(my_dict){
var tmp_string = '';
var link_str = '#linkstr#';
var key;
for (key in my_dict){
tmp_string += key + link_str + my_dict[key] + link_str;
}
return tmp_string.slice(0, tmp_string.length-9);
}
//字符串转换成字典回来填充发布页面
function stringToDict(my_string){
var link_str = '#linkstr#';
var tmp_array = my_string.split(link_str);
var tmp_dict = {};
for (i = 0; i < tmp_array.length; i++) {
if (i % 2 == 0) {
tmp_dict[tmp_array[i]] = tmp_array[i + 1];
}
}
return tmp_dict;
}
//下面两个函数用来为字符串赋予format方法:例如——'thank you {site}'.format({'site':'ttg'}) => 'thank you ttg'
String.prototype.replaceAll = function (exp, newStr) {
return this.replace(new RegExp(exp, "gm"), newStr);
};
String.prototype.format = function(args) {
var result = this;
if (arguments.length < 1) {
return result;
}
var data = arguments; // 如果模板参数是数组
if (arguments.length == 1 && typeof (args) == "object") {
// 如果模板参数是对象
data = args;
}
for ( var key in data) {
var value = data[key];
if (undefined != value) {
result = result.replaceAll("\\{" + key + "\\}", value);
}
}
return result;
};
//下面几个函数为字符串赋予获取各种编码信息的方法——适用于页面基本信息和字符串
String.prototype.medium_sel = function() { //媒介
var result = this;
if (result.match(/(UHD|UltraHD)/i)) {
result = 'UHD';
} else if (result.match(/(Encode|Matroska|MP4)/i)) {
result = 'Encode';
} else if (result.match(/(DVDRip|DVD)/i)) {
result = 'DVD';
} else if (result.match(/(Webdl|Web-dl)/i)) {
result = 'WEB-DL';
} else if (result.match(/(HDTV)/i)) {
result = 'HDTV';
} else if (result.match(/(Remux)/i)) {
result = 'Remux';
} else if (result.match(/(Blu-ray|.MPLS)/i)) {
result = 'Blu-ray';
} else {
result = '';
}
return result;
};
String.prototype.codec_sel = function() { //编码
var result = this;
if (result.match(/(H264|H\.264|AVC)/i)) {
result = 'H264';
} else if (result.match(/(HEVC|H265)/i)) {
result = 'H265';
} else if (result.match(/(X265)/i)) {
result = 'X265';
} else if (result.match(/(X264)/i)) {
result = 'X264';
} else if (result.match(/(VC-1)/i)) {
result = 'VC-1';
} else if (result.match(/(MPEG-2)/i)) {
result = 'MPEG-2';
} else if (result.match(/(MPEG-4)/i)) {
result = 'MPEG-4';
} else if (result.match(/(XVID)/i)) {
result = 'XVID';
} else {
result = '';
}
return result;
};
String.prototype.audiocodec_sel = function() { //音频编码
var result = this;
if (result.match(/(DD|AC3|AC-3|Dolby Digital)/i)) {
result = 'AC3';
} else if (result.match(/(AAC)/i)) {
result = 'AAC';
} else if (result.match(/(DTS-HDMA:X 7\.1)/i)){
result = 'DTS-HDMA:X 7.1';
} else if (result.match(/(DTS-HD.?MA)/i)) {
result = 'DTS-HDMA';
} else if (result.match(/(DTS-HD)/i)) {
result = 'DTS-HD';
} else if (result.match(/(TrueHD Atmos)/i)) {
result = 'TrueHD Atmos';
} else if (result.match(/(Atmos)/i)) {
result = 'Atmos';
} else if (result.match(/(TrueHD)/i)) {
result = 'TrueHD';
} else if (result.match(/(DTS)/i)) {
result = 'DTS';
} else if (result.match(/(LPCM)/i)) {
result = 'LPCM';
} else if (result.match(/(Flac)/i)) {
result = 'Flac';
} else if (result.match(/(APE)/i)) {
result = 'APE';
} else if (result.match(/(MP3)/i)) {
result = 'MP3';
} else if (result.match(/(WAV)/i)) {
result = 'WAV';
} else {
result = '';
}
return result;
};
String.prototype.standard_sel = function() {
var result = this;
if (result.match(/(2160p|4k)/i)){
result = '4K';
} else if (result.match(/(1080p|2K)/i)){
result = '1080p';
} else if (result.match(/(720p)/i)){
result = '720p';
} else if (result.match(/(1080i)/i)){
result = '1080i';
} else if (result.match(/(576p|480p)/i)){
result = 'SD';
} else {
result = '';
}
return result;
};
//获取类型
String.prototype.get_type = function() {
var result = this;
if (result.match(/(Movie|电影|UHD原盘)/i)) {
result = '电影';
} else if (result.match(/(TV.*Series|剧|TV-PACK|TV-Episode)/i)) {
result = '剧集';
} else if (result.match(/(Docu|纪录)/i)) {
result = '纪录';
} else if (result.match(/(Animations|动漫)/i)) {
result = '动漫';
} else if (result.match(/(TV.*Show|综艺)/i)) {
result = '综艺';
} else if (result.match(/(Music|音乐)/i)) {
result = '音乐';
} else if (result.match(/(Sport|体育)/i)) {
result = '体育';
} else if (result.match(/(学习|资料|Study)/i)) {
result = '学习';
} else if (result.match(/(Software|软件)/i)) {
result = '软件';
} else if (result.match(/(Game|游戏)/i)) {
result = '游戏';
} else {
result = '';
}
return result;
};
//获取副标题或是否中字、国语、粤语
String.prototype.get_label = function(){
var my_string = this;
var labels = {'gy': false, 'yy': false, 'zz': false};
//先从副标题开始写
if (my_string.match(/([简繁].{0,12}字幕|[简繁中].{0,3}字|DIY.{1,5}字|内封.{0,3}[繁中字])/i)){
labels.zz = true;
}
if (my_string.match(/(国.{0,3}语|国.{0,3}配|台.{0,3}语|台.{0,3}配)/i)){
labels.gy = true;
}
if (my_string.match(/(粤.{0,3}语|粤.{0,3}配)/i)){
labels.yy = true;
}
if (my_string.match(/DIY/i)){
labels.diy = true;
}
return labels;
};
function set_selected_option_by_value(my_id, value){
var box = document.getElementById(my_id);
for (i=0; i < box.options.length; i++){
if ( box.options[i].value == value){
box.options[i].selected = true;
}
}
}
//从简介和名称获取副标题
function get_small_descr_from_descr(descr, name){
var small_descr = '';
var vidoename = ''; //译名
var sub_str = ''; //剧集季集信息
var type_str = ''; //类别信息
if (descr.match(/译.{0,5}名[^\r\n]+/)) {
vidoename = descr.match(/译.*?名([^\r\n]+)/)[1];
videoname = vidoename.trim(); //去除首尾空格
if (name.match(/S\d{2}E\d{2}/ig)) { //电视剧单集
sub_str = name.match(/(S\d{2}E\d{2})/ig)[0];
sub_str = sub_str.replace(/S/i, '*第');
sub_str = sub_str.replace(/E/i, '季 第') + '集*';
}
small_descr = vidoename + sub_str;
}
if (descr.match(/类.{0,5}}别[^\r\n]+/)) {
type_str = descr.match(/类.*别([^\r\n]+)/)[1];
type_str = type_str.trim(); //去除首尾空格
type_str = type_str.replace(/\//g, ''); //去除/
small_descr = small_descr + type_str;
}
return small_descr.trim();
}
//根据简介获取来源,也就是地区国家产地之类的——尤其分类是日韩或者港台的,有的站点需要明确一下
function get_source_sel_from_descr(descr){
var region = '';
var reg_region = descr.match(/(地.{0,5}?区|国.{0,5}?家|产.{0,5}?地)([^\r\n]+)/);
if (reg_region) {
region = reg_region[2];
region = region.trim(); //去除首尾空格
reg_region = RegExp(us_ue, 'i');
if (region.match(reg_region)){
region = '欧美';
} else if (region.match(/香港/)){
region = '香港';
} else if (region.match(/台湾/)){
region = '台湾';
} else if (region.match(/日本/)){
region = '日本';
} else if (region.match(/韩国/)){
region = '韩国';
} else if (region.match(/印度/)){
region = '印度';
} else if (region.match(/中国|大陆/)){
region = '大陆';
}
}
return region;
}
//为获取豆瓣信息提供链接简化 promise-
function create_site_url_for_douban_info(raw_info, is_douban_search_needed){
var p = new Promise(function(resolve, reject){
if (is_douban_search_needed){
season = raw_info.name.match(/S(\d{2})/ig)[0];
season = season.slice(1,season.length);
season = parseInt(season);
var season_chinese = "第" + numToChinese(season) + "季";
var search_name = raw_info.name.split(raw_info.name.match(/S\d{2}/ig)[0])[0];
search_name = search_name.replace(/\d{4}/ig, '').trim(); //去除首尾空格和年份
api_key = '&apikey=0dad551ec0f84ed02907ff5c42e8ec70';
GM_xmlhttpRequest({
method: 'GET',
url: "http://api.douban.com/v2/movie/search?q=" + search_name + api_key,
onload: function(res) {
var response = JSON.parse(res.responseText);
for (var i = 0; i < response.subjects.length; i++) {
if (response.subjects[i].title.match(season_chinese)) {
raw_info.dburl = response.subjects[i].alt;
break;
}
}
resolve(raw_info);
}
});
} else {
resolve(raw_info);
}
});
return p;
}
/*
---------------------------------------part 3 页面逻辑处理(源网页)------------------------------------------
*/
if (judge_if_the_site_as_source() == 1) {
//需要从源网页获取的信息,有些可能没有
var raw_info = {
//填充类信息
'name': '', //主标题
'small_descr': '', //副标题
'url': '', //imdb链接
'dburl': '', //豆瓣链接
'descr': '',
//选择类信息
'type': '', //type:可取值——电影/纪录/体育/剧集/动画/综艺……
'source_sel': '', //来源(地区):可取值——欧美/大陆/港台/日本/韩国/印度……
'standard_sel': '', //分辨率:可取值——4K/1080p/1080i/720p/SD
'audiocodec_sel': '', //音频:可取值——AAC/AC3/DTS…………
'codec_sel': '', //编码:可取值——H264/H265……
'medium_sel': '', //媒介:可取值——web-dl/remux/encode……
//其他
'origin_site': '', //记录源站点用于跳转后识别
'mediainfo_cmct': '',
'img_info_cmct': ''
};
//用来识别是哪个站点
var origin_site = find_origin_site(site_url);
raw_info.origin_site = origin_site;
var title; //主标题对应的标签
var small_descr; //副标题对应的标签
var descr; //简介对应的标签
var tbody; //tbody对应的标签
var frds_nfo; //朋友的nfo对应的标签
var cmct_mode = 1; //cmct页面——1原始页面;2新页面
var torrent_id = "";//mtv种子id
var thanks_str = "[quote]转自{site},感谢原制作者发布。[/quote]\n\n{descr}";
var douban_button_needed = false;
var is_inserted = false;
//----------------------------------标题简介获取——国内站点-------------------------------------------
if (judge_if_the_site_in_domestic(site_url)) {
if (origin_site == 'TTG' || origin_site == 'PuTao' || origin_site == 'HDArea') {
title = document.getElementsByTagName("h1")[0];
}else{
title = document.getElementById("top");
}
for (i = 0; i < title.childNodes.length; i++) {
raw_info.name = raw_info.name + title.childNodes[i].textContent;
}
if (origin_site == 'TTG') {
descr = document.getElementById("kt_d");
}
else {
descr = document.getElementById("kdescr"); //kdescr
if (!descr && origin_site == 'CMCT') {
descr = document.getElementById("kposter");
cmct_mode = 2;
}
if (origin_site == 'FRDS') {
frds_nfo = document.getElementById("knfo"); //kdescr
}
}
//获取最外层table
tbody = descr.parentNode.parentNode.parentNode;
descr = descr.cloneNode(true);
try{
var codemain = descr.getElementsByClassName('codemain');
var codetop = descr.getElementsByClassName('codetop');
if (codetop.length>0) {
descr.removeChild(codetop[0]);
}
if (codemain.length>0) {
codemain[0].innerHTML = '[quote]{mediainfo}[/quote]'.format({ 'mediainfo': codemain[0].innerHTML });
}
//pter官种去除table
if (origin_site == 'PTer' && descr.getElementsByTagName('table')[0]){
var descr_table = descr.getElementsByTagName('table')[0];
if (descr_table.textContent.match(/general/i)){
descr.removeChild(descr_table);
}
}
}catch(err){
console.log(err);
}
//遍历简介标签获取简介字符串
raw_info.descr = walkDOM(descr);
if (origin_site == 'FRDS') {
if (frds_nfo != null) {
raw_info.descr = raw_info.descr + "[quote]" + frds_nfo.textContent + "[/quote]";
}
}
//ourbits没有简介的话补充简介
if (origin_site == 'OurBits') {
try{
var imdbnew2 = document.getElementsByClassName("imdbnew2")[0];
var reg_imdb = imdbnew2.innerHTML.match(/http(s*):\/\/www.imdb.com\/title\/tt\d+/i);
if (reg_imdb){
raw_info.url = reg_imdb[0] + '/';
}
} catch(err){
console.log(err);
}
if (raw_info.descr.search(/主.*演/i) < 0 && raw_info.descr.search(/类.*别/i) < 0) {
try{
var doubanimg = document.getElementsByClassName("doubannew")[0];
doubanimg = doubanimg.getElementsByTagName("img")[0].src;
var douban = document.getElementsByClassName("doubaninfo")[0];
var douban_new = douban.cloneNode(true);
douban = domToString(douban_new);
douban = douban.replace(/<br>/g, '\n');
douban = douban.replace('<div class="doubaninfo">', '');
douban = douban.replace('</div>', '');
raw_info.descr = '[img]' + doubanimg + '[/img]\n' + douban + '\n\n' + raw_info.descr;
} catch(err){
if (raw_info.url) {
douban_button_needed = true;
}
}
}
}
if (origin_site == 'HDChina'){
if (raw_info.descr.search(/主.*演/i) < 0 && raw_info.descr.search(/类.*别/i) < 0){
var douban_content = document.getElementsByClassName('douban_content');
if (douban_content[0]){
if (douban_content[0].textContent.match(/http(s*):\/\/.*?douban.com\/subject\/(\d+)/i)){
raw_info.dburl = douban_content[0].textContent.match(/http(s*):\/\/.*?douban.com\/subject\/(\d+)/i)[0]+ '/';
douban_button_needed = true;
}
}
}
}
}
//--------------------------------------国外站点table获取(简介后续单独处理)-------------------------------------------
if (origin_site == 'hdt') {
tbody = document.getElementById("Torrent'sdetailsHideShowTR");
tbody = tbody.getElementsByTagName('tbody')[0];
}
if (origin_site == 'PHD' || origin_site == 'avz') {
tbody = document.getElementsByTagName("tbody")[0];
}
if (origin_site == 'MTV') {
if (site_url.match(/torrentid=(\d+)/)) {
torrent_id = site_url.match(/torrentid=(\d+)/)[1];
}
var imdb_box = document.getElementsByClassName('box torrent_description')[0];
if (imdb_box.innerHTML.match(/http(s*):\/\/www.imdb.com\/title\/tt(\d+)/i)){
raw_info.url = imdb_box.innerHTML.match(/http(s*):\/\/www.imdb.com\/title\/tt(\d+)/i)[0];
}
tbody = document.getElementById('torrent_details');
}
//-------------------------------------根据table获取其他信息——包含插入节点(混合)-------------------------------------------
var tds = tbody.getElementsByTagName("td");
var table;
var insert_row;
var douban_box;
//循环处理所有信息
for (i = 0; i < tds.length; i++) {
if (origin_site == 'PHD' || origin_site == 'avz') {
if (i == 1 && tds[i].innerHTML.match(/Movie$/i)) {
raw_info.type = '电影';
}
if (i == 1 && tds[i].innerHTML.match(/TV-Show$/i)) {
raw_info.type = '剧集';
}
if (i == 3) {
raw_info.name = tds[i].innerHTML;
}
if (tds[i].textContent == 'Video Quality') {
raw_info.standard_sel = tds[i + 1].innerHTML.trim();
}
if (tds[i].textContent == 'Description') {
raw_info.descr += walkDOM(tds[i + 1]);
}
if (tds[i].textContent == 'Rip Type') {
var tmp_type = tds[i + 1].innerHTML.trim();
if (tmp_type.match(/BluRay Raw/i)){
raw_info.medium_sel = 'Blu-ray';
} else if (tmp_type.match(/BluRay/i)){
raw_info.medium_sel = 'Encode';
}
}
if (tds[i].textContent == 'Filename') {
table = tds[i].parentNode.parentNode;
insert_row = table.insertRow(i / 2 + 1); //insert_row用来加转发图标
douban_box = table.insertRow(i / 2 + 1); //再加一行来获取豆瓣
}
}
if (origin_site == 'hdt') {
if (tds[i].textContent.match(/Category:/i) && i>1) {
if(tds[i+1].textContent.match(/Movie/i)){
raw_info.type = '电影';
} else if (tds[i+1].textContent.match(/TV Show/i)) {
raw_info.type = '剧集';
}
if (tds[i+1].textContent.medium_sel()) {
raw_info.medium_sel = tds[i+1].textContent.medium_sel();
}
}
if (i < 5 && tds[i].textContent.match(/Torrent/)) {
raw_info.name = tds[i+1].textContent;
}
if (i < 8 && tds[i].innerHTML.match(/http(s*):\/\/www.imdb.com\/title\/tt(\d+)/i)) {
raw_info.url = tds[i].innerHTML.match(/http(s*):\/\/www.imdb.com\/title\/tt(\d+)/i)[0] + '/';
}
}
if (origin_site == 'MTV') {
raw_info.type = '剧集';
if (tds[i].innerHTML.match('torrent_' + torrent_id)) {
table = tds[i].parentNode.parentNode;
var child_nodes = table.childNodes;
var rowcount = 0;
for (k = 0; k < child_nodes.length; k++) {
if (child_nodes[k].nodeName == 'TR') {
rowcount = rowcount + 1;
if (child_nodes[k].id.match('torrent_' + torrent_id)) {
break;
}
}
}
insert_row = table.insertRow(rowcount - 1);
}
}
//瓷器好像有时候也没有豆瓣简介,可能有必要获取一下豆瓣?
if (origin_site == 'HDChina') {
if (tds[i].innerHTML == '字幕') {
table = tds[i].parentNode.parentNode;
insert_row = table.insertRow(i / 2 + 1);
if (douban_button_needed){
douban_box = table.insertRow(i / 2 + 1);
}
}
}
else {
if (['行为', '小货车', '行為'].indexOf(tds[i].innerHTML) >-1 || tds[i].textContent.match(/Tools/i)) {
if (!is_inserted){
if (origin_site != 'MTV') {
table = tds[i].parentNode.parentNode;
if (origin_site == 'TTG'){
insert_row = table.insertRow(i / 2 - 1);
} else {
insert_row = table.insertRow(i / 2 + 1);
}
}