Class: BTScraper::HTTPScrape
- Inherits:
-
Object
- Object
- BTScraper::HTTPScrape
- Defined in:
- lib/btscraper/httpscrape.rb
Overview
This class permits you to scrape an HTTP torrent tracker according to the BEP 48
Instance Attribute Summary collapse
-
#info_hash ⇒ Array<String>
readonly
Returns array of infohashes.
-
#tracker ⇒ String
readonly
Returns tracker full url.
Instance Method Summary collapse
-
#initialize(tracker, info_hash) ⇒ HTTPScrape
constructor
Create a new HTTPScrape object.
-
#scrape ⇒ Hash
The method returns a hash with the scraped data.
Constructor Details
#initialize(tracker, info_hash) ⇒ HTTPScrape
Create a new HTTPScrape object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/btscraper/httpscrape.rb', line 29 def initialize(tracker, info_hash) unless tracker.instance_of? String raise TypeError, "String excpected, got #{tracker.class}" end unless info_hash.instance_of? String or info_hash.instance_of? Array raise TypeError, "String or Array excpected, got #{info_hash.class}" end if info_hash.instance_of? String info_hash.downcase! BTScraper.check_info_hash Array(info_hash) else info_hash.map(&:downcase!) BTScraper.check_info_hash info_hash end @tracker = tracker @info_hash = Array(info_hash) end |
Instance Attribute Details
#info_hash ⇒ Array<String> (readonly)
Returns array of infohashes
29 30 31 |
# File 'lib/btscraper/httpscrape.rb', line 29 def info_hash @info_hash end |
#tracker ⇒ String (readonly)
Returns tracker full url
29 30 31 |
# File 'lib/btscraper/httpscrape.rb', line 29 def tracker @tracker end |
Instance Method Details
#scrape ⇒ Hash
Returns The method returns a hash with the scraped data.
50 51 52 53 54 55 56 57 58 |
# File 'lib/btscraper/httpscrape.rb', line 50 def scrape unhex_info_hash = @info_hash.map{|x| Binascii.a2b_hex(x)} params = unhex_info_hash.map{|h| "info_hash=#{CGI.escape(h.to_s)}"}.join('&') begin HTTParty.get(@tracker, :query => params, :headers => {'User-Agent' => "btscraper #{VERSION}"}, :timeout => 10).body.bdecode rescue HTTParty::Error => e raise BTScraperError, e end end |