diff --git a/README.md b/README.md index 2a245a5..407e30e 100644 --- a/README.md +++ b/README.md @@ -40,8 +40,7 @@ use ytd_rs::YtDlp; #[tokio::main] async fn main() -> Result<(), Box> { YtDlp::new("https://www.youtube.com/watch?v=uTO0KnDsVH0") - .extract_audio(true) - .audio_format("mp3") + .extract_audio_only("mp3") .download() .await?; Ok(()) diff --git a/src/lib.rs b/src/lib.rs index 7862e86..a9eb9e1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -150,6 +150,11 @@ impl YtDlp { self.arg_with("--audio-format", format) } + /// Configures yt-dlp to download only the best audio and extract it to the given format (e.g., "mp3"). + pub fn extract_audio_only(self, format: impl Into) -> Self { + self.best_audio().extract_audio(true).audio_format(format) + } + /// Convenience method for --output template. pub fn output_template(self, template: impl Into) -> Self { self.arg_with("--output", template) @@ -165,6 +170,11 @@ impl YtDlp { self.format("bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best") } + /// Select the best quality audio only. + pub fn best_audio(self) -> Self { + self.format("bestaudio/best") + } + /// Path to a cookies file. pub fn cookies(self, path: impl Into) -> Self { self.arg_with("--cookies", path)