Class: Addic7ed::Episode

Inherits:
Object
  • Object
show all
Defined in:
lib/addic7ed/episode.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ Episode

Returns a new instance of Episode.



9
10
11
# File 'lib/addic7ed/episode.rb', line 9

def initialize(filename)
  @filename = Addic7ed::Filename.new(filename)
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



7
8
9
# File 'lib/addic7ed/episode.rb', line 7

def filename
  @filename
end

Instance Method Details

#best_subtitle(lang = 'fr') ⇒ Object



25
26
27
28
29
# File 'lib/addic7ed/episode.rb', line 25

def best_subtitle(lang = 'fr')
  check_language_availability(lang)
  find_best_subtitle(lang) unless @best_subtitle and @best_subtitle[lang]
  return @best_subtitle[lang]
end

#download_best_subtitle!(lang, http_redirect_limit = 8) ⇒ Object

Raises:

  • (HTTPError)


31
32
33
34
35
36
37
38
39
40
# File 'lib/addic7ed/episode.rb', line 31

def download_best_subtitle!(lang, http_redirect_limit = 8)
  raise HTTPError.new('Too many HTTP redirects') unless http_redirect_limit > 0
  uri = URI(best_subtitle(lang).url)
  response = get_http_response(uri, url(lang))
  if response.kind_of?(Net::HTTPRedirection)
    follow_redirection(lang, response['location'], http_redirect_limit)
  else
    save_subtitle response.body
  end
end

#subtitles(lang = 'fr') ⇒ Object



19
20
21
22
23
# File 'lib/addic7ed/episode.rb', line 19

def subtitles(lang = 'fr')
  check_language_availability(lang)
  find_subtitles(lang) unless @subtitles and @subtitles[lang]
  return @subtitles[lang]
end

#url(lang = 'fr') ⇒ Object



13
14
15
16
17
# File 'lib/addic7ed/episode.rb', line 13

def url(lang = 'fr')
  check_language_availability(lang)
  @localized_urls ||= {}
  @localized_urls[lang] ||= "http://www.addic7ed.com/serie/#{@filename.encoded_showname}/#{@filename.season}/#{@filename.episode}/#{LANGUAGES[lang][:id]}"
end