Class: M3u8::Reader

Inherits:
Object
  • Object
show all
Defined in:
lib/m3u8/reader.rb

Overview

Reader provides parsing of m3u8 playlists

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(strict: false) ⇒ Reader

Returns a new instance of Reader.



8
9
10
11
12
13
14
15
16
# File 'lib/m3u8/reader.rb', line 8

def initialize(strict: false)
  @strict = strict
  @has_endlist = false
  @tags = [basic_tags,
           media_segment_tags,
           media_playlist_tags,
           master_playlist_tags,
           universal_tags].inject(:merge)
end

Instance Attribute Details

#itemObject

Returns the value of attribute item.



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

def item
  @item
end

#masterObject

Returns the value of attribute master.



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

def master
  @master
end

#openObject

Returns the value of attribute open.



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

def open
  @open
end

#playlistObject

Returns the value of attribute playlist.



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

def playlist
  @playlist
end

#tagsObject

Returns the value of attribute tags.



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

def tags
  @tags
end

Instance Method Details

#read(input) ⇒ Playlist

Parse an m3u8 playlist from a String or IO.

Parameters:

  • input (String, IO)

    playlist content

Returns:



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/m3u8/reader.rb', line 21

def read(input)
  @playlist = Playlist.new
  @has_endlist = false
  lines = input.is_a?(String) ? input : input.read
  lines.split(/\r\n|\r|\n/).each_with_index do |line, index|
    if index.zero?
      validate_file_format(line)
      next
    end
    parse_line(line)
  end
  playlist.live = !@has_endlist unless master
  playlist.freeze
end