Class: DownloadTV::Torrent
- Inherits:
-
Object
- Object
- DownloadTV::Torrent
- Defined in:
- lib/download_tv/torrent.rb
Overview
Class in charge of managing the link grabbers
Instance Attribute Summary collapse
-
#g_instances ⇒ Object
readonly
Returns the value of attribute g_instances.
-
#tries ⇒ Object
readonly
Returns the value of attribute tries.
Instance Method Summary collapse
- #change_grabbers ⇒ Object
- #check_grabber_online ⇒ Object
- #get_links(show) ⇒ Object
- #grabbers ⇒ Object
-
#initialize(default_grabber = nil) ⇒ Torrent
constructor
A new instance of Torrent.
- #reset_grabbers_order ⇒ Object
- #reset_tries ⇒ Object
Constructor Details
#initialize(default_grabber = nil) ⇒ Torrent
Returns a new instance of Torrent.
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/download_tv/torrent.rb', line 14 def initialize(default_grabber = nil) g_names = grabbers # Silently ignores bad names found_default = g_names.find_index(default_grabber) g_names.rotate! found_default if found_default @g_instances = g_names.map { |g| (DownloadTV.const_get g).new } reset_tries check_grabber_online end |
Instance Attribute Details
#g_instances ⇒ Object (readonly)
Returns the value of attribute g_instances.
7 8 9 |
# File 'lib/download_tv/torrent.rb', line 7 def g_instances @g_instances end |
#tries ⇒ Object (readonly)
Returns the value of attribute tries.
7 8 9 |
# File 'lib/download_tv/torrent.rb', line 7 def tries @tries end |
Instance Method Details
#change_grabbers ⇒ Object
41 42 43 44 45 |
# File 'lib/download_tv/torrent.rb', line 41 def change_grabbers # Rotates the instantiated grabbers @g_instances.rotate! check_grabber_online end |
#check_grabber_online ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/download_tv/torrent.rb', line 27 def check_grabber_online if @g_instances.empty? warn 'There are no available grabbers.' exit 1 end return if @g_instances.first.online? # We won't be using this grabber warn "Problem accessing #{@g_instances.first.class.name}" @tries -= 1 @g_instances.shift # Removes first element check_grabber_online end |
#get_links(show) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/download_tv/torrent.rb', line 47 def get_links(show) links = @g_instances.first.get_links(show) reset_grabbers_order reset_tries links rescue NoTorrentsError # Use next grabber if @tries.positive? @tries -= 1 change_grabbers retry else reset_grabbers_order reset_tries puts "No torrents found for #{show}" [] end end |
#grabbers ⇒ Object
9 10 11 12 |
# File 'lib/download_tv/torrent.rb', line 9 def grabbers # %w[TorrentAPI ThePirateBay Eztv KAT] %w[TorrentAPI Eztv] end |
#reset_grabbers_order ⇒ Object
73 74 75 |
# File 'lib/download_tv/torrent.rb', line 73 def reset_grabbers_order @g_instances.rotate!(@tries + 1) end |
#reset_tries ⇒ Object
69 70 71 |
# File 'lib/download_tv/torrent.rb', line 69 def reset_tries @tries = @g_instances.size - 1 end |