Class: DownloadTV::KAT

Inherits:
LinkGrabber show all
Defined in:
lib/download_tv/grabbers/kat.rb

Overview

KATcr.co grabber

Instance Attribute Summary collapse

Attributes inherited from LinkGrabber

#url

Instance Method Summary collapse

Methods inherited from LinkGrabber

#online?

Constructor Details

#initializeKAT

Returns a new instance of KAT.



9
10
11
12
# File 'lib/download_tv/grabbers/kat.rb', line 9

def initialize
  super('https://katcr.co/advanced-usearch/')
  @max_tries = 5
end

Instance Attribute Details

#max_triesObject (readonly)

Returns the value of attribute max_tries.



7
8
9
# File 'lib/download_tv/grabbers/kat.rb', line 7

def max_tries
  @max_tries
end

Instance Method Details



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/download_tv/grabbers/kat.rb', line 14

def get_links(show)
  tries = 0

  params = {
    'category': 'TV',
    'orderby': 'seeds-desc',
    'search': show
  }

  data = @agent.post(@url, params)
               .search('tbody tr td[1]')

  names = data.map do |i|
    i.search('a.torrents_table__torrent_title b')
     .text
  end

  links = data.map do |i|
    i.search('div.torrents_table__actions a[3]')
     .first
     .attribute('href')
     .text
  end

  raise NoTorrentsError if data.empty?

  names.zip(links)
rescue Net::HTTP::Persistent::Error => e
  raise unless e.message =~ /too many connection resets/
  raise if tries >= @max_tries

  tries += 1
  retry
end