Finish vetting changes for autoplay stability

This commit is contained in:
broquemonsieur 2023-08-03 02:33:07 -07:00
parent f05d38aa8e
commit d7a53d0159
8 changed files with 39 additions and 35 deletions

View File

@ -423,17 +423,17 @@ def extract_compilation_videos(initial_data : Hash(String, JSON::Any))
end
videos << CompilationVideo.new({
title: title,
id: video_id,
author: author,
ucid: ucid,
length_seconds: length_seconds,
title: title,
id: video_id,
author: author,
ucid: ucid,
length_seconds: length_seconds,
starting_timestamp_seconds: starting_timestamp_seconds,
ending_timestamp_seconds: ending_timestamp_seconds,
published: Time.utc,
compid: compid,
index: index,
order_index: order_index
ending_timestamp_seconds: ending_timestamp_seconds,
published: Time.utc,
compid: compid,
index: index,
order_index: order_index
})
end
end

View File

@ -334,13 +334,13 @@ module Invidious::Database::CompilationVideos
PG_DB.exec(request, id, starting_timestamp_seconds)
end
def update_end_timestamp(id : String, ending_timestamp_seconds : Int64)
def update_end_timestamp(id : String, ending_timestamp_seconds : Int32)
request = <<-SQL
UPDATE compilation_videos
SET ending_timestamp_seconds = ending_timestamp_seconds
SET ending_timestamp_seconds = $2
WHERE id = $1
SQL
PG_DB.exec(request, id)
PG_DB.exec(request, id, ending_timestamp_seconds)
end
end

View File

@ -35,8 +35,10 @@ def decode_length_seconds(string)
end
def recode_length_seconds(time)
if time <= 0
if time < 0
return ""
elsif time == 0
return "0:00"
else
time = time.seconds
text = "#{time.minutes.to_s.rjust(2, '0')}:#{time.seconds.to_s.rjust(2, '0')}"

View File

@ -244,7 +244,6 @@ module Invidious::Routes::Compilations
compilation_video_index = compilation.index[index]
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"
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?
start_timestamp_seconds = decode_length_seconds(start_timestamp)
@ -254,14 +253,14 @@ module Invidious::Routes::Compilations
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"
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?
end_timestamp_seconds = decode_length_seconds(end_timestamp)
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
Invidious::Database::CompilationVideos.update_end_timestamp(compilation_video[0].id, end_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.to_i)
end
end
end
@ -303,11 +302,18 @@ module Invidious::Routes::Compilations
begin
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
videos = [] of SearchVideo
items = [] of SearchVideo
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
templated "add_compilation_items"
end
@ -414,7 +420,7 @@ module Invidious::Routes::Compilations
author: video.author,
ucid: video.ucid,
length_seconds: video.length_seconds,
starting_timestamp_seconds: video.length_seconds,
starting_timestamp_seconds: 0,
ending_timestamp_seconds: video.length_seconds,
published: video.published,
compid: compilation_id,

View File

@ -31,10 +31,4 @@
</script>
<script src="/js/compilation_widget.js?v=<%= ASSET_COMMIT %>"></script>
<div class="pure-g">
<% videos.each_slice(4) do |slice| %>
<% slice.each do |item| %>
<%= rendered "components/item" %>
<% end %>
<% end %>
</div>
<%= rendered "components/items_paginated" %>

View File

@ -138,12 +138,13 @@
<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>
</form>
<% 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">
<%- elsif compid_form = env.get?("add_compilation_items") -%>
<%- 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) || "") %>">
<p class="watched">
<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>
</p>
<button type="submit" class="pure-button pure-button-secondary low-profile"
data-onclick="add_compilation_item" data-id="<%= item.id %>" data-compid="<%= compid_form %>"><i class="icon ion-md-add"></i>
</button>
</form>
<%- 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")}" -%>

View File

@ -174,7 +174,7 @@
<label for="default_home"><%= translate(locale, "preferences_default_home_label") %></label>
<select name="default_home" id="default_home">
<% 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 %>
</select>
</div>
@ -184,7 +184,7 @@
<% (feed_options.size - 1).times do |index| %>
<select name="feed_menu[<%= index %>]" id="feed_menu[<%= index %>]">
<% 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 %>
</select>
<% end %>

View File

@ -50,6 +50,7 @@ we're going to need to do it here in order to allow for translations.
"id" => video.id,
"index" => continuation,
"plid" => plid,
"compid" => compid,
"length_seconds" => video.length_seconds.to_f,
"play_next" => !video.related_videos.empty? && !plid && params.continue,
"next_video" => video.related_videos.select { |rv| rv["id"]? }[0]?.try &.["id"],