From bb5a1ad5136d9c85dd89def312921ae61bd4f856 Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Fri, 19 Apr 2019 09:38:27 -0500 Subject: [PATCH] Add 'continue_autoplay' preference --- src/invidious.cr | 9 +++++++-- src/invidious/helpers/helpers.cr | 1 + src/invidious/users.cr | 1 + src/invidious/videos.cr | 5 +++++ src/invidious/views/embed.ecr | 16 ++++++++-------- src/invidious/views/preferences.ecr | 7 ++++++- src/invidious/views/watch.ecr | 24 ++++++++++++------------ 7 files changed, 40 insertions(+), 23 deletions(-) diff --git a/src/invidious.cr b/src/invidious.cr index 4e48fab0..57db7e28 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -1150,8 +1150,8 @@ post "/login" do |env| view_name = "subscriptions_#{sha256(user.email)}" PG_DB.exec("CREATE MATERIALIZED VIEW #{view_name} AS \ - SELECT * FROM channel_videos WHERE \ - ucid = ANY ((SELECT subscriptions FROM users WHERE email = E'#{user.email.gsub("'", "\\'")}')::text[]) \ + SELECT * FROM channel_videos WHERE \ + ucid = ANY ((SELECT subscriptions FROM users WHERE email = E'#{user.email.gsub("'", "\\'")}')::text[]) \ ORDER BY published DESC;") if Kemal.config.ssl || config.https_only @@ -1241,6 +1241,10 @@ post "/preferences" do |env| continue ||= "off" continue = continue == "on" + continue_autoplay = env.params.body["continue_autoplay"]?.try &.as(String) + continue_autoplay ||= "off" + continue_autoplay = continue_autoplay == "on" + listen = env.params.body["listen"]?.try &.as(String) listen ||= "off" listen = listen == "on" @@ -1309,6 +1313,7 @@ post "/preferences" do |env| "video_loop" => video_loop, "autoplay" => autoplay, "continue" => continue, + "continue_autoplay" => continue_autoplay, "listen" => listen, "local" => local, "speed" => speed, diff --git a/src/invidious/helpers/helpers.cr b/src/invidious/helpers/helpers.cr index 9b29210d..14b7719b 100644 --- a/src/invidious/helpers/helpers.cr +++ b/src/invidious/helpers/helpers.cr @@ -63,6 +63,7 @@ struct ConfigPreferences captions: {type: Array(String), default: ["", "", ""], converter: StringToArray}, comments: {type: Array(String), default: ["youtube", ""], converter: StringToArray}, continue: {type: Bool, default: false}, + continue_autoplay: {type: Bool, default: true}, dark_mode: {type: Bool, default: false}, latest_only: {type: Bool, default: false}, listen: {type: Bool, default: false}, diff --git a/src/invidious/users.cr b/src/invidious/users.cr index 43a55eac..2e9ec1e5 100644 --- a/src/invidious/users.cr +++ b/src/invidious/users.cr @@ -88,6 +88,7 @@ struct Preferences captions: {type: Array(String), default: CONFIG.default_user_preferences.captions, converter: StringToArray}, comments: {type: Array(String), default: CONFIG.default_user_preferences.comments, converter: StringToArray}, continue: {type: Bool, default: CONFIG.default_user_preferences.continue}, + continue_autoplay: {type: Bool, default: CONFIG.default_user_preferences.continue_autoplay}, dark_mode: {type: Bool, default: CONFIG.default_user_preferences.dark_mode}, latest_only: {type: Bool, default: CONFIG.default_user_preferences.latest_only}, listen: {type: Bool, default: CONFIG.default_user_preferences.listen}, diff --git a/src/invidious/videos.cr b/src/invidious/videos.cr index bdd21a48..2ad6cdaa 100644 --- a/src/invidious/videos.cr +++ b/src/invidious/videos.cr @@ -1017,6 +1017,7 @@ end def process_video_params(query, preferences) autoplay = query["autoplay"]?.try &.to_i? continue = query["continue"]?.try &.to_i? + continue_autoplay = query["continue_autoplay"]?.try &.to_i? listen = query["listen"]? && (query["listen"] == "true" || query["listen"] == "1").to_unsafe local = query["local"]? && (query["local"] == "true").to_unsafe preferred_captions = query["subtitles"]?.try &.split(",").map { |a| a.downcase } @@ -1031,6 +1032,7 @@ def process_video_params(query, preferences) # region ||= preferences.region autoplay ||= preferences.autoplay.to_unsafe continue ||= preferences.continue.to_unsafe + continue_autoplay ||= preferences.continue_autoplay.to_unsafe listen ||= preferences.listen.to_unsafe local ||= preferences.local.to_unsafe preferred_captions ||= preferences.captions @@ -1043,6 +1045,7 @@ def process_video_params(query, preferences) autoplay ||= CONFIG.default_user_preferences.autoplay.to_unsafe continue ||= CONFIG.default_user_preferences.continue.to_unsafe + continue_autoplay ||= CONFIG.default_user_preferences.continue_autoplay.to_unsafe listen ||= CONFIG.default_user_preferences.listen.to_unsafe local ||= CONFIG.default_user_preferences.local.to_unsafe preferred_captions ||= CONFIG.default_user_preferences.captions @@ -1054,6 +1057,7 @@ def process_video_params(query, preferences) autoplay = autoplay == 1 continue = continue == 1 + continue_autoplay = continue_autoplay == 1 listen = listen == 1 local = local == 1 related_videos = related_videos == 1 @@ -1087,6 +1091,7 @@ def process_video_params(query, preferences) params = { autoplay: autoplay, continue: continue, + continue_autoplay: continue_autoplay, controls: controls, listen: listen, local: local, diff --git a/src/invidious/views/embed.ecr b/src/invidious/views/embed.ecr index ac69512f..8ae46114 100644 --- a/src/invidious/views/embed.ecr +++ b/src/invidious/views/embed.ecr @@ -55,13 +55,13 @@ function get_playlist(timeouts = 0) { location.assign("/embed/" + xhr.response.nextVideo + "?list=<%= plid %>" - <% if params[:listen] %> - + "&listen=1" + <% if params[:listen] != preferences.listen %> + + "&listen=<%= params[:listen] %>" <% end %> - <% if params[:autoplay] %> + <% if params[:autoplay] || params[:continue_autoplay] %> + "&autoplay=1" <% end %> - <% if params[:speed] %> + <% if params[:speed] != preferences.speed %> + "&speed=<%= params[:speed] %>" <% end %> ); @@ -85,13 +85,13 @@ player.on('ended', function() { <% if !video_series.empty? %> + "?playlist=<%= video_series.join(",") %>" <% end %> - <% if params[:listen] %> - + "&listen=1" + <% if params[:listen] != preferences.listen %> + + "&listen=<%= params[:listen] %>" <% end %> - <% if params[:autoplay] %> + <% if params[:autoplay] || params[:continue_autoplay] %> + "&autoplay=1" <% end %> - <% if params[:speed] %> + <% if params[:speed] != preferences.speed %> + "&speed=<%= params[:speed] %>" <% end %> ); diff --git a/src/invidious/views/preferences.ecr b/src/invidious/views/preferences.ecr index 5dfe779b..3984a4ab 100644 --- a/src/invidious/views/preferences.ecr +++ b/src/invidious/views/preferences.ecr @@ -24,10 +24,15 @@ function update_value(element) {
- + checked<% end %>>
+
+ + checked<% end %>> +
+
checked<% end %>> diff --git a/src/invidious/views/watch.ecr b/src/invidious/views/watch.ecr index c5f4e2ba..accbca52 100644 --- a/src/invidious/views/watch.ecr +++ b/src/invidious/views/watch.ecr @@ -202,13 +202,13 @@ player.on('ended', function() { location.assign("/watch?v=" + "<%= rvs.select { |rv| rv["id"]? }[0]?.try &.["id"] %>" + "&continue=1" - <% if params[:listen] %> - + "&listen=1" + <% if params[:listen] != preferences.listen %> + + "&listen=<%= params[:listen] %>" <% end %> - <% if params[:autoplay] %> + <% if params[:autoplay] || params[:continue_autoplay] %> + "&autoplay=1" <% end %> - <% if params[:speed] %> + <% if params[:speed] != preferences.speed %> + "&speed=<%= params[:speed] %>" <% end %> ); @@ -221,13 +221,13 @@ function continue_autoplay(target) { location.assign("/watch?v=" + "<%= rvs.select { |rv| rv["id"]? }[0]?.try &.["id"] %>" + "&continue=1" - <% if params[:listen] %> - + "&listen=1" + <% if params[:listen] != preferences.listen %> + + "&listen=<%= params[:listen] %>" <% end %> - <% if params[:autoplay] %> + <% if params[:autoplay] || params[:continue_autoplay] %> + "&autoplay=1" <% end %> - <% if params[:speed] %> + <% if params[:speed] != preferences.speed %> + "&speed=<%= params[:speed] %>" <% end %> ); @@ -287,13 +287,13 @@ function get_playlist(timeouts = 0) { location.assign("/watch?v=" + xhr.response.nextVideo + "&list=<%= plid %>" - <% if params[:listen] %> - + "&listen=1" + <% if params[:listen] != preferences.listen %> + + "&listen=<%= params[:listen] %>" <% end %> - <% if params[:autoplay] %> + <% if params[:autoplay] || params[:continue_autoplay] %> + "&autoplay=1" <% end %> - <% if params[:speed] %> + <% if params[:speed] != preferences.speed %> + "&speed=<%= params[:speed] %>" <% end %> );