renge/invidious: Rebase patch

This is a re-implementation since upstream added a similar functionality
but prefers aac over opus.
This commit is contained in:
Simon Bruder 2022-07-23 20:01:22 +02:00
parent edbb46da7a
commit 82b1eeac76
Signed by: simon
GPG key ID: 8D3C82F9F309F8EC

View file

@ -1,33 +1,46 @@
From c8fa5a9b2fd5f4a9a5fe3b1e0876702a1d6dd5e2 Mon Sep 17 00:00:00 2001
From 237067e0b6bf005763090a6b063daa3bc4bb8d90 Mon Sep 17 00:00:00 2001
From: Simon Bruder <simon@sbruder.de>
Date: Thu, 9 Sep 2021 16:56:57 +0200
Subject: [PATCH] Prefer opus audio streams in listen mode
---
src/invidious/views/components/player.ecr | 10 ++++++++++
1 file changed, 10 insertions(+)
src/invidious/views/components/player.ecr | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/src/invidious/views/components/player.ecr b/src/invidious/views/components/player.ecr
index fffefc9a..9c9ce553 100644
index c3c02df0..3278bcba 100644
--- a/src/invidious/views/components/player.ecr
+++ b/src/invidious/views/components/player.ecr
@@ -7,6 +7,16 @@
@@ -7,14 +7,14 @@
<source src="<%= URI.parse(hlsvp).request_target %><% if params.local %>?local=true<% end %>" type="application/x-mpegURL" label="livestream">
<% else %>
<% if params.listen %>
+ <%
+ opus_streams = audio_streams.select { |fmt|
+ metadata = itag_to_metadata?(fmt["itag"])
+ metadata ? metadata["acodec"] == "opus" : false
+ }.reverse!
+ if opus_streams.size > 0
+ audio_streams = opus_streams
+ end
+ audio_streams.sort_by! { |fmt| fmt["bitrate"].as_i }.reverse!
+ %>
<% audio_streams.each_with_index do |fmt, i|
src_url = "/latest_version?id=#{video.id}&itag=#{fmt["itag"]}"
src_url += "&local=true" if params.local
- <% # default to 128k m4a stream
- best_m4a_stream_index = 0
- best_m4a_stream_bitrate = 0
+ <% # default to 128k opus stream
+ best_opus_stream_index = 0
+ best_opus_stream_bitrate = 0
audio_streams.each_with_index do |fmt, i|
bandwidth = fmt["bitrate"].as_i
- if (fmt["mimeType"].as_s.starts_with?("audio/mp4") && bandwidth > best_m4a_stream_bitrate)
- best_m4a_stream_bitrate = bandwidth
- best_m4a_stream_index = i
+ if (fmt["mimeType"].as_s.starts_with?("audio/opus") && bandwidth > best_opus_stream_bitrate)
+ best_opus_stream_bitrate = bandwidth
+ best_opus_stream_index = i
end
end
@@ -25,7 +25,7 @@
bitrate = fmt["bitrate"]
mimetype = HTML.escape(fmt["mimeType"].as_s)
- selected = (i == best_m4a_stream_index)
+ selected = (i == best_opus_stream_index)
%>
<source src="<%= src_url %>" type='<%= mimetype %>' label="<%= bitrate %>k" selected="<%= selected %>">
<% if !params.local && !CONFIG.disabled?("local") %>
--
2.33.3
2.36.0