aboutsummaryrefslogtreecommitdiffstats
path: root/src/voice/mod.rs
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-11-04 01:30:24 +0100
committersalmonik <salmonik@tuta.io>2026-11-04 01:30:24 +0100
commitfa9486650e8de2be117757b1891fa0aacc4c47cd (patch)
tree4638ed4664910600a9ce86461755a412a25df9d7 /src/voice/mod.rs
parentnet: drop unused import (diff)
downloadsenator-sperma-fa9486650e8de2be117757b1891fa0aacc4c47cd.tar.gz
senator-sperma-fa9486650e8de2be117757b1891fa0aacc4c47cd.zip
downloads: cap yt-dlp media size
Diffstat (limited to 'src/voice/mod.rs')
-rw-r--r--src/voice/mod.rs12
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`.
27const RECORDING_SAMPLE_RATE: u32 = 48000; 27const 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.
31const MAX_MEDIA_BYTES: usize = 128 * 1024 * 1024;
32
29#[derive(Clone)] 33#[derive(Clone)]
30pub struct VoiceManager { 34pub 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}