I just released a new version of my m3u8 gem, this new version provides parsing of m3u8 playlists used in HTTP Live Streaming (HLS). It represents a significant refactoring since the original scope of the project was limited to only generation of playlists.

You can now read a playlist into the newly extended object model, modify or add segments/child playlists, and generate a new m3u8 output file. There is a new items array made up of either PlaylistItem instances for master playlists or SegmentItem instances for regular playlists containing MPEG transport stream files (MPEG-TS). New validation has been added to support modifying and adding items in this array.

require 'm3u8'
require 'tempfile'

file = File.open 'master.m3u8'
playlist = M3u8::Playlist.read file

# individual playlist items are accessed via this array:

# create a new playlist item with attributes:
params = { program_id: 1, width: 1920, height: 1080, profile: 'high',
           level: 4.1, audio: 'aac-lc', bitrate: 92000,
           playlist: 'http://test.url/veryhigh.m3u8' }
item = M3u8::PlaylistItem.new(params)

# insert at top of the master playlist:
playlist.items.insert 0, item

# generate new playlist output file with the modifications:
tmp = Tempfile.new 'master1.m3u8'
playlist.write tmp

You end up with a master playlist that looks something like this, with the new adaptive bitrate streaming quality level on top:


Regular playlists containing MPEG-TS segments (the kind of playlists each entry in the above master playlist would point to) work the same way except you use the SegmentItem class instead for the individual items that make up the playlist.

Feel free to take a look at the specs to get a better idea of how the API works.