<video style="outline:none;width:100%;background-color:#000" playsinline poster="<%= thumbnail %>" title="<%= HTML.escape(video.title) %>"
    id="player" class="video-js player-style-<%= params.player_style %>"
    onmouseenter='this["data-title"]=this["title"];this["title"]=""'
    onmouseleave='this["title"]=this["data-title"];this["data-title"]=""'
    oncontextmenu='this["title"]=this["data-title"]'
    <% if params.autoplay %>autoplay<% end %>
    <% if params.video_loop %>loop<% end %>
    <% if params.controls %>controls<% end %>>
    <% if hlsvp && !CONFIG.disabled?("livestreams") %>
        <source src="<%= hlsvp %>?local=true" type="application/x-mpegURL" label="livestream">
    <% else %>
        <% if params.listen %>
            <% audio_streams.each_with_index do |fmt, i| %>
                <source src="/latest_version?id=<%= video.id %>&itag=<%= fmt["itag"] %><% if params.local %>&local=true<% end %>" type='<%= fmt["type"] %>' label="<%= fmt["bitrate"] %>k" selected="<%= i == 0 ? true : false %>">
            <% end %>
          <% else %>
            <% if params.quality == "dash" %>
                <source src="/api/manifest/dash/id/<%= video.id %>?local=true" type='application/dash+xml' label="dash">
            <% end %>

            <% fmt_stream.each_with_index do |fmt, i| %>
                <% if params.quality %>
                    <source src="/latest_version?id=<%= video.id %>&itag=<%= fmt["itag"] %><% if params.local %>&local=true<% end %>" type='<%= fmt["type"] %>' label="<%= fmt["label"] %>" selected="<%= params.quality == fmt["label"].split(" - ")[0] %>">
                <% else %>
                    <source src="/latest_version?id=<%= video.id %>&itag=<%= fmt["itag"] %><% if params.local %>&local=true<% end %>" type='<%= fmt["type"] %>' label="<%= fmt["label"] %>" selected="<%= i == 0 ? true : false %>">
                <% end %>
            <% end %>
        <% end %>

        <% preferred_captions.each_with_index do |caption, i| %>
            <track kind="captions" src="/api/v1/captions/<%= video.id %>?label=<%= caption.name.simpleText %>&hl=<%= env.get("preferences").as(Preferences).locale %>"
                label="<%= caption.name.simpleText %>" <% if i == 0 %>default<% end %>>
        <% end %>

        <% captions.each do |caption| %>
            <track kind="captions" src="/api/v1/captions/<%= video.id %>?label=<%= caption.name.simpleText %>&hl=<%= env.get("preferences").as(Preferences).locale %>"
                label="<%= caption.name.simpleText %>">
        <% end %>
    <% end %>
</video>

<script>
var player_data = {
    aspect_ratio: '<%= aspect_ratio %>',
    title: "<%= video.title.dump_unquoted %>",
    description: "<%= HTML.escape(video.short_description) %>",
    thumbnail: "<%= thumbnail %>"
}
</script>
<script src="/js/player.js?v=<%= ASSET_COMMIT %>"></script>
