From 5fb47c5e9e76294312dd326a7861ae49eeb0e38d Mon Sep 17 00:00:00 2001 From: broquemonsieur Date: Tue, 6 Jun 2023 23:54:34 -0700 Subject: [PATCH] add Compilation symbols --- config/config.example.yml | 6 +++--- locales/en-US.json | 1 + spec/spec_helper.cr | 1 + src/invidious.cr | 2 +- src/invidious/routes/feeds.cr | 4 ++++ src/invidious/routes/misc.cr | 6 ++++++ src/invidious/routes/preferences.cr | 2 +- src/invidious/routing.cr | 1 + .../{channels/compilations.cr => views/compilation.ecr} | 0 src/invidious/views/components/feed_menu.ecr | 2 +- src/invidious/views/feeds/compilations.ecr | 4 ++++ src/invidious/views/user/preferences.ecr | 2 +- 12 files changed, 24 insertions(+), 7 deletions(-) rename src/invidious/{channels/compilations.cr => views/compilation.ecr} (100%) create mode 100644 src/invidious/views/feeds/compilations.ecr diff --git a/config/config.example.yml b/config/config.example.yml index e925a5e3..4c9f0cca 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" + ## "Subscriptions", "Playlists", "Compilations" ## - ## Default: ["Popular", "Trending", "Subscriptions", "Playlists"] (show all feeds) + ## Default: ["Popular", "Trending", "Subscriptions", "Playlists","Compilations"] (show all feeds) ## - #feed_menu: ["Popular", "Trending", "Subscriptions", "Playlists"] + #feed_menu: ["Popular", "Trending", "Subscriptions", "Playlists","Compilations"] ## ## Default feed to display on the home page. diff --git a/locales/en-US.json b/locales/en-US.json index 06d095dc..a65e2119 100644 --- a/locales/en-US.json +++ b/locales/en-US.json @@ -413,6 +413,7 @@ "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 b3060acf..2ce03e33 100644 --- a/spec/spec_helper.cr +++ b/spec/spec_helper.cr @@ -8,6 +8,7 @@ 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.cr b/src/invidious.cr index e0bd0101..270e999a 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -121,7 +121,7 @@ Kemal.config.extra_options do |parser| puts SOFTWARE.to_pretty_json exit end - parser.on("--migrate", "Run any migrations (beta, use at your own risk!!") do + parser.on("--migrate", "Run any migrations (beta, use at your own risk!!)") do Invidious::Database::Migrator.new(PG_DB).migrate exit end diff --git a/src/invidious/routes/feeds.cr b/src/invidious/routes/feeds.cr index 40bca008..cc275dfe 100644 --- a/src/invidious/routes/feeds.cr +++ b/src/invidious/routes/feeds.cr @@ -5,6 +5,10 @@ module Invidious::Routes::Feeds env.redirect "/feed/playlists" end + def self.compilations(env) + templated "feeds/compilations" + end + def self.playlists(env) locale = env.get("preferences").as(Preferences).locale diff --git a/src/invidious/routes/misc.cr b/src/invidious/routes/misc.cr index d6bd9571..bd3245cc 100644 --- a/src/invidious/routes/misc.cr +++ b/src/invidious/routes/misc.cr @@ -23,6 +23,12 @@ 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 abe0f34e..6d410e87 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 - 4.times do |index| + 5.times do |index| option = env.params.body["feed_menu[#{index}]"]?.try &.as(String) || "" if !option.empty? feed_menu << option diff --git a/src/invidious/routing.cr b/src/invidious/routing.cr index 9c43171c..a653c1a5 100644 --- a/src/invidious/routing.cr +++ b/src/invidious/routing.cr @@ -99,6 +99,7 @@ module Invidious::Routing get "/feed/popular", Routes::Feeds, :popular get "/feed/trending", Routes::Feeds, :trending get "/feed/subscriptions", Routes::Feeds, :subscriptions + get "/feed/compilations", Routes::Feeds, :compilations get "/feed/history", Routes::Feeds, :history # RSS Feeds diff --git a/src/invidious/channels/compilations.cr b/src/invidious/views/compilation.ecr similarity index 100% rename from src/invidious/channels/compilations.cr rename to src/invidious/views/compilation.ecr diff --git a/src/invidious/views/components/feed_menu.ecr b/src/invidious/views/components/feed_menu.ecr index 3dbeaf37..180a263f 100644 --- a/src/invidious/views/components/feed_menu.ecr +++ b/src/invidious/views/components/feed_menu.ecr @@ -1,7 +1,7 @@
<% feed_menu = env.get("preferences").as(Preferences).feed_menu.dup %> <% if !env.get?("user") %> - <% feed_menu.reject! {|item| {"Subscriptions", "Playlists"}.includes? item} %> + <% feed_menu.reject! {|item| {"Subscriptions", "Playlists", "Compilations"}.includes? item} %> <% end %> <% feed_menu.each do |feed| %> diff --git a/src/invidious/views/feeds/compilations.ecr b/src/invidious/views/feeds/compilations.ecr new file mode 100644 index 00000000..a55e1e5a --- /dev/null +++ b/src/invidious/views/feeds/compilations.ecr @@ -0,0 +1,4 @@ +<% content_for "header" do %> +<%= translate(locale, "Compilations") %> - Invidious +<% end %> + diff --git a/src/invidious/views/user/preferences.ecr b/src/invidious/views/user/preferences.ecr index dfda1434..1f24bd4e 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"} %> + <% feed_options = {"", "Popular", "Trending", "Subscriptions", "Playlists","Compilations"} %> <% else %> <% feed_options = {"", "Popular", "Trending"} %> <% end %>