Add captions to embedded videos

This commit is contained in:
Omar Roth 2018-08-02 17:08:33 -05:00
parent 42405a34f1
commit a12690cbfd
3 changed files with 20 additions and 10 deletions

View file

@ -1440,6 +1440,12 @@ get "/embed/:id" do |env|
next templated "error" next templated "error"
end end
player_response = JSON.parse(video.info["player_response"])
if player_response["captions"]?
captions = player_response["captions"]["playerCaptionsTracklistRenderer"]["captionTracks"]?.try &.as_a
end
captions ||= [] of JSON::Any
if video.info["hlsvp"]? if video.info["hlsvp"]?
hlsvp = video.info["hlsvp"] hlsvp = video.info["hlsvp"]

View file

@ -728,7 +728,7 @@ def fill_links(html, scheme, host)
end end
end end
html = html.to_xml html = html.xpath_node(%q(//p[@id="eow-description"])).not_nil!.to_xml
end end
def login_req(login_form, f_req) def login_req(login_form, f_req)

View file

@ -54,10 +54,14 @@ video, #my_video, .video-js, .vjs-default-skin
<source src="<%= fmt["url"] %>" type='<%= fmt["type"] %>' label="<%= fmt["label"] %>" selected="<%= quality == fmt["label"].split(" - ")[0] %>"> <source src="<%= fmt["url"] %>" type='<%= fmt["type"] %>' label="<%= fmt["label"] %>" selected="<%= quality == fmt["label"].split(" - ")[0] %>">
<% else %> <% else %>
<source src="<%= fmt["url"] %>" type='<%= fmt["type"] %>' label="<%= fmt["label"] %>" selected="<%= i == 0 ? true : false %>"> <source src="<%= fmt["url"] %>" type='<%= fmt["type"] %>' label="<%= fmt["label"] %>" selected="<%= i == 0 ? true : false %>">
<% end %> <% end %>
<% captions.each do |caption| %>
<track kind="captions" src="/api/v1/captions/<%= video.id %>?label=<%= caption["name"]["simpleText"] %>"
srclang="<%= caption["languageCode"] %>" label="<%= caption["name"]["simpleText"]%> ">
<% end %> <% end %>
<% end %> <% end %>
<% end %> <% end %>
<% end %>
</video> </video>
<script> <script>
@ -132,7 +136,7 @@ var player = videojs('player', options, function() {
player.share(shareOptions); player.share(shareOptions);
<% if video_start > 0 || video_end > 0 %> <%- if video_start > 0 || video_end > 0 -%>
player.markers({ player.markers({
onMarkerReached: function(marker) { onMarkerReached: function(marker) {
if (marker.text === 'End') { if (marker.text === 'End') {
@ -145,18 +149,18 @@ player.markers({
}, },
markers: [ markers: [
{time: <%= video_start %>, text: 'Start'}, {time: <%= video_start %>, text: 'Start'},
<% if video_end < 0 %> <%- if video_end < 0 -%>
{time: <%= video.info["length_seconds"].to_f - 0.5 %>, text: 'End'} {time: <%= video.info["length_seconds"].to_f - 0.5 %>, text: 'End'}
<% else %> <%- else -%>
{time: <%= video_end %>, text: 'End'} {time: <%= video_end %>, text: 'End'}
<% end %> <%- end -%>
] ]
}); });
player.currentTime(<%= video_start %>); player.currentTime(<%= video_start %>);
<% end %> <%- end -%>
<% if !listen %> <%- if !listen -%>
var currentSources = player.currentSources(); var currentSources = player.currentSources();
for ( var i = 0; i < currentSources.length; i++ ) { for ( var i = 0; i < currentSources.length; i++ ) {
if (player.canPlayType(currentSources[i]['type'].split(';')[0]) === '') { if (player.canPlayType(currentSources[i]['type'].split(';')[0]) === '') {
@ -166,7 +170,7 @@ for ( var i = 0; i < currentSources.length; i++ ) {
} }
player.src(currentSources); player.src(currentSources);
<% end %> <%- end -%>
</script> </script>
</body> </body>