Class: Media

Inherits:
Object
  • Object
show all
Defined in:
lib/gst-kitchen/media.rb

Defined Under Namespace

Classes: Format

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Media

Returns a new instance of Media.



18
19
20
21
# File 'lib/gst-kitchen/media.rb', line 18

def initialize(file)
  @file = file
  @md5_digest = Digest::MD5.file(@file).hexdigest.force_encoding("UTF-8")
end

Class Method Details

.format(format) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/gst-kitchen/media.rb', line 10

def self.format(format)
  case format
  when :m4a_aac then Media::Format::M4a
  when :mp3_mp3 then Media::Format::Mp3
  when :opus_opus then Media::Format::Opus
  end
end

Instance Method Details

#aquire_meta_data!Object



45
46
47
# File 'lib/gst-kitchen/media.rb', line 45

def aquire_meta_data!
  [:duration, :file_size].each { |m| send(m) }
end

#durationObject



35
36
37
38
39
40
41
42
43
# File 'lib/gst-kitchen/media.rb', line 35

def duration
  return @duration if @duration

  hours = length / (60 * 60)
  minutes = (length - hours * 60 * 60) / 60
  seconds = length % 60

  @duration = "#{"%02i" % hours}:#{"%02i" % minutes}:#{"%02i" % seconds}"
end

#file_sizeObject



31
32
33
# File 'lib/gst-kitchen/media.rb', line 31

def file_size
  @file_size ||= File.size(@file)
end

#lengthObject



23
24
25
# File 'lib/gst-kitchen/media.rb', line 23

def length
  media_info["length"].to_i
end

#titleObject



27
28
29
# File 'lib/gst-kitchen/media.rb', line 27

def title
  media_info["title"]
end