Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enchanced audio selection #4287

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/invidious/frontend/watch_page.cr
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ module Invidious::Frontend::WatchPage

video_assets.audio_streams.each do |option|
mimetype = option["mimeType"].as_s.split(";")[0]
if mimetype == "audio/webm"
mimetype = "audio/opus"
end

value = {"itag": option["itag"], "ext": mimetype.split("/")[1]}.to_json

Expand Down
4 changes: 3 additions & 1 deletion src/invidious/routes/api/manifest.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions src/invidious/views/components/player.ecr
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>
Expand Down
Loading