From 58d7e8655d24a4f7ac846b1e27dd771717588849 Mon Sep 17 00:00:00 2001 From: Jokler Date: Tue, 14 Jan 2020 19:51:24 +0100 Subject: 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. --- src/youtube_dl.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/youtube_dl.rs') 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(); -- cgit v1.2.3-70-g09d2