feat: add preference to set default trending page
Some checks failed
Build and release container directly from master / release (docker/Dockerfile, AMD64, ubuntu-latest, linux/amd64, ) (push) Has been cancelled
Build and release container directly from master / release (docker/Dockerfile.arm64, ARM64, ubuntu-24.04-arm, linux/arm64/v8, -arm64) (push) Has been cancelled
Invidious CI / build - crystal: ${{ matrix.crystal }}, stable: ${{ matrix.stable }} (1.12.2, true) (push) Has been cancelled
Invidious CI / build - crystal: ${{ matrix.crystal }}, stable: ${{ matrix.stable }} (1.13.3, true) (push) Has been cancelled
Invidious CI / build - crystal: ${{ matrix.crystal }}, stable: ${{ matrix.stable }} (1.14.1, true) (push) Has been cancelled
Invidious CI / build - crystal: ${{ matrix.crystal }}, stable: ${{ matrix.stable }} (1.15.1, true) (push) Has been cancelled
Invidious CI / build - crystal: ${{ matrix.crystal }}, stable: ${{ matrix.stable }} (1.16.3, true) (push) Has been cancelled
Invidious CI / build - crystal: ${{ matrix.crystal }}, stable: ${{ matrix.stable }} (nightly, false) (push) Has been cancelled
Invidious CI / Test ${{ matrix.name }} Docker build (AMD64, ubuntu-latest) (push) Has been cancelled
Invidious CI / Test ${{ matrix.name }} Docker build (ARM64, ubuntu-24.04-arm) (push) Has been cancelled
Invidious CI / lint (push) Has been cancelled

Closes https://git.nadeko.net/Fijxu/invidious/issues/212

Enjoy xCbl6YaK4PEX6d9g6m26YMdHJtQgJ
This commit is contained in:
Fijxu
2025-09-07 01:09:51 -03:00
parent 83760a8e66
commit 7250a6b25d
8 changed files with 34 additions and 4 deletions

View File

@@ -55,6 +55,8 @@ struct ConfigPreferences
property enable_dearrow : Bool = false
@[YAML::Field(ignore: true)]
property hidden_channels : Array(String)? = nil
@[YAML::Field(ignore: true)]
property default_trending_type : Invidious::Routes::Feeds::TrendingTypes = Invidious::Routes::Feeds::TrendingTypes::Default
def to_tuple
{% begin %}

View File

@@ -1,6 +1,13 @@
{% skip_file if flag?(:api_only) %}
module Invidious::Routes::Feeds
enum TrendingTypes
Default
Music
Gaming
Movies
end
def self.view_all_playlists_redirect(env)
env.redirect "/feed/playlists"
end
@@ -44,13 +51,14 @@ module Invidious::Routes::Feeds
end
def self.trending(env)
locale = env.get("preferences").as(Preferences).locale
preferences = env.get("preferences").as(Preferences)
locale = preferences.locale
trending_type = env.params.query["type"]?
trending_type ||= "Default"
trending_type ||= preferences.default_trending_type.to_s
region = env.params.query["region"]?
region ||= env.get("preferences").as(Preferences).region
region ||= preferences.region
begin
trending, plid = fetch_trending(trending_type, region, locale)

View File

@@ -168,6 +168,9 @@ module Invidious::Routes::PreferencesRoute
delete.reverse_each { |i| hidden_channels.delete_at(i) }
end
default_trending_type = env.params.body["default_trending_type"]?.try &.as(String)
default_trending_type ||= Invidious::Routes::Feeds::TrendingTypes::Default
# Convert to JSON and back again to take advantage of converters used for compatibility
preferences = Preferences.from_json({
annotations: annotations,
@@ -205,6 +208,7 @@ module Invidious::Routes::PreferencesRoute
show_nick: show_nick,
save_player_pos: save_player_pos,
hidden_channels: hidden_channels,
default_trending_type: default_trending_type,
}.to_json)
if user = env.get? "user"

View File

@@ -57,6 +57,7 @@ struct Preferences
property volume : Int32 = CONFIG.default_user_preferences.volume
property save_player_pos : Bool = CONFIG.default_user_preferences.save_player_pos
property hidden_channels : Array(String)? = nil
property default_trending_type : Invidious::Routes::Feeds::TrendingTypes = Invidious::Routes::Feeds::TrendingTypes::Default
module BoolToString
def self.to_json(value : String, json : JSON::Builder)

View File

@@ -21,7 +21,9 @@
</div>
<div class="pure-u-1-3">
<div class="pure-g" style="text-align:right">
<% {"Default", "Music", "Gaming", "Movies"}.each do |option| %>
<% TrendingTypes.each do |option|
option = option.to_s
%>
<div class="pure-u-1 pure-md-1-3">
<% if trending_type == option %>
<b><%= translate(locale, option) %></b>

View File

@@ -204,6 +204,17 @@
</div>
<% end %>
<div class="pure-control-group">
<label for="default_trending_type"><%= translate(locale, "preferences_default_trending_type") %></label>
<select name="default_trending_type" id="default_trending_type">
<% Invidious::Routes::Feeds::TrendingTypes.each do |option|
option = option.to_s
%>
<option value="<%= option %>" <% if preferences.default_trending_type.to_s == option %> selected <% end %>><%= translate(locale, option) %></option>
<% end %>
</select>
</div>
<legend><%= translate(locale, "preferences_category_misc") %></legend>
<div class="pure-control-group">