summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main.rs14
-rw-r--r--src/youtube_dl.rs6
2 files changed, 11 insertions, 9 deletions
diff --git a/src/main.rs b/src/main.rs
index e19a9ae..18b9cc7 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -115,8 +115,8 @@ impl Application {
self.player.play().unwrap();
}
- pub fn add_audio(&self, url: String) {
- match youtube_dl::get_audio_download_url(url) {
+ pub async fn add_audio(&self, url: String) {
+ match youtube_dl::get_audio_download_url(url).await {
Ok((audio_url, audio_title)) => {
info!("Found audio url: {}", audio_url);
@@ -162,7 +162,7 @@ impl Application {
self.with_teamspeak(|ts| ts.set_description(desc));
}
- fn on_text(&self, message: Message) -> Result<(), AudioPlayerError> {
+ async fn on_text(&self, message: Message) -> Result<(), AudioPlayerError> {
let msg = message.text;
if msg.starts_with("!") {
let tokens = msg[1..].split_whitespace().collect::<Vec<_>>();
@@ -173,7 +173,7 @@ impl Application {
// strip bbcode tags from url
let url = url.replace("[URL]", "").replace("[/URL]", "");
- self.add_audio(url.to_string());
+ self.add_audio(url.to_string()).await;
}
}
Some("play") => {
@@ -257,14 +257,14 @@ impl Application {
Ok(())
}
- pub fn on_message(&self, message: ApplicationMessage) -> Result<(), AudioPlayerError> {
+ pub async fn on_message(&self, message: ApplicationMessage) -> Result<(), AudioPlayerError> {
match message {
ApplicationMessage::TextMessage(message) => {
if let MessageTarget::Poke(who) = message.target {
info!("Poked by {}, joining their channel", who);
self.with_teamspeak(|ts| ts.join_channel_of_user(who));
} else {
- self.on_text(message)?;
+ self.on_text(message).await?;
}
}
ApplicationMessage::StateChange(state) => {
@@ -357,7 +357,7 @@ async fn async_main() {
loop {
while let Some(msg) = rx.recv().await {
- application.on_message(msg).unwrap();
+ application.on_message(msg).await.unwrap();
}
}
}
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();