Class: Ktsh::Meta

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(video_path, samples, width) ⇒ Meta

Returns a new instance of Meta.



14
15
16
17
18
19
20
21
22
# File 'lib/ktsh.rb', line 14

def initialize(video_path, samples, width)
  @video_path = video_path
  @samples = samples
  @width = width
  @tmpdir = FileUtils.mkdir_p(File.join(Dir.tmpdir, 'ktsh', SecureRandom.uuid))[0]

  probe_video
  extract_thumbnails
end

Instance Attribute Details

#durationObject (readonly)

Returns the value of attribute duration.



12
13
14
# File 'lib/ktsh.rb', line 12

def duration
  @duration
end

#resolutionObject (readonly)

Returns the value of attribute resolution.



12
13
14
# File 'lib/ktsh.rb', line 12

def resolution
  @resolution
end

#samplesObject (readonly)

Returns the value of attribute samples.



12
13
14
# File 'lib/ktsh.rb', line 12

def samples
  @samples
end

#sizeObject (readonly)

Returns the value of attribute size.



12
13
14
# File 'lib/ktsh.rb', line 12

def size
  @size
end

#tmpdirObject (readonly)

Returns the value of attribute tmpdir.



12
13
14
# File 'lib/ktsh.rb', line 12

def tmpdir
  @tmpdir
end

#video_pathObject (readonly)

Returns the value of attribute video_path.



12
13
14
# File 'lib/ktsh.rb', line 12

def video_path
  @video_path
end

#widthObject (readonly)

Returns the value of attribute width.



12
13
14
# File 'lib/ktsh.rb', line 12

def width
  @width
end

Instance Method Details

#info_fileObject



24
25
26
27
28
29
30
# File 'lib/ktsh.rb', line 24

def info_file
  File.join(tmpdir, 'info.txt').tap do |name|
    File.open(name, 'w') do |f|
      f.puts "名称: #{File.basename(video_path)}\n体积: #{human_size(size)}\n尺寸: #{resolution}\n时长: #{human_time(duration)}"
    end
  end
end