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