1
0
Fork 0
mirror of https://github.com/sile/hls_m3u8.git synced 2024-11-22 15:21:01 +00:00
hls_m3u8/examples/parse.rs
2019-09-13 16:06:52 +02:00

32 lines
887 B
Rust

extern crate clap;
extern crate hls_m3u8;
use clap::{App, Arg};
use hls_m3u8::{MasterPlaylist, MediaPlaylist};
use std::io::{self, Read};
fn main() {
let matches = App::new("parse")
.arg(
Arg::with_name("M3U8_TYPE")
.long("m3u8-type")
.takes_value(true)
.default_value("media")
.possible_values(&["media", "master"]),
)
.get_matches();
let mut m3u8 = String::new();
io::stdin().read_to_string(&mut m3u8).unwrap();
match matches.value_of("M3U8_TYPE").unwrap() {
"media" => {
let playlist: MediaPlaylist = m3u8.parse().unwrap();
println!("{}", playlist);
}
"master" => {
let playlist: MasterPlaylist = m3u8.parse().unwrap();
println!("{}", playlist);
}
_ => unreachable!(),
}
}