mirror of
https://github.com/iv-org/invidious.git
synced 2025-05-15 11:01:15 +00:00

Fix #4110 by adding an option to control the preloading of video data on page load. If disabled ("false"), the browser will not preload any video data until the user explicitly hits the "Play" button. If enabled ("true"), the default behavior will be used, which means the browser decides how much of the video will be preloaded.
83 lines
3.7 KiB
Plaintext
83 lines
3.7 KiB
Plaintext
<video style="outline:none;width:100%;background-color:#000" playsinline poster="<%= thumbnail %>"
|
|
id="player" class="on-video_player video-js player-style-<%= params.player_style %>"
|
|
preload="<% if params.preload %>auto<% else %>none<% end %>"
|
|
<% if params.autoplay %>autoplay<% end %>
|
|
<% if params.video_loop %>loop<% end %>
|
|
<% if params.controls %>controls<% end %>>
|
|
<% if (hlsvp = video.hls_manifest_url) && !CONFIG.disabled?("livestreams") %>
|
|
<source src="<%= URI.parse(hlsvp).request_target %><% if params.local %>?local=true<% end %>" type="application/x-mpegURL" label="livestream">
|
|
<% else %>
|
|
<% if params.listen %>
|
|
<% # default to 128k m4a stream
|
|
best_m4a_stream_index = 0
|
|
best_m4a_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
|
|
end
|
|
end
|
|
|
|
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
|
|
|
|
bitrate = fmt["bitrate"]
|
|
mimetype = HTML.escape(fmt["mimeType"].as_s)
|
|
|
|
selected = (i == best_m4a_stream_index)
|
|
%>
|
|
<source src="<%= src_url %>" type='<%= mimetype %>' label="<%= bitrate %>k" selected="<%= selected %>">
|
|
<% if !params.local && !CONFIG.disabled?("local") %>
|
|
<source src="<%= src_url %>&local=true" type='<%= mimetype %>' hidequalityoption="true">
|
|
<% end %>
|
|
<% end %>
|
|
<% else %>
|
|
<% if params.quality == "dash" %>
|
|
<source src="/api/manifest/dash/id/<%= video.id %>?local=true&unique_res=1" type='application/dash+xml' label="dash">
|
|
<% end %>
|
|
|
|
<%
|
|
fmt_stream.reject! { |f| f["itag"] == 17 }
|
|
fmt_stream.sort_by! {|f| params.quality == f["quality"] ? 0 : 1 }
|
|
fmt_stream.each_with_index do |fmt, i|
|
|
src_url = "/latest_version?id=#{video.id}&itag=#{fmt["itag"]}"
|
|
src_url += "&local=true" if params.local
|
|
|
|
quality = fmt["quality"]
|
|
mimetype = HTML.escape(fmt["mimeType"].as_s)
|
|
|
|
selected = params.quality ? (params.quality == quality) : (i == 0)
|
|
%>
|
|
<source src="<%= src_url %>" type="<%= mimetype %>" label="<%= quality %>" selected="<%= selected %>">
|
|
<% if !params.local && !CONFIG.disabled?("local") %>
|
|
<source src="<%= src_url %>&local=true" type="<%= mimetype %>" hidequalityoption="true">
|
|
<% end %>
|
|
<% end %>
|
|
<% end %>
|
|
|
|
<% preferred_captions.each do |caption| %>
|
|
<track kind="captions" src="/api/v1/captions/<%= video.id %>?label=<%= caption.name %>" label="<%= caption.name %>">
|
|
<% end %>
|
|
|
|
<% captions.each do |caption| %>
|
|
<track kind="captions" src="/api/v1/captions/<%= video.id %>?label=<%= caption.name %>" label="<%= caption.name %>">
|
|
<% end %>
|
|
<% end %>
|
|
</video>
|
|
|
|
<script id="player_data" type="application/json">
|
|
<%=
|
|
{
|
|
"aspect_ratio" => aspect_ratio,
|
|
"title" => video.title,
|
|
"description" => HTML.escape(video.short_description),
|
|
"thumbnail" => thumbnail,
|
|
"preferred_caption_found" => !preferred_captions.empty?,
|
|
"preload" => params.preload ? "auto" : "none"
|
|
}.to_pretty_json
|
|
%>
|
|
</script>
|
|
<script src="/js/player.js?v=<%= ASSET_COMMIT %>"></script>
|