Class: SubtitulosDownloader::ShowEpisode
- Inherits:
-
Object
- Object
- SubtitulosDownloader::ShowEpisode
- Defined in:
- lib/subtitulos_downloader/show_episode.rb
Instance Attribute Summary collapse
-
#episode ⇒ Object
Returns the value of attribute episode.
-
#episode_name ⇒ Object
Returns the value of attribute episode_name.
-
#season ⇒ Object
Returns the value of attribute season.
-
#show_name ⇒ Object
Returns the value of attribute show_name.
-
#subtitles ⇒ Object
Returns the value of attribute subtitles.
-
#tvdb_episode ⇒ Object
Returns the value of attribute tvdb_episode.
-
#tvdb_show ⇒ Object
Returns the value of attribute tvdb_show.
Class Method Summary collapse
Instance Method Summary collapse
- #episode_path ⇒ Object
- #fetch_data_from_tvdb(key) ⇒ Object
- #full_name ⇒ Object
-
#initialize(show_name, season, episode, options = {}) ⇒ ShowEpisode
constructor
A new instance of ShowEpisode.
- #season_path ⇒ Object
- #show_path ⇒ Object
- #subtitle_language(lang) ⇒ Object
Constructor Details
#initialize(show_name, season, episode, options = {}) ⇒ ShowEpisode
Returns a new instance of ShowEpisode.
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/subtitulos_downloader/show_episode.rb', line 10 def initialize(show_name, season, episode, = {}) @show_name = show_name @season = season.to_i @episode = episode.to_i @options = @subtitles = [] if @options[:tvdb_api_key] fetch_data_from_tvdb(@options[:tvdb_api_key]) end end |
Instance Attribute Details
#episode ⇒ Object
Returns the value of attribute episode.
7 8 9 |
# File 'lib/subtitulos_downloader/show_episode.rb', line 7 def episode @episode end |
#episode_name ⇒ Object
Returns the value of attribute episode_name.
7 8 9 |
# File 'lib/subtitulos_downloader/show_episode.rb', line 7 def episode_name @episode_name end |
#season ⇒ Object
Returns the value of attribute season.
7 8 9 |
# File 'lib/subtitulos_downloader/show_episode.rb', line 7 def season @season end |
#show_name ⇒ Object
Returns the value of attribute show_name.
7 8 9 |
# File 'lib/subtitulos_downloader/show_episode.rb', line 7 def show_name @show_name end |
#subtitles ⇒ Object
Returns the value of attribute subtitles.
8 9 10 |
# File 'lib/subtitulos_downloader/show_episode.rb', line 8 def subtitles @subtitles end |
#tvdb_episode ⇒ Object
Returns the value of attribute tvdb_episode.
8 9 10 |
# File 'lib/subtitulos_downloader/show_episode.rb', line 8 def tvdb_episode @tvdb_episode end |
#tvdb_show ⇒ Object
Returns the value of attribute tvdb_show.
8 9 10 |
# File 'lib/subtitulos_downloader/show_episode.rb', line 8 def tvdb_show @tvdb_show end |
Class Method Details
.new_from_file_name(file_name, options = {}) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/subtitulos_downloader/show_episode.rb', line 74 def self.new_from_file_name(file_name, ={}) # House.S04E13.HDTV.XviD-XOR.avi # my.name.is.earl.s03e07-e08.hdtv.xvid-xor.[VTV].avi # My_Name_Is_Earl.3x17.No_Heads_And_A_Duffel_Bag.HDTV_XviD-FoV.[VTV].avi # My Name Is Earl - 3x04.avi # MythBusters - S04E01 - Newspaper Crossbow.avi # my.name.is.earl.305.hdtv-lol.[VTV].avi # TODO look up the regex used in XBMC to get data from TV episodes re = /^(.*?)(?:\s?[-\.]\s?)?\s*\[?s?(?: (?: (\d{1,2}) \s?\.?\s?[ex-]\s? (?:(\d{2})(?:\s?[,-]\s?[ex]?(\d{2}))?) ) | (?: \.(\d{1})(\d{2})(?!\d) ) )\]?\s?.*$/ix if match = file_name.to_s.match(re) series = match[1].gsub(/[\._]/, ' ').strip.gsub(/\b\w/){$&.upcase} season = (match[2] || match[5]).to_i episode = (match[3] || match[6]).to_i episode = (episode)..(match[4].to_i) unless match[4].nil? show_episode = ShowEpisode.new(series, season, episode, ) else nil end end |
Instance Method Details
#episode_path ⇒ Object
70 71 72 |
# File 'lib/subtitulos_downloader/show_episode.rb', line 70 def episode_path "#{@show_name}/Season #{@season}/#{self.full_name}" end |
#fetch_data_from_tvdb(key) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/subtitulos_downloader/show_episode.rb', line 23 def fetch_data_from_tvdb(key) @tvdb = TVdb::Client.new(key) tvdb_show = @tvdb.search(@show_name) if tvdb_show.count > 0 tvdb_show = tvdb_show[0] @show_name = tvdb_show.seriesname tvdb_show.episodes.each do |ep| ep_number = ep.episodenumber ep_season = ep.combined_season if ep_number.to_i == @episode && ep_season.to_i == @season @episode_name = ep.episodename break end end else raise ShowNotFound, "[TVdb] show #{@show_name} not found" end end |
#full_name ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/subtitulos_downloader/show_episode.rb', line 53 def full_name episode_str = "%02d" % @episode if @episode_name "#{@show_name} - #{@season}x#{episode_str} - #{@episode_name}" else "#{@show_name} - #{@season}x#{episode_str}" end end |
#season_path ⇒ Object
66 67 68 |
# File 'lib/subtitulos_downloader/show_episode.rb', line 66 def season_path "#{@show_name}/Season #{@season}" end |
#show_path ⇒ Object
62 63 64 |
# File 'lib/subtitulos_downloader/show_episode.rb', line 62 def show_path "#{@show_name}" end |
#subtitle_language(lang) ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/subtitulos_downloader/show_episode.rb', line 42 def subtitle_language(lang) subs = nil @subtitles.each do |sub| if sub.language == lang return sub break end end return nil end |