Class: DownloadTV::Torrent

Inherits:
Object
  • Object
show all
Defined in:
lib/download_tv/torrent.rb

Overview

Class in charge of managing the link grabbers

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(default_grabber = nil) ⇒ Torrent

Returns a new instance of Torrent.



20
21
22
23
24
25
26
27
# File 'lib/download_tv/torrent.rb', line 20

def initialize(default_grabber = nil)
  @g_instances = self.class.grabbers\
    .rotate(self.class.grabbers.find_index(default_grabber) || 0)
    .map { |g| (DownloadTV.const_get g).new }
  reset_tries

  remove_grabber_if_offline
end

Class Method Details

.grabbersObject



8
9
10
# File 'lib/download_tv/torrent.rb', line 8

def grabbers
  %w[Torrentz ThePirateBay Eztv]
end

.healthcheckObject



12
13
14
15
16
17
# File 'lib/download_tv/torrent.rb', line 12

def healthcheck
  grabbers.each do |g|
    grabber = (DownloadTV.const_get g).new
    puts "#{g}: #{grabber.online? ? 'online' : 'offline'}"
  end
end

Instance Method Details



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/download_tv/torrent.rb', line 29

def get_links(show)
  @g_instances.first.get_links(show)
rescue NoTorrentsError
  if @tries.positive?
    change_grabbers
    retry
  end
  # We're out of grabbers to try
  puts "No torrents found for #{show}"
  []
ensure
  reset_grabbers_order
end