Skip to content
Permalink
Browse files

Add continuous playback

  • Loading branch information...
omarroth committed Nov 11, 2018
1 parent 1465cef commit 4b76b93610e64a63d61d1369fdef9af119852aab
Showing with 69 additions and 1 deletion.
  1. +5 −0 src/invidious.cr
  2. +5 −1 src/invidious/users.cr
  3. +5 −0 src/invidious/videos.cr
  4. +5 −0 src/invidious/views/preferences.ecr
  5. +49 −0 src/invidious/views/watch.ecr
@@ -965,6 +965,10 @@ post "/preferences" do |env|
autoplay ||= "off"
autoplay = autoplay == "on"

continue = env.params.body["continue"]?.try &.as(String)
continue ||= "off"
continue = continue == "on"

listen = env.params.body["listen"]?.try &.as(String)
listen ||= "off"
listen = listen == "on"
@@ -1024,6 +1028,7 @@ post "/preferences" do |env|
preferences = {
"video_loop" => video_loop,
"autoplay" => autoplay,
"continue" => continue,
"listen" => listen,
"speed" => speed,
"quality" => quality,
@@ -70,7 +70,11 @@ class Preferences
JSON.mapping({
video_loop: Bool,
autoplay: Bool,
listen: {
continue: {
type: Bool,
default: false,
},
listen: {
type: Bool,
default: false,
},
@@ -730,6 +730,7 @@ end

def process_video_params(query, preferences)
autoplay = query["autoplay"]?.try &.to_i?
continue = query["continue"]?.try &.to_i?
listen = query["listen"]? && (query["listen"] == "true" || query["listen"] == "1").to_unsafe
preferred_captions = query["subtitles"]?.try &.split(",").map { |a| a.downcase }
quality = query["quality"]?
@@ -739,6 +740,7 @@ def process_video_params(query, preferences)

if preferences
autoplay ||= preferences.autoplay.to_unsafe
continue ||= preferences.continue.to_unsafe
listen ||= preferences.listen.to_unsafe
preferred_captions ||= preferences.captions
quality ||= preferences.quality
@@ -748,6 +750,7 @@ def process_video_params(query, preferences)
end

autoplay ||= 0
continue ||= 0
listen ||= 0
preferred_captions ||= [] of String
quality ||= "hd720"
@@ -756,6 +759,7 @@ def process_video_params(query, preferences)
volume ||= 100

autoplay = autoplay == 1
continue = continue == 1
listen = listen == 1
video_loop = video_loop == 1

@@ -786,6 +790,7 @@ def process_video_params(query, preferences)

params = {
autoplay: autoplay,
continue: continue,
controls: controls,
listen: listen,
preferred_captions: preferred_captions,
@@ -23,6 +23,11 @@ function update_value(element) {
<input name="autoplay" id="autoplay" type="checkbox" <% if user.preferences.autoplay %>checked<% end %>>
</div>

<div class="pure-control-group">
<label for="continue">Automatically play next video: </label>
<input name="continue" id="continue" type="checkbox" <% if user.preferences.continue %>checked<% end %>>
</div>

<div class="pure-control-group">
<label for="listen">Listen by default: </label>
<input name="listen" id="listen" type="checkbox" <% if user.preferences.listen %>checked<% end %>>
@@ -140,6 +140,15 @@

<% if !preferences || preferences && preferences.related_videos %>
<div class="h-box">

<% if !plid && !rvs.empty? %>
<div class="pure-control-group">
<label for="continue">Autoplay next video: </label>
<input name="continue" onclick="continue_autoplay(this)" id="continue" type="checkbox" <% if params[:continue] %>checked<% end %>>
</div>
<hr>
<% end %>

<% rvs.each do |rv| %>
<% if rv.has_key?("id") %>
<a href="/watch?v=<%= rv["id"] %>">
@@ -163,6 +172,46 @@
</div>

<script>
<% if !rvs.empty? && !plid && params[:continue] %>
player.on('ended', function() {
window.location.replace("/watch?v="
+ "<%= rvs[0]?.try &.["id"] %>"
+ "&continue=1"
<% if params[:listen] %>
+ "&listen=1"
<% end %>
<% if params[:autoplay] %>
+ "&autoplay=1"
<% end %>
<% if params[:speed] %>
+ "&speed=<%= params[:speed] %>"
<% end %>
);
});
<% end %>
function continue_autoplay(target) {
if (target.checked) {
player.on('ended', function() {
window.location.replace("/watch?v="
+ "<%= rvs[0]?.try &.["id"] %>"
+ "&continue=1"
<% if params[:listen] %>
+ "&listen=1"
<% end %>
<% if params[:autoplay] %>
+ "&autoplay=1"
<% end %>
<% if params[:speed] %>
+ "&speed=<%= params[:speed] %>"
<% end %>
);
});
} else {
player.off('ended');
}
}
function number_with_separator(val) {
while (/(\d+)(\d{3})/.test(val.toString())) {
val = val.toString().replace(/(\d+)(\d{3})/, "$1" + "," + "$2");

0 comments on commit 4b76b93

Please sign in to comment.
You can’t perform that action at this time.