In Files

Parent

Included Modules

OggInfo

Constants

VERSION

Attributes

channels[R]
nominal_bitrate[R]
samplerate[R]
tag[R]

tag is a hash containing the vorbis tag like "Artist", "Title", and the like

Public Class Methods

new(filename, charset = nil) click to toggle source

create new instance of OggInfo use of charset is deprecated! please use utf-8 encoded strings and leave charset to nil")

# File lib/ogginfo.rb, line 39
def initialize(filename, charset = nil)
  if charset
    warn("use of charset is deprecated! please use utf-8 encoded tags")
  end
  @filename = filename
  @length = nil
  @bitrate = nil
  filesize = File.size(@filename)
  File.open(@filename, 'rb') do |file|
    begin
      info = read_headers(file)
      @samplerate = info[:samplerate]
      @nominal_bitrate = info[:nominal_bitrate]
      @channels = info[:channels]
      @tag = info[:tag]
      # filesize is used to calculate bitrate
      # but we don't want to include the headers
      @filesize = file.stat.size - file.pos
    rescue Ogg::StreamError => se
      raise(OggInfoError, se.message, se.backtrace)
    end
  end

  @original_tag = @tag.dup
end
open(*args) click to toggle source

"block version" of ::new()

# File lib/ogginfo.rb, line 84
def self.open(*args)
  m = self.new(*args)
  ret = nil
  if block_given?
    begin
      ret = yield(m)
    ensure
      m.close
    end
  else
    ret = m
  end
  ret
end

Public Instance Methods

bitrate() click to toggle source

Calculated bit rate, also lazily loaded since we depend on the length

# File lib/ogginfo.rb, line 79
def bitrate
  @bitrate ||= (@filesize * 8).to_f / length()
end
close() click to toggle source

commits any tags to file

# File lib/ogginfo.rb, line 100
def close
  if tag != @original_tag
    path = File.join(Dir.tmpdir, "ruby-ogginfo_#{$$}.ogg") 
    tempfile = File.new(path, "wb")

    File.open(@filename, "rb") do | input |
      replace_tags(input, tempfile, tag)
    end
    tempfile.close
    FileUtils.mv(path, @filename)
  end
end
hastag?() click to toggle source

check the presence of a tag

# File lib/ogginfo.rb, line 114
def hastag?
  !tag.empty?
end
length() click to toggle source

The length in seconds of the track since this requires reading the whole file we only get it if called

# File lib/ogginfo.rb, line 68
def length
  unless @length
    File.open(@filename) do |file|
      @length = compute_length(file)
    end
  end
  return @length 
end
to_s() click to toggle source
# File lib/ogginfo.rb, line 118
def to_s
  "channels #{channels} samplerate #{samplerate} bitrate #{nominal_bitrate} #{tag.inspect}"
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.