Class: TorrentCrawler::Crawlers::LinuxTracker
- Inherits:
-
Base
- Object
- Base
- TorrentCrawler::Crawlers::LinuxTracker
show all
- Defined in:
- lib/crawlers/linux_tracker.rb
Instance Attribute Summary
Attributes inherited from Base
#results
Instance Method Summary
collapse
Methods inherited from Base
#headers, #initialize, #result, #tracker_key
Instance Method Details
#detail(tracker_id) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/crawlers/linux_tracker.rb', line 39
def detail(tracker_id)
doc = Nokogiri::HTML(open(self.detail_url(tracker_id), self.))
result do |torrent|
torrent.tracker_id = tracker_id
torrent.hash = tracker_id
torrent.title = doc.css('tr:nth-child(1) .row1:nth-child(2)').first.text.strip
torrent.uploader = doc.css('tr:nth-child(16) a').first.text.strip
torrent.size = doc.css('tr:nth-child(13) .row1').first.text.strip
torrent.files = doc.css('tr:nth-child(14) .row1').first.text.gsub(/.*(\d+) files?.*/im, '\1')
torrent.seeders = doc.css('tr:nth-child(19) .row1').first.text.gsub(/.*Seeds: (\d+).*/, '\1')
torrent.leechers = doc.css('tr:nth-child(19) .row1').first.text.gsub(/.*Leechers: (\d+).*/, '\1')
torrent.snatches = doc.css('tr:nth-child(18) .row1').first.text.gsub(/[^\d]+/, '')
torrent.uploaded_at = Time.now
torrent.tags << torrent.uploader
torrent
end
end
|
#detail_url(tracker_id) ⇒ Object
7
8
9
|
# File 'lib/crawlers/linux_tracker.rb', line 7
def detail_url(tracker_id)
"http://linuxtracker.org/index.php?page=torrent-details&id=#{tracker_id}"
end
|
#index(last_seen = nil) ⇒ Object
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
|
# File 'lib/crawlers/linux_tracker.rb', line 11
def index(last_seen = nil)
doc = Nokogiri::HTML(open(self.index_url, self.))
doc.css('#rightcol :nth-child(4) table > tr').each do |tr|
next if tr.css(':nth-child(2) a').first.nil?
result do |torrent|
torrent.tracker_id = tr.css(':nth-child(2) a').first['href'].gsub(/.*id=([a-z0-9]+).*/, '\1')
return results if torrent.tracker_id == last_seen
torrent.hash = torrent.tracker_id
torrent.title = tr.css(':nth-child(2) a').first.text.strip
torrent.size = tr.css(':nth-child(5)').first.text.strip
torrent.seeders = tr.css(':nth-child(6)').first.text.strip
torrent.leechers = tr.css(':nth-child(7)').first.text.strip
torrent.snatches = tr.css(':nth-child(8)').first.text.strip
torrent.snatches = '0' if torrent.snatches == '---'
torrent.uploaded_at = Time.now
results << torrent
end
end
results
end
|
#index_url ⇒ Object
3
4
5
|
# File 'lib/crawlers/linux_tracker.rb', line 3
def index_url
"http://linuxtracker.org/"
end
|