Module: Playlist::Format::Cue
- Defined in:
- lib/playlist/format/cue.rb
Overview
Module to parse and generate Cue Sheet file format
Class Method Summary collapse
-
.generate(playlist) ⇒ String
Generate a Cue Sheet from a Playlist.
-
.parse(input) ⇒ Playlist
Parse a Cue Sheet file into a [Playlist].
Class Method Details
.generate(playlist) ⇒ String
Generate a Cue Sheet from a Playlist
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/playlist/format/cue.rb', line 31 def generate(playlist) text = '' playlist.calculate_start_times text += generate_line(0, 'TITLE', playlist.title) text += generate_line( 0, 'FILE', format_filename(playlist.media_location), false ) playlist.tracks.each_with_index do |track, index| text += generate_track(track, index + 1) end text end |
.parse(input) ⇒ Playlist
Parse a Cue Sheet file into a [Playlist]
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/playlist/format/cue.rb', line 8 def parse(input) Playlist.new do |playlist| track = nil input.each_line do |line| if line =~ /^\s*REM\s/ next elsif (matches = line.match(/^\s*TRACK (\d+) AUDIO/)) track = Playlist::Track.new( :track_number => matches[1].to_i ) playlist.add_track(track) elsif !track.nil? parse_track_line(track, line.strip) else parse_playlist_line(playlist, line.strip) end end end end |