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.
This commit is contained in:
Paul van Tilburg 2023-01-29 14:24:10 +01:00
parent 371b758962
commit 7f1120fd47
Signed by: paul
GPG Key ID: C6DE073EDA9EEC4D
1 changed files with 6 additions and 2 deletions

View File

@ -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<String
let stream = video
.streams()
.await?
.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())
.ok_or(Error::NoRedirectUrlFound)?;