Module: Playlist::Format::PLS
- Defined in:
- lib/playlist/format/pls.rb
Overview
Module to parse and generate PLS playlists
Class Method Summary collapse
-
.generate(playlist) ⇒ String
Generate a PLS file from a [Playlist].
-
.parse(input) ⇒ Playlist
Parse a PLS file into a [Playlist].
Class Method Details
.generate(playlist) ⇒ String
Generate a PLS file from a [Playlist]
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/playlist/format/pls.rb', line 18 def generate(playlist) text = "[playlist]\n\n" playlist.tracks.each_with_index do |t, index| index += 1 duration = (t.duration / 1000).round text += "File#{index}=#{t.location}\n" if t.creator && t.title text += "Title#{index}=#{t.creator} - #{t.title}\n" elsif t.title text += "Title#{index}=#{t.title}\n" end text += "Length#{index}=#{duration}\n" text += "\n" end text += "NumberOfEntries=#{playlist.tracks.count}\n" text += "Version=2\n" text end |
.parse(input) ⇒ Playlist
Parse a PLS file into a [Playlist]
8 9 10 11 12 13 |
# File 'lib/playlist/format/pls.rb', line 8 def parse(input) tracks = parse_lines_to_array(input) # Now convert to objects array_to_object(tracks) end |