Class: M3u8::Playlist

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

Overview

Playlist represents an m3u8 playlist, it can be a master playlist or a set of media segments

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Playlist

Returns a new instance of Playlist.



8
9
10
11
# File 'lib/m3u8/playlist.rb', line 8

def initialize(options = {})
  assign_options options
  self.items = []
end

Instance Attribute Details

#cacheObject

Returns the value of attribute cache.



5
6
7
# File 'lib/m3u8/playlist.rb', line 5

def cache
  @cache
end

#iframes_onlyObject

Returns the value of attribute iframes_only.



5
6
7
# File 'lib/m3u8/playlist.rb', line 5

def iframes_only
  @iframes_only
end

#itemsObject

Returns the value of attribute items.



5
6
7
# File 'lib/m3u8/playlist.rb', line 5

def items
  @items
end

#sequenceObject

Returns the value of attribute sequence.



5
6
7
# File 'lib/m3u8/playlist.rb', line 5

def sequence
  @sequence
end

#targetObject

Returns the value of attribute target.



5
6
7
# File 'lib/m3u8/playlist.rb', line 5

def target
  @target
end

#typeObject

Returns the value of attribute type.



5
6
7
# File 'lib/m3u8/playlist.rb', line 5

def type
  @type
end

#versionObject

Returns the value of attribute version.



5
6
7
# File 'lib/m3u8/playlist.rb', line 5

def version
  @version
end

Class Method Details

.codecs(options = {}) ⇒ Object



13
14
15
16
# File 'lib/m3u8/playlist.rb', line 13

def self.codecs(options = {})
  item = PlaylistItem.new options
  item.codecs
end

.read(input) ⇒ Object



18
19
20
21
# File 'lib/m3u8/playlist.rb', line 18

def self.read(input)
  reader = Reader.new
  reader.read input
end

Instance Method Details

#durationObject



44
45
46
47
48
49
50
# File 'lib/m3u8/playlist.rb', line 44

def duration
  duration = 0.0
  items.each do |item|
    duration += item.duration if item.is_a?(M3u8::SegmentItem)
  end
  duration
end

#master?Boolean

Returns:

  • (Boolean)


28
29
30
31
# File 'lib/m3u8/playlist.rb', line 28

def master?
  return false if playlist_size == 0 && segment_size == 0
  playlist_size > 0
end

#to_sObject



33
34
35
36
37
# File 'lib/m3u8/playlist.rb', line 33

def to_s
  output = StringIO.open
  write output
  output.string
end

#valid?Boolean

Returns:

  • (Boolean)


39
40
41
42
# File 'lib/m3u8/playlist.rb', line 39

def valid?
  return false if playlist_size > 0 && segment_size > 0
  true
end

#write(output) ⇒ Object



23
24
25
26
# File 'lib/m3u8/playlist.rb', line 23

def write(output)
  writer = Writer.new output
  writer.write self
end