youtube-dl-rs
youtube-dl-rs copied to clipboard
Multiple async download through one builder
Hi !
I wanted to know if it is possible to download multiple link from one builder asynchronously. I read the documentation and the code and I didn't found any clue for doing that...
Thanks in advance !
Hello, no, this is not supported by the API at the moment. Would the advantage be that you just need one yt-dlp/youtube-dl process to download multiple files? Because if that's not a problem, you could just use multiple builders and run them in parallel with something like future::join_all
Hello, no, this is not supported by the API at the moment. Would the advantage be that you just need one yt-dlp/youtube-dl process to download multiple files? Because if that's not a problem, you could just use multiple builders and run them in parallel with something like
future::join_all
Yeah thats what I basically did, here's a snippet:
async fn download_audio(link: &str) -> Result<YoutubeDlOutput, Error> {
YoutubeDl::new(link)
.socket_timeout("15")
.extract_audio(true)
.extra_arg("-x")
.extra_arg("--continue")
.extra_arg(r#"-o %(title)s.%(ext)s"#)
.extra_arg("--prefer-ffmpeg")
.extra_arg("--ppa")
.extra_arg("ThumbnailsConvertor+FFmpeg_o:-c:v mjpeg -vf crop=\"'if(gt(ih,iw),iw,ih)':'if(gt(iw,ih),ih,iw)'\"")
.extra_arg("--embed-metadata")
.extra_arg("--embed-thumbnail")
.extra_arg("--audio-format")
.extra_arg("mp3")
.extra_arg("-P")
.extra_arg("...")
.extra_arg("--no-simulate")
.extra_arg("--no-progress")
.run_async().await
}
pub async fn download_audio_from_links(
url: String,
state: tauri::State<'_, AsyncProcInputTx>,
) -> Result<(), String> {
let links = retrieve_possible_links(&url);
let mut futures = futures::stream::FuturesUnordered::new();
for link in &links {
futures.push(async move { download_audio(link).await });
}
while let Some(res) = futures.next().await {
match res {
...................
}
}
Ok(())
}
thank you !