aboutsummaryrefslogtreecommitdiff
path: root/src/voice/streamer.rs
diff options
context:
space:
mode:
authoracdenisSK <[email protected]>2017-07-27 06:42:48 +0200
committeracdenisSK <[email protected]>2017-07-27 07:30:23 +0200
commit550030264952f0e0043b63f4582bb817ef8bbf37 (patch)
treeb921e2f78fd603a5ca671623083a32806fd16090 /src/voice/streamer.rs
parentUse a consistent indentation style (diff)
downloadserenity-550030264952f0e0043b63f4582bb817ef8bbf37.tar.xz
serenity-550030264952f0e0043b63f4582bb817ef8bbf37.zip
rustfmt
Diffstat (limited to 'src/voice/streamer.rs')
-rw-r--r--src/voice/streamer.rs58
1 files changed, 24 insertions, 34 deletions
diff --git a/src/voice/streamer.rs b/src/voice/streamer.rs
index 4d3b9a9..c755da2 100644
--- a/src/voice/streamer.rs
+++ b/src/voice/streamer.rs
@@ -4,7 +4,7 @@ use std::ffi::OsStr;
use std::io::{ErrorKind as IoErrorKind, Read, Result as IoResult};
use std::process::{Child, Command, Stdio};
use super::{AudioSource, VoiceError};
-use ::internal::prelude::*;
+use internal::prelude::*;
struct ChildContainer(Child);
@@ -17,18 +17,18 @@ impl Read for ChildContainer {
struct PcmSource<R: Read + Send + 'static>(bool, R);
impl<R: Read + Send> AudioSource for PcmSource<R> {
- fn is_stereo(&mut self) -> bool {
- self.0
- }
+ fn is_stereo(&mut self) -> bool { self.0 }
fn read_frame(&mut self, buffer: &mut [i16]) -> Option<usize> {
for (i, v) in buffer.iter_mut().enumerate() {
*v = match self.1.read_i16::<LittleEndian>() {
Ok(v) => v,
- Err(ref e) => return if e.kind() == IoErrorKind::UnexpectedEof {
- Some(i)
- } else {
- None
+ Err(ref e) => {
+ return if e.kind() == IoErrorKind::UnexpectedEof {
+ Some(i)
+ } else {
+ None
+ }
},
}
}
@@ -43,11 +43,7 @@ pub fn ffmpeg<P: AsRef<OsStr>>(path: P) -> Result<Box<AudioSource>> {
/// Will fail if the path is not to a file on the fs. Likely a YouTube URI.
let is_stereo = is_stereo(path).unwrap_or(false);
- let stereo_val = if is_stereo {
- "2"
- } else {
- "1"
- };
+ let stereo_val = if is_stereo { "2" } else { "1" };
let args = [
"-f",
@@ -74,8 +70,7 @@ pub fn ffmpeg<P: AsRef<OsStr>>(path: P) -> Result<Box<AudioSource>> {
}
/// Creates a PCM audio source.
-pub fn pcm<R: Read + Send + 'static>(is_stereo: bool, reader: R)
- -> Box<AudioSource> {
+pub fn pcm<R: Read + Send + 'static>(is_stereo: bool, reader: R) -> Box<AudioSource> {
Box::new(PcmSource(is_stereo, reader))
}
@@ -106,9 +101,11 @@ pub fn ytdl(uri: &str) -> Result<Box<AudioSource>> {
};
let uri = match obj.remove("url") {
- Some(v) => match v {
- Value::String(uri) => uri,
- other => return Err(Error::Voice(VoiceError::YouTubeDLUrl(other))),
+ Some(v) => {
+ match v {
+ Value::String(uri) => uri,
+ other => return Err(Error::Voice(VoiceError::YouTubeDLUrl(other))),
+ }
},
None => return Err(Error::Voice(VoiceError::YouTubeDLUrl(Value::Object(obj)))),
};
@@ -117,14 +114,7 @@ pub fn ytdl(uri: &str) -> Result<Box<AudioSource>> {
}
fn is_stereo(path: &OsStr) -> Result<bool> {
- let args = [
- "-v",
- "quiet",
- "-of",
- "json",
- "-show-streams",
- "-i",
- ];
+ let args = ["-v", "quiet", "-of", "json", "-show-streams", "-i"];
let out = Command::new("ffprobe")
.args(&args)
@@ -134,19 +124,19 @@ fn is_stereo(path: &OsStr) -> Result<bool> {
let value: Value = serde_json::from_reader(&out.stdout[..])?;
- let streams = value.as_object()
+ let streams = value
+ .as_object()
.and_then(|m| m.get("streams"))
.and_then(|v| v.as_array())
.ok_or(Error::Voice(VoiceError::Streams))?;
- let check = streams.iter()
- .any(|stream| {
- let channels = stream.as_object()
- .and_then(|m| m.get("channels")
- .and_then(|v| v.as_i64()));
+ let check = streams.iter().any(|stream| {
+ let channels = stream
+ .as_object()
+ .and_then(|m| m.get("channels").and_then(|v| v.as_i64()));
- channels == Some(2)
- });
+ channels == Some(2)
+ });
Ok(check)
}