Add 'continue_autoplay' preference

This commit is contained in:
Omar Roth 2019-04-19 09:38:27 -05:00
parent eac0a52f10
commit bb5a1ad513
7 changed files with 40 additions and 23 deletions

View File

@ -1241,6 +1241,10 @@ post "/preferences" do |env|
continue ||= "off" continue ||= "off"
continue = continue == "on" 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 = env.params.body["listen"]?.try &.as(String)
listen ||= "off" listen ||= "off"
listen = listen == "on" listen = listen == "on"
@ -1309,6 +1313,7 @@ post "/preferences" do |env|
"video_loop" => video_loop, "video_loop" => video_loop,
"autoplay" => autoplay, "autoplay" => autoplay,
"continue" => continue, "continue" => continue,
"continue_autoplay" => continue_autoplay,
"listen" => listen, "listen" => listen,
"local" => local, "local" => local,
"speed" => speed, "speed" => speed,

View File

@ -63,6 +63,7 @@ struct ConfigPreferences
captions: {type: Array(String), default: ["", "", ""], converter: StringToArray}, captions: {type: Array(String), default: ["", "", ""], converter: StringToArray},
comments: {type: Array(String), default: ["youtube", ""], converter: StringToArray}, comments: {type: Array(String), default: ["youtube", ""], converter: StringToArray},
continue: {type: Bool, default: false}, continue: {type: Bool, default: false},
continue_autoplay: {type: Bool, default: true},
dark_mode: {type: Bool, default: false}, dark_mode: {type: Bool, default: false},
latest_only: {type: Bool, default: false}, latest_only: {type: Bool, default: false},
listen: {type: Bool, default: false}, listen: {type: Bool, default: false},

View File

@ -88,6 +88,7 @@ struct Preferences
captions: {type: Array(String), default: CONFIG.default_user_preferences.captions, converter: StringToArray}, captions: {type: Array(String), default: CONFIG.default_user_preferences.captions, converter: StringToArray},
comments: {type: Array(String), default: CONFIG.default_user_preferences.comments, converter: StringToArray}, comments: {type: Array(String), default: CONFIG.default_user_preferences.comments, converter: StringToArray},
continue: {type: Bool, default: CONFIG.default_user_preferences.continue}, 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}, dark_mode: {type: Bool, default: CONFIG.default_user_preferences.dark_mode},
latest_only: {type: Bool, default: CONFIG.default_user_preferences.latest_only}, latest_only: {type: Bool, default: CONFIG.default_user_preferences.latest_only},
listen: {type: Bool, default: CONFIG.default_user_preferences.listen}, listen: {type: Bool, default: CONFIG.default_user_preferences.listen},

View File

