class M3U8::DateRangeItem

Overview

DateRangeItem encapsulates an EXT-X-DATERANGE tag in an HLS playlist.

As defined in RFC 8216, Section 4.3.2.7, the XT-X-DATERANGE tag is used to associate a specific date range with a collection of attribute/value pairs. It is typically used for signaling events such as ad insertion, content segmentation, or SCTE-35 splice points.

Example tag format:

#EXT-X-DATERANGE:ID="...",CLASS="...",START-DATE="...",END-DATE="...",...

The EXT-X-DATERANGE tag stores the following attributes:

Included Modules

Extended Modules

Defined in:

m3u8/date_range_item.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(params : NamedTuple = NamedTuple.new) #

Creates a new DateRangeItem from a NamedTuple of parameters.

The NamedTuple keys should match the attribute names (using symbols):

Examples:

options = {
  id:                "test_id",
  start_date:        "2014-03-05T11:15:00Z",
  class_name:        "test_class",
  end_date:          "2014-03-05T11:16:00Z",
  duration:          60.1,
  planned_duration:  59.993,
  scte35_out:        "0xFC002F0000000000FF0",
  scte35_in:         "0xFC002F0000000000FF1",
  scte35_cmd:        "0xFC002F0000000000FF2",
  end_on_next:       true,
  client_attributes: {"X-CUSTOM" => 45.3},
}
DateRangeItem.new(options)
# => #<M3U8::DateRangeItem:0x7d6bff706f00
#     @class_name="test_class",
#     @client_attributes={"X-CUSTOM" => 45.3},
#     @duration=60.1,
#     @end_date="2014-03-05T11:16:00Z",
#     @end_on_next=true,
#     @id="test_id",
#     @planned_duration=59.993,
#     @scte35_cmd="0xFC002F0000000000FF2",
#     @scte35_in="0xFC002F0000000000FF1",
#     @scte35_out="0xFC002F0000000000FF0",
#     @start_date="2014-03-05T11:15:00Z">

[View source]
def self.new(id : Nil | String = nil, start_date : Nil | String = nil, class_name : Nil | String = nil, end_date : Nil | String = nil, duration : Float64 | Nil = nil, planned_duration : Float64 | Nil = nil, scte35_cmd : Nil | String = nil, scte35_out : Nil | String = nil, scte35_in : Nil | String = nil, end_on_next : Bool | Nil = nil, client_attributes = nil) #

Initializes a new DateRangeItem instance.

The instance variables are directly set from the constructor arguments.

Example:

DateRangeItem.new

[View source]

Class Method Detail

def self.parse(text : String) #

Parses a complete EXT-X-DATERANGE tag line and returns a new DateRangeItem.

The tag line is expected to follow the format defined in RFC 8216:

  #EXT-X-DATERANGE:ID="...",CLASS="...",START-DATE="...",END-DATE="...",...

Examples:

text = %(#EXT-X-DATERANGE:ID="test_id",CLASS="test_class",\
       START-DATE="2014-03-05T11:15:00Z",END-DATE="2014-03-05T11:16:00Z",\
       DURATION=60.1,PLANNED-DURATION=59.993,X-CUSTOM=45.3,\
       SCTE35-CMD=0xFC002F0000000000FF2,SCTE35-OUT=0xFC002F0000000000FF0,\
       SCTE35-IN=0xFC002F0000000000FF1,END-ON-NEXT=YES)
DateRangeItem.parse(text)
# => #<M3U8::DateRangeItem:0x7d6bff706f00
#     @class_name="test_class",
#     @client_attributes={"X-CUSTOM" => 45.3},
#     @duration=60.1,
#     @end_date="2014-03-05T11:16:00Z",
#     @end_on_next=true,
#     @id="test_id",
#     @planned_duration=59.993,
#     @scte35_cmd="0xFC002F0000000000FF2",
#     @scte35_in="0xFC002F0000000000FF1",
#     @scte35_out="0xFC002F0000000000FF0",
#     @start_date="2014-03-05T11:15:00Z">

[View source]

Instance Method Detail

def class_name : String | Nil #

A client-defined category for the date range.


[View source]
def class_name=(class_name : String | Nil) #

A client-defined category for the date range.


[View source]
def client_attributes : ClientAttributeType #

Client-specific attributes (those whose keys start with X-).


[View source]
def client_attributes=(client_attributes : ClientAttributeType) #

Client-specific attributes (those whose keys start with X-).


[View source]
def duration : Float64 | Nil #

The duration in seconds.


[View source]
def duration=(duration : Float64 | Nil) #

The duration in seconds.


[View source]
def end_date : String | Nil #

The end date/time in ISO-8601 format.


[View source]
def end_date=(end_date : String | Nil) #

The end date/time in ISO-8601 format.


[View source]
def end_on_next : Bool | Nil #

A boolean flag; if true, outputs "END-ON-NEXT=YES".


[View source]
def end_on_next=(end_on_next : Bool | Nil) #

A boolean flag; if true, outputs "END-ON-NEXT=YES".


[View source]
def id : String | Nil #

A unique identifier for the date range.


[View source]
def id=(id : String | Nil) #

A unique identifier for the date range.


[View source]
def planned_duration : Float64 | Nil #

The expected duration in seconds.


[View source]
def planned_duration=(planned_duration : Float64 | Nil) #

The expected duration in seconds.


[View source]
def scte35_cmd : String | Nil #

SCTE-35 splice information.


[View source]
def scte35_cmd=(scte35_cmd : String | Nil) #

SCTE-35 splice information.


[View source]
def scte35_in : String | Nil #

SCTE-35 splice information.


[View source]
def scte35_in=(scte35_in : String | Nil) #

SCTE-35 splice information.


[View source]
def scte35_out : String | Nil #

SCTE-35 splice information.


[View source]
def scte35_out=(scte35_out : String | Nil) #

SCTE-35 splice information.


[View source]
def start_date : String | Nil #

The start date/time in ISO-8601 format.


[View source]
def start_date=(start_date : String | Nil) #

The start date/time in ISO-8601 format.


[View source]
def to_s #

Returns the string representation of the EXT-X-DATERANGE tag.

The output is constructed by concatenating all formatted attribute strings (e.g. ID, CLASS, START-DATE, etc.) separated by commas, and prefixed with #EXT-X-DATERANGE:.

Example:

options = {
  id:                "test_id",
  start_date:        "2014-03-05T11:15:00Z",
  class_name:        "test_class",
  end_date:          "2014-03-05T11:16:00Z",
  duration:          60.1,
  planned_duration:  59.993,
  scte35_out:        "0xFC002F0000000000FF0",
  scte35_in:         "0xFC002F0000000000FF1",
  scte35_cmd:        "0xFC002F0000000000FF2",
  end_on_next:       true,
  client_attributes: {"X-CUSTOM" => 45.3},
}
DateRangeItem.new(options).to_s
# => #(EXT-X-DATERANGE:ID="test_id",CLASS="test_class",START-DATE="2014-03-05T11:15:00Z",
#      END-DATE="2014-03-05T11:16:00Z",DURATION=60.1,PLANNED-DURATION=59.993,
#      X-CUSTOM="45.3",SCTE35-CMD=0xFC002F0000000000FF2,
#      SCTE35-OUT=0xFC002F0000000000FF0,SCTE35-IN=0xFC002F0000000000FF1,
#      END-ON-NEXT=YES)

[View source]