class AirPlayer::Playlist

Public Class Methods

new(options = {}) click to toggle source
# File lib/airplayer/playlist.rb, line 7
def initialize(options = {})
  @shuffle = options['shuffle'] || false
  @repeat  = options['repeat'] || false
end

Public Instance Methods

add(item) click to toggle source
# File lib/airplayer/playlist.rb, line 12
def add(item)
  case type(item)
  when :local_dir
    concat(media_in_local(item))
  when :podcast
    concat(media_in_podcast(item))
  when :url
    push(Media.new(item))
  end

  self
end
entries(&blk) click to toggle source
# File lib/airplayer/playlist.rb, line 25
def entries(&blk)
  loop do
    shuffle! if @shuffle
    send(:each, &blk)
    break unless @repeat
  end
end

Private Instance Methods

media_in_local(path) click to toggle source
# File lib/airplayer/playlist.rb, line 45
def media_in_local(path)
  Dir.entries(File.expand_path(path)).sort.map do |node|
    Media.new(File.expand_path(node, path)) if Media.playable? node
  end.compact
end
media_in_podcast(path) click to toggle source
# File lib/airplayer/playlist.rb, line 51
def media_in_podcast(path)
  strict_parse = false
  RSS::Parser.parse(path, strict_parse).items.map do |node|
    Media.new(node.link)
  end
end
type(item) click to toggle source
# File lib/airplayer/playlist.rb, line 35
def type(item)
  if Dir.exist?(File.expand_path(item))
    :local_dir
  elsif Media.playable?(item)
    :url
  elsif item.match(/.+(xml|rss)$/)
    :podcast
  end
end