mirror of
https://github.com/narrrl/ytd-rs.git
synced 2026-11-03 16:41:27 +01:00
559a310d36204e069327c1638511cecdf331ce1d
ytd-rs
An async, feature-rich Rust wrapper for yt-dlp.
Features
- Async API: Built on top of
tokio. - Builder Pattern: Fluent API for configuring downloads.
- Structured Metadata: Extract video info as JSON via
serde. - Custom Arguments: Passthrough for any
yt-dlpflag.
Prerequisites
You must have yt-dlp installed and available in your PATH.
Usage
Simple Download
use ytd_rs::YtDlp;
use std::path::PathBuf;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let ytd = YtDlp::new("https://www.youtube.com/watch?v=uTO0KnDsVH0")
.output_dir(PathBuf::from("./downloads"))
.arg("--quiet");
let result = ytd.download().await?;
println!("Output: {}", result.output());
Ok(())
}
Extract Audio
use ytd_rs::YtDlp;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
YtDlp::new("https://www.youtube.com/watch?v=uTO0KnDsVH0")
.extract_audio(true)
.audio_format("mp3")
.download()
.await?;
Ok(())
}
Get Video Metadata
use ytd_rs::YtDlp;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let ytd = YtDlp::new("https://www.youtube.com/watch?v=uTO0KnDsVH0");
let infos = ytd.get_info().await?;
for info in infos {
println!("Title: {}", info.title);
println!("Duration: {:?}", info.duration);
}
Ok(())
}
License
MIT
Languages
Rust
100%