-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpiratebayex.rb
142 lines (118 loc) · 3.56 KB
/
piratebayex.rb
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
require 'nokogiri'
require 'open-uri'
require 'openssl'
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
def fourth_ex(query, categories, range)
if query == nil
recent_torrents
else
parse_range(range).each do |page|
doc = Nokogiri::HTML(open("https://thepiratebay.mn/search/" + query + "/" + page.to_s + "/99/" + categories_query(categories)))
torrents = doc.css("tr")
unless torrents == 0
torrents.shift
for torrent in torrents
p "Name: " + torrent.css("a.detLink").attr("title").text
p "Link: " + torrent.css("td")[1].css("a")[1].attr("href")
p "Seeders: " + torrent.css("td")[2].text
p "Leechers: " + torrent.css("td")[3].text
end
end
end
end
end
def parse_range(range)
return 0..0 if range == nil
nums = range.split("-")
first = nums.first.to_i/30
last = nums.last.to_i/30
return first..last
end
def recent_torrents
doc = Nokogiri::HTML(open("https://thepiratebay.mn/recent"))
torrents = doc.css("tr")
unless torrents == 0
torrents.shift
for torrent in torrents
p "Name: " + torrent.css("a.detLink").attr("title").text
p "Link: " + torrent.css("td")[1].css("a")[1].attr("href")
p "Seeders: " + torrent.css("td")[2].text
p "Leechers: " + torrent.css("td")[3].text
end
end
end
def categories_query(categories)
if categories == "All" or categories == nil
return "100,200,300,400,500"
end
nums = []
categories_hash = {"Audio" => 100, "Video" => 200, "Applications" => 300, "Games" => 400, "Porn" => 500}
for category in categories.split(",")
nums.push(categories_hash[category])
end
query = nums.compact.join(",")
return query
end
fourth_ex("jimi", "Audio", nil)
=begin
def fifth_ex(query, categories, range)
nums = range.split("-")
first = nums.first.to_i/30
last = nums.last.to_i/30
(first..last).each do |page|
Thread.new do
p page
doc = Nokogiri::HTML(open("https://thepiratebay.mn/search/" + query + "/" + page.to_s + "/99/" + categories_query(categories)))
torrents = doc.css("tr")
unless torrents == 0
torrents.shift
for torrent in torrents
p "Name: " + torrent.css("a.detLink").attr("title").text
p "Link: " + torrent.css("td")[1].css("a")[1].attr("href")
p "Seeders: " + torrent.css("td")[2].text
p "Leechers: " + torrent.css("td")[3].text
end
end
end
end
end
def first_ex
doc = Nokogiri::HTML(open("https://thepiratebay.mn/recent"))
torrents = doc.css("tr")
unless torrents == 0
torrents.shift
for torrent in torrents
p "Name: " + torrent.css("a.detLink").attr("title").text
p "Link: " + torrent.css("td")[1].css("a")[1].attr("href")
p "Seeders: " + torrent.css("td")[2].text
p "Leechers: " + torrent.css("td")[3].text
end
end
end
def second_ex(query)
doc = Nokogiri::HTML(open("https://thepiratebay.mn/search/" + query + "/0/99/0"))
torrents = doc.css("tr")
unless torrents == 0
torrents.shift
for torrent in torrents
p "Name: " + torrent.css("a.detLink").attr("title").text
p "Link: " + torrent.css("td")[1].css("a")[1].attr("href")
p "Seeders: " + torrent.css("td")[2].text
p "Leechers: " + torrent.css("td")[3].text
end
end
end
def third_ex(query, categories)
doc = Nokogiri::HTML(open("https://thepiratebay.mn/search/" + query + "/0/99/" + categories_query(categories)))
torrents = doc.css("tr")
unless torrents == 0
torrents.shift
for torrent in torrents
p "Name: " + torrent.css("a.detLink").attr("title").text
p "Link: " + torrent.css("td")[1].css("a")[1].attr("href")
p "Seeders: " + torrent.css("td")[2].text
p "Leechers: " + torrent.css("td")[3].text
end
end
end
=end