Class: Episode

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tv_show, path) ⇒ Episode

Returns a new instance of Episode.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/episode.rb', line 5

def initialize(tv_show, path)
  @path = path
  @ext  = File.extname(@path)
  @name = File.basename(path, @ext)
  @tv_show = tv_show.gsub(/\s\([0-9]{4}\)/,'').chomp(' ')
  @srt = []
  
  search_existing_srt
  define_format
  define_season_and_episode_number
end

Instance Attribute Details

#extObject

Returns the value of attribute ext.



3
4
5
# File 'lib/episode.rb', line 3

def ext
  @ext
end

#formatObject

Returns the value of attribute format.



3
4
5
# File 'lib/episode.rb', line 3

def format
  @format
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/episode.rb', line 3

def name
  @name
end

#numberObject

Returns the value of attribute number.



3
4
5
# File 'lib/episode.rb', line 3

def number
  @number
end

#pathObject

Returns the value of attribute path.



3
4
5
# File 'lib/episode.rb', line 3

def path
  @path
end

#seasonObject

Returns the value of attribute season.



3
4
5
# File 'lib/episode.rb', line 3

def season
  @season
end

#srtObject

Returns the value of attribute srt.



3
4
5
# File 'lib/episode.rb', line 3

def srt
  @srt
end

#tv_showObject

Returns the value of attribute tv_show.



3
4
5
# File 'lib/episode.rb', line 3

def tv_show
  @tv_show
end

Class Method Details

.valid?(filename) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/episode.rb', line 42

def self.valid?(filename)
  filename.match(/.*(([0-9]{1,2}X[0-9]{1,2})|(S[0-9][0-9]E[0-9][0-9])).*((\.avi)|(\.mkv))$/i)
end

Instance Method Details

#episode_nameObject



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

def episode_name
  "#{@tv_show} S#{@season < 10 ? "0#{@season}" : @season}E#{@number < 10 ? "0#{@number}" : @number}"
end

#episode_name_with_formatObject



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

def episode_name_with_format    
  episode_name + "#{format == 'hd' ? ' 720p' : ''}"
end

#filenameObject



17
18
19
# File 'lib/episode.rb', line 17

def filename
  @name + @ext
end

#good_format?(filename) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
49
50
51
52
53
# File 'lib/episode.rb', line 46

def good_format?(filename)
  case @format
  when 'hd'
    filename.include?('720p') || filename.include?('720')
  when 'sd'
    !filename.include?('720p')
  end
end

#need_srt?(langs) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
35
36
# File 'lib/episode.rb', line 29

def need_srt?(langs)
  need = -1
  langs = langs.reverse
  langs.each do |lang|
    need = langs.index(lang) if @srt.include?(lang) && need < langs.index(lang)
  end
  need != langs.size - 1
end

#srt_filename(lang) ⇒ Object



38
39
40
# File 'lib/episode.rb', line 38

def srt_filename(lang)
  "#{File.dirname(path)}/#{name}.#{lang}.srt"
end