Sha256: 666dce9d6ac733481d9b9f453f364c9f73f3c6107b52383c42eba6e09bf13e5e

Contents?: true

Size: 1.04 KB

Versions: 9

Compression:

Stored size: 1.04 KB

Contents

module M3u8
  # Writer provides generation of text output of playlists in m3u8 format
  class Writer
    attr_accessor :io

    def initialize(io)
      self.io = io
    end

    def write(playlist)
      validate playlist

      io.puts '#EXTM3U'
      write_header(playlist) unless playlist.master?

      playlist.items.each do |item|
        io.puts item.to_s
      end

      return if playlist.master?
      io.puts '#EXT-X-ENDLIST'
    end

    private

    def validate(playlist)
      return if playlist.valid?
      fail PlaylistTypeError, 'Playlist is invalid.'
    end

    def write_header(playlist)
      io.puts "#EXT-X-PLAYLIST-TYPE:#{playlist.type}" unless playlist.type.nil?
      io.puts "#EXT-X-VERSION:#{playlist.version}"
      io.puts '#EXT-X-I-FRAMES-ONLY' if playlist.iframes_only
      io.puts "#EXT-X-MEDIA-SEQUENCE:#{playlist.sequence}"
      io.puts "#EXT-X-ALLOW-CACHE:#{cache(playlist)}"
      io.puts "#EXT-X-TARGETDURATION:#{playlist.target}"
    end

    def cache(playlist)
      playlist.cache ? 'YES' : 'NO'
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
m3u8-0.6.6 lib/m3u8/writer.rb
m3u8-0.6.5 lib/m3u8/writer.rb
m3u8-0.6.4 lib/m3u8/writer.rb
m3u8-0.6.3 lib/m3u8/writer.rb
m3u8-0.6.2 lib/m3u8/writer.rb
m3u8-0.6.1 lib/m3u8/writer.rb
m3u8-0.5.3 lib/m3u8/writer.rb
m3u8-0.5.2 lib/m3u8/writer.rb
m3u8-0.5.1 lib/m3u8/writer.rb