From 7f1120fd4772d058b4e279377a2a5565519cf420 Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Sun, 29 Jan 2023 14:24:10 +0100 Subject: [PATCH] Select MP4 audio streams only (experimental) The filter used to select the stream with the highest bitrate, but this may result in a stream with a codec/container that is not supported by all podcast clients, such as WEBM. Select the (almost always available) highest stream using the MP4 container instead. --- src/backends/youtube.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/backends/youtube.rs b/src/backends/youtube.rs index e08d251..13dea73 100644 --- a/src/backends/youtube.rs +++ b/src/backends/youtube.rs @@ -308,7 +308,9 @@ async fn fetch_stream( .streams() .await .ok()? - .filter(|v| v.is_audio()) + // Select the well-supported, almost always available MP4 container format with + // only an audio stream and then the one with the highest bitrate. + .filter(|v| v.is_audio() && v.mime_type().contains("mp4")) .max_by_key(|v| v.bitrate())?; let content_length = stream.content_length().await.ok()?; @@ -337,7 +339,9 @@ async fn retrieve_redirect_url(client: &Client, video_id: &str) -> Result