Class: MovieFile

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, stdout = nil) ⇒ MovieFile

Returns a new instance of MovieFile.



67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/subdl.rb', line 67

def initialize filename, stdout=nil
  @filename = filename
  text = File.basename filename
  text = remove_year_from text

  if m = /^(.*)\.S(\d\d)E(\d\d)/.match(text)
    @show = m[1].gsub '.', ' '
    @season = remove_leading_zeros m[2]
    @episode = remove_leading_zeros m[3]
  end
  @stdout = stdout
end

Instance Attribute Details

#episodeObject (readonly)

Returns the value of attribute episode.



65
66
67
# File 'lib/subdl.rb', line 65

def episode
  @episode
end

#seasonObject (readonly)

Returns the value of attribute season.



65
66
67
# File 'lib/subdl.rb', line 65

def season
  @season
end

#showObject (readonly)

Returns the value of attribute show.



65
66
67
# File 'lib/subdl.rb', line 65

def show
  @show
end

Instance Method Details

#next_distinguisherObject



100
101
102
103
104
105
106
107
108
# File 'lib/subdl.rb', line 100

def next_distinguisher
  if @subs_added
    distinguisher = ".#{@subs_added}"
  else
    distinguisher = ''
  end
  @subs_added = @subs_added.to_i + 1
  return distinguisher
end

#remove_leading_zeros(text) ⇒ Object



84
85
86
# File 'lib/subdl.rb', line 84

def remove_leading_zeros text
  text.gsub /^0*/, ''
end

#remove_year_from(text) ⇒ Object



80
81
82
# File 'lib/subdl.rb', line 80

def remove_year_from text
  text.gsub /\.20\d\d/, ''
end

#save_subtitle(contents, fs, source_id) ⇒ Object

TODO: accept filename instead of source_id



93
94
95
96
97
98
# File 'lib/subdl.rb', line 93

def save_subtitle contents, fs, source_id
  srt_filename = @filename.gsub /.mp4$/, ''
  srt_filename += ".#{source_id}#{next_distinguisher}.srt"
  @stdout.puts "Downloaded as #{srt_filename}"
  fs.save_file srt_filename, contents
end

#search_termObject



88
89
90
# File 'lib/subdl.rb', line 88

def search_term
  "%s %dx%02d" % [show, season, episode]
end