aboutsummaryrefslogtreecommitdiff
path: root/src/audio
diff options
context:
space:
mode:
authorNathan Perry <avaglir@gmail.com>2019-03-02 23:54:01 -0500
committerNathan Perry <avaglir@gmail.com>2019-03-02 23:54:01 -0500
commit410596f875111fab3d666a472c61be8869d7f7ec (patch)
tree80e115f1ba84e50261e32ae4aa32d42359600d76 /src/audio
parenta81f91f062b446c742a1a9fe41e3eeab7b08502b (diff)
remove unused code, fixup imports
Diffstat (limited to 'src/audio')
-rw-r--r--src/audio/ytdl.rs113
1 files changed, 0 insertions, 113 deletions
diff --git a/src/audio/ytdl.rs b/src/audio/ytdl.rs
index 8239683..46f0e27 100644
--- a/src/audio/ytdl.rs
+++ b/src/audio/ytdl.rs
@@ -1,83 +1,21 @@
/// This module is entirely adapted from the relevant code in Serenity.
use std::{
- io::{
- Read,
- Result as IoResult,
- },
process::{
- Child,
Command,
Stdio,
},
};
-use chrono::Duration;
use serde_json::Value;
use serenity::{
voice::{
- AudioSource,
- pcm,
VoiceError,
}
};
use crate::Result;
-struct ChildContainer(Child);
-
-impl Read for ChildContainer {
- fn read(&mut self, buffer: &mut [u8]) -> IoResult<usize> {
- self.0.stdout.as_mut().unwrap().read(buffer)
- }
-}
-
-impl Drop for ChildContainer {
- fn drop(&mut self) {
- if let Err(e) = self.0.kill() {
- debug!("Error awaiting child process: {:?}", e);
- }
- }
-}
-
-pub(crate) trait CodecInfo {
- fn ffmpeg_opts() -> &'static[&'static str];
-}
-
-pub(crate) struct Pcm {}
-
-#[allow(dead_code)]
-pub(crate) struct Opus {}
-
-impl CodecInfo for Pcm {
- #[inline]
- fn ffmpeg_opts() -> &'static[&'static str] {
- lazy_static! {
- static ref OPTS: Vec<&'static str> = vec! [
- "-f", "s16le",
- "-acodec", "pcm_s16le",
- ];
- }
-
- &*OPTS
- }
-}
-
-impl CodecInfo for Opus {
- #[inline]
- fn ffmpeg_opts() -> &'static[&'static str] {
- lazy_static! {
- static ref OPTS: Vec<&'static str> = vec! [
- "-f", "opus",
- "-acodec", "libopus",
- "-b:a 96k",
- ];
- }
-
- &*OPTS
- }
-}
-
pub fn ytdl_url(uri: &str) -> Result<String> {
let args = [
"-f",
@@ -111,54 +49,3 @@ pub fn ytdl_url(uri: &str) -> Result<String> {
None => Err(VoiceError::YouTubeDLUrl(Value::Object(obj)).into()),
}
}
-
-pub(crate) fn ffmpeg_dl<T: CodecInfo>(uri: &str, start: Option<Duration>, end: Option<Duration>, size_limit: Option<usize>) -> Result<Box<dyn Read + Send>> {
- let start = start.unwrap_or(Duration::zero());
- let start_str = format!("{:02}:{:02}:{:02}", start.num_hours(), start.num_minutes() % 60, start.num_seconds() % 60);
-
- let mut opts = vec! [
- "-ac",
- "2", // force stereo -- this may cause issues
- "-ar",
- "48000",
- "-ss",
- &start_str,
- ]
- .into_iter()
- .map(|s| s.to_owned())
- .collect::<Vec<_>>();
-
- if let Some(e) = end {
- opts.push("-to".to_owned());
- opts.push(format!("{:02}:{:02}:{:02}", e.num_hours(), e.num_minutes() % 60, e.num_seconds() % 60));
- }
-
- let codec_opts = T::ffmpeg_opts().into_iter().map(|&s| s.to_owned()).collect::<Vec<_>>();
- opts.extend(codec_opts);
-
- if let Some(limit) = size_limit {
- opts.push("-fs".to_owned());
- opts.push(format!("{}", limit));
- }
-
- opts.push("-".to_owned());
-
- debug!("ffmpeg -i \"{}\" {}", uri, opts.join(" "));
-
- let command = Command::new("ffmpeg")
- .arg("-i")
- .arg(uri)
- .args(opts)
- .stderr(Stdio::piped())
- .stdin(Stdio::null())
- .stdout(Stdio::piped())
- .spawn()?;
-
- Ok(Box::new(ChildContainer(command)))
-}
-
-pub fn ytdl(uri: &str, start: Option<Duration>, end: Option<Duration>) -> Result<Box<AudioSource>> {
- let youtube_uri = ytdl_url(uri)?;
- let command = ffmpeg_dl::<Pcm>(&youtube_uri, start, end, None)?;
- Ok(pcm(true, command))
-}