summaryrefslogtreecommitdiff
path: root/src/invidious/views/components/player.ecr
blob: fffefc9a3403e22c47d028a36007a8ad5e49af6e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<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 %>"
    <% 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 %>
            <% 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 == 0 ? true : false
            %>
                <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?
}.to_pretty_json
%>
</script>
<script src="/js/player.js?v=<%= ASSET_COMMIT %>"></script>