lib/download_tv/grabbers/torrentapi.rb in download_tv-2.3.0 vs lib/download_tv/grabbers/torrentapi.rb in download_tv-2.4.0

- old
+ new

@@ -1,8 +1,9 @@ module DownloadTV ## # TorrentAPI.org grabber + # Interfaces with http://torrentapi.org/apidocs_v2.txt class TorrentAPI < LinkGrabber attr_accessor :token attr_reader :wait def initialize @@ -12,28 +13,25 @@ ## # Specific implementation for TorrentAPI (requires token) def online? @agent.read_timeout = 2 - @agent.get(format(@url, 'test', 'test')) + @agent.head(format(@url, 'test', 'test')) true rescue Mechanize::ResponseCodeError, Net::HTTP::Persistent::Error false end ## - # Connects to Torrentapi.org and requests a token. - # Returns said token. + # Connects to Torrentapi.org and requests a token, returning it + # Tokens automatically expire every 15 minutes def renew_token page = @agent.get('https://torrentapi.org/pubapi_v2.php?get_token=get_token&app_id=DownloadTV').content obj = JSON.parse(page) @token = obj['token'] - # Tokens automaticly expire in 15 minutes. - # The api has a 1req/2s limit. - # http://torrentapi.org/apidocs_v2.txt end def get_links(s) @token ||= renew_token @@ -49,14 +47,12 @@ page = @agent.get(search).content obj = JSON.parse(page) end while obj['error_code'] == 5 # Violate 1req/2s limit - # puts 'Torrentapi request limit hit. Wait a few seconds...' sleep(@wait) page = @agent.get(search).content obj = JSON.parse(page) - end raise NoTorrentsError if obj['error'] names = obj['torrent_results'].collect { |i| i['filename'] }