Module: Firecracker
- Defined in:
- lib/firecracker.rb,
lib/firecracker/base.rb,
lib/firecracker/version.rb,
lib/firecracker/tcp_scraper.rb,
lib/firecracker/udp_scraper.rb
Defined Under Namespace
Classes: Base, TCPScraper, UDPScraper
Constant Summary collapse
- VERSION =
"1.0.2"
Class Method Summary collapse
-
.calculate(torrent, protocols = [:udp, :tcp]) ⇒ Object
Hash Seeders, leechers and the amounts of downloads.
- .hash(torrent) ⇒ Object
-
.load(torrent, protocols = [:udp, :tcp]) ⇒ Object
Hash Seeders, leechers and the amounts of downloads.
-
.raw(raw, protocols = [:udp, :tcp]) ⇒ Object
Hash Seeders, leechers and the amounts of downloads.
- .tcp_trackers(torrent) ⇒ Object
- .udp_trackers(torrent) ⇒ Object
Class Method Details
.calculate(torrent, protocols = [:udp, :tcp]) ⇒ Object
Returns Hash Seeders, leechers and the amounts of downloads.
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 |
# File 'lib/firecracker.rb', line 31 def self.calculate(torrent, protocols = [:udp, :tcp]) raise "At least one protocol needs to be passed" if protocols.empty? # UDP related trackers if protocols.include?(:udp) trackers = udp_trackers(torrent) udp_results = trackers.map do |tracker| begin Firecracker::UDPScraper.new({ tracker: tracker, hashes: [hash(torrent)] }).process! rescue # raise $! unless silent end end.reject(&:nil?).map(&:values).flatten end # TCP related trackers if protocols.include?(:tcp) trackers = tcp_trackers(torrent) tcp_results = trackers.map do |tracker| begin Firecracker::TCPScraper.new({ tracker: tracker, hashes: [hash(torrent)] }).process! rescue # raise $! unless silent end end.reject(&:nil?).map(&:values).flatten end (tcp_results + udp_results).inject{ |memo, el| memo.merge(el){ |k, old_v, new_v| old_v + new_v } } end |
.hash(torrent) ⇒ Object
105 106 107 |
# File 'lib/firecracker.rb', line 105 def self.hash(torrent) Digest::SHA1.hexdigest(torrent["info"].bencode) end |
.load(torrent, protocols = [:udp, :tcp]) ⇒ Object
Returns Hash Seeders, leechers and the amounts of downloads.
13 14 15 |
# File 'lib/firecracker.rb', line 13 def self.load(torrent, protocols = [:udp, :tcp]) Firecracker.raw(File.read(torrent)) end |
.raw(raw, protocols = [:udp, :tcp]) ⇒ Object
Returns Hash Seeders, leechers and the amounts of downloads.
22 23 24 |
# File 'lib/firecracker.rb', line 22 def self.raw(raw, protocols = [:udp, :tcp]) Firecracker.calculate(raw.bdecode) end |
.tcp_trackers(torrent) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/firecracker.rb', line 87 def self.tcp_trackers(torrent) announce = torrent["announce"] announce_list = torrent["announce-list"] trackers = announce_list.flatten.select{|tracker| tracker.match(/^http:\/\//)} if announce.match(/^http:\/\//) trackers << announce end # TPBs tracker is no longer active return trackers.map{|t| t.gsub(/announce/, "scrape")}.reject{|t| t.match(%r{thepiratebay})} end |
.udp_trackers(torrent) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/firecracker.rb', line 71 def self.udp_trackers(torrent) announce = torrent["announce"] announce_list = torrent["announce-list"] trackers = announce_list.flatten.select{|tracker| tracker.match(/^udp:\/\//)} if announce.match(/^udp:\/\//) trackers << announce end return trackers end |