diff options
Diffstat (limited to '')
| -rw-r--r-- | src/voice/mod.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/voice/mod.rs b/src/voice/mod.rs index 5043508..d8308eb 100644 --- a/src/voice/mod.rs +++ b/src/voice/mod.rs | |||
| @@ -26,6 +26,10 @@ use crate::recording::{Recorder, RecorderEventHandler}; | |||
| 26 | /// and the ffmpeg `s16le` encode. Must match the `DecodeConfig` set in `main.rs`. | 26 | /// and the ffmpeg `s16le` encode. Must match the `DecodeConfig` set in `main.rs`. |
| 27 | const RECORDING_SAMPLE_RATE: u32 = 48000; | 27 | const RECORDING_SAMPLE_RATE: u32 = 48000; |
| 28 | 28 | ||
| 29 | /// Upper bound for yt-dlp media buffered in memory. Audio is decoded to f32 | ||
| 30 | /// PCM afterwards (another 4x), so a multi-hundred-MB download would OOM. | ||
| 31 | const MAX_MEDIA_BYTES: usize = 128 * 1024 * 1024; | ||
| 32 | |||
| 29 | #[derive(Clone)] | 33 | #[derive(Clone)] |
| 30 | pub struct VoiceManager { | 34 | pub struct VoiceManager { |
| 31 | pub songbird: Arc<Songbird>, | 35 | pub songbird: Arc<Songbird>, |
| @@ -247,6 +251,8 @@ pub async fn ytdlp_download(url: &str) -> Result<Vec<u8>> { | |||
| 247 | "-o", | 251 | "-o", |
| 248 | "-", | 252 | "-", |
| 249 | "--no-playlist", | 253 | "--no-playlist", |
| 254 | "--max-filesize", | ||
| 255 | "128M", | ||
| 250 | "--", | 256 | "--", |
| 251 | url, | 257 | url, |
| 252 | ]) | 258 | ]) |
| @@ -269,6 +275,12 @@ pub async fn ytdlp_download(url: &str) -> Result<Vec<u8>> { | |||
| 269 | ); | 275 | ); |
| 270 | return Err(Error::Custom(lang::fmt_ytdlp_stderr(&stderr))); | 276 | return Err(Error::Custom(lang::fmt_ytdlp_stderr(&stderr))); |
| 271 | } | 277 | } |
| 278 | if output.stdout.len() > MAX_MEDIA_BYTES { | ||
| 279 | return Err(Error::Custom(format!( | ||
| 280 | "media is too large (limit {} MiB)", | ||
| 281 | MAX_MEDIA_BYTES / (1024 * 1024) | ||
| 282 | ))); | ||
| 283 | } | ||
| 272 | 284 | ||
| 273 | Ok(output.stdout) | 285 | Ok(output.stdout) |
| 274 | } | 286 | } |
