Class: TorrentCrawler::Crawlers::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/crawlers/base.rb

Direct Known Subclasses

LinuxTracker, Mininova

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.


6
7
8
# File 'lib/crawlers/base.rb', line 6

def initialize
  @results = []
end

Instance Attribute Details

#resultsObject

Returns the value of attribute results


4
5
6
# File 'lib/crawlers/base.rb', line 4

def results
  @results
end

Instance Method Details

#detail(tracker_id) ⇒ Object

Raises:


30
31
32
# File 'lib/crawlers/base.rb', line 30

def detail(tracker_id)
  raise BadCrawlerError, "A method named detail has not been implemented in this Crawler class"
end

#detail_urlObject

Raises:


22
23
24
# File 'lib/crawlers/base.rb', line 22

def detail_url
  raise BadCrawlerError, "A method named detail_url has not been implemented in this Crawler class"
end

#headersObject


10
11
12
13
14
15
16
# File 'lib/crawlers/base.rb', line 10

def headers
  {
    'User-Agent'      => "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.63 Safari/534.3",
    'Accept-Language' => 'en-us,en;q=0.5',
    'Referer'         => index_url
  }
end

#index(last_seen = nil) ⇒ Object

Raises:


26
27
28
# File 'lib/crawlers/base.rb', line 26

def index(last_seen = nil)
  raise BadCrawlerError, "A method named index has not been implemented in this Crawler class"
end

#index_urlObject

Raises:


18
19
20
# File 'lib/crawlers/base.rb', line 18

def index_url
  raise BadCrawlerError, "A method named index_url has not been implemented in this Crawler class"
end

#result {|torrent| ... } ⇒ Object

Yields:

  • (torrent)

34
35
36
37
38
39
# File 'lib/crawlers/base.rb', line 34

def result(&block)
  torrent = TorrentCrawler::Torrent.new
  torrent.tracker_key = self.tracker_key

  yield torrent
end

#tracker_keyObject


41
42
43
44
45
46
47
48
# File 'lib/crawlers/base.rb', line 41

def tracker_key
  self.class.to_s.gsub(/::/, '/').
    gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
    gsub(/([a-z\d])([A-Z])/,'\1_\2').
    tr("-", "_").
    downcase.
    gsub(/.*\/([^\/]+)$/, '\1')
end