Provide enchanced audio selection for user

With this change, instdead of showing bitrate in bps to the user, user
will see pure bitrate in kbps or codec and bitrate for when listening
mode is used.
This commit is contained in:
Daniil Hikkamorii 2023-11-23 19:35:21 +02:00
parent 9ce9c54399
commit 4634465368
2 changed files with 9 additions and 3 deletions

View File

@ -68,7 +68,9 @@ module Invidious::Routes::API::Manifest
# However, most players don't support auto quality switching, so we have to trick them
# into providing a quality selector.
# See https://github.com/iv-org/invidious/issues/3074 for more details.
xml.element("AdaptationSet", id: i, mimeType: mime_type, startWithSAP: 1, subsegmentAlignment: true, label: fmt["bitrate"].to_s + "k") do
bitrate = ( fmt["bitrate"].as_i / 1000 ).round(0).to_i.to_s + "k"
xml.element("AdaptationSet", id: i, mimeType: mime_type, startWithSAP: 1, subsegmentAlignment: true, label: bitrate) do
codecs = fmt["mimeType"].as_s.split("codecs=")[1].strip('"')
bandwidth = fmt["bitrate"].as_i
itag = fmt["itag"].as_i

View File

@ -22,12 +22,16 @@
src_url = "/latest_version?id=#{video.id}&itag=#{fmt["itag"]}"
src_url += "&local=true" if params.local
bitrate = fmt["bitrate"]
codec = fmt["mimeType"].as_s.split(";")[0].split("/")[1]
codec = codec == "webm" ? "opus" : codec
bitrate = ( fmt["bitrate"].as_i / 1000 ).round(0).to_i.to_s
quality_audio = "#{codec} @ #{bitrate}k"
mimetype = HTML.escape(fmt["mimeType"].as_s)
selected = (i == best_m4a_stream_index)
%>
<source src="<%= src_url %>" type='<%= mimetype %>' label="<%= bitrate %>k" selected="<%= selected %>">
<source src="<%= src_url %>" type='<%= mimetype %>' label="<%= quality_audio %>" selected="<%= selected %>">
<% if !params.local && !CONFIG.disabled?("local") %>
<source src="<%= src_url %>&local=true" type='<%= mimetype %>' hidequalityoption="true">
<% end %>