Class: Sh::Playlist

Inherits:
Object show all
Defined in:
lib/sh_playlist.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir) ⇒ Playlist

Returns a new instance of Playlist.



3
4
5
6
# File 'lib/sh_playlist.rb', line 3

def initialize dir
  @dir = dir
  @songs = []
end

Class Method Details

.parse(path) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/sh_playlist.rb', line 8

def Playlist.parse(path)
  list = Playlist.new(File.dirname(path))
  open(path) do |f|
    while line = f.gets
      line.strip!
      unless line[0] == ?# or line.empty?
        ref = File.expand_path(line.gsub('\\', '/'), File.dirname(path))
        if File.exists? ref
          if Sh::Global::SUPPORTED_EXTENSIONS.include? File.extname(ref)
            list << ($db.songs(:path => ref).first || Sh::Song.new(ref).read_tags!)
          end
        else
          puts "Not found: " + ref
        end
      end
    end
  end
  return list
end

Instance Method Details

#<<(song) ⇒ Object



28
29
30
# File 'lib/sh_playlist.rb', line 28

def <<(song)
  @songs << song
end

#songsObject



32
33
34
# File 'lib/sh_playlist.rb', line 32

def songs
  return @songs.dup
end