diff options
| author | Jokler <jokler@protonmail.com> | 2020-01-14 19:51:24 +0100 |
|---|---|---|
| committer | Jokler <jokler@protonmail.com> | 2020-01-14 19:51:24 +0100 |
| commit | 58d7e8655d24a4f7ac846b1e27dd771717588849 (patch) | |
| tree | 86c731ad9bcfa18c9b81bdb7b1762c6065c2c7b8 /src/youtube_dl.rs | |
| parent | 6bc3285baa3e51c6fa65cfa5f37de3c56da940d6 (diff) | |
| download | pokebot-58d7e8655d24a4f7ac846b1e27dd771717588849.tar.gz pokebot-58d7e8655d24a4f7ac846b1e27dd771717588849.zip | |
Make youtube-dl execution async again
If tokio is run with a low thread count running youtube-dl
can freeze audio playback. This should prevent that by waiting
for the command asynchronously.
Diffstat (limited to 'src/youtube_dl.rs')
| -rw-r--r-- | src/youtube_dl.rs | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/youtube_dl.rs b/src/youtube_dl.rs index ac4635a..d588760 100644 --- a/src/youtube_dl.rs +++ b/src/youtube_dl.rs @@ -1,8 +1,10 @@ use std::process::{Command, Stdio}; +use tokio_process::CommandExt; +use futures::compat::Future01CompatExt; use log::debug; -pub fn get_audio_download_url(uri: String) -> Result<(String, String), String> { +pub async fn get_audio_download_url(uri: String) -> Result<(String, String), String> { let ytdl_args = [ "--no-playlist", "-f", @@ -20,7 +22,7 @@ pub fn get_audio_download_url(uri: String) -> Result<(String, String), String> { debug!("yt-dl command: {:?}", cmd); - let ytdl_output = cmd.output().unwrap(); + let ytdl_output = cmd.output_async().compat().await.unwrap(); let output = String::from_utf8(ytdl_output.stdout.clone()).unwrap(); |
