Class: Addic7ed::Episode
- Inherits:
-
Object
- Object
- Addic7ed::Episode
- Defined in:
- lib/addic7ed/episode.rb
Instance Attribute Summary collapse
-
#untagged ⇒ Object
readonly
Returns the value of attribute untagged.
-
#video_file ⇒ Object
readonly
Returns the value of attribute video_file.
Instance Method Summary collapse
- #best_subtitle(lang = 'fr', no_hi = false) ⇒ Object
- #download_best_subtitle!(lang, no_hi = false, http_redirect_limit = 8) ⇒ Object
-
#initialize(filename, untagged = false) ⇒ Episode
constructor
A new instance of Episode.
- #subtitles(lang = 'fr') ⇒ Object
- #url(lang = 'fr') ⇒ Object
Constructor Details
#initialize(filename, untagged = false) ⇒ Episode
Returns a new instance of Episode.
9 10 11 12 |
# File 'lib/addic7ed/episode.rb', line 9 def initialize(filename, untagged = false) @video_file = Addic7ed::VideoFile.new(filename) @untagged = untagged end |
Instance Attribute Details
#untagged ⇒ Object (readonly)
Returns the value of attribute untagged.
7 8 9 |
# File 'lib/addic7ed/episode.rb', line 7 def untagged @untagged end |
#video_file ⇒ Object (readonly)
Returns the value of attribute video_file.
7 8 9 |
# File 'lib/addic7ed/episode.rb', line 7 def video_file @video_file end |
Instance Method Details
#best_subtitle(lang = 'fr', no_hi = false) ⇒ Object
26 27 28 29 30 |
# File 'lib/addic7ed/episode.rb', line 26 def best_subtitle(lang = 'fr', no_hi = false) check_language_availability(lang) find_best_subtitle(lang, no_hi) unless @best_subtitle and @best_subtitle[lang] return @best_subtitle[lang] end |
#download_best_subtitle!(lang, no_hi = false, http_redirect_limit = 8) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/addic7ed/episode.rb', line 32 def download_best_subtitle!(lang, no_hi = false, http_redirect_limit = 8) raise HTTPError.new('Too many HTTP redirects') unless http_redirect_limit > 0 uri = URI(best_subtitle(lang, no_hi).url) response = get_http_response(uri, url(lang)) if response.kind_of?(Net::HTTPRedirection) follow_redirection(lang, no_hi, response['location'], http_redirect_limit) else save_subtitle(response.body, lang) end end |
#subtitles(lang = 'fr') ⇒ Object
20 21 22 23 24 |
# File 'lib/addic7ed/episode.rb', line 20 def subtitles(lang = 'fr') check_language_availability(lang) find_subtitles(lang) unless @subtitles and @subtitles[lang] return @subtitles[lang] end |
#url(lang = 'fr') ⇒ Object
14 15 16 17 18 |
# File 'lib/addic7ed/episode.rb', line 14 def url(lang = 'fr') check_language_availability(lang) @localized_urls ||= {} @localized_urls[lang] ||= "http://www.addic7ed.com/serie/#{ShowList.url_segment_for(video_file.showname)}/#{video_file.season}/#{video_file.episode}/#{LANGUAGES[lang][:id]}" end |