docs: update README with async builder and JSON parsing examples

This commit is contained in:
nvrl committed 2026-03-22 12:07:55 +01:00
1 parent 1b5b684e26
commit 559a310d36
1 file changed
+56 -15
+56 -15
View File
@@ -2,27 +2,68 @@
[![Build status](https://github.com/nirusu99/ytd-rs/actions/workflows/rust.yml/badge.svg)](https://github.com/nirusu99/ytd-rs/actions)
[![crates.io](https://img.shields.io/crates/v/ytd-rs.svg)](https://crates.io/crates/ytd-rs)
[![docs.rs](https://docs.rs/ytd-rs/badge.svg)](https://docs.rs/ytd-rs)
[![dependency status](https://deps.rs/repo/github/nirusu99/ytd-rs/status.svg)](https://deps.rs/repo/github/nirusu99/ytd-rs)
This is a simple wrapper for [youtube-dl](https://youtube-dl.org/) in rust.
An async, feature-rich Rust wrapper for [yt-dlp](https://github.com/yt-dlp/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-dlp` flag.
## Prerequisites
You must have `yt-dlp` installed and available in your `PATH`.
## Usage
### Simple Download
```rust
use ytd_rs::{YoutubeDL, Arg};
use ytd_rs::YtDlp;
use std::path::PathBuf;
use std::error::Error;
fn main() -> Result<(), Box<dyn Error>> {
// youtube-dl arguments quietly run process and to format the output
// one doesn't take any input and is an option, the other takes the desired output format as input
let args = vec![Arg::new("--quiet"), Arg::new_with_arg("--output", "%(title).90s.%(ext)s")];
let link = "https://www.youtube.com/watch?v=uTO0KnDsVH0";
let path = PathBuf::from("./path/to/download/directory");
let ytd = YoutubeDL::new(&path, args, link)?;
// start download
let download = ytd.download()?;
#[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");
// print out the download path
println!("Your download: {}", download.output_dir().to_string_lossy());
let result = ytd.download().await?;
println!("Output: {}", result.output());
Ok(())
}
```
### Extract Audio
```rust
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
```rust
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