Function m3u8_rs::parse_playlist
source · pub fn parse_playlist(input: &[u8]) -> IResult<&[u8], Playlist>
Expand description
Parse an m3u8 playlist.
§Examples
use std::io::Read;
use m3u8_rs::Playlist;
let mut file = std::fs::File::open("playlist.m3u8").unwrap();
let mut bytes: Vec<u8> = Vec::new();
file.read_to_end(&mut bytes).unwrap();
let parsed = m3u8_rs::parse_playlist(&bytes);
let playlist = match parsed {
Result::Ok((i, playlist)) => playlist,
Result::Err(e) => panic!("Parsing error: \n{}", e),
};
match playlist {
Playlist::MasterPlaylist(pl) => println!("Master playlist:\n{:?}", pl),
Playlist::MediaPlaylist(pl) => println!("Media playlist:\n{:?}", pl),
}
Examples found in repository?
examples/with_nom_result.rs (line 9)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
fn main() {
let mut file = std::fs::File::open("playlist.m3u8").unwrap();
let mut bytes: Vec<u8> = Vec::new();
file.read_to_end(&mut bytes).unwrap();
let parsed = m3u8_rs::parse_playlist(&bytes);
let playlist = match parsed {
Result::Ok((_i, playlist)) => playlist,
Result::Err(e) => panic!("Parsing error: \n{}", e),
};
match playlist {
Playlist::MasterPlaylist(pl) => println!("Master playlist:\n{:?}", pl),
Playlist::MediaPlaylist(pl) => println!("Media playlist:\n{:?}", pl),
}
}
#[allow(unused)]
fn main_alt() {
let mut file = std::fs::File::open("playlist.m3u8").unwrap();
let mut bytes: Vec<u8> = Vec::new();
file.read_to_end(&mut bytes).unwrap();
let parsed = m3u8_rs::parse_playlist(&bytes);
match parsed {
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),
}
}