Class: Suby::Downloader::Addic7ed

Inherits:
Suby::Downloader show all
Defined in:
lib/suby/downloader/addic7ed.rb

Constant Summary collapse

SITE =
'www.addic7ed.com'
FORMAT =
:file
SUBTITLE_TYPES =
[:tvshow]
LANG_IDS =
{
  en:  1, es:  5, it:  7, fr:  8, pt: 10, de: 11, ca: 12, eu: 13, cs: 14,
  gl: 15, tr: 16, nl: 17, sv: 18, ru: 19, hu: 20, pl: 21, sl: 22, he: 23,
  zh: 24, sk: 25, ro: 26, el: 27, fi: 28, no: 29, da: 30, hr: 31, ja: 32,
  bg: 35, sr: 36, id: 37, ar: 38, ms: 40, ko: 42, fa: 43, bs: 44, vi: 45,
  th: 46, bn: 47
}
FILTER_IGNORED =
"Couldn't find any subs with the specified language. " +
"Filter ignored"

Constants inherited from Suby::Downloader

DOWNLOADERS

Instance Attribute Summary

Attributes inherited from Suby::Downloader

#episode, #file, #lang, #season, #show, #video_data

Instance Method Summary collapse

Methods inherited from Suby::Downloader

#convert_to_utf8_from_latin1, #download, #encode, #extract, #find_nfo_file, #get, #get_redirection, #http, #imdbid, inherited, #initialize, #post, #sub_extension, #sub_name, #subtitles, #success_message, #support_video_type?, #to_s, #xmlrpc

Constructor Details

This class inherits a constructor from Suby::Downloader

Instance Method Details

#download_urlObject

Raises:



54
55
56
57
58
59
60
61
62
63
# File 'lib/suby/downloader/addic7ed.rb', line 54

def download_url
  link = Nokogiri(subtitles_body).css('a').find { |a|
    a[:href].start_with? '/original/' or
    a[:href].start_with? '/updated/'
  }
  raise NotFoundError, "show/season/episode not found" unless link
  download_url = link[:href]

  redirected_url download_url
end

#redirected_url(download_url) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/suby/downloader/addic7ed.rb', line 39

def redirected_url download_url
  header = { 'Referer' => "http://#{SITE}#{subtitles_url}" }
  response = get download_url, header, false
  case response
  when Net::HTTPSuccess
    response
  when Net::HTTPFound
    location = response['Location']
    if location == '/downloadexceeded.php'
      raise NotFoundError, "download exceeded"
    end
    URI.escape location
  end
end

#subtitles_bodyObject

Raises:



29
30
31
32
33
34
35
36
37
# File 'lib/suby/downloader/addic7ed.rb', line 29

def subtitles_body
  body = subtitles_response.body
  body.strip!
  raise NotFoundError, "show/season/episode not found" if body.empty?
  if body.include? FILTER_IGNORED
    raise NotFoundError, "no subtitles available"
  end
  body
end

#subtitles_responseObject



21
22
23
24
25
26
27
# File 'lib/suby/downloader/addic7ed.rb', line 21

def subtitles_response
  response = get(subtitles_url, {}, false)
  unless Net::HTTPSuccess === response
    raise NotFoundError, "show/season/episode not found"
  end
  response
end

#subtitles_urlObject



17
18
19
# File 'lib/suby/downloader/addic7ed.rb', line 17

def subtitles_url
  "/serie/#{CGI.escape show}/#{season}/#{episode}/#{LANG_IDS[lang]}"
end