diff --git a/assets/css/default.css b/assets/css/default.css index 49fff446..8ff2afc3 100644 --- a/assets/css/default.css +++ b/assets/css/default.css @@ -1069,3 +1069,8 @@ h1, h2, h3, h4, h5, p, .video-transcript > footer select { width: 75%; } + +.hidden-channels { + width: 300px; + height: 200px; +} \ No newline at end of file diff --git a/locales/en-US.json b/locales/en-US.json index 39b438c8..df88f362 100644 --- a/locales/en-US.json +++ b/locales/en-US.json @@ -122,6 +122,8 @@ "Redirect homepage to feed: ": "Redirect homepage to feed: ", "preferences_max_results_label": "Number of videos shown in feed: ", "preferences_sort_label": "Sort videos by: ", + "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/UCw-aR42z5gUcarpPGN5OKfA", "published": "published", "published - reverse": "published - reverse", "alphabetically": "alphabetically", diff --git a/locales/es.json b/locales/es.json index b728fc4b..c815db14 100644 --- a/locales/es.json +++ b/locales/es.json @@ -78,6 +78,8 @@ "Redirect homepage to feed: ": "Redirigir la página de inicio a la fuente: ", "preferences_max_results_label": "Número de videos mostrados en la fuente: ", "preferences_sort_label": "Ordenar los videos por: ", + "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/UCw-aR42z5gUcarpPGN5OKfA", "published": "fecha de publicación", "published - reverse": "fecha de publicación: orden inverso", "alphabetically": "alfabéticamente", diff --git a/src/invidious/config.cr b/src/invidious/config.cr index 55ed6716..c3f44649 100644 --- a/src/invidious/config.cr +++ b/src/invidious/config.cr @@ -53,6 +53,8 @@ struct ConfigPreferences property show_nick : Bool = true property save_player_pos : Bool = false property enable_dearrow : Bool = false + @[YAML::Field(ignore: true)] + property hidden_channels : Array(String)? = nil def to_tuple {% begin %} diff --git a/src/invidious/routes/feeds.cr b/src/invidious/routes/feeds.cr index ada5714d..f90af73e 100644 --- a/src/invidious/routes/feeds.cr +++ b/src/invidious/routes/feeds.cr @@ -35,6 +35,7 @@ module Invidious::Routes::Feeds locale = env.get("preferences").as(Preferences).locale if CONFIG.popular_enabled + preferences = env.get("preferences").as(Preferences) templated "feeds/popular" else message = translate(locale, "The Popular feed has been disabled by the administrator.") diff --git a/src/invidious/routes/preferences.cr b/src/invidious/routes/preferences.cr index 8058ab1a..a40b05bb 100644 --- a/src/invidious/routes/preferences.cr +++ b/src/invidious/routes/preferences.cr @@ -144,6 +144,30 @@ module Invidious::Routes::PreferencesRoute notifications_only ||= "off" notifications_only = notifications_only == "on" + hidden_channels = env.params.body["hidden_channels"]?.try &.as(String) + if hidden_channels + hidden_channels = hidden_channels.split("\n") + + delete = [] of Int32 + hidden_channels.each_with_index do |ucid, idx| + u = ucid.rstrip("\r") + + if (u == "") || (u == "\r") + delete << idx + next + end + + # 24 is the length of channel UCIDs + if u.size != 24 + raise InfoException.new("Channel ID has to be 25 characters long!") + else + hidden_channels[idx] = u + end + end + + delete.reverse_each { |i| hidden_channels.delete_at(i) } + end + # Convert to JSON and back again to take advantage of converters used for compatibility preferences = Preferences.from_json({ annotations: annotations, @@ -180,6 +204,7 @@ module Invidious::Routes::PreferencesRoute vr_mode: vr_mode, show_nick: show_nick, save_player_pos: save_player_pos, + hidden_channels: hidden_channels, }.to_json) if user = env.get? "user" diff --git a/src/invidious/user/preferences.cr b/src/invidious/user/preferences.cr index 0a8525f3..7f54c12f 100644 --- a/src/invidious/user/preferences.cr +++ b/src/invidious/user/preferences.cr @@ -56,6 +56,7 @@ struct Preferences property extend_desc : Bool = CONFIG.default_user_preferences.extend_desc 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 module BoolToString def self.to_json(value : String, json : JSON::Builder) diff --git a/src/invidious/views/feeds/popular.ecr b/src/invidious/views/feeds/popular.ecr index 02171431..20ef4636 100644 --- a/src/invidious/views/feeds/popular.ecr +++ b/src/invidious/views/feeds/popular.ecr @@ -13,6 +13,11 @@