webmetro/src/commands/filter.rs

44 lines
1.2 KiB
Rust
Raw Normal View History

2018-04-12 02:03:46 -04:00
use std::{
io,
io::prelude::*
};
2018-04-12 23:29:12 -04:00
use clap::{App, Arg, ArgMatches, SubCommand};
2018-04-14 04:53:18 -04:00
use futures::prelude::*;
2018-04-12 02:03:46 -04:00
use super::stdin_stream;
2018-04-12 02:03:46 -04:00
use webmetro::{
chunk::{
Chunk,
WebmStream
},
error::WebmetroError,
2018-04-12 02:03:46 -04:00
fixers::ChunkStream,
stream_parser::StreamEbml
};
pub fn options() -> App<'static, 'static> {
SubCommand::with_name("filter")
.about("Copies WebM from stdin to stdout, applying the same cleanup & stripping the relay server does.")
2018-04-12 23:29:12 -04:00
.arg(Arg::with_name("throttle")
.long("throttle")
.help("Slow down output to \"realtime\" speed as determined by the timestamps (useful for streaming)"))
2018-04-12 02:03:46 -04:00
}
pub fn run(args: &ArgMatches) -> Box<Future<Item=(), Error=WebmetroError> + Send> {
let mut chunk_stream: Box<Stream<Item = Chunk, Error = WebmetroError> + Send> = Box::new(
stdin_stream()
2018-04-12 02:03:46 -04:00
.parse_ebml()
.chunk_webm()
.fix_timecodes()
);
2018-04-12 23:29:12 -04:00
if args.is_present("throttle") {
chunk_stream = Box::new(chunk_stream.throttle());
}
Box::new(chunk_stream.for_each(|chunk| {
io::stdout().write_all(chunk.as_ref()).map_err(WebmetroError::IoError)
}))
2018-04-12 02:03:46 -04:00
}