2018-04-12 06:03:46 +00:00
|
|
|
use std::{
|
|
|
|
io,
|
|
|
|
io::prelude::*
|
|
|
|
};
|
|
|
|
|
2018-04-13 03:29:12 +00:00
|
|
|
use clap::{App, Arg, ArgMatches, SubCommand};
|
2020-05-08 03:14:43 +00:00
|
|
|
use futures::prelude::*;
|
2018-04-12 06:03:46 +00:00
|
|
|
|
2018-04-14 22:18:50 +00:00
|
|
|
use super::stdin_stream;
|
2018-04-12 06:03:46 +00:00
|
|
|
use webmetro::{
|
|
|
|
chunk::{
|
|
|
|
Chunk,
|
|
|
|
WebmStream
|
|
|
|
},
|
2018-04-14 08:45:35 +00:00
|
|
|
error::WebmetroError,
|
2019-10-11 04:28:08 +00:00
|
|
|
fixers::{
|
|
|
|
ChunkTimecodeFixer,
|
2019-10-21 07:18:51 +00:00
|
|
|
Throttle,
|
2019-10-11 04:28:08 +00:00
|
|
|
},
|
2018-04-12 06:03:46 +00:00
|
|
|
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")
|
2018-04-15 05:43:23 +00:00
|
|
|
.help("Slow down output to \"real time\" speed as determined by the timestamps (useful for streaming static files)"))
|
2018-04-12 06:03:46 +00:00
|
|
|
}
|
|
|
|
|
2020-05-08 03:14:43 +00:00
|
|
|
#[tokio::main]
|
|
|
|
pub async fn run(args: &ArgMatches) -> Result<(), WebmetroError> {
|
2019-10-11 04:28:08 +00:00
|
|
|
let mut timecode_fixer = ChunkTimecodeFixer::new();
|
2019-10-21 07:18:51 +00:00
|
|
|
let mut chunk_stream: Box<dyn TryStream<Item = Result<Chunk, WebmetroError>, Ok = Chunk, Error = WebmetroError> + Send + Unpin> = Box::new(
|
2018-04-14 22:18:50 +00:00
|
|
|
stdin_stream()
|
2018-04-12 06:03:46 +00:00
|
|
|
.parse_ebml()
|
|
|
|
.chunk_webm()
|
2019-10-21 07:18:51 +00:00
|
|
|
.map_ok(move |chunk| timecode_fixer.process(chunk))
|
2018-04-12 06:03:46 +00:00
|
|
|
);
|
|
|
|
|
2018-04-13 03:29:12 +00:00
|
|
|
if args.is_present("throttle") {
|
2019-10-21 07:18:51 +00:00
|
|
|
chunk_stream = Box::new(Throttle::new(chunk_stream));
|
2018-04-13 03:29:12 +00:00
|
|
|
}
|
|
|
|
|
2020-05-08 03:14:43 +00:00
|
|
|
while let Some(chunk) = chunk_stream.next().await {
|
|
|
|
chunk?.try_for_each(|buffer|
|
|
|
|
io::stdout().write_all(&buffer)
|
|
|
|
)?;
|
|
|
|
};
|
|
|
|
Ok(())
|
2018-04-12 06:03:46 +00:00
|
|
|
}
|