Class: M3u8::Playlist
- Inherits:
-
Object
- Object
- M3u8::Playlist
- Includes:
- Serializable
- 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
- #cache ⇒ Array, ...
- #discontinuity_sequence ⇒ Array, ...
- #iframes_only ⇒ Array, ...
- #independent_segments ⇒ Array, ...
- #items ⇒ Array, ...
- #live ⇒ Array, ...
- #part_inf ⇒ Array, ...
- #sequence ⇒ Array, ...
- #server_control ⇒ Array, ...
- #target ⇒ Array, ...
- #type ⇒ Array, ...
-
#unknown_tags ⇒ Array<String>
readonly
Unrecognized #EXT tags found while parsing.
- #version ⇒ Array, ...
Class Method Summary collapse
-
.build(options = {}) {|Builder| ... } ⇒ Playlist
Build a playlist using a DSL block.
-
.codecs(options = {}) ⇒ String?
Generate a codecs string from codec options.
-
.from_h(hash) ⇒ Playlist
Reconstruct a playlist from a Hash produced by #to_h.
-
.read(input, strict: false) ⇒ Playlist
Parse an m3u8 playlist from a String or IO.
Instance Method Summary collapse
- #date_ranges ⇒ Array<DateRangeItem>
-
#duration ⇒ Float
Total duration of all segments.
-
#errors ⇒ Array<String>
Collect validation errors for the playlist.
-
#freeze ⇒ Playlist
Freeze the playlist and all its items.
-
#initialize(options = {}) ⇒ Playlist
constructor
A new instance of Playlist.
- #keys ⇒ Array<KeyItem>
-
#live? ⇒ Boolean
Whether this is a live (non-VOD) media playlist.
- #maps ⇒ Array<MapItem>
-
#master? ⇒ Boolean
Whether this is a master (multivariant) playlist.
- #media_items ⇒ Array<MediaItem>
- #parts ⇒ Array<PartItem>
- #playlists ⇒ Array<PlaylistItem>
-
#resolve_variables(imported: {}, query: {}) ⇒ Playlist
Resolve EXT-X-DEFINE variable references into a new Playlist.
- #segments ⇒ Array<SegmentItem>
- #session_data ⇒ Array<SessionDataItem>
- #session_keys ⇒ Array<SessionKeyItem>
-
#to_h ⇒ Hash<Symbol, Object>
Convert the playlist into a Hash of its attributes and items.
-
#to_s ⇒ String
Render the playlist as an m3u8 string.
-
#valid? ⇒ Boolean
Whether the playlist passes all validations.
-
#warnings ⇒ Array<String>
Collect non-fatal conformance warnings (version compatibility and Low-Latency HLS recommendations).
-
#write(output) ⇒ void
Write the playlist to an IO object.
Methods included from Serializable
Constructor Details
#initialize(options = {}) ⇒ Playlist
Returns a new instance of Playlist.
30 31 32 33 34 |
# File 'lib/m3u8/playlist.rb', line 30 def initialize( = {}) () @items = [] @unknown_tags = [] end |
Instance Attribute Details
#cache ⇒ Array, ...
21 22 23 |
# File 'lib/m3u8/playlist.rb', line 21 def cache @cache end |
#discontinuity_sequence ⇒ Array, ...
21 22 23 |
# File 'lib/m3u8/playlist.rb', line 21 def discontinuity_sequence @discontinuity_sequence end |
#iframes_only ⇒ Array, ...
21 22 23 |
# File 'lib/m3u8/playlist.rb', line 21 def iframes_only @iframes_only end |
#independent_segments ⇒ Array, ...
21 22 23 |
# File 'lib/m3u8/playlist.rb', line 21 def independent_segments @independent_segments end |
#items ⇒ Array, ...
21 22 23 |
# File 'lib/m3u8/playlist.rb', line 21 def items @items end |
#live ⇒ Array, ...
21 22 23 |
# File 'lib/m3u8/playlist.rb', line 21 def live @live end |
#part_inf ⇒ Array, ...
21 22 23 |
# File 'lib/m3u8/playlist.rb', line 21 def part_inf @part_inf end |
#sequence ⇒ Array, ...
21 22 23 |
# File 'lib/m3u8/playlist.rb', line 21 def sequence @sequence end |
#server_control ⇒ Array, ...
21 22 23 |
# File 'lib/m3u8/playlist.rb', line 21 def server_control @server_control end |
#target ⇒ Array, ...
21 22 23 |
# File 'lib/m3u8/playlist.rb', line 21 def target @target end |
#type ⇒ Array, ...
21 22 23 |
# File 'lib/m3u8/playlist.rb', line 21 def type @type end |
#unknown_tags ⇒ Array<String> (readonly)
Returns unrecognized #EXT tags found while parsing.
27 28 29 |
# File 'lib/m3u8/playlist.rb', line 27 def @unknown_tags end |
#version ⇒ Array, ...
21 22 23 |
# File 'lib/m3u8/playlist.rb', line 21 def version @version end |
Class Method Details
.build(options = {}) {|Builder| ... } ⇒ Playlist
Build a playlist using a DSL block.
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/m3u8/playlist.rb', line 40 def self.build( = {}, &block) playlist = new() builder = Builder.new(playlist) if block.arity == 1 yield builder else builder.instance_eval(&block) end playlist.freeze end |
.codecs(options = {}) ⇒ String?
Generate a codecs string from codec options.
54 55 56 57 |
# File 'lib/m3u8/playlist.rb', line 54 def self.codecs( = {}) item = PlaylistItem.new() item.codecs end |
.from_h(hash) ⇒ Playlist
Reconstruct a playlist from a Hash produced by #to_h.
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/m3u8/playlist.rb', line 71 def self.from_h(hash) hash = hash.transform_keys(&:to_sym) items = hash.delete(:items) || [] part_inf = hash.delete(:part_inf) server_control = hash.delete(:server_control) playlist = new(hash) playlist.part_inf = nested(PartInfItem, part_inf) playlist.server_control = nested(ServerControlItem, server_control) items.each { |attributes| playlist.items << item_from_h(attributes) } playlist end |
Instance Method Details
#date_ranges ⇒ Array<DateRangeItem>
249 250 251 |
# File 'lib/m3u8/playlist.rb', line 249 def date_ranges items.grep(DateRangeItem) end |
#duration ⇒ Float
Total duration of all segments.
270 271 272 |
# File 'lib/m3u8/playlist.rb', line 270 def duration segments.sum(&:duration) end |
#errors ⇒ Array<String>
Collect validation errors for the playlist.
193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/m3u8/playlist.rb', line 193 def errors [].tap do |errors| validate_mixed_items(errors) validate_target_duration(errors) validate_segment_items(errors) validate_playlist_items(errors) validate_media_items(errors) validate_key_items(errors) validate_session_key_items(errors) validate_session_data_items(errors) validate_part_items(errors) end end |
#freeze ⇒ Playlist
Freeze the playlist and all its items.
153 154 155 156 157 158 159 160 |
# File 'lib/m3u8/playlist.rb', line 153 def freeze items.each { |item| freeze_item(item) } items.freeze .freeze part_inf&.freeze server_control&.freeze super end |
#keys ⇒ Array<KeyItem>
239 240 241 |
# File 'lib/m3u8/playlist.rb', line 239 def keys items.grep(KeyItem) end |
#live? ⇒ Boolean
Whether this is a live (non-VOD) media playlist.
136 137 138 139 140 |
# File 'lib/m3u8/playlist.rb', line 136 def live? return false if master? @live end |
#maps ⇒ Array<MapItem>
244 245 246 |
# File 'lib/m3u8/playlist.rb', line 244 def maps items.grep(MapItem) end |
#master? ⇒ Boolean
Whether this is a master (multivariant) playlist.
144 145 146 147 148 149 |
# File 'lib/m3u8/playlist.rb', line 144 def master? return @master unless @master.nil? return false if playlist_size.zero? && segment_size.zero? playlist_size.positive? end |
#media_items ⇒ Array<MediaItem>
234 235 236 |
# File 'lib/m3u8/playlist.rb', line 234 def media_items items.grep(MediaItem) end |
#parts ⇒ Array<PartItem>
254 255 256 |
# File 'lib/m3u8/playlist.rb', line 254 def parts items.grep(PartItem) end |
#playlists ⇒ Array<PlaylistItem>
229 230 231 |
# File 'lib/m3u8/playlist.rb', line 229 def playlists items.grep(PlaylistItem) end |
#resolve_variables(imported: {}, query: {}) ⇒ Playlist
Resolve EXT-X-DEFINE variable references into a new Playlist.
130 131 132 |
# File 'lib/m3u8/playlist.rb', line 130 def resolve_variables(imported: {}, query: {}) VariableResolver.new(self, imported: imported, query: query).resolve end |
#segments ⇒ Array<SegmentItem>
224 225 226 |
# File 'lib/m3u8/playlist.rb', line 224 def segments items.grep(SegmentItem) end |
#session_data ⇒ Array<SessionDataItem>
259 260 261 |
# File 'lib/m3u8/playlist.rb', line 259 def session_data items.grep(SessionDataItem) end |
#session_keys ⇒ Array<SessionKeyItem>
264 265 266 |
# File 'lib/m3u8/playlist.rb', line 264 def session_keys items.grep(SessionKeyItem) end |
#to_h ⇒ Hash<Symbol, Object>
Convert the playlist into a Hash of its attributes and items. Each item Hash carries an :item_type key identifying its class.
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/m3u8/playlist.rb', line 173 def to_h { master: master?, live: live?, version: version, independent_segments: independent_segments, iframes_only: iframes_only, type: type, target: target, sequence: sequence, discontinuity_sequence: discontinuity_sequence, cache: cache, part_inf: part_inf&.to_h, server_control: server_control&.to_h, items: items.map { |item| item_to_h(item) } } end |
#to_s ⇒ String
Render the playlist as an m3u8 string.
164 165 166 167 168 |
# File 'lib/m3u8/playlist.rb', line 164 def to_s output = StringIO.open write(output) output.string end |
#valid? ⇒ Boolean
Whether the playlist passes all validations.
209 210 211 |
# File 'lib/m3u8/playlist.rb', line 209 def valid? errors.empty? end |
#warnings ⇒ Array<String>
Collect non-fatal conformance warnings (version compatibility and Low-Latency HLS recommendations).
216 217 218 219 220 221 |
# File 'lib/m3u8/playlist.rb', line 216 def warnings [].tap do |list| version_warnings(list) low_latency_warnings(list) end end |