class Elasticmusic::Song

Public Instance Methods

set_metatags() click to toggle source
# File lib/elasticmusic/song.rb, line 12
def set_metatags
  fileref = TagLib::FileRef.new(path)

  unless fileref.null?
    self.tag        = tags(fileref)
    self.properties = audio_properties(fileref)
    fileref.close
  end
end

Private Instance Methods

audio_properties(fileref) click to toggle source
# File lib/elasticmusic/song.rb, line 35
def audio_properties(fileref)
  {
    bitrate:     fileref.audio_properties.bitrate,
    channels:    fileref.audio_properties.channels,
    length:      fileref.audio_properties.length,
    sample_rate: fileref.audio_properties.sample_rate
  }
end
tags(fileref) click to toggle source
# File lib/elasticmusic/song.rb, line 24
def tags(fileref)
  {
    title:  fileref.tag.title,
    artist: fileref.tag.artist,
    album:  fileref.tag.album,
    genre:  fileref.tag.genre,
    track:  fileref.tag.track,
    year:   fileref.tag.year
  }
end
validate_file() click to toggle source
# File lib/elasticmusic/song.rb, line 44
def validate_file
  if File.exists?(path.to_s)
    if !Elasticmusic::SUPPORTED_FORMATS.include?(File.extname(path))
      errors.add(:path, "The format #{File.extname(path).downcase} is not suported")
    end
  else
    errors.add(:path, 'The specified path is not valid')
  end
end