Class: Jwthumbs::Movie

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path = nil, options = {}) ⇒ Movie

Returns a new instance of Movie.

Raises:

  • (Errno::ENOENT)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/movie.rb', line 10

def initialize(file_path=nil, options={})
	raise Errno::ENOENT, "the file '#{file_path}' does not exist" unless File.exists?(file_path)

	command = "ffprobe -i #{file_path} -show_format | grep duration"
	output = Open3.popen3(command) { |stdin, stdout, stderr| stderr.read }
	output[/Duration: (\d{2}):(\d{2}):(\d{2}\.\d{2})/]
	@duration = ($1.to_i*60*60) + ($2.to_i*60) + $3.to_f

	@file_path = file_path
	@clear_files = options[:clear_files] ||= true
	@seconds_between = options[:seconds_between] ||= @duration.to_i/10
	@thumb_width = options[:thumb_width] ||= 100 
	@spritefile = options[:spritefile] ||= "#{File.basename(@file_path, File.extname(@file_path))}_sprite.jpg"
	@vttfile_name = options[:vttfile_name] ||= "thumbs.vtt"
	@outdir = options[:thumb_outdir] ||= "output/thumbs_#{Time.now.to_i.to_s}"
	@vttfile = File.basename(@file_path, File.extname(@file_path))+"_"+@vttfile_name	
	@gallery_mode_on = options[:gallery_mode_on] ||= false
end

Instance Attribute Details

#clear_filesObject

Returns the value of attribute clear_files.



8
9
10
# File 'lib/movie.rb', line 8

def clear_files
  @clear_files
end

#durationObject (readonly)

Returns the value of attribute duration.



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

def duration
  @duration
end

#file_pathObject (readonly)

Returns the value of attribute file_path.



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

def file_path
  @file_path
end

Returns the value of attribute gallery_mode_on.



8
9
10
# File 'lib/movie.rb', line 8

def gallery_mode_on
  @gallery_mode_on
end

#outdirObject

Returns the value of attribute outdir.



8
9
10
# File 'lib/movie.rb', line 8

def outdir
  @outdir
end

#seconds_betweenObject

Returns the value of attribute seconds_between.



8
9
10
# File 'lib/movie.rb', line 8

def seconds_between
  @seconds_between
end

#spritefileObject

Returns the value of attribute spritefile.



8
9
10
# File 'lib/movie.rb', line 8

def spritefile
  @spritefile
end

#thumb_widthObject

Returns the value of attribute thumb_width.



8
9
10
# File 'lib/movie.rb', line 8

def thumb_width
  @thumb_width
end

#vttfileObject

Returns the value of attribute vttfile.



8
9
10
# File 'lib/movie.rb', line 8

def vttfile
  @vttfile
end

Instance Method Details

#create_thumbs!Object



30
31
32
# File 'lib/movie.rb', line 30

def create_thumbs!
	Shutter.new(self)
end