Invidious is an alternative front-end to YouTube
Add `popular-enabled` option
saltycrys198dfffaeb91
diff --git a/src/invidious.cr b/src/invidious.crindex 40acd9df..af36e25c 100644--- a/src/invidious.cr+++ b/src/invidious.cr@@ -162,13 +162,16 @@ endInvidious::Jobs.register Invidious::Jobs::RefreshChannelsJob.new(PG_DB, logger, config)Invidious::Jobs.register Invidious::Jobs::RefreshFeedsJob.new(PG_DB, logger, config)Invidious::Jobs.register Invidious::Jobs::SubscribeToFeedsJob.new(PG_DB, logger, config, HMAC_KEY)-Invidious::Jobs.register Invidious::Jobs::PullPopularVideosJob.new(PG_DB)Invidious::Jobs.register Invidious::Jobs::UpdateDecryptFunctionJob.newif config.statistics_enabledInvidious::Jobs.register Invidious::Jobs::StatisticsRefreshJob.new(PG_DB, config, SOFTWARE)end+if config.popular_enabled+ Invidious::Jobs.register Invidious::Jobs::PullPopularVideosJob.new(PG_DB)+end+if config.captcha_keyInvidious::Jobs.register Invidious::Jobs::BypassCaptchaJob.new(logger, config)end@@ -1140,13 +1143,20 @@ endget "/feed/top" do |env|locale = LOCALES[env.get("preferences").as(Preferences).locale]?- env.redirect "/"++ message = translate(locale, "The Top feed has been removed from Invidious.")+ templated "message"endget "/feed/popular" do |env|locale = LOCALES[env.get("preferences").as(Preferences).locale]?- templated "popular"+ if config.popular_enabled+ templated "popular"+ else+ message = translate(locale, "The Popular feed has been disabled by the administrator.")+ templated "message"+ endendget "/feed/trending" do |env|@@ -2210,6 +2220,12 @@ get "/api/v1/popular" do |env|env.response.content_type = "application/json"+ if !config.popular_enabled+ error_message = {"error" => "Administrator has disabled this endpoint."}.to_json+ env.response.status_code = 400+ next error_message+ end+JSON.build do |json|json.array dopopular_videos.each do |video|@@ -2223,7 +2239,8 @@ get "/api/v1/top" do |env|locale = LOCALES[env.get("preferences").as(Preferences).locale]?env.response.content_type = "application/json"- "[]"+ env.response.status_code = 400+ {"error" => "The Top feed has been removed from Invidious."}.to_jsonendget "/api/v1/channels/:ucid" do |env|diff --git a/src/invidious/helpers/helpers.cr b/src/invidious/helpers/helpers.crindex dc68fb5c..29fd6a86 100644--- a/src/invidious/helpers/helpers.cr+++ b/src/invidious/helpers/helpers.cr@@ -60,7 +60,7 @@ struct ConfigPreferencesendend-struct Config+class Configinclude YAML::Serializableproperty channel_threads : Int32 # Number of threads to use for crawling videos from channels (for updating subscriptions)@@ -71,6 +71,7 @@ struct Configproperty hmac_key : String? # HMAC signing key for CSRF tokens and verifying pubsub subscriptionsproperty domain : String? # Domain to be used for links to resources on the site where an absolute URL is requiredproperty use_pubsub_feeds : Bool | Int32 = false # Subscribe to channels using PubSubHubbub (requires domain, hmac_key)+ property popular_enabled : Bool = trueproperty captcha_enabled : Bool = trueproperty login_enabled : Bool = trueproperty registration_enabled : Bool = truediff --git a/src/invidious/routes/home.cr b/src/invidious/routes/home.crindex 9b1bf61b..486a7344 100644--- a/src/invidious/routes/home.cr+++ b/src/invidious/routes/home.cr@@ -5,30 +5,24 @@ class Invidious::Routes::Home < Invidious::Routes::BaseRouteuser = env.get? "user"case preferences.default_home- when ""- templated "empty"when "Popular"- templated "popular"+ env.redirect "/feed/popular"when "Trending"env.redirect "/feed/trending"when "Subscriptions"if userenv.redirect "/feed/subscriptions"else- templated "popular"+ env.redirect "/feed/popular"endwhen "Playlists"if userenv.redirect "/view_all_playlists"else- templated "popular"+ env.redirect "/feed/popular"endelsetemplated "empty"endend-- private def popular_videos- Jobs::PullPopularVideosJob::POPULAR_VIDEOS.get- endenddiff --git a/src/invidious/routes/user_preferences.cr b/src/invidious/routes/user_preferences.crindex 3e4ec330..a0125ed5 100644--- a/src/invidious/routes/user_preferences.cr+++ b/src/invidious/routes/user_preferences.cr@@ -154,6 +154,10 @@ class Invidious::Routes::UserPreferences < Invidious::Routes::BaseRouteendconfig.default_user_preferences.feed_menu = admin_feed_menu+ popular_enabled = env.params.body["popular_enabled"]?.try &.as(String)+ popular_enabled ||= "off"+ config.popular_enabled = popular_enabled == "on"+captcha_enabled = env.params.body["captcha_enabled"]?.try &.as(String)captcha_enabled ||= "off"config.captcha_enabled = captcha_enabled == "on"diff --git a/src/invidious/views/message.ecr b/src/invidious/views/message.ecrnew file mode 100644index 00000000..8c7bf611--- /dev/null+++ b/src/invidious/views/message.ecr@@ -0,0 +1,12 @@+<% content_for "header" do %>+<meta name="description" content="<%= translate(locale, "An alternative front-end to YouTube") %>">+<title>+ Invidious+</title>+<% end %>++<%= rendered "components/feed_menu" %>++<p>+ <%= message %>+</p>diff --git a/src/invidious/views/preferences.ecr b/src/invidious/views/preferences.ecrindex aebdab9e..c05a902c 100644--- a/src/invidious/views/preferences.ecr+++ b/src/invidious/views/preferences.ecr@@ -227,6 +227,12 @@<% end %></div>+ <div class="pure-control-group">+ <label for="popular_enabled"><%= translate(locale, "Popular enabled: ") %></label>+ <input name="popular_enabled" id="popular_enabled" type="checkbox" <% if config.popular_enabled %>checked<% end %>>+ </div>++<div class="pure-control-group"><label for="captcha_enabled"><%= translate(locale, "CAPTCHA enabled: ") %></label><input name="captcha_enabled" id="captcha_enabled" type="checkbox" <% if config.captcha_enabled %>checked<% end %>>