-
Notifications
You must be signed in to change notification settings - Fork 5
/
urls.lua
1908 lines (1792 loc) · 59.3 KB
/
urls.lua
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
local urlparse = require("socket.url")
local http = require("socket.http")
local idn2 = require("idn2")
local html_entities = require("htmlEntities")
JSON = (loadfile "JSON.lua")()
local item_dir = os.getenv("item_dir")
local item_name = os.getenv("item_name")
local custom_items = os.getenv("custom_items")
local warc_file_base = os.getenv("warc_file_base")
local extract_outlinks_domains_data = os.getenv("extract_outlinks_domains")
local SPECIAL_INTEREST_FROM_MAIN = "special-interest-from-main"
local url_count = 0
local downloaded = {}
local abortgrab = false
local killgrab = false
local exit_url = false
local min_dedup_mb = 5
local timestamp = nil
local current_file = nil
local current_file_html = nil
local current_file_url = nil
if urlparse == nil or http == nil or html_entities == nil then
io.stdout:write("Dependencies not corrently installed.\n")
io.stdout:flush()
abortgrab = true
end
normalize_url = function(url)
local candidate_current = url
while true do
local temp = string.lower(urlparse.unescape(candidate_current))
if temp == candidate_current then
break
end
candidate_current = temp
end
return candidate_current
end
local urls = {}
for url in string.gmatch(item_name, "([^\n]+)") do
urls[normalize_url(url)] = true
end
local urls_settings = JSON:decode(custom_items)
for k, v in pairs(urls_settings) do
k = normalize_url(k)
urls_settings[k] = v
urls[k] = true
end
local extract_outlinks_domains = {}
for _, domain in pairs(JSON:decode(extract_outlinks_domains_data)) do
extract_outlinks_domains[string.gsub(domain, "([^%w])", "%%%1")] = true
end
local status_code = nil
local redirect_urls = {}
local visited_urls = {}
local ids_to_ignore = {}
for _, lengths in pairs({{8, 4, 4, 4, 12}, {8, 4, 4, 12}}) do
local uuid = ""
for _, i in pairs(lengths) do
for j=1,i do
uuid = uuid .. "[0-9a-fA-F]"
end
if i ~= 12 then
uuid = uuid .. "%-"
end
end
ids_to_ignore[uuid] = true
end
local to_ignore = ""
for i=1,9 do
to_ignore = to_ignore .. "[0-9]"
end
ids_to_ignore["%?" .. to_ignore .. "$"] = true
ids_to_ignore["%?" .. to_ignore .. "[0-9]$"] = true
ids_to_ignore[to_ignore .. "[0-9]%.[0-9][0-9][0-9][0-9]$"] = true
to_ignore = ""
for i=1,50 do
to_ignore = to_ignore .. "[0-9a-zA-Z]"
end
ids_to_ignore[to_ignore .. "%-[0-9][0-9][0-9][0-9][0-9]"] = true
ids_to_ignore["[0-9a-zA-Z%-_]!%-?[0-9]"] = true
to_ignore = ""
for i=1,32 do
to_ignore = to_ignore .. "[0-9a-fA-F]"
end
ids_to_ignore["[^0-9a-fA-F]" .. to_ignore .. "[^0-9a-fA-F]"] = true
ids_to_ignore["[^0-9a-fA-F]" .. to_ignore .. "$"] = true
local current_url = nil
local current_settings = nil
local bad_urls = {}
local queued_urls = {}
local skip_parent_urls_check = {}
local skip_parent_urls = {}
local remove_params = {}
local filter_discovered = {}
local exit_url_patterns = {}
local page_requisite_patterns = {}
local duplicate_urls = {}
local one_time_patterns = {}
local skip_double_patterns = {}
local paths = {}
local extract_from_domain = {}
local nothing_on_3xx = {}
local item_first_url = nil
local redirect_domains = {}
local checked_domains = {}
local tlds = {}
local year_month = os.date("%Y", timestamp) .. tostring(math.floor(os.date("*t").yday))
local periodic_shard = "periodic" .. year_month
local filter_pattern_sets = {
["^https?://[^%./]+%.[^%./]+%.[a-z]+/"]={
["pics"]="^https?://[^%./]+%.[^%./]+%.[a-z]+/pics/[a-zA-Z0-9%-_]+%.[a-z]+$",
--["vicom"]="/[vV][iI]com[0-9]+/",
["k8"]={
"^https?://[kK]8",
"^https?://[^/]+/pics/[kK]888"
}
},
["^https?://[a-z0-9]+%.[^%./]+%.de/pages/"]={
["pages"]="^https?://[a-z0-9]+%.[^%./]+%.de/pages/.+%.html",
--["css"]="%s.*%.css$"
},
["^https?://[a-z0-9]+%.[^%./]+%.de/news/"]={
["news"]="^https?://[a-z0-9]+%.[^%./]+%.de/news/[^&%?/]+$",
--["css"]="%.css"
},
--[[["^https?://[a-z0-9]+%.[^%./]+%.[a-z]+/.*%%20"]={
["space"]={
"^https?://[a-z0-9]+%.[^%./]+%.[a-z]+/.*%s",
"^https?://[a-z0-9]+%.[^%./]+%.[a-z]+/.*%%20"
}
},]]
["^https?://[^/]+.*/X[a-z0-9]+"]={
["x"]="^https?://[^/]+.*/X[a-z0-9]+.*/X[a-z0-9]",
["tk88"]="[tT][kK]88"
},
["^http://"]={
["index-robots"]={
"^https?://[^/]+//index%.php%?robots%.txt$",
"^https?://[^/]+/robots%.txt$"
},
["index-sitemap"]={
"^https?://[^/]+//index%.php%?sitemap%.xml$",
"^https?://[^/]+/sitemap%.xml$"
},
["index-html"]={
"^https?://[^/]+//index%.php%?[a-z]+/[0-9]+%.html$",
"^https?://[^/]+/[0-9]+%.html$"
},
["images"]="^https?://[^/]+/uploads/images/[0-9]+%.jpg$",
["html"]="^https?://[^/]+/[a-z]+/[0-9]+%.html$",
["page"]="^https?://[^/]+/[a-z]+/[0-9]+/$"
},
["^http://[a-z0-9]+%.[^%./]+%.[a-z]+/$"]={
["sinaimgcn"]="^http://n%.sinaimg%.cn/.+%.jpg$",
["sitemap"]="^http://[a-z0-9]+%.[^%./]+%.[a-z]+/sitemap%.xml",
["template"]="/template/default/04190%-44/",
["domain"]="^http://[a-z0-9]+%.[^%./]+%.[a-z]+/$"
},
-- fx- spam
["^https?://[a-z0-9]+%.[^/]+%.[a-z]+/.?"]={
["url"]={
"^https?://[a-z0-9]+%.[^/]+%.[a-z]+/_static_index/",
"^https?://[a-z0-9]+%.[^/]+%.[a-z]+/.+/static/",
"^https?://[a-z0-9]+%.[^/]+%.[a-z]+.*/spring_php/",
"^https?://[a-z0-9]+%.[^/]+%.[a-z]+.*/count_php/",
"^https?://[a-z0-9]+%.[^/]+%.[a-z]+.*/plus/.*[_%.]php",
"^https?://[a-z0-9]+%./"
},
["base"]="^https?://[a-z0-9]+%.[^/]+%.[a-z]+/$",
["image"]="^https?://[a-z0-9]+%.[^/]+%.[a-z]+/fx%-[a-zA-Z0-9=]+/uploads/[0-9]+/[0-9]+/[0-9]+/[0-9]+%.jpg$",
--["html"]="^https?://[a-z0-9]+%.[^%./]+%.[a-z]+/[a-z0-9]+%.html$",
--["abouthtml"]="^https?://[a-z0-9]+%.[^%./]+%.[a-z]+/about%.html$",
--["sitemaphtml"]="^https?://[a-z0-9]+%.[^%./]+%.[a-z]+/sitemap%.html$",
--["announcehtml"]="^https?://[a-z0-9]+%.[^%./]+%.[a-z]+/announce%.html$",
--["number"]="^https?://[a-z0-9]+%./"
},
-- news/show spam
["^https?://[^/]+%.[^%./]+%.[a-z]+/"]={
--[[["newslist"]={
"^https?://[^/]+%.[^%./]+%.[a-z]+/newslist/[0-9]+/$",
"^https?://[^/]+%.[^%./]+%.[a-z]+/list/[0-9]+/$",
"^https?://[^/]+%.[^%./]+%.[a-z]+/product/[a-z]+_?[0-9]+/$"
},]]
["images"]={
"^https?://[^/]+%.[^%./]+%.[a-z]+/uploads/images/",
"^https?://[^/]+%.[^%./]+%.[a-z]+/{{pasePath}}images/",
"^https?://[^/]+%.[^%./]+%.[a-z]+/redian/",
"^https?://[^/]+%.[^%./]+%.[a-z]+/template/news/.*images/",
"^https?://[^/]+%.[^%./]+%.[a-z]+/template/news/baike",
"^https?://[^/]+%.[^%./]+%.[a-z]+/template/news/xzx",
"^https?://[^/]+%.[^%./]+%.[a-z]+/template/news/b1/",
"^https?://[^/]+%.[^%./]+%.[a-z]+/template/news/3dm/",
"^https?://[^/]+%.[^%./]+%.[a-z]+/template/news/m[0-9]/static/",
"^https?://[^/]+%.[^%./]+%.[a-z]+/template/news/boke[0-9]+/",
"^https?://[^/]+%.[^%./]+%.[a-z]+/template/company/hbshgzx/",
},
--["main"]="^https?://[^/]+%.[^%./]+%.[a-z]+/",
["news"]={
"^https?://[^/]+%.[^%./]+%.[a-z]+/news/[0-9a-zA-Z/]+%.html$",
"^https?://[^/]+%.[^%./]+%.[a-z]+/newshtml/[0-9a-zA-Z/]+%.html$",
"^https?://[^/]+%.[^%./]+%.[a-z]+/show/[0-9a-zA-Z/]+%.html$",
"^https?://[^/]+%.[^%./]+%.[a-z]+/html/[0-9a-zA-Z/]+%.html$",
"^https?://[^/]+%.[^%./]+%.[a-z]+/txt/[0-9a-zA-Z/]+%.html$",
"^https?://[^/]+%.[^%./]+%.[a-z]+/xml/[0-9a-zA-Z/]+%.html$",
"^https?://[^/]+%.[^%./]+%.[a-z]+/product/[a-z]+_[0-9/]+%.html$",
"^https?://[^/]+%.[^%./]+%.[a-z]+/[a-zA-Z0-9]+%.html$",
"^https?://[^/]+%.[^%./]+%.[a-z]+/[0-9a-f]+/[0-9]+%.html$",
"^https?://[^/]+%.[^%./]+%.[a-z]+/[0-9]+/[0-9a-f]+%.html$"
},
["template"]="^https?://[^/]+%.[^%./]+%.[a-z]+/template/"
},
-- xml spam
["^https?://[^/]+%.[^%./]+%.[a-z]+/.?"]={
["num"]="^https?://[^/]+%.[^%./]+%.[a-z]+/[0-9]+/[a-z0-9_]+%.xml$",
["num2"]="^https?://[^/]+%.[^%./]+%.[a-z]+/[a-z]+/[a-z0-9_]+%.xml$",
--["vip"]="/[vV][iI][pP]%-[0-9]+%.",
["styles"]="^https?://[^/]+%.[^%./]+%.[a-z]+/styles/",
--["itc"]="^https?://[^/]*itc%.cn/"
},
["^https?://[^/]+%.[^%./]+%.[a-z]+/.?.?"]={
["htmlnews"]={
"^https?://[^/]+%.[^%./]+%.[a-z]+/html/[a-z0-9]+%.html$",
"^https?://[^/]+%.[^%./]+%.[a-z]+/newshtml/[a-z0-9]+%.html$",
"^https?://[^/]+%.[^%./]+%.[a-z]+/news/[a-z0-9]+%.html$"
},
["baidu"]="^https?://[^/]*baidu%.com/",
["a"]="^https?://[^/]+%.[^%./]+%.[a-z]+/[a-z]+/$",
["sitemap"]="sitemap%.xml$"
},
["^https?://[^/]*%.de/[^/]+_fonts/.*woff"]={
["fonts"]="^https?://[^/]*%.de/[^/]+_fonts/.*woff"
},
["^https?://[^/]+%.[^%./]+%.[a-z]+/.?.?.?"]={
--["swf"]="%.swf$",
--["flashplayer"]="^https?://www%.macromedia%.com/go/getflashplayer$",
["tupian"]={
"^https?://[^/]+%.[^%./]+%.[a-z]+/tupian_1/[^%./]+%.jpg$",
"^https?://[^/]+%.[^%./]+%.[a-z]+/templates?/moban[0-9]*/",
"^https?://[^/]+%.[^%./]+%.[a-z]+/templates?/[^/]+/moban[0-9]*/",
"^https?://[^/]+%.[^%./]+%.[a-z]+/templates?/[^/]+/chahua[0-9]*/"
},
["slash"]={
"^https?://[^/]+%.[^%./]+%.[a-z]+/[^/]+/$",
"^https?://[^/]+%.[^%./]+%.[a-z]+/$"
},
["other1"]={
"tk88",
"^https?://[^/]+%.[^%./]+%.[a-z]+/list_[a-z]+/$",
"^https?://[^/]+%.[^%./]+%.[a-z]+/booklist%-[0-9]+%.html$",
"^https?://[^/]+%.[^%./]+%.[a-z]+/news/[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9]",
"^https?://[^/]+%.[^%./]+%.[a-z]+/static/logo%.jpg"
},
["other"]={
"%.xlsx?$",
"%.pptx?$",
"%.docx?$",
"^https?://[^/]+%.[^%./]+%.[a-z]+/[^/]+/[0-9]+/$",
"^https?://[^/]+%.[^%./]+%.[a-z]+/cnki/images/",
"^https?://[^/]+%.[^%./]+%.[a-z]+/uploads/allimg/",
"^https?://[^/]+%.[^%./]+%.[a-z]+/[a-z]%-[a-z0-9%-]+%.html$",
"^https?://[^/]+%.[^%./]+%.[a-z]+/books/[^/]+/[0-9]+%.html$"
}
},
["^https?://[^/]+%.[^%./]+%.[a-z]+/.?.?.?.?"]={
["search"]="^https?://[^/]+/.*/?search/",
["catalogsearch"]="^https?://[^/]+/.*/?catalogsearch/",
["s"]="^https?://[^/]+/%?s=",
["brackets"]="【[^%.】]+%.[a-zA-Z0-9]+】"
},
["^https?://[^/]+%.[^%./]+%.[a-z]+/.?.?.?.?.?"]={
["article"]="^https?://[^/]+/article/2023[01][1-9][0-9A-Za-z]+%.html$",
["article2"]="^https?://[^/]+/2023[01][1-9][0-9A-Za-z]+%.html$"
},
["^https?://[^/]+%.[^%./]+%.[a-z]+/.?.?.?.?.?.?"]={
["appsstore.cdf"]="^https?://download%.appsstore%.cfd/"
},
["^https?://[^/]+%.[^%./]+%.[a-z]+/.?.?.?.?.?.?.?"]={
["yamaxun"]="^https?://[^/]+%.[^%./]+%.[a-z]+/template/yamaxun/",
["upluds"]="^https?://[^/]+%.[^%./]+%.[a-z]+/upluds/"
},
["^https?://[^/]+%.[^%./]+%.[a-z]+/.?.?.?.?.?.?.?.?"]={
["company-en"]="^https?://[^/]+%.[^%./]+%.[a-z]+/template/company/en[0-9]+/static/",
["uploads"]="^https?://[^/]+%.[^%./]+%.[a-z]+/uploads/images/[0-9]+%.jpg$"
},
["^https?://[^/]+%.[a-z]+/.?.?.?.?.?.?.?.?.?"]={
["search"]="^https?://[^/]+/.*search/",
["catalogsearch"]="^https?://[^/]+/.*catalogsearch/",
["brackets"]="【[^】]+】",
["zonghe"]="^https?://[^/]+/styles/zonghe/",
["html"]="^https?://[^/]+/[a-z0-9]+/[0-9]+%.html$",
["sitemap"]="^https?://[^/]+/[a-z0-9]+/sitemap%.xml$"
},
["^https?://[^/]+/[a-z]+/[a-z0-9%.]+$"]={
["games"]="^https?://[^/]+/games/[a-z0-9%.]+$",
["show"]="^https?://[^/]+/show/[a-z0-9%.]+$",
["slots"]="^https?://[^/]+/slots/[a-z0-9%.]+$",
["news"]="^https?://[^/]+/news/[a-z0-9%.]+$",
["html"]="^https?://[^/]+/html/[a-z0-9%.]+$",
["uploads"]="^https?://[^/]+/uploads/image/",
["casinoguru"]="^https?://static%.casino%.guru/",
}
}
local imgur_items = {
[""] = {}
}
local pastebin_items = {
[""]={}
}
local mediafire_items = {
[""]={}
}
local telegram_posts = {
[""]={},
[periodic_shard]={}
}
local telegram_channels = {
[""]={},
[periodic_shard]={}
}
local urls_sitemap_news = {[""]={}}
local ftp_urls = {[""]={}}
local onion_urls = {[""]={}}
local urls_news = {[""]={}}
local urls_all = {}
local month_timestamp = os.date("%Y%m", timestamp)
local parenturl_uuid = nil
local parenturl_requisite = nil
local dupes_file = io.open("duplicate-urls.txt", "r")
for url in dupes_file:lines() do
duplicate_urls[url] = true
end
dupes_file:close()
local tlds_file = io.open("static-tlds.txt", "r")
for tld in tlds_file:lines() do
tlds[tld] = true
end
tlds_file:close()
local remove_params_file = io.open("static-remove-params.txt", "r")
for param in remove_params_file:lines() do
local param = string.gsub(
param, "([a-zA-Z])",
function(c)
return "[" .. string.lower(c) .. string.upper(c) .. "]"
end
)
table.insert(remove_params, param)
end
remove_params_file:close()
local filter_discovered_file = io.open("static-filter-discovered.txt", "r")
for pattern in filter_discovered_file:lines() do
table.insert(filter_discovered, pattern)
end
filter_discovered_file:close()
local nothing_on_3xx_file = io.open("static-nothing-on-3xx.txt", "r")
for pattern in nothing_on_3xx_file:lines() do
table.insert(nothing_on_3xx, pattern)
end
nothing_on_3xx_file:close()
local exit_url_patterns_file = io.open("static-exit-url-patterns.txt", "r")
for pattern in exit_url_patterns_file:lines() do
table.insert(exit_url_patterns, pattern)
end
exit_url_patterns_file:close()
local skip_double_patterns_file = io.open("static-skip-double-patterns.txt", "r")
for pattern in skip_double_patterns_file:lines() do
table.insert(skip_double_patterns, pattern)
end
skip_double_patterns_file:close()
local page_requisite_patterns_file = io.open("static-page-requisite-patterns.txt", "r")
for pattern in page_requisite_patterns_file:lines() do
table.insert(page_requisite_patterns, pattern)
end
page_requisite_patterns_file:close()
local one_time_patterns_file = io.open("static-one-time-patterns.txt", "r")
for pattern in one_time_patterns_file:lines() do
table.insert(one_time_patterns, pattern)
end
one_time_patterns_file:close()
local paths_file = io.open("static-paths.txt", "r")
for line in paths_file:lines() do
paths[line] = true
end
paths_file:close()
local extract_from_domain_file = io.open("static-extract-from-domain.txt", "r")
for pattern in extract_from_domain_file:lines() do
if not string.match(pattern, "^#") then
extract_from_domain[pattern] = true
end
end
extract_from_domain_file:close()
kill_grab = function(item)
io.stdout:write("Aborting crawling.\n")
killgrab = true
end
read_file = function(file, bytes)
if not bytes then
bytes = "*all"
end
if file then
local f = assert(io.open(file))
local data = f:read(bytes)
f:close()
if not data then
data = ""
end
return data
else
return ""
end
end
table_length = function(t)
local count = 0
if not t then
return count
end
for _ in pairs(t) do
count = count + 1
end
return count
end
bad_code = function(status_code)
return status_code ~= 200
and status_code ~= 301
and status_code ~= 302
and status_code ~= 303
and status_code ~= 307
and status_code ~= 308
and status_code ~= 404
and status_code ~= 410
end
find_path_loop = function(url, max_repetitions)
local tested = {}
local tempurl = urlparse.unescape(url)
tempurl = string.match(tempurl, "^https?://[^/]+(.*)$")
if not tempurl then
return false
end
for s in string.gmatch(tempurl, "([^/%?&]+)") do
s = string.lower(s)
if not tested[s] then
if s == "" then
tested[s] = -2
else
tested[s] = 0
end
end
tested[s] = tested[s] + 1
if tested[s] == max_repetitions then
return true
end
end
return false
end
percent_encode_url = function(url)
temp = ""
for c in string.gmatch(url, "(.)") do
local b = string.byte(c)
if b < 32 or b > 126 then
c = string.format("%%%02X", b)
end
temp = temp .. c
end
return temp
end
queue_url = function(url, withcustom)
if not url then
return nil
end
local origurl = url
--[[if string.match(url, "^http://")
and string.match(current_url, "^http://")
and string.match(url, "^http://([^/]+)") ~= string.match(current_url, "^http://([^/]+)") then
return nil
end]]
queue_new_urls(url)
if not string.match(url, "^https?://[^/]+%.") then
return nil
end
--local original = url
load_setting_depth = function(s)
n = tonumber(current_settings[s])
if n == nil then
n = 0
end
return n - 1
end
url = string.gsub(url, "'%s*%+%s*'", "")
url = percent_encode_url(url)
url = string.match(url, "^([^#{<\\]+)")
if current_settings and current_settings["all"] and withcustom then
local depth = load_setting_depth("depth")
local keep_random = load_setting_depth("keep_random")
local keep_all = load_setting_depth("keep_all")
local any_domain = load_setting_depth("any_domain")
if depth >= 0 then
local random = current_settings["random"]
local comment = current_settings["comment"]
if comment then
comment = "-" .. comment
end
local all = current_settings["all"]
if keep_random < 0 or random == "" then
random = nil
keep_random = nil
end
if keep_all < 0 or all == 0 then
all = nil
keep_all = nil
end
if any_domain <= 0 then
any_domain = nil
end
local settings = {
depth=depth,
all=all,
keep_all=keep_all,
random=random,
keep_random=keep_random,
url=url,
any_domain=any_domain,
comment=comment
}
url = "custom:"
for _, k in pairs(
{"all", "any_domain", "comment", "depth", "keep_all", "keep_random", "random", "url"}
) do
local v = settings[k]
if v ~= nil then
url = url .. k .. "=" .. urlparse.escape(tostring(v)) .. "&"
end
end
url = string.sub(url, 1, -2)
end
end
local shard = ""
if string.match(url, "&random=") then
shard = "periodic"
end
if shard == "" then
for _, pattern in pairs(one_time_patterns) do
if string.match(url, pattern) then
shard = "onetime"
break
end
end
end
local target_project = queued_urls
if string.match(origurl, "^https?://[^/]+%.([a-z]+)") == "onion" then
target_project = onion_urls
local newurl = string.match(origurl, "^(https?://[^/]+)")
queue_monthly_url(newurl)
end
if not target_project[shard] then
target_project[shard] = {}
end
if not duplicate_urls[url] and not target_project[shard][url] then
if find_path_loop(url, 2) then
return false
end
--print("queuing",original, url)
target_project[shard][url] = current_url
end
end
queue_monthly_url = function(url, comment)
if find_path_loop(url, 3) then
return nil
end
local origurl = url
url = percent_encode_url(url)
url = string.match(url, "^([^#]+)")
local extra_params = ""
local comment_string = ""
if comment then
comment_string = "comment=" .. urlparse.escape(tostring(comment)) .. "&"
end
local target_project = queued_urls
if string.match(origurl, "^https?://[^/]+%.([a-z]+)") == "onion" then
target_project = onion_urls
extra_params = "&depth=1&all=1&keep_all=1&any_domain=1"
end
queue_monthly_item("custom:" .. comment_string .. "random=" .. month_timestamp .. extra_params .. "&url=" .. urlparse.escape(tostring(url)), target_project)
end
queue_monthly_item = function(item, t)
if not t[month_timestamp] then
t[month_timestamp] = {}
end
--print("monthly", item)
t[month_timestamp][item] = current_url
end
remove_param = function(url, param_pattern)
local newurl = url
repeat
url = newurl
newurl = string.gsub(url, "([%?&;])" .. param_pattern .. "=[^%?&;]*[%?&;]?", "%1")
until newurl == url
return string.match(newurl, "^(.-)[%?&;]?$")
end
queue_new_urls = function(url)
if not url then
return nil
end
local newurl = string.gsub(url, "([%?&;])[aA][mM][pP];", "%1")
if url == current_url then
if newurl ~= url then
queue_url(newurl)
end
end
for _, param_pattern in pairs(remove_params) do
newurl = remove_param(newurl, param_pattern)
end
if newurl ~= url then
queue_url(newurl)
end
newurl = string.match(newurl, "^([^%?&]+)")
if newurl ~= url then
queue_url(newurl)
end
url = string.gsub(url, """, '"')
url = string.gsub(url, "&", "&")
for newurl in string.gmatch(url, '([^"\\]+)') do
if newurl ~= url then
queue_url(newurl)
end
end
--[[for newurl in string.gmatch(url, "(https?%%3[aA]%%2[fF][^%?&;]+)") do
newurl = urlparse.unescape(newurl)
queue_url(newurl)
end
for _, pattern in pairs({
".(https?:/[^&%?;]+)",
".(https?:/[^&%?]+)",
".(https?:/[^&]+)",
".(https?:/.+)"
}) do
for newurl in string.gmatch(url, pattern) do
queue_url(newurl)
end
end
if string.match(url, "^https?:/[^/]") then
queue_url(string.gsub(url, "^(https?:/)(.+)", "%1/%2"))
end]]
end
report_bad_url = function(url)
if current_url ~= nil then
bad_urls[current_url] = true
else
bad_urls[string.lower(url)] = true
end
end
strip_url = function(url)
url = string.match(url, "^https?://(.+)$")
newurl = string.match(url, "^www%.(.+)$")
if newurl then
url = newurl
end
return url
end
queue_telegram = function(rest)
local rest = string.match(rest, "^([^%?&]+)")
if string.len(rest) == 0 then
return nil
end
local _, temp = string.match(rest, "^/s(/.+)$")
if temp then
rest = temp
end
local user = string.match(rest, "^/([^/]+)")
if user then
telegram_posts[periodic_shard]["channel:" .. user] = current_url
telegram_channels[""]["channel:" .. user] = current_url
else
return nil
end
local post = string.match(rest, "^/[^/]+/([0-9]+)$")
if post then
telegram_posts[periodic_shard]["post:" .. user .. ":" .. post] = current_url
end
end
queue_pastebin = function(rest)
for s in string.gmatch(rest, "([a-zA-Z0-9]+)") do
if string.len(s) == 8 then
pastebin_items[""][s] = current_url
end
end
end
queue_imgur = function(rest)
local imgur_item_type = nil
for s in string.gmatch(rest, "[^A-Za-z0-9]([a-z]+)[^A-Za-z0-9]") do
if s == "gallery" or s == "ajaxalbums" then
imgur_item_type = "gallery"
elseif s == "album" then
imgur_item_type = "album"
end
if imgur_item_type then
break
end
end
if not imgur_item_type then
if string.match(rest, "^/g/") then
imgur_item_type = "gallery"
elseif string.match(rest, "^/user/") then
imgur_items[""]["user:" .. string.match(rest, "^/user/([a-zA-Z0-9_%-]+)")] = current_url
return nil
else
imgur_item_type = "i"
end
end
for s in string.gmatch(rest, "[/%?&;=]([a-zA-Z0-9,]+)") do
for t in string.gmatch(s, "([^,]+)") do
if imgur_item_type == "album" or imgur_item_type == "gallery" then
imgur_items[""][imgur_item_type .. ":" .. t] = current_url
elseif imgur_item_type == "i" then
if string.len(t) > 3 then
local start, ending = string.match(t, "^(.+)(...)$")
if ending == "jpg" or ending == "png" or ending == "gif" or ending == "mp4" then
t = start
end
end
local l = string.len(t)
if l == 6 or l == 8 then
imgur_items[""][imgur_item_type .. ":" .. string.match(t, "^(.+).$")] = current_url
end
if l == 5 or l == 7 then
imgur_items[""][imgur_item_type .. ":" .. t] = current_url
end
end
end
end
end
queue_mediafire = function(rest)
for s in string.gmatch(rest, "([a-zA-Z0-9]+)") do
s = string.lower(s)
if string.len(s) >= 10 then
mediafire_items[""]["id:" .. s] = current_url
s = string.match(s, "^(.-).g$")
if s then
mediafire_items[""]["id:" .. s] = current_url
end
end
end
end
queue_services = function(url)
if not url then
return nil
end
local domain, rest = string.match(url, "^https?://[^/]-([^/%.]+%.[^/%.]+)(/.*)$")
if domain == "t.me" or domain == "telegram.me" then
queue_telegram(rest)
elseif domain == "pastebin.com" then
queue_pastebin(rest)
elseif domain == "mediafire.com" or domain == "mfi.re" then
queue_mediafire(rest)
elseif domain == "imgur.com" then
queue_imgur(rest)
end
end
wget.callbacks.download_child_p = function(urlpos, parent, depth, start_url_parsed, iri, verdict, reason)
local url = urlpos["url"]["url"]
local parenturl = parent["url"]
local extract_page_requisites = false
if string.match(url, "^https?://(.+)$") == string.match(parenturl, "^https?://(.+)$") then
return false
end
--print(url)
local current_settings_all = current_settings and current_settings["all"]
local current_settings_any_domain = current_settings and current_settings["any_domain"]
local same_domain = string.match(parenturl, "^(https?://[^/]+)") == string.match(url, "^(https?://[^/]+)")
queue_services(url)
if string.match(url, "^ftp://") then
ftp_urls[""][url] = current_url
return false
end
if string.match(url, "^https?://[^/]+%.onion/")
and not string.match(parenturl, "^https?://[^/]+%.onion/") then
--and string.match(url .. "/", "^https?://([^/]-)([^%./]+%.[^%./]+)/") ~= string.match(parenturl .. "/", "^https?://([^/]-)([^%./]+%.[^%./]+)/") then
queue_url(url)
return false
end
if skip_parent_urls[parenturl] then
return false
end
if url ~= parenturl then
for parenturl_pattern, pattern_table in pairs(filter_pattern_sets) do
if string.match(parenturl, parenturl_pattern) then
local found_any = false
local check_string = parenturl_pattern .. parenturl
if not skip_parent_urls_check[check_string] then
skip_parent_urls_check[check_string] = {}
for k, _ in pairs(pattern_table) do
skip_parent_urls_check[check_string][k] = false
end
end
for pattern_name, patterns in pairs(pattern_table) do
if not skip_parent_urls_check[check_string][pattern_name] then
if type(patterns) == "string" then
patterns = {patterns}
end
for _, pattern in pairs(patterns) do
if string.match(url, pattern) then
found_any = true
--print(check_string, pattern_name)
skip_parent_urls_check[check_string][pattern_name] = true
break
end
end
end
end
if found_any then
local all_true = true
for _, v in pairs(skip_parent_urls_check[check_string]) do
if not v then
all_true = false
break
end
end
if all_true then
io.stdout:write("Skipping all URLs discovered for URL " .. parenturl .. ".\n")
io.stdout:flush()
skip_parent_urls[parenturl] = true
end
end
end
end
end
local parenturl_base = string.match(parenturl, "^(https://[^/]+)")
if parenturl_base then
for path, _ in pairs(paths) do
if string.len(path) > 1
and parenturl_base .. path == parenturl then
return false
end
end
end
--queue_monthly_item(url, urls_all)
--queue_monthly_url(string.match(url, "^(https?://[^/]+)") .. "/")
if redirect_urls[parenturl] and not (
status_code == 300 and string.match(parenturl, "^https?://[^/]*feb%-web%.ru/")
) then
return true
end
if (
string.match(parenturl, "^https://[^/%.]+%.[^/%.]+%.de/en/")
or string.match(parenturl, "^https://[^/%.]+%.[^/%.]+%.de/mobile/")
or string.match(parenturl, "^https://[^/%.]+%.[^/%.]+%.de/page/")
or (
string.match(parenturl, "^https://[^/%.]+%.[^/%.]+%.de/")
and (
string.match(parenturl, "%%20")
or string.match(parenturl, "_desktop_img/")
)
)
)
and (
string.match(url, "^https://[^/%.]+%.[^/%.]+%.de/en/")
or string.match(url, "^https://[^/%.]+%.[^/%.]+%.de/mobile/")
or string.match(url, "^https://[^/%.]+%.[^/%.]+%.de/page/")
or (
string.match(url, "^https://[^/%.]+%.[^/%.]+%.de/")
and (
string.match(url, " ")
or string.match(url, "%%20")
or string.match(url, "_desktop_img/")
)
)
)
and (
string.match(parenturl, "[/%.][a-z0-9]+$")
or string.match(parenturl, "[/%.][a-z0-9]+%?")
)
and (
string.match(url, "[/%.][a-z0-9]+$")
or string.match(url, "[/%.][a-z0-9]+%?")
) then
return false
end
-- prevent loop on some bad srcset URLs
if parenturl == current_file_url
and (
string.match(url, "https?://[a-z]+%.[^%.]+%.[a-z]+/[a-z]+$")
or string.match(url, "https?://[a-z]+%.[^%.]+%.[a-z]+/en/[a-z]+$")
) then
if current_file_html == nil then
current_file_html = read_file(current_file)
end
for srcset in string.gmatch(current_file_html, 'srcset="([^"]+)"') do
for srcset_url in string.gmatch(srcset, "([^,]+)") do
if string.match(url, "([a-z]+)$") == string.match(srcset_url, "^%s*([a-z]+)%s[^%s].-%s[0-9]+w$") then
return false
end
end
end
end
if string.match(parenturl, "^https?://[^/]+/$")
and same_domain then
local temp = string.match(url, "^https?://[^/]+(.*)$")
if temp then
for s in string.gmatch(temp, "([a-zA-Z0-9]+)") do
if extract_from_domain[s] then
queue_monthly_url(url, SPECIAL_INTEREST_FROM_MAIN)
end
end
end
end
if find_path_loop(url, 2) then
return false
end
local _, count = string.gsub(url, "[/%?]", "")
if count >= 16 then
return false
end
--[[if same_domain and current_settings
and current_settings["comment"] == SPECIAL_INTEREST_FROM_MAIN then
queue_url(url)
end]]
for _, pattern in pairs(skip_double_patterns) do
if string.match(parenturl, pattern)
and string.match(url, pattern) then
return false
end
end
if not string.match(url, "^https?://[^%./]+%.[^%./]+%.[a-z]+/sitemapa%.xml") then -- remove loop due to sitemapa.xml pointing to other domains
for _, extension in pairs({
"pdf",
"doc[mx]?",
"xls[mx]?",
"ppt[mx]?",
"dot[mx]?",
"pot[mx]?",
"pps[mx]?",
"xlt[mx]?",
"txt",
"rtf",
"jar",