webmetro/src/commands/filter.rs

48 lines
1.1 KiB
Rust
Raw Normal View History

2018-04-12 06:03:46 +00:00
use std::{
error::Error,
io,
io::prelude::*
};
2018-04-13 03:29:12 +00:00
use clap::{App, Arg, ArgMatches, SubCommand};
2018-04-14 08:53:18 +00:00
use futures::prelude::*;
2018-04-12 06:03:46 +00:00
use super::stdin_stream;
2018-04-12 06:03:46 +00:00
use webmetro::{
chunk::{
Chunk,
WebmStream
},
error::WebmetroError,
2018-04-12 06:03:46 +00: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-13 03:29:12 +00: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 06:03:46 +00:00
}
2018-04-13 03:29:12 +00:00
pub fn run(args: &ArgMatches) -> Result<(), Box<Error>> {
2018-04-12 06:03:46 +00:00
let mut chunk_stream: Box<Stream<Item = Chunk, Error = WebmetroError>> = Box::new(
stdin_stream()
2018-04-12 06:03:46 +00:00
.parse_ebml()
.chunk_webm()
.fix_timecodes()
);
2018-04-13 03:29:12 +00:00
if args.is_present("throttle") {
chunk_stream = Box::new(chunk_stream.throttle());
}
chunk_stream.fold((), |_, chunk| {
2018-04-14 08:53:18 +00:00
io::stdout().write_all(chunk.as_ref())
}).wait()?;
Ok(())
2018-04-12 06:03:46 +00:00
}