diff options
| author | Jokler <jokler@protonmail.com> | 2020-01-12 18:11:02 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-01-12 18:11:02 +0100 |
| commit | 78690b2e2949ed3be38a136f1c6ac2866ac32df7 (patch) | |
| tree | 64535e2e534e57ef94a057f8010b87c88fc56021 /src/youtube_dl.rs | |
| parent | fc62434581e5f7411177e7c30dd1f4543ec354be (diff) | |
| parent | 193987e0c7185eb63827b2d91f1e2779c4e557d3 (diff) | |
| download | pokebot-78690b2e2949ed3be38a136f1c6ac2866ac32df7.tar.gz pokebot-78690b2e2949ed3be38a136f1c6ac2866ac32df7.zip | |
Merge pull request #1 from fkaa/refactoring
Add enterprise logging and split out gstreamer & teamspeak specific code
Diffstat (limited to 'src/youtube_dl.rs')
| -rw-r--r-- | src/youtube_dl.rs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/youtube_dl.rs b/src/youtube_dl.rs new file mode 100644 index 0000000..1eff302 --- /dev/null +++ b/src/youtube_dl.rs @@ -0,0 +1,38 @@ +use std::process::{Command, Stdio}; + +use log::{debug}; + +pub fn get_audio_download_url(uri: String) -> Result<(String, String), String> { + let ytdl_args = [ + "--no-playlist", + "-f", + "bestaudio/best", + "-g", + "--get-filename", + "-o", + "%(title)s", + &uri, + ]; + + let mut cmd = Command::new("youtube-dl"); + cmd.args(&ytdl_args); + cmd.stdin(Stdio::null()); + + debug!("yt-dl command: {:?}", cmd); + + let ytdl_output = cmd + .output() + .unwrap(); + + let output = String::from_utf8(ytdl_output.stdout.clone()).unwrap(); + + if ytdl_output.status.success() == false { + return Err(String::from_utf8(ytdl_output.stderr.clone()).unwrap()); + } + + let lines = output.lines().collect::<Vec<_>>(); + let url = lines[0].to_owned(); + let title = lines[1].to_owned(); + + Ok((url, title)) +}
\ No newline at end of file |
