diff --git a/src/invidious/database/compilations.cr b/src/invidious/database/compilations.cr index b5bf8bf3..babe59bc 100644 --- a/src/invidious/database/compilations.cr +++ b/src/invidious/database/compilations.cr @@ -217,6 +217,26 @@ module Invidious::Database::CompilationVideos return PG_DB.query_all(request, compid, index, limit, offset, as: CompilationVideo) end + def select_id_from_order_index(order_index : Int32) + request = <<-SQL + SELECT id FROM compilation_videos + WHERE order_index = $1 + LIMIT 1 + SQL + + return PG_DB.query_one?(request, order_index, as: String) + end + + def select_index_from_order_index(order_index : Int32) + request = <<-SQL + SELECT index FROM compilation_videos + WHERE order_index = $1 + LIMIT 1 + SQL + + return PG_DB.query_one?(request, order_index, as: VideoIndex) + end + def select_index(compid : String, vid : String) : Int64? request = <<-SQL SELECT index FROM compilation_videos @@ -253,10 +273,23 @@ module Invidious::Database::CompilationVideos # Update # ------------------- - def update_start_timestamp(compid : String, index : VideoIndex, starting_timestamp_seconds : Int64) + def update_start_timestamp(id : String, starting_timestamp_seconds : Int32) request = <<-SQL UPDATE compilation_videos SET starting_timestamp_seconds = starting_timestamp_seconds - WHERE id = $2 + WHERE id = $1 + SQL + + PG_DB.exec(request, id) + end + + def update_end_timestamp(id : String, ending_timestamp_seconds : Int64) + request = <<-SQL + UPDATE compilation_videos + SET ending_timestamp_seconds = ending_timestamp_seconds + WHERE id = $1 + SQL + + PG_DB.exec(request, id) end end diff --git a/src/invidious/routes/compilations.cr b/src/invidious/routes/compilations.cr index a76e72b5..3171bebc 100644 --- a/src/invidious/routes/compilations.cr +++ b/src/invidious/routes/compilations.cr @@ -225,33 +225,39 @@ module Invidious::Routes::Compilations updated = compilation.updated end - {1...Invidious::Database::Compilations.count_owned_by(user.email)} each do |index| - start_timestamp = env.params.json["_start_timestamp"]?.try &.as(String).byte_slice(0, 150) || compilation.title + #{1...Invidious::Database::Compilations.count_owned_by(user.email)}.each do |index| + # start_timestamp = env.params.json["_start_timestamp"]?.try &.as(String).byte_slice(0, 150) || compilation.title - (1..Invidious::Database::Compilations.count_owned_by(user.email)).each do |index| { - compilation_video = Invidious::Database::CompilationVideos.select(order_index: index) - start_timestamp = env.params.json[index+"_start_timestamp"]?.try &.as(String).byte_slice(0, 8) - if !start_timestamp.empty? + (0..Invidious::Database::Compilations.count_owned_by(user.email)).each do |index| + compilation_video_id = Invidious::Database::CompilationVideos.select_id_from_order_index(order_index: index) + #compilation_video_index = Invidious::Database::CompilationVideos.select_index_from_order_index(order_index: index) + compilation_video = Invidious::Database::CompilationVideos.select(compid, compilation.index, 0, 1) + #numerical_string = index.to + json_timestamp_query = index.to_s + "_start_timestamp" + start_timestamp = env.params.json[json_timestamp_query]?.try &.as(String).byte_slice(0, 8) + if !start_timestamp.nil? && !compilation_video_id.nil? start_timestamp_seconds = decode_length_seconds(start_timestamp) - if !start_timestamp_seconds.empty - if start_timestamp_seconds >= 0 && start_timestamp_seconds <= compilation_video - Invidious::Database::CompilationVideos.update_start_timestamp(compid, compilation_video.index, start_timestamp_seconds) + if !start_timestamp_seconds.nil? + if start_timestamp_seconds >= 0 && start_timestamp_seconds <= compilation_video[0].starting_timestamp_seconds + Invidious::Database::CompilationVideos.update_start_timestamp(compilation_video_id, start_timestamp_seconds) end end end - end_timestamp = env.params.json[index+"_end_timestamp"]?.try &.as(String).byte_slice(0, 8) - if !end_timestamp.empty? + json_timestamp_query = index.to_s + "_end_timestamp" + end_timestamp = env.params.json[json_timestamp_query]?.try &.as(String).byte_slice(0, 8) + if !end_timestamp.nil? && !compilation_video_id.nil? end_timestamp_seconds = decode_length_seconds(end_timestamp) - if !end_timestamp_seconds.empty - if end_timestamp_seconds >= 0 && end_timestamp_seconds <= compilation_video - Invidious::Database::CompilationVideos.update_end_timestamp(compid, compilation_video.index, end_timestamp_seconds) + if !end_timestamp_seconds.nil? + if end_timestamp_seconds >= 0 && end_timestamp_seconds <= compilation_video[0].ending_timestamp_seconds + Invidious::Database::CompilationVideos.update_end_timestamp(compilation_video_id, end_timestamp_seconds) end end end - } - + end + end + def self.add_compilation_items_page(env) LOGGER.info("13. add_compilation_items") diff --git a/src/invidious/views/components/item.ecr b/src/invidious/views/components/item.ecr index 63f44e8c..4a9bacb3 100644 --- a/src/invidious/views/components/item.ecr +++ b/src/invidious/views/components/item.ecr @@ -53,7 +53,7 @@

<%= translate_count(locale, "generic_channels_count", item.channel_count, NumberFormatting::Separator) %>

<%- end -%> - <% when SearchPlaylist, InvidiousPlaylist %> + <% when SearchPlaylist, InvidiousPlaylist, InvidiousCompilation %> <%- if item.id.starts_with? "RD" link_url = "/mix?list=#{item.id}&continuation=#{URI.parse(item.thumbnail || "/vi/-----------").request_target.split("/")[2]}" @@ -87,20 +87,6 @@

- <% when InvidiousCompilation %> - <% link_url = "/compilation?list=#{item.id}" %> - - <% if !env.get("preferences").as(Preferences).thin_mode %> -
- " alt="" /> -

<%= translate_count(locale, "generic_videos_count", item.video_count, NumberFormatting::Separator) %>

-
- <% end %> -

<%= HTML.escape(item.title) %>

-
- -

<%= HTML.escape(item.author) %><% if !item.is_a?(InvidiousCompilation) && !item.is_a?(InvidiousPlaylist) && !item.author_verified.nil? && item.author_verified %> <% end %>

-
<% when Category %> <% else %> <%-