Crate m3u8_rs[][src]

Expand description

A library to parse m3u8 playlists HTTP Live Streaming.

Examples

Parsing a playlist and let the parser figure out if it’s a media or master playlist.

use m3u8_rs::Playlist;
use nom::IResult;
use std::io::Read;

let mut file = std::fs::File::open("playlist.m3u8").unwrap();
let mut bytes: Vec<u8> = Vec::new();
file.read_to_end(&mut bytes).unwrap();

match m3u8_rs::parse_playlist(&bytes) {
    Result::Ok((i, Playlist::MasterPlaylist(pl))) => println!("Master playlist:\n{:?}", pl),
    Result::Ok((i, Playlist::MediaPlaylist(pl))) => println!("Media playlist:\n{:?}", pl),
    Result::Err(e) =>  panic!("Parsing error: \n{}", e),
}

Parsing a master playlist directly

use std::io::Read;
use nom::IResult;

let mut file = std::fs::File::open("masterplaylist.m3u8").unwrap();
let mut bytes: Vec<u8> = Vec::new();
file.read_to_end(&mut bytes).unwrap();

if let Result::Ok((_, pl)) = m3u8_rs::parse_master_playlist(&bytes) {
    println!("{:?}", pl);
}

Creating a playlist and writing it back to a vec/file

use m3u8_rs::{MediaPlaylist, MediaPlaylistType, MediaSegment};

let playlist = MediaPlaylist {
    version: 6,
    target_duration: 3.0,
    media_sequence: 338559,
    discontinuity_sequence: 1234,
    end_list: true,
    playlist_type: Some(MediaPlaylistType::Vod),
    segments: vec![
        MediaSegment {
            uri: "20140311T113819-01-338559live.ts".into(),
            duration: 2.002,
            title: Some("title".into()),
            ..Default::default()
        },
    ],
    ..Default::default()
};

//let mut v: Vec<u8> = Vec::new();
//playlist.write_to(&mut v).unwrap();

//let mut file = std::fs::File::open("playlist.m3u8").unwrap();
//playlist.write_to(&mut file).unwrap();

Structs

A simple #EXT- tag

A Master Playlist provides a set of Variant Streams, each of which describes a different version of the same content.

A Media Playlist contains a list of Media Segments, which when played sequentially will play the multimedia presentation.

A Media Segment is specified by a URI and optionally a byte range.

#EXT-X-SESSION-DATA:<attribute-list> The EXT-X-SESSION-DATA tag allows arbitrary session data to be carried in a Master Playlist.

#EXT-X-SESSION-KEY:<attribute-list> The EXT-X-SESSION-KEY tag allows encryption keys from Media Playlists to be specified in a Master Playlist. This allows the client to preload these keys without having to read the Media Playlist(s) first.

Enums

Functions

When a media tag or no master tag is found, this returns false.

Parse input as a master playlist

Parse input as a master playlist

Parse input as a media playlist

Parse input as a media playlist

Parse an m3u8 playlist.

Parses an m3u8 playlist just like parse_playlist, except that this returns an std::result::Result instead of a nom::IResult. However, since nom::IResult is now an alias to Result, this is no longer needed.