class DownloadTV::Torrent
Class in charge of managing the link grabbers
Attributes
g_instances[R]
tries[R]
Public Class Methods
new(default_grabber = nil)
click to toggle source
# File lib/download_tv/torrent.rb, line 13 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
Public Instance Methods
change_grabbers()
click to toggle source
# File lib/download_tv/torrent.rb, line 40 def change_grabbers @tries -= 1 @g_instances.rotate! check_grabber_online end
check_grabber_online()
click to toggle source
# File lib/download_tv/torrent.rb, line 26 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)
click to toggle source
# File lib/download_tv/torrent.rb, line 46 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
grabbers()
click to toggle source
# File lib/download_tv/torrent.rb, line 9 def grabbers %w[TorrentAPI Torrentz Eztv] end
reset_grabbers_order()
click to toggle source
# File lib/download_tv/torrent.rb, line 64 def reset_grabbers_order @g_instances.rotate!(@tries + 1) reset_tries end
reset_tries()
click to toggle source
# File lib/download_tv/torrent.rb, line 60 def reset_tries @tries = @g_instances.size - 1 end