Class: M3u8::SegmentItem

Inherits:
Object
  • Object
show all
Includes:
M3u8, AttributeFormatter, Serializable
Defined in:
lib/m3u8/segment_item.rb

Overview

SegmentItem represents EXTINF attributes with the URI that follows, optionally allowing an EXT-X-BYTERANGE tag to be set.

Constant Summary

Constants included from M3u8

VERSION

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Serializable

#as_json, serialize, #to_h, #to_json

Methods included from AttributeFormatter

#boolean_format, #decimal_format, #quoted_format, #unquoted_format

Methods included from M3u8

#initialize_with_byterange, #parse_attributes, #parse_float, #parse_int, #parse_yes_no, #to_yes_no

Constructor Details

#initialize(params = {}) ⇒ SegmentItem

Returns a new instance of SegmentItem.

Parameters:

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

    attribute key-value pairs



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

def initialize(params = {})
  initialize_with_byterange(params)
end

Instance Attribute Details

#byterangeFloat, ...

Returns:

  • (Float, nil)

    segment duration in seconds

  • (String, nil)

    segment URI

  • (String, nil)

    human-readable comment after duration

  • (TimeItem, Time, nil)

    program date-time

  • (ByteRange, nil)

    byte range



16
17
18
# File 'lib/m3u8/segment_item.rb', line 16

def byterange
  @byterange
end

#commentFloat, ...

Returns:

  • (Float, nil)

    segment duration in seconds

  • (String, nil)

    segment URI

  • (String, nil)

    human-readable comment after duration

  • (TimeItem, Time, nil)

    program date-time

  • (ByteRange, nil)

    byte range



16
17
18
# File 'lib/m3u8/segment_item.rb', line 16

def comment
  @comment
end

#durationFloat, ...

Returns:

  • (Float, nil)

    segment duration in seconds

  • (String, nil)

    segment URI

  • (String, nil)

    human-readable comment after duration

  • (TimeItem, Time, nil)

    program date-time

  • (ByteRange, nil)

    byte range



16
17
18
# File 'lib/m3u8/segment_item.rb', line 16

def duration
  @duration
end

#program_date_timeFloat, ...

Returns:

  • (Float, nil)

    segment duration in seconds

  • (String, nil)

    segment URI

  • (String, nil)

    human-readable comment after duration

  • (TimeItem, Time, nil)

    program date-time

  • (ByteRange, nil)

    byte range



16
17
18
# File 'lib/m3u8/segment_item.rb', line 16

def program_date_time
  @program_date_time
end

#segmentFloat, ...

Returns:

  • (Float, nil)

    segment duration in seconds

  • (String, nil)

    segment URI

  • (String, nil)

    human-readable comment after duration

  • (TimeItem, Time, nil)

    program date-time

  • (ByteRange, nil)

    byte range



16
17
18
# File 'lib/m3u8/segment_item.rb', line 16

def segment
  @segment
end

Class Method Details

.parse(text) ⇒ SegmentItem

Parse an EXTINF tag line.

Parameters:

  • text (String)

    raw tag line

Returns:



26
27
28
29
30
31
32
# File 'lib/m3u8/segment_item.rb', line 26

def self.parse(text)
  values = text.gsub('#EXTINF:', '')
               .tr("\n", ',').split(',')
  options = { duration: values[0].to_f }
  options[:comment] = values[1] unless values[1].nil?
  SegmentItem.new(options)
end

Instance Method Details

#date_formatObject



41
42
43
44
45
46
47
48
49
50
# File 'lib/m3u8/segment_item.rb', line 41

def date_format
  return if program_date_time.nil?

  pdt = if program_date_time.is_a?(TimeItem)
          program_date_time
        else
          TimeItem.new(time: program_date_time)
        end
  "#{pdt}\n"
end

#to_sString

Render as an m3u8 EXTINF tag with segment URI.

Returns:

  • (String)


36
37
38
39
# File 'lib/m3u8/segment_item.rb', line 36

def to_s
  "#EXTINF:#{decimal_format(duration)},#{comment}#{byterange_format}" \
    "\n#{date_format}#{segment}"
end