Class: Livelist::Playlist

Inherits:
Object
  • Object
show all
Defined in:
lib/livelist/playlist.rb

Overview

A Playlist m3u8

Instance Method Summary collapse

Constructor Details

#initialize(path, options = {}) ⇒ Playlist

Returns a new instance of Playlist.

Parameters:

  • path (String)

    where will be the final m3u8

  • options (Hash) (defaults to: {})

    all options allowed

Options Hash (options):

  • :version (Integer)

    playlist version defaults 1

  • :allow (Boolean)

    playlist allow cache defaults false

  • :target_duration (Integer)

    playlist target duration in seconds defaults 10

Raises:



14
15
16
17
18
19
# File 'lib/livelist/playlist.rb', line 14

def initialize(path, options = {})
  @path = path
  @options = options
  @tag = "#EXTM3U"
  raise Exceptions::InvalidFormat unless File.extname(path) == '.m3u8'
end

Instance Method Details

#pathObject



21
22
23
# File 'lib/livelist/playlist.rb', line 21

def path
  @path
end

#to_sObject

Return a string version of m3u8 file



40
41
42
43
44
45
46
47
48
# File 'lib/livelist/playlist.rb', line 40

def to_s
  [
    @tag,
    version,
    media_sequence,
    allow_cache?,
    target_duration
  ].join("\n")
end

#writeObject

Write the m3u8 file



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/livelist/playlist.rb', line 26

def write
  File.open(@path, 'w') do |file|
    [
      @tag,
      type,
      version,
      media_sequence,
      allow_cache?,
      target_duration,
    ].each { |tag| file.puts tag }
  end
end