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

@@ -124,6 +124,7 @@
"preferences_sort_label": "Sort videos by: ", "preferences_sort_label": "Sort videos by: ",
"preferences_hidden_channels": "Hidden channels", "preferences_hidden_channels": "Hidden channels",
"preferences_hidden_channels_label": "(Experimental) Channel ID list separated by ENTER key. This only hides channels from the popular page for now. You can get the ID of the channel clicking on the channel and copying the part that starts with 'UC' in the channel link. Example: /channel/<b>UCw-aR42z5gUcarpPGN5OKfA</b>", "preferences_hidden_channels_label": "(Experimental) Channel ID list separated by ENTER key. This only hides channels from the popular page for now. You can get the ID of the channel clicking on the channel and copying the part that starts with 'UC' in the channel link. Example: /channel/<b>UCw-aR42z5gUcarpPGN5OKfA</b>",
"preferences_default_trending_type": "Default trending page: ",
"published": "published", "published": "published",
"published - reverse": "published - reverse", "published - reverse": "published - reverse",
"alphabetically": "alphabetically", "alphabetically": "alphabetically",

View File

@@ -80,6 +80,7 @@
"preferences_sort_label": "Ordenar los videos por: ", "preferences_sort_label": "Ordenar los videos por: ",
"preferences_hidden_channels": "Canales ocultos", "preferences_hidden_channels": "Canales ocultos",
"preferences_hidden_channels_label": "(Experimental) Lista de IDs de canales separados por la tecla ENTER. Por ahora, esto solo oculta canales de la pagina popular. Puedes conseguir la ID del canal entrando al canal y copiando la parte que empieza por 'UC' en el enlace. Ejemplo: /channel/<b>UCw-aR42z5gUcarpPGN5OKfA</b>", "preferences_hidden_channels_label": "(Experimental) Lista de IDs de canales separados por la tecla ENTER. Por ahora, esto solo oculta canales de la pagina popular. Puedes conseguir la ID del canal entrando al canal y copiando la parte que empieza por 'UC' en el enlace. Ejemplo: /channel/<b>UCw-aR42z5gUcarpPGN5OKfA</b>",
"preferences_default_trending_type": "Página de tendencias por defecto: ",
"published": "fecha de publicación", "published": "fecha de publicación",
"published - reverse": "fecha de publicación: orden inverso", "published - reverse": "fecha de publicación: orden inverso",
"alphabetically": "alfabéticamente", "alphabetically": "alfabéticamente",

View File

@@ -55,6 +55,8 @@ struct ConfigPreferences
property enable_dearrow : Bool = false property enable_dearrow : Bool = false
@[YAML::Field(ignore: true)] @[YAML::Field(ignore: true)]
property hidden_channels : Array(String)? = nil 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 def to_tuple
{% begin %} {% begin %}

View File

@@ -1,6 +1,13 @@
{% skip_file if flag?(:api_only) %} {% skip_file if flag?(:api_only) %}
module Invidious::Routes::Feeds module Invidious::Routes::Feeds
enum TrendingTypes
Default
Music
Gaming
Movies
end
def self.view_all_playlists_redirect(env) def self.view_all_playlists_redirect(env)
env.redirect "/feed/playlists" env.redirect "/feed/playlists"
end end
@@ -44,13 +51,14 @@ module Invidious::Routes::Feeds
end end
def self.trending(env) 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 = env.params.query["type"]?
trending_type ||= "Default" trending_type ||= preferences.default_trending_type.to_s
region = env.params.query["region"]? region = env.params.query["region"]?
region ||= env.get("preferences").as(Preferences).region region ||= preferences.region
begin begin
trending, plid = fetch_trending(trending_type, region, locale) 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) } delete.reverse_each { |i| hidden_channels.delete_at(i) }
end 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 # Convert to JSON and back again to take advantage of converters used for compatibility
preferences = Preferences.from_json({ preferences = Preferences.from_json({
annotations: annotations, annotations: annotations,
@@ -205,6 +208,7 @@ module Invidious::Routes::PreferencesRoute
show_nick: show_nick, show_nick: show_nick,
save_player_pos: save_player_pos, save_player_pos: save_player_pos,
hidden_channels: hidden_channels, hidden_channels: hidden_channels,
default_trending_type: default_trending_type,
}.to_json) }.to_json)
if user = env.get? "user" if user = env.get? "user"

View File

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

View File

@@ -21,7 +21,9 @@
</div> </div>
<div class="pure-u-1-3"> <div class="pure-u-1-3">
<div class="pure-g" style="text-align:right"> <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"> <div class="pure-u-1 pure-md-1-3">
<% if trending_type == option %> <% if trending_type == option %>
<b><%= translate(locale, option) %></b> <b><%= translate(locale, option) %></b>

View File

@@ -204,6 +204,17 @@
</div> </div>
<% end %> <% 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> <legend><%= translate(locale, "preferences_category_misc") %></legend>
<div class="pure-control-group"> <div class="pure-control-group">