mirror of https://github.com/iv-org/invidious.git
Finish vetting changes for autoplay stability
This commit is contained in:
parent
f05d38aa8e
commit
d7a53d0159
|
@ -423,17 +423,17 @@ def extract_compilation_videos(initial_data : Hash(String, JSON::Any))
|
||||||
end
|
end
|
||||||
|
|
||||||
videos << CompilationVideo.new({
|
videos << CompilationVideo.new({
|
||||||
title: title,
|
title: title,
|
||||||
id: video_id,
|
id: video_id,
|
||||||
author: author,
|
author: author,
|
||||||
ucid: ucid,
|
ucid: ucid,
|
||||||
length_seconds: length_seconds,
|
length_seconds: length_seconds,
|
||||||
starting_timestamp_seconds: starting_timestamp_seconds,
|
starting_timestamp_seconds: starting_timestamp_seconds,
|
||||||
ending_timestamp_seconds: ending_timestamp_seconds,
|
ending_timestamp_seconds: ending_timestamp_seconds,
|
||||||
published: Time.utc,
|
published: Time.utc,
|
||||||
compid: compid,
|
compid: compid,
|
||||||
index: index,
|
index: index,
|
||||||
order_index: order_index
|
order_index: order_index
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -334,13 +334,13 @@ module Invidious::Database::CompilationVideos
|
||||||
PG_DB.exec(request, id, starting_timestamp_seconds)
|
PG_DB.exec(request, id, starting_timestamp_seconds)
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_end_timestamp(id : String, ending_timestamp_seconds : Int64)
|
def update_end_timestamp(id : String, ending_timestamp_seconds : Int32)
|
||||||
request = <<-SQL
|
request = <<-SQL
|
||||||
UPDATE compilation_videos
|
UPDATE compilation_videos
|
||||||
SET ending_timestamp_seconds = ending_timestamp_seconds
|
SET ending_timestamp_seconds = $2
|
||||||
WHERE id = $1
|
WHERE id = $1
|
||||||
SQL
|
SQL
|
||||||
|
|
||||||
PG_DB.exec(request, id)
|
PG_DB.exec(request, id, ending_timestamp_seconds)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -35,8 +35,10 @@ def decode_length_seconds(string)
|
||||||
end
|
end
|
||||||
|
|
||||||
def recode_length_seconds(time)
|
def recode_length_seconds(time)
|
||||||
if time <= 0
|
if time < 0
|
||||||
return ""
|
return ""
|
||||||
|
elsif time == 0
|
||||||
|
return "0:00"
|
||||||
else
|
else
|
||||||
time = time.seconds
|
time = time.seconds
|
||||||
text = "#{time.minutes.to_s.rjust(2, '0')}:#{time.seconds.to_s.rjust(2, '0')}"
|
text = "#{time.minutes.to_s.rjust(2, '0')}:#{time.seconds.to_s.rjust(2, '0')}"
|
||||||
|
|
|
@ -244,7 +244,6 @@ module Invidious::Routes::Compilations
|
||||||
compilation_video_index = compilation.index[index]
|
compilation_video_index = compilation.index[index]
|
||||||
compilation_video = Invidious::Database::CompilationVideos.select_video(compid, compilation.index, compilation_video_index, 0, 1)
|
compilation_video = Invidious::Database::CompilationVideos.select_video(compid, compilation.index, compilation_video_index, 0, 1)
|
||||||
json_timestamp_query_start = compilation_video_index.to_s + "_start_timestamp"
|
json_timestamp_query_start = compilation_video_index.to_s + "_start_timestamp"
|
||||||
|
|
||||||
start_timestamp = env.params.body[json_timestamp_query_start]?.try &.as(String).byte_slice(0, 8)
|
start_timestamp = env.params.body[json_timestamp_query_start]?.try &.as(String).byte_slice(0, 8)
|
||||||
if !start_timestamp.nil? && !compilation_video[0].id.nil?
|
if !start_timestamp.nil? && !compilation_video[0].id.nil?
|
||||||
start_timestamp_seconds = decode_length_seconds(start_timestamp)
|
start_timestamp_seconds = decode_length_seconds(start_timestamp)
|
||||||
|
@ -254,14 +253,14 @@ module Invidious::Routes::Compilations
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
compilation_video = Invidious::Database::CompilationVideos.select_video(compid, compilation.index, compilation_video_index, 0, 1)
|
||||||
json_timestamp_query_end = compilation_video_index.to_s + "_end_timestamp"
|
json_timestamp_query_end = compilation_video_index.to_s + "_end_timestamp"
|
||||||
end_timestamp = env.params.json[json_timestamp_query_end]?.try &.as(String).byte_slice(0, 8)
|
end_timestamp = env.params.json[json_timestamp_query_end]?.try &.as(String).byte_slice(0, 8)
|
||||||
if !end_timestamp.nil? && !compilation_video[0].id.nil?
|
if !end_timestamp.nil? && !compilation_video[0].id.nil?
|
||||||
end_timestamp_seconds = decode_length_seconds(end_timestamp)
|
end_timestamp_seconds = decode_length_seconds(end_timestamp)
|
||||||
if !end_timestamp_seconds.nil?
|
if !end_timestamp_seconds.nil?
|
||||||
if end_timestamp_seconds >= 0 && end_timestamp_seconds <= compilation_video[0].ending_timestamp_seconds && end_timestamp_seconds > compilation_video[0].starting_timestamp_seconds
|
if end_timestamp_seconds >= 0 && end_timestamp_seconds <= compilation_video[0].length_seconds && end_timestamp_seconds > compilation_video[0].starting_timestamp_seconds
|
||||||
Invidious::Database::CompilationVideos.update_end_timestamp(compilation_video[0].id, end_timestamp_seconds)
|
Invidious::Database::CompilationVideos.update_end_timestamp(compilation_video[0].id, end_timestamp_seconds.to_i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -303,11 +302,18 @@ module Invidious::Routes::Compilations
|
||||||
|
|
||||||
begin
|
begin
|
||||||
query = Invidious::Search::Query.new(env.params.query, :compilation, region)
|
query = Invidious::Search::Query.new(env.params.query, :compilation, region)
|
||||||
videos = query.process.select(SearchVideo).map(&.as(SearchVideo))
|
items = query.process.select(SearchVideo).map(&.as(SearchVideo))
|
||||||
rescue ex
|
rescue ex
|
||||||
videos = [] of SearchVideo
|
items = [] of SearchVideo
|
||||||
end
|
end
|
||||||
|
|
||||||
|
query_encoded = URI.encode_www_form(query.try &.text || "", space_to_plus: true)
|
||||||
|
page_nav_html = Frontend::Pagination.nav_numeric(locale,
|
||||||
|
base_url: "/add_compilation_items?list=#{compilation.id}&q=#{query_encoded}",
|
||||||
|
current_page: page,
|
||||||
|
show_next: (items.size >= 20)
|
||||||
|
)
|
||||||
|
|
||||||
env.set "add_compilation_items", compid
|
env.set "add_compilation_items", compid
|
||||||
templated "add_compilation_items"
|
templated "add_compilation_items"
|
||||||
end
|
end
|
||||||
|
@ -414,7 +420,7 @@ module Invidious::Routes::Compilations
|
||||||
author: video.author,
|
author: video.author,
|
||||||
ucid: video.ucid,
|
ucid: video.ucid,
|
||||||
length_seconds: video.length_seconds,
|
length_seconds: video.length_seconds,
|
||||||
starting_timestamp_seconds: video.length_seconds,
|
starting_timestamp_seconds: 0,
|
||||||
ending_timestamp_seconds: video.length_seconds,
|
ending_timestamp_seconds: video.length_seconds,
|
||||||
published: video.published,
|
published: video.published,
|
||||||
compid: compilation_id,
|
compid: compilation_id,
|
||||||
|
|
|
@ -31,10 +31,4 @@
|
||||||
</script>
|
</script>
|
||||||
<script src="/js/compilation_widget.js?v=<%= ASSET_COMMIT %>"></script>
|
<script src="/js/compilation_widget.js?v=<%= ASSET_COMMIT %>"></script>
|
||||||
|
|
||||||
<div class="pure-g">
|
<%= rendered "components/items_paginated" %>
|
||||||
<% videos.each_slice(4) do |slice| %>
|
|
||||||
<% slice.each do |item| %>
|
|
||||||
<%= rendered "components/item" %>
|
|
||||||
<% end %>
|
|
||||||
<% end %>
|
|
||||||
</div>
|
|
|
@ -138,12 +138,13 @@
|
||||||
<button type="submit" class="pure-button pure-button-secondary low-profile"
|
<button type="submit" class="pure-button pure-button-secondary low-profile"
|
||||||
data-onclick="add_playlist_item" data-id="<%= item.id %>" data-plid="<%= plid_form %>"><i class="icon ion-md-add"></i></button>
|
data-onclick="add_playlist_item" data-id="<%= item.id %>" data-plid="<%= plid_form %>"><i class="icon ion-md-add"></i></button>
|
||||||
</form>
|
</form>
|
||||||
<% elsif compid_form = env.get? "add_compilation_items" %>
|
<%- elsif compid_form = env.get?("add_compilation_items") -%>
|
||||||
<form data-onsubmit="return_false" action="/compilation_ajax?action_add_video=1&video_id=<%= item.id %>&compilation_id=<%= compid_form %>&referer=<%= env.get("current_page") %>" method="post">
|
<%- form_parameters = "action_add_video=1&video_id=#{item.id}&compilation_id=#{compid_form}&referer=#{env.get("current_page")}" -%>
|
||||||
|
<form data-onsubmit="return_false" action="/compilation_ajax?<%= form_parameters %>" method="post">
|
||||||
<input type="hidden" name="csrf_token" value="<%= HTML.escape(env.get?("csrf_token").try &.as(String) || "") %>">
|
<input type="hidden" name="csrf_token" value="<%= HTML.escape(env.get?("csrf_token").try &.as(String) || "") %>">
|
||||||
<p class="watched">
|
<button type="submit" class="pure-button pure-button-secondary low-profile"
|
||||||
<button type="submit" style="all:unset" data-onclick="add_compilation_item" data-id="<%= item.id %>" data-compid="<%= compid_form %>"><i class="icon ion-md-add"></i></button>
|
data-onclick="add_compilation_item" data-id="<%= item.id %>" data-compid="<%= compid_form %>"><i class="icon ion-md-add"></i>
|
||||||
</p>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
<%- elsif item.is_a?(PlaylistVideo) && (plid_form = env.get?("remove_playlist_items")) -%>
|
<%- elsif item.is_a?(PlaylistVideo) && (plid_form = env.get?("remove_playlist_items")) -%>
|
||||||
<%- form_parameters = "action_remove_video=1&set_video_id=#{item.index}&playlist_id=#{plid_form}&referer=#{env.get("current_page")}" -%>
|
<%- form_parameters = "action_remove_video=1&set_video_id=#{item.index}&playlist_id=#{plid_form}&referer=#{env.get("current_page")}" -%>
|
||||||
|
|
|
@ -174,7 +174,7 @@
|
||||||
<label for="default_home"><%= translate(locale, "preferences_default_home_label") %></label>
|
<label for="default_home"><%= translate(locale, "preferences_default_home_label") %></label>
|
||||||
<select name="default_home" id="default_home">
|
<select name="default_home" id="default_home">
|
||||||
<% feed_options.each do |option| %>
|
<% feed_options.each do |option| %>
|
||||||
<option value="<%= option %>" <% if preferences.default_home == option %> selected <% end %>><%= translate(locale, option.blank? ? "Compilations" : option) %></option>
|
<option value="<%= option %>" <% if preferences.default_home == option %> selected <% end %>><%= translate(locale, option.blank? ? "Search" : option) %></option>
|
||||||
<% end %>
|
<% end %>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
@ -184,7 +184,7 @@
|
||||||
<% (feed_options.size - 1).times do |index| %>
|
<% (feed_options.size - 1).times do |index| %>
|
||||||
<select name="feed_menu[<%= index %>]" id="feed_menu[<%= index %>]">
|
<select name="feed_menu[<%= index %>]" id="feed_menu[<%= index %>]">
|
||||||
<% feed_options.each do |option| %>
|
<% feed_options.each do |option| %>
|
||||||
<option value="<%= option %>" <% if preferences.feed_menu[index]? == option %> selected <% end %>><%= translate(locale, option.blank? ? "Compilations" : option) %></option>
|
<option value="<%= option %>" <% if preferences.feed_menu[index]? == option %> selected <% end %>><%= translate(locale, option.blank? ? "Search" : option) %></option>
|
||||||
<% end %>
|
<% end %>
|
||||||
</select>
|
</select>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -50,6 +50,7 @@ we're going to need to do it here in order to allow for translations.
|
||||||
"id" => video.id,
|
"id" => video.id,
|
||||||
"index" => continuation,
|
"index" => continuation,
|
||||||
"plid" => plid,
|
"plid" => plid,
|
||||||
|
"compid" => compid,
|
||||||
"length_seconds" => video.length_seconds.to_f,
|
"length_seconds" => video.length_seconds.to_f,
|
||||||
"play_next" => !video.related_videos.empty? && !plid && params.continue,
|
"play_next" => !video.related_videos.empty? && !plid && params.continue,
|
||||||
"next_video" => video.related_videos.select { |rv| rv["id"]? }[0]?.try &.["id"],
|
"next_video" => video.related_videos.select { |rv| rv["id"]? }[0]?.try &.["id"],
|
||||||
|
|
Loading…
Reference in New Issue