Class: M3u8::PlaylistItem

Inherits:
Object
  • Object
show all
Extended by:
M3u8
Defined in:
lib/m3u8/playlist_item.rb

Overview

PlaylistItem represents a set of EXT-X-STREAM-INF or EXT-X-I-FRAME-STREAM-INF attributes

Constant Summary collapse

MISSING_CODEC_MESSAGE =
'Audio or video codec info should be provided.'

Constants included from M3u8

VERSION

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from M3u8

intialize_with_byterange, parse_attributes, parse_yes_no

Constructor Details

#initialize(params = {}) ⇒ PlaylistItem

Returns a new instance of PlaylistItem.



11
12
13
14
15
16
# File 'lib/m3u8/playlist_item.rb', line 11

def initialize(params = {})
  self.iframe = false
  params.each do |key, value|
    instance_variable_set("@#{key}", value)
  end
end

Instance Attribute Details

#audioObject

Returns the value of attribute audio.



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

def audio
  @audio
end

#audio_codec=(value) ⇒ Object

Sets the attribute audio_codec

Parameters:

  • value

    the value to set the attribute audio_codec to.



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

def audio_codec=(value)
  @audio_codec = value
end

#average_bandwidthObject

Returns the value of attribute average_bandwidth.



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

def average_bandwidth
  @average_bandwidth
end

#bandwidthObject

Returns the value of attribute bandwidth.



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

def bandwidth
  @bandwidth
end

#closed_captionsObject

Returns the value of attribute closed_captions.



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

def closed_captions
  @closed_captions
end

#codecsObject

Returns the value of attribute codecs.



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

def codecs
  @codecs
end

#heightObject

Returns the value of attribute height.



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

def height
  @height
end

#iframeObject

Returns the value of attribute iframe.



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

def iframe
  @iframe
end

#levelObject

Returns the value of attribute level.



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

def level
  @level
end

#profileObject

Returns the value of attribute profile.



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

def profile
  @profile
end

#program_idObject

Returns the value of attribute program_id.



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

def program_id
  @program_id
end

#subtitlesObject

Returns the value of attribute subtitles.



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

def subtitles
  @subtitles
end

#uriObject

Returns the value of attribute uri.



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

def uri
  @uri
end

#videoObject

Returns the value of attribute video.



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

def video
  @video
end

#widthObject

Returns the value of attribute width.



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

def width
  @width
end

Class Method Details

.parse(text) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/m3u8/playlist_item.rb', line 18

def self.parse(text)
  attributes = parse_attributes text
  resolution = parse_resolution attributes['RESOLUTION']
  average = parse_average_bandwidth attributes['AVERAGE-BANDWIDTH']
  options = { program_id: attributes['PROGRAM-ID'],
              codecs: attributes['CODECS'],
              width: resolution[:width],
              height: resolution[:height],
              bandwidth: attributes['BANDWIDTH'].to_i,
              average_bandwidth: average,
              video: attributes['VIDEO'], audio: attributes['AUDIO'],
              uri: attributes['URI'], subtitles: attributes['SUBTITLES'],
              closed_captions: attributes['CLOSED-CAPTIONS'] }
  PlaylistItem.new options
end

Instance Method Details

#resolutionObject



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

def resolution
  return if width.nil?
  "#{width}x#{height}"
end

#to_sObject



55
56
57
58
59
# File 'lib/m3u8/playlist_item.rb', line 55

def to_s
  validate

  m3u8_format
end