M3U8::DateRangeItem
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:
- ID (required): A unique identifier for the date range.
- CLASS (optional): A client-defined category for the date range.
- START-DATE (required): The starting date/time in ISO-8601 format.
- END-DATE (optional): The ending date/time in ISO-8601 format.
- DURATION (optional): The duration of the date range, in seconds.
- PLANNED-DURATION (optional): The expected duration, in seconds.
- SCTE35-CMD, SCTE35-OUT, SCTE35-IN (optional): Attributes carrying SCTE-35 splice data.
- END-ON-NEXT (optional): A boolean flag that, if true, outputs
"END-ON-NEXT=YES". - Client-specific attributes (optional): Any additional attributes with keys starting with
X-.
Constructors
Creates a new DateRangeItem from a NamedTuple of parameters.
The NamedTuple keys should match the attribute names (using symbols):
idstart_dateclass_nameend_datedurationplanned_duration,scte35_cmdscte35_outscte35_inend_on_nextclient_attributes.
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">
Initializes a new DateRangeItem instance.
The instance variables are directly set from the constructor arguments.
Example:
DateRangeItem.new
Class methods
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">
Instance methods
Client-specific attributes (those whose keys start with X-).
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)