diff --git a/config/config.example.yml b/config/config.example.yml index de051bb0..e925a5e3 100644 --- a/config/config.example.yml +++ b/config/config.example.yml @@ -627,11 +627,11 @@ default_user_preferences: ## ## Accepted values: A list of strings ## Each entry can be one of: "Popular", "Trending", - ## "Subscriptions", "Playlists", "Compilations" + ## "Subscriptions", "Playlists" ## - ## Default: ["Popular", "Trending", "Subscriptions", "Playlists", "Compilations"] (show all feeds) + ## Default: ["Popular", "Trending", "Subscriptions", "Playlists"] (show all feeds) ## - #feed_menu: ["Popular", "Trending", "Subscriptions", "Playlists", "Compilations"] + #feed_menu: ["Popular", "Trending", "Subscriptions", "Playlists"] ## ## Default feed to display on the home page. diff --git a/config/sql/compilation_videos.sql b/config/sql/compilation_videos.sql new file mode 100644 index 00000000..91eb886c --- /dev/null +++ b/config/sql/compilation_videos.sql @@ -0,0 +1,20 @@ +-- Table: public.compilation_videos + +-- DROP TABLE public.compilation_videos; + +CREATE TABLE IF NOT EXISTS public.compilation_videos +( + title text, + id text, + author text, + ucid text, + length_seconds integer, + starting_timestamp_seconds integer, + ending_timestamp_seconds integer, + published timestamptz, + compid text references compilations(id), + index int8, + PRIMARY KEY (index,compid) +); + +GRANT ALL ON TABLE public.compilation_videos TO current_user; diff --git a/config/sql/compilations.sql b/config/sql/compilations.sql index 4076e1b8..d1ee949b 100644 --- a/config/sql/compilations.sql +++ b/config/sql/compilations.sql @@ -1,3 +1,13 @@ +-- Type: public.privacy + +-- DROP TYPE public.privacy; + +CREATE TYPE public.privacy AS ENUM +( + 'Unlisted', + 'Private' +); + -- Table: public.compilations -- DROP TABLE public.compilations; @@ -15,4 +25,4 @@ CREATE TABLE IF NOT EXISTS public.compilations index int8[] ); -GRANT ALL ON public.playlists TO current_user; \ No newline at end of file +GRANT ALL ON public.compilations TO current_user; diff --git a/docker/init-invidious-db.sh b/docker/init-invidious-db.sh index f7fe3e7f..62df4229 100755 --- a/docker/init-invidious-db.sh +++ b/docker/init-invidious-db.sh @@ -11,4 +11,4 @@ psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/annotation psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/playlists.sql psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/playlist_videos.sql psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/compilations.sql -psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/compilation_videos.sql +psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/compilation_videos.sql \ No newline at end of file diff --git a/locales/en-US.json b/locales/en-US.json index a65e2119..06d095dc 100644 --- a/locales/en-US.json +++ b/locales/en-US.json @@ -413,7 +413,6 @@ "Audio mode": "Audio mode", "Video mode": "Video mode", "Playlists": "Playlists", - "Compilations": "Compilations", "search_filters_title": "Filters", "search_filters_date_label": "Upload date", "search_filters_date_option_none": "Any date", diff --git a/spec/spec_helper.cr b/spec/spec_helper.cr index 2ce03e33..b3060acf 100644 --- a/spec/spec_helper.cr +++ b/spec/spec_helper.cr @@ -8,7 +8,6 @@ require "../src/invidious/channels/*" require "../src/invidious/videos/caption" require "../src/invidious/videos" require "../src/invidious/playlists" -require "../src/invidious/compilations" require "../src/invidious/search/ctoken" require "../src/invidious/trending" require "spectator" diff --git a/src/invidious/compilations.cr b/src/invidious/compilations.cr deleted file mode 100644 index e2b037b8..00000000 --- a/src/invidious/compilations.cr +++ /dev/null @@ -1,14 +0,0 @@ -struct Compilation - include DB::Serializable - - property title : String - property id : String - property author : String - property ucid : String - property length_seconds : Int32 - property published : Time - property plid : String - property index : Int64 - property live_now : Bool - -end \ No newline at end of file diff --git a/src/invidious/database/compilations.cr b/src/invidious/database/compilations.cr index 80672abf..69281a55 100644 --- a/src/invidious/database/compilations.cr +++ b/src/invidious/database/compilations.cr @@ -1,7 +1,7 @@ require "./base.cr" # -# This module contains functions related to the "playlists" table. +# This module contains functions related to the "compilations" table. # module Invidious::Database::Compilations extend self @@ -10,22 +10,22 @@ module Invidious::Database::Compilations # Insert / delete # ------------------- - def insert(playlist : InvidiousPlaylist) - playlist_array = playlist.to_a + def insert(compilation : InvidiousCompilation) + compilation_array = compilation.to_a request = <<-SQL - INSERT INTO playlists - VALUES (#{arg_array(playlist_array)}) + INSERT INTO compilations + VALUES (#{arg_array(compilation_array)}) SQL - PG_DB.exec(request, args: playlist_array) + PG_DB.exec(request, args: compilation_array) end - # deletes the given playlist and connected playlist videos + # deletes the given compilation and connected compilation videos def delete(id : String) - PlaylistVideos.delete_by_playlist(id) + CompilationVideos.delete_by_compilation(id) request = <<-SQL - DELETE FROM playlists * + DELETE FROM compilations * WHERE id = $1 SQL @@ -38,7 +38,7 @@ module Invidious::Database::Compilations def update(id : String, title : String, privacy, description, updated) request = <<-SQL - UPDATE playlists + UPDATE compilations SET title = $1, privacy = $2, description = $3, updated = $4 WHERE id = $5 SQL @@ -48,7 +48,7 @@ module Invidious::Database::Compilations def update_description(id : String, description) request = <<-SQL - UPDATE playlists + UPDATE compilations SET description = $1 WHERE id = $2 SQL @@ -56,19 +56,9 @@ module Invidious::Database::Compilations PG_DB.exec(request, description, id) end - def update_subscription_time(id : String) - request = <<-SQL - UPDATE playlists - SET subscribed = now() - WHERE id = $1 - SQL - - PG_DB.exec(request, id) - end - def update_video_added(id : String, index : String | Int64) request = <<-SQL - UPDATE playlists + UPDATE compilations SET index = array_append(index, $1), video_count = cardinality(index) + 1, updated = now() @@ -80,7 +70,7 @@ module Invidious::Database::Compilations def update_video_removed(id : String, index : String | Int64) request = <<-SQL - UPDATE playlists + UPDATE compilations SET index = array_remove(index, $1), video_count = cardinality(index) - 1, updated = now() @@ -94,51 +84,51 @@ module Invidious::Database::Compilations # Salect # ------------------- - def select(*, id : String) : InvidiousPlaylist? + def select(*, id : String) : InvidiousCompilation? request = <<-SQL - SELECT * FROM playlists + SELECT * FROM compilations WHERE id = $1 SQL - return PG_DB.query_one?(request, id, as: InvidiousPlaylist) + return PG_DB.query_one?(request, id, as: InvidiousCompilation) end - def select_all(*, author : String) : Array(InvidiousPlaylist) + def select_all(*, author : String) : Array(InvidiousCompilation) request = <<-SQL - SELECT * FROM playlists + SELECT * FROM compilations WHERE author = $1 SQL - return PG_DB.query_all(request, author, as: InvidiousPlaylist) + return PG_DB.query_all(request, author, as: InvidiousCompilation) end # ------------------- # Salect (filtered) # ------------------- - def select_like_iv(email : String) : Array(InvidiousPlaylist) + def select_like_iv(email : String) : Array(InvidiousCompilation) request = <<-SQL - SELECT * FROM playlists + SELECT * FROM compilation WHERE author = $1 AND id LIKE 'IV%' ORDER BY created SQL - PG_DB.query_all(request, email, as: InvidiousPlaylist) + PG_DB.query_all(request, email, as: InvidiousCompilation) end - def select_not_like_iv(email : String) : Array(InvidiousPlaylist) + def select_not_like_iv(email : String) : Array(InvidiousCompilation) request = <<-SQL - SELECT * FROM playlists + SELECT * FROM compilations WHERE author = $1 AND id NOT LIKE 'IV%' ORDER BY created SQL - PG_DB.query_all(request, email, as: InvidiousPlaylist) + PG_DB.query_all(request, email, as: InvidiousCompilation) end - def select_user_created_playlists(email : String) : Array({String, String}) + def select_user_created_compilations(email : String) : Array({String, String}) request = <<-SQL - SELECT id,title FROM playlists + SELECT id,title FROM compilations WHERE author = $1 AND id LIKE 'IV%' SQL @@ -149,20 +139,20 @@ module Invidious::Database::Compilations # Misc checks # ------------------- - # Check if given playlist ID exists + # Check if given compilation ID exists def exists?(id : String) : Bool request = <<-SQL - SELECT id FROM playlists + SELECT id FROM compilations WHERE id = $1 SQL return PG_DB.query_one?(request, id, as: String).nil? end - # Count how many playlist a user has created. + # Count how many compilations a user has created. def count_owned_by(author : String) : Int64 request = <<-SQL - SELECT count(*) FROM playlists + SELECT count(*) FROM compilations WHERE author = $1 SQL @@ -171,7 +161,7 @@ module Invidious::Database::Compilations end # -# This module contains functions related to the "playlist_videos" table. +# This module contains functions related to the "compilation_videos" table. # module Invidious::Database::CompilationVideos extend self @@ -184,7 +174,7 @@ module Invidious::Database::CompilationVideos video_array = video.to_a request = <<-SQL - INSERT INTO playlist_videos + INSERT INTO compilation_videos VALUES (#{arg_array(video_array)}) SQL @@ -193,67 +183,67 @@ module Invidious::Database::CompilationVideos def delete(index) request = <<-SQL - DELETE FROM playlist_videos * + DELETE FROM compilation_videos * WHERE index = $1 SQL PG_DB.exec(request, index) end - def delete_by_playlist(plid : String) + def delete_by_compilation(compid : String) request = <<-SQL - DELETE FROM playlist_videos * - WHERE plid = $1 + DELETE FROM compilation_videos * + WHERE compid = $1 SQL - PG_DB.exec(request, plid) + PG_DB.exec(request, compid) end # ------------------- # Salect # ------------------- - def select(plid : String, index : VideoIndex, offset, limit = 100) : Array(PlaylistVideo) + def select(compid : String, index : VideoIndex, offset, limit = 100) : Array(CompilationVideo) request = <<-SQL - SELECT * FROM playlist_videos - WHERE plid = $1 + SELECT * FROM compilation_videos + WHERE compid = $1 ORDER BY array_position($2, index) LIMIT $3 OFFSET $4 SQL - return PG_DB.query_all(request, plid, index, limit, offset, as: PlaylistVideo) + return PG_DB.query_all(request, compid, index, limit, offset, as: CompilationVideo) end - def select_index(plid : String, vid : String) : Int64? + def select_index(compid : String, vid : String) : Int64? request = <<-SQL - SELECT index FROM playlist_videos - WHERE plid = $1 AND id = $2 + SELECT index FROM compilation_videos + WHERE compid = $1 AND id = $2 LIMIT 1 SQL - return PG_DB.query_one?(request, plid, vid, as: Int64) + return PG_DB.query_one?(request, compid, vid, as: Int64) end - def select_one_id(plid : String, index : VideoIndex) : String? + def select_one_id(compid : String, index : VideoIndex) : String? request = <<-SQL - SELECT id FROM playlist_videos - WHERE plid = $1 + SELECT id FROM compilation_videos + WHERE compid = $1 ORDER BY array_position($2, index) LIMIT 1 SQL - return PG_DB.query_one?(request, plid, index, as: String) + return PG_DB.query_one?(request, compid, index, as: String) end - def select_ids(plid : String, index : VideoIndex, limit = 500) : Array(String) + def select_ids(compid : String, index : VideoIndex, limit = 500) : Array(String) request = <<-SQL - SELECT id FROM playlist_videos - WHERE plid = $1 + SELECT id FROM compilation_videos + WHERE compid = $1 ORDER BY array_position($2, index) LIMIT $3 SQL - return PG_DB.query_all(request, plid, index, limit, as: String) + return PG_DB.query_all(request, compid, index, limit, as: String) end end diff --git a/src/invidious/database/playlists.cr b/src/invidious/database/playlists.cr index c6754a1e..c961c16e 100644 --- a/src/invidious/database/playlists.cr +++ b/src/invidious/database/playlists.cr @@ -159,7 +159,7 @@ module Invidious::Database::Playlists return PG_DB.query_one?(request, id, as: String).nil? end - # Count how many playlist a user has created. + # Count how many playlists a user has created. def count_owned_by(author : String) : Int64 request = <<-SQL SELECT count(*) FROM playlists diff --git a/src/invidious/routes/compilations.cr b/src/invidious/routes/compilations.cr deleted file mode 100644 index 600d34de..00000000 --- a/src/invidious/routes/compilations.cr +++ /dev/null @@ -1,2 +0,0 @@ -module Invidious::Routes::Compilations -end \ No newline at end of file diff --git a/src/invidious/routes/feeds.cr b/src/invidious/routes/feeds.cr index affd165d..fec94682 100644 --- a/src/invidious/routes/feeds.cr +++ b/src/invidious/routes/feeds.cr @@ -8,6 +8,26 @@ module Invidious::Routes::Feeds def self.compilations(env) locale = env.get("preferences").as(Preferences).locale + user = env.get? "user" + referer = get_referer(env) + + return env.redirect "/" if user.nil? + + user = user.as(User) + + # TODO: make a single DB call and separate the items here? + items_created = Invidious::Database::Compilations.select_like_iv(user.email) + items_created.map! do |item| + item.author = "" + item + end + + items_saved = Invidious::Database::Compilations.select_not_like_iv(user.email) + items_saved.map! do |item| + item.author = "" + item + end + templated "feeds/compilations" end diff --git a/src/invidious/routes/misc.cr b/src/invidious/routes/misc.cr index bd3245cc..d6bd9571 100644 --- a/src/invidious/routes/misc.cr +++ b/src/invidious/routes/misc.cr @@ -23,12 +23,6 @@ module Invidious::Routes::Misc else env.redirect "/feed/popular" end - when "Compilations" - if user - env.redirect "/feed/compilations" - else - env.redirect "/feed/popular" - end else templated "search_homepage", navbar_search: false end diff --git a/src/invidious/routes/preferences.cr b/src/invidious/routes/preferences.cr index eea93858..abe0f34e 100644 --- a/src/invidious/routes/preferences.cr +++ b/src/invidious/routes/preferences.cr @@ -99,7 +99,7 @@ module Invidious::Routes::PreferencesRoute default_home = env.params.body["default_home"]?.try &.as(String) || CONFIG.default_user_preferences.default_home feed_menu = [] of String - 5.times do |index| + 4.times do |index| option = env.params.body["feed_menu[#{index}]"]?.try &.as(String) || "" if !option.empty? feed_menu << option @@ -186,7 +186,7 @@ module Invidious::Routes::PreferencesRoute CONFIG.default_user_preferences.default_home = env.params.body["admin_default_home"]?.try &.as(String) || CONFIG.default_user_preferences.default_home admin_feed_menu = [] of String - 5.times do |index| + 4.times do |index| option = env.params.body["admin_feed_menu[#{index}]"]?.try &.as(String) || "" if !option.empty? admin_feed_menu << option diff --git a/src/invidious/views/compilation.ecr b/src/invidious/views/compilation.ecr deleted file mode 100644 index 0dff7417..00000000 --- a/src/invidious/views/compilation.ecr +++ /dev/null @@ -1,6 +0,0 @@ -<% title = HTML.escape(compilation.title) %> -<% author = HTML.escape(compilation.author) %> - -<% content_for "header" do %> -<%= title %> - Invidious -<% end %> \ No newline at end of file diff --git a/src/invidious/views/components/feed_menu.ecr b/src/invidious/views/components/feed_menu.ecr index 180a263f..3fb20086 100644 --- a/src/invidious/views/components/feed_menu.ecr +++ b/src/invidious/views/components/feed_menu.ecr @@ -1,11 +1,11 @@
<% feed_menu = env.get("preferences").as(Preferences).feed_menu.dup %> <% if !env.get?("user") %> - <% feed_menu.reject! {|item| {"Subscriptions", "Playlists", "Compilations"}.includes? item} %> + <% feed_menu.reject! {|item| {"Subscriptions", "Playlists"}.includes? item} %> <% end %> <% feed_menu.each do |feed| %> <%= translate(locale, feed) %> <% end %> -
+ \ No newline at end of file diff --git a/src/invidious/views/feeds/compilations.ecr b/src/invidious/views/feeds/compilations.ecr deleted file mode 100644 index de605f27..00000000 --- a/src/invidious/views/feeds/compilations.ecr +++ /dev/null @@ -1,6 +0,0 @@ -<% content_for "header" do %> -<%= translate(locale, "Compilations") %> - Invidious -<% end %> - -<%= rendered "components/feed_menu" %> - diff --git a/src/invidious/views/user/preferences.ecr b/src/invidious/views/user/preferences.ecr index 1f24bd4e..dfda1434 100644 --- a/src/invidious/views/user/preferences.ecr +++ b/src/invidious/views/user/preferences.ecr @@ -165,7 +165,7 @@ <% if env.get?("user") %> - <% feed_options = {"", "Popular", "Trending", "Subscriptions", "Playlists","Compilations"} %> + <% feed_options = {"", "Popular", "Trending", "Subscriptions", "Playlists"} %> <% else %> <% feed_options = {"", "Popular", "Trending"} %> <% end %>