class Media
Public Class Methods
format(format)
click to toggle source
# 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
new(file)
click to toggle source
# 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
Public Instance Methods
aquire_meta_data!()
click to toggle source
# File lib/gst-kitchen/media.rb, line 45 def aquire_meta_data! [:duration, :file_size].each { |m| send(m) } end
duration()
click to toggle source
# 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_size()
click to toggle source
# File lib/gst-kitchen/media.rb, line 31 def file_size @file_size ||= File.size(@file) end
length()
click to toggle source
# File lib/gst-kitchen/media.rb, line 23 def length media_info["length"].to_i end
title()
click to toggle source
# File lib/gst-kitchen/media.rb, line 27 def title media_info["title"] end
Private Instance Methods
media_info()
click to toggle source
# File lib/gst-kitchen/media.rb, line 51 def media_info return @media_info if @media_info @media_info = TagLib::FileRef.open(@file) do |ref| { "title" => ref.tag.title, "length" => ref.audio_properties.length } end end