@ -1017,6 +1017,7 @@ end
def process_video_params(query, preferences) def process_video_params(query, preferences)
autoplay = query["autoplay"]?.try &.to_i? autoplay = query["autoplay"]?.try &.to_i?
continue = query["continue"]?.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 listen = query["listen"]? && (query["listen"] == "true" || query["listen"] == "1").to_unsafe
local = query["local"]? && (query["local"] == "true").to_unsafe local = query["local"]? && (query["local"] == "true").to_unsafe
preferred_captions = query["subtitles"]?.try &.split(",").map { |a| a.downcase } preferred_captions = query["subtitles"]?.try &.split(",").map { |a| a.downcase }
@ -1031,6 +1032,7 @@ def process_video_params(query, preferences)
# region ||= preferences.region # region ||= preferences.region
autoplay ||= preferences.autoplay.to_unsafe autoplay ||= preferences.autoplay.to_unsafe
continue ||= preferences.continue.to_unsafe continue ||= preferences.continue.to_unsafe
continue_autoplay ||= preferences.continue_autoplay.to_unsafe
listen ||= preferences.listen.to_unsafe listen ||= preferences.listen.to_unsafe
local ||= preferences.local.to_unsafe local ||= preferences.local.to_unsafe
preferred_captions ||= preferences.captions preferred_captions ||= preferences.captions
@ -1043,6 +1045,7 @@ def process_video_params(query, preferences)
autoplay ||= CONFIG.default_user_preferences.autoplay.to_unsafe autoplay ||= CONFIG.default_user_preferences.autoplay.to_unsafe
continue ||= CONFIG.default_user_preferences.continue.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 listen ||= CONFIG.default_user_preferences.listen.to_unsafe
local ||= CONFIG.default_user_preferences.local.to_unsafe local ||= CONFIG.default_user_preferences.local.to_unsafe
preferred_captions ||= CONFIG.default_user_preferences.captions preferred_captions ||= CONFIG.default_user_preferences.captions
@ -1054,6 +1057,7 @@ def process_video_params(query, preferences)
autoplay = autoplay == 1 autoplay = autoplay == 1
continue = continue == 1 continue = continue == 1
continue_autoplay = continue_autoplay == 1
listen = listen == 1 listen = listen == 1
local = local == 1 local = local == 1
related_videos = related_videos == 1 related_videos = related_videos == 1
@ -1087,6 +1091,7 @@ def process_video_params(query, preferences)
params = { params = {
autoplay: autoplay, autoplay: autoplay,
continue: continue, continue: continue,
continue_autoplay: continue_autoplay,
controls: controls, controls: controls,
listen: listen, listen: listen,
local: local, local: local,

View File

@ -55,13 +55,13 @@ function get_playlist(timeouts = 0) {
location.assign("/embed/" location.assign("/embed/"
+ xhr.response.nextVideo + xhr.response.nextVideo
+ "?list=<%= plid %>" + "?list=<%= plid %>"
<% if params[:listen] %> <% if params[:listen] != preferences.listen %>
+ "&listen=1" + "&listen=<%= params[:listen] %>"
<% end %> <% end %>
<% if params[:autoplay] %> <% if params[:autoplay] || params[:continue_autoplay] %>
+ "&autoplay=1" + "&autoplay=1"
<% end %> <% end %>
<% if params[:speed] %> <% if params[:speed] != preferences.speed %>
+ "&speed=<%= params[:speed] %>" + "&speed=<%= params[:speed] %>"
<% end %> <% end %>
); );
@ -85,13 +85,13 @@ player.on('ended', function() {
<% if !video_series.empty? %> <% if !video_series.empty? %>
+ "?playlist=<%= video_series.join(",") %>" + "?playlist=<%= video_series.join(",") %>"
<% end %> <% end %>
<% if params[:listen] %> <% if params[:listen] != preferences.listen %>
+ "&listen=1" + "&listen=<%= params[:listen] %>"
<% end %> <% end %>
<% if params[:autoplay] %> <% if params[:autoplay] || params[:continue_autoplay] %>
+ "&autoplay=1" + "&autoplay=1"
<% end %> <% end %>
<% if params[:speed] %> <% if params[:speed] != preferences.speed %>
+ "&speed=<%= params[:speed] %>" + "&speed=<%= params[:speed] %>"
<% end %> <% end %>
); );

View File

@ -24,10 +24,15 @@ function update_value(element) {
</div> </div>
<div class="pure-control-group"> <div class="pure-control-group">
<label for="continue"><%= translate(locale, "Autoplay next video: ") %></label> <label for="continue"><%= translate(locale, "Play next by default: ") %></label>
<input name="continue" id="continue" type="checkbox" <% if preferences.continue %>checked<% end %>> <input name="continue" id="continue" type="checkbox" <% if preferences.continue %>checked<% end %>>
</div> </div>
<div class="pure-control-group">
<label for="continue_autoplay"><%= translate(locale, "Autoplay next video: ") %></label>
<input name="continue_autoplay" id="continue_autoplay" type="checkbox" <% if preferences.continue_autoplay %>checked<% end %>>
</div>
<div class="pure-control-group"> <div class="pure-control-group">
<label for="local"><%= translate(locale, "Proxy videos? ") %></label> <label for="local"><%= translate(locale, "Proxy videos? ") %></label>
<input name="local" id="local" type="checkbox" <% if preferences.local %>checked<% end %>> <input name="local" id="local" type="checkbox" <% if preferences.local %>checked<% end %>>

View File

@ -202,13 +202,13 @@ player.on('ended', function() {
location.assign("/watch?v=" location.assign("/watch?v="
+ "<%= rvs.select { |rv| rv["id"]? }[0]?.try &.["id"] %>" + "<%= rvs.select { |rv| rv["id"]? }[0]?.try &.["id"] %>"
+ "&continue=1" + "&continue=1"
<% if params[:listen] %> <% if params[:listen] != preferences.listen %>
+ "&listen=1" + "&listen=<%= params[:listen] %>"
<% end %> <% end %>
<% if params[:autoplay] %> <% if params[:autoplay] || params[:continue_autoplay] %>
+ "&autoplay=1" + "&autoplay=1"
<% end %> <% end %>
<% if params[:speed] %> <% if params[:speed] != preferences.speed %>
+ "&speed=<%= params[:speed] %>" + "&speed=<%= params[:speed] %>"
<% end %> <% end %>
); );
@ -221,13 +221,13 @@ function continue_autoplay(target) {
location.assign("/watch?v=" location.assign("/watch?v="
+ "<%= rvs.select { |rv| rv["id"]? }[0]?.try &.["id"] %>" + "<%= rvs.select { |rv| rv["id"]? }[0]?.try &.["id"] %>"
+ "&continue=1" + "&continue=1"
<% if params[:listen] %> <% if params[:listen] != preferences.listen %>
+ "&listen=1" + "&listen=<%= params[:listen] %>"
<% end %> <% end %>
<% if params[:autoplay] %> <% if params[:autoplay] || params[:continue_autoplay] %>
+ "&autoplay=1" + "&autoplay=1"
<% end %> <% end %>
<% if params[:speed] %> <% if params[:speed] != preferences.speed %>
+ "&speed=<%= params[:speed] %>" + "&speed=<%= params[:speed] %>"
<% end %> <% end %>
); );
@ -287,13 +287,13 @@ function get_playlist(timeouts = 0) {
location.assign("/watch?v=" location.assign("/watch?v="
+ xhr.response.nextVideo + xhr.response.nextVideo
+ "&list=<%= plid %>" + "&list=<%= plid %>"
<% if params[:listen] %> <% if params[:listen] != preferences.listen %>
+ "&listen=1" + "&listen=<%= params[:listen] %>"
<% end %> <% end %>
<% if params[:autoplay] %> <% if params[:autoplay] || params[:continue_autoplay] %>
+ "&autoplay=1" + "&autoplay=1"
<% end %> <% end %>
<% if params[:speed] %> <% if params[:speed] != preferences.speed %>
+ "&speed=<%= params[:speed] %>" + "&speed=<%= params[:speed] %>"
<% end %> <% end %>
); );