class MikePlayer::Song

Attributes

filename[R]

Public Class Methods

as_duration_str(l, t = nil) click to toggle source
# File lib/mikeplayer/song.rb, line 37
def self.as_duration_str(l, t = nil)
  l_hr  = "%02d" % (l / 3600).floor
  l_min = "%02d" % ((l % 3600 )/ 60).floor
  l_sec = "%02d" % (l % 60)
  e_min = "%02d" % (t / 60).floor unless t.nil?
  e_sec = "%02d" % (t % 60) unless t.nil?

  result = "#{l_min}:#{l_sec}"
  result = "#{l_hr}:#{result}" if l >= 3600
  result = "#{e_min}:#{e_sec} [#{result}]" unless t.nil?

  return result
end
new(filename) click to toggle source
# File lib/mikeplayer/song.rb, line 5
def initialize(filename)
  @filename = filename
  @mp3info  = Mp3Info.new(filename)
end

Public Instance Methods

info() click to toggle source
# File lib/mikeplayer/song.rb, line 10
def info
  artist = "#{@mp3info.tag.artist}"
  title  = "#{@mp3info.tag.title}"

  if (true == artist.empty?) && (true == title.empty?)
    return File.basename(@filename, '.mp3')
  elsif (true == artist.empty?)
    artist = "?????"
  elsif (true == title.empty?)
    title  = "?????"
  end

  return "#{artist} - #{title}"
end
length() click to toggle source
# File lib/mikeplayer/song.rb, line 25
def length
  return @mp3info.length || 0
end
length_str(elapsed_time) click to toggle source
# File lib/mikeplayer/song.rb, line 29
def length_str(elapsed_time)
  return Song.as_duration_str(self.length, elapsed_time)
end
to_json() click to toggle source
# File lib/mikeplayer/song.rb, line 33
def to_json
  return @filename.to_s
end