diff options
| author | salmonik <salmonik@tuta.io> | 2026-11-04 01:11:50 +0100 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-11-04 01:11:50 +0100 |
| commit | fd93334a21907f959018e1b1f5df747a98d186c8 (patch) | |
| tree | 259e595a570b42a5ea082f596e1cb97e5011cfba /src/voice/mod.rs | |
| parent | http: add connect and request timeouts (diff) | |
| download | senator-sperma-fd93334a21907f959018e1b1f5df747a98d186c8.tar.gz senator-sperma-fd93334a21907f959018e1b1f5df747a98d186c8.zip | |
processes: add timeouts and keep decoding off the runtime
Diffstat (limited to 'src/voice/mod.rs')
| -rw-r--r-- | src/voice/mod.rs | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/src/voice/mod.rs b/src/voice/mod.rs index a6baa64..5043508 100644 --- a/src/voice/mod.rs +++ b/src/voice/mod.rs | |||
| @@ -237,22 +237,26 @@ fn decode_stream(mss: MediaSourceStream) -> Result<songbird::input::Input> { | |||
| 237 | /// Download audio via yt-dlp, collect stdout into memory, return the raw bytes. | 237 | /// Download audio via yt-dlp, collect stdout into memory, return the raw bytes. |
| 238 | /// Works for both finite media and live streams (yt-dlp handles the difference). | 238 | /// Works for both finite media and live streams (yt-dlp handles the difference). |
| 239 | pub async fn ytdlp_download(url: &str) -> Result<Vec<u8>> { | 239 | pub async fn ytdlp_download(url: &str) -> Result<Vec<u8>> { |
| 240 | let output = tokio::process::Command::new("yt-dlp") | 240 | let output = tokio::time::timeout( |
| 241 | .args([ | 241 | Duration::from_secs(600), |
| 242 | "--ignore-config", | 242 | tokio::process::Command::new("yt-dlp") |
| 243 | "-f", | 243 | .args([ |
| 244 | "bestaudio", | 244 | "--ignore-config", |
| 245 | "-o", | 245 | "-f", |
| 246 | "-", | 246 | "bestaudio", |
| 247 | "--no-playlist", | 247 | "-o", |
| 248 | "--", | 248 | "-", |
| 249 | url, | 249 | "--no-playlist", |
| 250 | ]) | 250 | "--", |
| 251 | .stdout(std::process::Stdio::piped()) | 251 | url, |
| 252 | .stderr(std::process::Stdio::piped()) | 252 | ]) |
| 253 | .output() | 253 | .stdout(std::process::Stdio::piped()) |
| 254 | .await | 254 | .stderr(std::process::Stdio::piped()) |
| 255 | .map_err(|e| Error::Custom(lang::fmt_voice_ytdlp_launch(&e)))?; | 255 | .output(), |
| 256 | ) | ||
| 257 | .await | ||
| 258 | .map_err(|_| Error::Custom("yt-dlp timed out after 10 minutes".into()))? | ||
| 259 | .map_err(|e| Error::Custom(lang::fmt_voice_ytdlp_launch(&e)))?; | ||
| 256 | 260 | ||
| 257 | if !output.status.success() { | 261 | if !output.status.success() { |
| 258 | let stderr = String::from_utf8_lossy(&output.stderr); | 262 | let stderr = String::from_utf8_lossy(&output.stderr); |
