feat: add convenience methods for extracting audio only

This commit is contained in:
nvrl committed 2026-03-22 12:29:39 +01:00
1 parent f5d2083248
commit c9872ccfbc
2 files changed
+11 -2

No files matched your search

+1 -2
View File
@@ -40,8 +40,7 @@ use ytd_rs::YtDlp;
#[tokio::main] #[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> { async fn main() -> Result<(), Box<dyn std::error::Error>> {
YtDlp::new("https://www.youtube.com/watch?v=uTO0KnDsVH0") YtDlp::new("https://www.youtube.com/watch?v=uTO0KnDsVH0")
.extract_audio(true) .extract_audio_only("mp3")
.audio_format("mp3")
.download() .download()
.await?; .await?;
Ok(()) Ok(())
+10
View File
@@ -150,6 +150,11 @@ impl YtDlp {
self.arg_with("--audio-format", format) 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<String>) -> Self {
self.best_audio().extract_audio(true).audio_format(format)
}
/// Convenience method for --output template. /// Convenience method for --output template.
pub fn output_template(self, template: impl Into<String>) -> Self { pub fn output_template(self, template: impl Into<String>) -> Self {
self.arg_with("--output", template) self.arg_with("--output", template)
@@ -165,6 +170,11 @@ impl YtDlp {
self.format("bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best") 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. /// Path to a cookies file.
pub fn cookies(self, path: impl Into<String>) -> Self { pub fn cookies(self, path: impl Into<String>) -> Self {
self.arg_with("--cookies", path) self.arg_with("--cookies", path)