lib/download_tv/grabbers/torrentapi.rb in download_tv-2.4.3 vs lib/download_tv/grabbers/torrentapi.rb in download_tv-2.4.4
- old
+ new
@@ -6,18 +6,18 @@
attr_accessor :token
attr_reader :wait
def initialize
super('https://torrentapi.org/pubapi_v2.php?mode=search&search_string=%s&token=%s&app_id=DownloadTV')
- @wait = 2.1
+ @wait = 0.1
end
##
# Specific implementation for TorrentAPI (requires token)
def online?
@agent.read_timeout = 2
- @agent.head(format(@url, 'test', 'test'))
+ renew_token
true
rescue Mechanize::ResponseCodeError, Net::HTTP::Persistent::Error
false
end
@@ -58,8 +58,16 @@
names = obj['torrent_results'].collect { |i| i['filename'] }
links = obj['torrent_results'].collect { |i| i['download'] }
names.zip(links)
+ rescue Mechanize::ResponseCodeError => e
+ if e.response_code == '429'
+ sleep(@wait)
+ retry
+ else
+ warn 'An unexpected error has occurred. Try updating the gem.'
+ exit 1
+ end
end
end
end