8 releases (4 breaking)

0.5.2 Jul 9, 2024
0.5.1 Jul 9, 2024
0.4.2 Jul 9, 2024
0.3.0 Jul 1, 2019
0.1.0 Jan 4, 2019

#53 in Video

Download history 629/week @ 2024-07-11 394/week @ 2024-07-18 396/week @ 2024-07-25 453/week @ 2024-08-01 619/week @ 2024-08-08 503/week @ 2024-08-15 386/week @ 2024-08-22 396/week @ 2024-08-29 498/week @ 2024-09-05 422/week @ 2024-09-12 364/week @ 2024-09-19 442/week @ 2024-09-26 389/week @ 2024-10-03 381/week @ 2024-10-10 420/week @ 2024-10-17 322/week @ 2024-10-24

1,550 downloads per month
Used in 3 crates (2 directly)

ISC license

28KB
640 lines

Stream Lib

This library makes it possible to download various types of video streams. Currently it supports HLS and chunked http streams.

Example

use futures_util::StreamExt as _;
use reqwest::Client;
use stream_lib::Event;
use tokio::io::AsyncWriteExt;

/// Write buffer
pub const WRITE_SIZE: usize = 131_072;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    tracing_subscriber::fmt::init();
    let args = std::env::args().collect::<Vec<_>>();
    let url = args.get(1).expect("Pass a url as the first argument");

    let http = Client::new();
    let req = http.get(url).build()?;
    let mut dl = stream_lib::download_hls(http, req, None);

    let mut file = tokio::io::BufWriter::with_capacity(
        WRITE_SIZE,
        tokio::fs::File::create("./example.mp4").await?,
    );

    while let Some(event) = dl.next().await {
        match event {
            Event::Bytes { bytes } => {
                file.write_all(&bytes).await?;
            }
            Event::End => break,
            Event::Error { error } => {
                eprintln!("Encounted error: {}", error);
                break;
            }
        }
    }
    Ok(())
}

Dependencies

~8–19MB
~274K SLoC