1
0
Fork 0
mirror of https://github.com/sile/hls_m3u8.git synced 2024-11-15 20:01:01 +00:00
hls_m3u8/examples/parse.rs

37 lines
944 B
Rust
Raw Normal View History

2018-02-13 15:25:33 +00:00
extern crate clap;
2018-02-11 06:10:52 +00:00
extern crate hls_m3u8;
#[macro_use]
extern crate trackable;
use std::io::{self, Read};
2018-02-13 15:25:33 +00:00
use clap::{App, Arg};
use hls_m3u8::media_playlist::MediaPlaylist;
2018-02-11 06:10:52 +00:00
use trackable::error::Failure;
fn main() {
2018-02-13 15:25:33 +00:00
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();
2018-02-11 06:10:52 +00:00
let mut m3u8 = String::new();
track_try_unwrap!(
io::stdin()
.read_to_string(&mut m3u8)
.map_err(Failure::from_error)
);
2018-02-13 15:25:33 +00:00
match matches.value_of("M3U8_TYPE").unwrap() {
"media" => {
let playlist: MediaPlaylist = track_try_unwrap!(m3u8.parse());
println!("{}", playlist);
}
"master" => unimplemented!(),
_ => unreachable!(),
2018-02-11 06:10:52 +00:00
}
}