class Bathyscaphe::Addic7ed

Class to interact with addic7ed.com

Exaple:

sub = Bathyscaphe::Addic7ed.new(tv_show, season, episode)
sub.save("path/to/save/subtitles")

Constants

HOST
HTTP_HOST

Public Class Methods

new(tv_show, season, episode) click to toggle source
# File lib/bathyscaphe/addic7ed.rb, line 22
def initialize(tv_show, season, episode)
  @tv_show = tv_show
  @season = season
  @episode = episode
  @temp_file = download
end

Public Instance Methods

download() click to toggle source

Fakes your identity as if you came directly from episode page (otherwise addic7ed will redirect you to this episode page) and downloads subtitles.

Returns object of TempFile with subtitles.

# File lib/bathyscaphe/addic7ed.rb, line 33
def download

  uri = URI( download_link )
  path = uri.path.empty? ? "/" : uri.path

  headers = { "Host" => HOST,
              "Referer" => episode_link(:referer)
            }
  @temp_file = Tempfile.open("bathyscaphe_"+@tv_show+@season+@episode)
  begin
    Net::HTTP.start(uri.host, uri.port) { |http|
      resp = http.get(path, headers)
      @temp_file.write resp.body
      raise "Limit exceeded" if resp.code.to_s == "302"
    }
  rescue Exception => e
    puts e
  ensure
    @temp_file.close
  end

  @temp_file

end
get_html() click to toggle source

Returns Tempfile with html regarding your episode

# File lib/bathyscaphe/addic7ed.rb, line 121
def get_html
  io_html = eat(episode_link(:lang))
rescue URI::InvalidURIError => e
  STDERR.puts "\e[31m"+"We generated url the wrong way. Shame on us."+"\e[0m"
  STDERR.puts e
  STDERR.puts episode_link(:lang)
  exit
rescue HTTPClient::BadResponseError => the_error
  STDERR.puts "\e[31m"+the_error+". Haven't seen it yet."+"\e[0m"
  STDERR.puts episode_link(:lang)
  exit
rescue OpenURI::HTTPError => the_error
  STDERR.puts "\e[31m"+"Server responded with funny status code #{the_error.io.status[0]}. Haven't seen it yet."+"\e[0m"
  STDERR.puts episode_link(:lang)
  exit
end
save(local_path) click to toggle source

Moves downloaded subtitles to local_path

# File lib/bathyscaphe/addic7ed.rb, line 61
def save local_path
  @temp_file ||= download
  FileUtils.mv(@temp_file.path, local_path)
  puts "\e[32m"+"We've downloaded them: #{local_path}"+"\e[0m"
end