Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple async download through one builder #57

Open
aaalloc opened this issue Oct 27, 2023 · 2 comments
Open

Multiple async download through one builder #57

aaalloc opened this issue Oct 27, 2023 · 2 comments
Assignees

Comments

@aaalloc
Copy link

aaalloc commented Oct 27, 2023

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 !

@GyrosOfWar GyrosOfWar self-assigned this Oct 28, 2023
@GyrosOfWar
Copy link
Owner

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

@aaalloc
Copy link
Author

aaalloc commented Nov 4, 2023

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 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants