From 2b88d09d0f42c9ee7bc609480aa85ad7705bac2f Mon Sep 17 00:00:00 2001 From: Tangent Wantwight Date: Sun, 22 May 2022 20:50:47 -0400 Subject: [PATCH] Teach filter subcommand to recognize --skip and --take options --- CHANGELOG.md | 1 + src/commands/filter.rs | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a799719..030f641 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ ## v0.3.1-dev +- Teach filter subcommand to recognize --skip and --take options - MSRV now rustc 1.61 - forget a channel's initialization segment when no transmitter is active. This improves behavior when a channel is occasionally used for streams with different codecs. - Add INFO logging for channel creation/garbage-collection diff --git a/src/commands/filter.rs b/src/commands/filter.rs index a120e0c..79180b6 100644 --- a/src/commands/filter.rs +++ b/src/commands/filter.rs @@ -1,9 +1,9 @@ -use std::{io, io::prelude::*, pin::Pin}; +use std::{io, io::prelude::*, pin::Pin, time::Duration}; use clap::Args; use futures::prelude::*; -use super::stdin_stream; +use super::{parse_time, stdin_stream}; use webmetro::{ chunk::{Chunk, WebmStream}, error::WebmetroError, @@ -15,19 +15,31 @@ use webmetro::{ #[derive(Args, Debug)] pub struct FilterArgs { /// Slow down output to "real time" speed as determined by the timestamps (useful for streaming static files) - #[clap(long, short)] + #[clap(long)] throttle: bool, + /// Skip approximately n seconds of content before uploading or throttling + #[clap(long, short, parse(try_from_str = parse_time))] + skip: Option, + /// Stop uploading after approximately n seconds of content + #[clap(long, short, parse(try_from_str = parse_time))] + take: Option, } #[tokio::main] pub async fn run(args: FilterArgs) -> Result<(), WebmetroError> { + let start_time = args.skip.map_or(0, |s| s.as_millis()); + let stop_time = args + .take + .map_or(std::u128::MAX, |t| t.as_millis() + start_time); + let mut timecode_fixer = ChunkTimecodeFixer::new(); let mut chunk_stream: Pin> + Send>> = Box::pin( stdin_stream() .parse_ebml() .chunk_webm() - .map_ok(move |chunk| timecode_fixer.process(chunk)), + .map_ok(move |chunk| timecode_fixer.process(chunk)) + .try_filter(move |chunk| future::ready(chunk.overlaps(start_time, stop_time))), ); if args.throttle {