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.



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

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

Instance Attribute Details

#cacheObject

Returns the value of attribute cache.



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

def cache
  @cache
end

#iframes_onlyObject

Returns the value of attribute iframes_only.



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

def iframes_only
  @iframes_only
end

#independent_segmentsObject

Returns the value of attribute independent_segments.



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

def independent_segments
  @independent_segments
end

#itemsObject

Returns the value of attribute items.



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

def items
  @items
end

#sequenceObject

Returns the value of attribute sequence.



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

def sequence
  @sequence
end

#targetObject

Returns the value of attribute target.



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

def target
  @target
end

#typeObject

Returns the value of attribute type.



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

def type
  @type
end

#versionObject

Returns the value of attribute version.



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

def version
  @version
end

Class Method Details

.codecs(options = {}) ⇒ Object



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

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

.read(input) ⇒ Object



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

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

Instance Method Details

#durationObject



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

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)


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

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

#to_sObject



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

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

#valid?Boolean

Returns:

  • (Boolean)


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

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

#write(output) ⇒ Object



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

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