mirror of
https://gitea.invidious.io/iv-org/invidious-copy-2023-06-08.git
synced 2024-08-15 00:53:38 +00:00
Use enum where possible
Use enum for the theme ('dark_mode'), the home pages, the player styles and the sort option. Video qualities still require 'quality' and 'quality_dash' to be merged.
This commit is contained in:
parent
0f0677bf43
commit
555de5f4ef
9 changed files with 263 additions and 147 deletions
|
@ -25,11 +25,13 @@ require "xml"
|
||||||
require "yaml"
|
require "yaml"
|
||||||
require "compress/zip"
|
require "compress/zip"
|
||||||
require "protodec/utils"
|
require "protodec/utils"
|
||||||
|
|
||||||
require "./invidious/helpers/*"
|
require "./invidious/helpers/*"
|
||||||
require "./invidious/*"
|
require "./invidious/*"
|
||||||
require "./invidious/channels/*"
|
require "./invidious/channels/*"
|
||||||
require "./invidious/routes/**"
|
require "./invidious/routes/**"
|
||||||
require "./invidious/jobs/**"
|
require "./invidious/jobs/**"
|
||||||
|
require "./invidious/user/*"
|
||||||
|
|
||||||
CONFIG = Config.load
|
CONFIG = Config.load
|
||||||
HMAC_KEY = CONFIG.hmac_key || Random::Secure.hex(32)
|
HMAC_KEY = CONFIG.hmac_key || Random::Secure.hex(32)
|
||||||
|
@ -281,12 +283,14 @@ before_all do |env|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
dark_mode = convert_theme(env.params.query["dark_mode"]?) || preferences.dark_mode.to_s
|
theme = env.params.query["dark_mode"]?
|
||||||
|
theme = Settings::Converters::Theme.from_s(theme) if theme
|
||||||
|
preferences.dark_mode = theme if theme
|
||||||
|
|
||||||
thin_mode = env.params.query["thin_mode"]? || preferences.thin_mode.to_s
|
thin_mode = env.params.query["thin_mode"]? || preferences.thin_mode.to_s
|
||||||
thin_mode = thin_mode == "true"
|
thin_mode = thin_mode == "true"
|
||||||
locale = env.params.query["hl"]? || preferences.locale
|
locale = env.params.query["hl"]? || preferences.locale
|
||||||
|
|
||||||
preferences.dark_mode = dark_mode
|
|
||||||
preferences.thin_mode = thin_mode
|
preferences.thin_mode = thin_mode
|
||||||
preferences.locale = locale
|
preferences.locale = locale
|
||||||
env.set "preferences", preferences
|
env.set "preferences", preferences
|
||||||
|
|
|
@ -397,19 +397,6 @@ def parse_range(range)
|
||||||
return 0_i64, nil
|
return 0_i64, nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def convert_theme(theme)
|
|
||||||
case theme
|
|
||||||
when "true"
|
|
||||||
"dark"
|
|
||||||
when "false"
|
|
||||||
"light"
|
|
||||||
when "", nil
|
|
||||||
nil
|
|
||||||
else
|
|
||||||
theme
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def fetch_random_instance
|
def fetch_random_instance
|
||||||
begin
|
begin
|
||||||
instance_api_client = HTTP::Client.new(URI.parse("https://api.invidious.io"))
|
instance_api_client = HTTP::Client.new(URI.parse("https://api.invidious.io"))
|
||||||
|
|
|
@ -5,24 +5,22 @@ class Invidious::Routes::Misc < Invidious::Routes::BaseRoute
|
||||||
user = env.get? "user"
|
user = env.get? "user"
|
||||||
|
|
||||||
case preferences.default_home
|
case preferences.default_home
|
||||||
when "Popular"
|
when Settings::HomePages::Popular ; env.redirect "/feed/popular"
|
||||||
env.redirect "/feed/popular"
|
when Settings::HomePages::Trending; env.redirect "/feed/trending"
|
||||||
when "Trending"
|
when Settings::UserHomePages::Subscriptions
|
||||||
env.redirect "/feed/trending"
|
|
||||||
when "Subscriptions"
|
|
||||||
if user
|
if user
|
||||||
env.redirect "/feed/subscriptions"
|
env.redirect "/feed/subscriptions"
|
||||||
else
|
else
|
||||||
env.redirect "/feed/popular"
|
env.redirect "/feed/popular"
|
||||||
end
|
end
|
||||||
when "Playlists"
|
when Settings::UserHomePages::Playlists
|
||||||
if user
|
if user
|
||||||
env.redirect "/view_all_playlists"
|
env.redirect "/view_all_playlists"
|
||||||
else
|
else
|
||||||
env.redirect "/feed/popular"
|
env.redirect "/feed/popular"
|
||||||
end
|
end
|
||||||
else
|
else # Settings::HomePages::Search
|
||||||
templated "search_homepage", navbar_search: false
|
env.redirect "/search"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -48,8 +48,8 @@ class Invidious::Routes::PreferencesRoute < Invidious::Routes::BaseRoute
|
||||||
speed = env.params.body["speed"]?.try &.as(String).to_f32?
|
speed = env.params.body["speed"]?.try &.as(String).to_f32?
|
||||||
speed ||= CONFIG.default_user_preferences.speed
|
speed ||= CONFIG.default_user_preferences.speed
|
||||||
|
|
||||||
player_style = env.params.body["player_style"]?.try &.as(String)
|
player_style = env.params.body["player_style"]?.try { |x| Settings::PlayerStyles.parse?(x) }
|
||||||
player_style ||= CONFIG.default_user_preferences.player_style
|
player_style = CONFIG.default_user_preferences.player_style if !player_style
|
||||||
|
|
||||||
quality = env.params.body["quality"]?.try &.as(String)
|
quality = env.params.body["quality"]?.try &.as(String)
|
||||||
quality ||= CONFIG.default_user_preferences.quality
|
quality ||= CONFIG.default_user_preferences.quality
|
||||||
|
@ -86,7 +86,8 @@ class Invidious::Routes::PreferencesRoute < Invidious::Routes::BaseRoute
|
||||||
related_videos ||= "off"
|
related_videos ||= "off"
|
||||||
related_videos = related_videos == "on"
|
related_videos = related_videos == "on"
|
||||||
|
|
||||||
default_home = env.params.body["default_home"]?.try &.as(String) || CONFIG.default_user_preferences.default_home
|
default_home = env.params.body["default_home"]?.try { |x| Settings::HomePages.parse?(x) || Settings::UserHomePages.parse?(x) }
|
||||||
|
default_home = CONFIG.default_user_preferences.default_home.to_s if !default_home
|
||||||
|
|
||||||
feed_menu = [] of String
|
feed_menu = [] of String
|
||||||
4.times do |index|
|
4.times do |index|
|
||||||
|
@ -103,8 +104,8 @@ class Invidious::Routes::PreferencesRoute < Invidious::Routes::BaseRoute
|
||||||
locale = env.params.body["locale"]?.try &.as(String)
|
locale = env.params.body["locale"]?.try &.as(String)
|
||||||
locale ||= CONFIG.default_user_preferences.locale
|
locale ||= CONFIG.default_user_preferences.locale
|
||||||
|
|
||||||
dark_mode = env.params.body["dark_mode"]?.try &.as(String)
|
theme = env.params.body["dark_mode"]?.try { |x| Settings::Themes.parse?(x) }
|
||||||
dark_mode ||= CONFIG.default_user_preferences.dark_mode
|
theme = CONFIG.default_user_preferences.dark_mode if !theme
|
||||||
|
|
||||||
thin_mode = env.params.body["thin_mode"]?.try &.as(String)
|
thin_mode = env.params.body["thin_mode"]?.try &.as(String)
|
||||||
thin_mode ||= "off"
|
thin_mode ||= "off"
|
||||||
|
@ -113,8 +114,8 @@ class Invidious::Routes::PreferencesRoute < Invidious::Routes::BaseRoute
|
||||||
max_results = env.params.body["max_results"]?.try &.as(String).to_i?
|
max_results = env.params.body["max_results"]?.try &.as(String).to_i?
|
||||||
max_results ||= CONFIG.default_user_preferences.max_results
|
max_results ||= CONFIG.default_user_preferences.max_results
|
||||||
|
|
||||||
sort = env.params.body["sort"]?.try &.as(String)
|
sort = env.params.body["sort"]?.try { |x| Settings::SortOptions.parse?(x) }
|
||||||
sort ||= CONFIG.default_user_preferences.sort
|
sort = CONFIG.default_user_preferences.sort if !sort
|
||||||
|
|
||||||
latest_only = env.params.body["latest_only"]?.try &.as(String)
|
latest_only = env.params.body["latest_only"]?.try &.as(String)
|
||||||
latest_only ||= "off"
|
latest_only ||= "off"
|
||||||
|
@ -137,7 +138,7 @@ class Invidious::Routes::PreferencesRoute < Invidious::Routes::BaseRoute
|
||||||
comments: comments,
|
comments: comments,
|
||||||
continue: continue,
|
continue: continue,
|
||||||
continue_autoplay: continue_autoplay,
|
continue_autoplay: continue_autoplay,
|
||||||
dark_mode: dark_mode,
|
dark_mode: theme,
|
||||||
latest_only: latest_only,
|
latest_only: latest_only,
|
||||||
listen: listen,
|
listen: listen,
|
||||||
local: local,
|
local: local,
|
||||||
|
@ -167,14 +168,13 @@ class Invidious::Routes::PreferencesRoute < Invidious::Routes::BaseRoute
|
||||||
PG_DB.exec("UPDATE users SET preferences = $1 WHERE email = $2", preferences, user.email)
|
PG_DB.exec("UPDATE users SET preferences = $1 WHERE email = $2", preferences, user.email)
|
||||||
|
|
||||||
if CONFIG.admins.includes? user.email
|
if CONFIG.admins.includes? user.email
|
||||||
CONFIG.default_user_preferences.default_home = env.params.body["admin_default_home"]?.try &.as(String) || CONFIG.default_user_preferences.default_home
|
default_home = env.params.body["admin_default_home"]?.try { |x| Settings::HomePages.parse?(x) || Settings::UserHomePages.parse?(x) }
|
||||||
|
CONFIG.default_user_preferences.default_home = default_home if default_home
|
||||||
|
|
||||||
admin_feed_menu = [] of String
|
admin_feed_menu = [] of Settings::AnyHomePages
|
||||||
4.times do |index|
|
4.times do |index|
|
||||||
option = env.params.body["admin_feed_menu[#{index}]"]?.try &.as(String) || ""
|
option = env.params.body["admin_feed_menu[#{index}]"]?.try { |x| Settings::HomePages.parse?(x) || Settings::UserHomePages.parse?(x) }
|
||||||
if !option.empty?
|
admin_feed_menu << option if option
|
||||||
admin_feed_menu << option
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
CONFIG.default_user_preferences.feed_menu = admin_feed_menu
|
CONFIG.default_user_preferences.feed_menu = admin_feed_menu
|
||||||
|
|
||||||
|
@ -229,28 +229,15 @@ class Invidious::Routes::PreferencesRoute < Invidious::Routes::BaseRoute
|
||||||
|
|
||||||
if user = env.get? "user"
|
if user = env.get? "user"
|
||||||
user = user.as(User)
|
user = user.as(User)
|
||||||
|
|
||||||
preferences = user.preferences
|
preferences = user.preferences
|
||||||
|
preferences.toggle_theme
|
||||||
case preferences.dark_mode
|
|
||||||
when "dark"
|
|
||||||
preferences.dark_mode = "light"
|
|
||||||
else
|
|
||||||
preferences.dark_mode = "dark"
|
|
||||||
end
|
|
||||||
|
|
||||||
preferences = preferences.to_json
|
preferences = preferences.to_json
|
||||||
|
|
||||||
PG_DB.exec("UPDATE users SET preferences = $1 WHERE email = $2", preferences, user.email)
|
PG_DB.exec("UPDATE users SET preferences = $1 WHERE email = $2", preferences, user.email)
|
||||||
else
|
else
|
||||||
preferences = env.get("preferences").as(Preferences)
|
preferences = env.get("preferences").as(Preferences)
|
||||||
|
preferences.toggle_theme
|
||||||
case preferences.dark_mode
|
|
||||||
when "dark"
|
|
||||||
preferences.dark_mode = "light"
|
|
||||||
else
|
|
||||||
preferences.dark_mode = "dark"
|
|
||||||
end
|
|
||||||
|
|
||||||
preferences = preferences.to_json
|
preferences = preferences.to_json
|
||||||
|
|
||||||
if Kemal.config.ssl || CONFIG.https_only
|
if Kemal.config.ssl || CONFIG.https_only
|
||||||
|
|
|
@ -5,6 +5,84 @@
|
||||||
|
|
||||||
require "json"
|
require "json"
|
||||||
require "yaml"
|
require "yaml"
|
||||||
|
require "html"
|
||||||
|
|
||||||
|
#
|
||||||
|
# Enumerates types and constants
|
||||||
|
#
|
||||||
|
|
||||||
|
module Settings
|
||||||
|
ALLOWED_SPEED_VALUES = {
|
||||||
|
2.00_f32, # Double speed
|
||||||
|
1.75_f32,
|
||||||
|
1.50_f32,
|
||||||
|
1.25_f32,
|
||||||
|
1.00_f32, # Normal
|
||||||
|
0.75_f32,
|
||||||
|
0.50_f32, # Half speed
|
||||||
|
0.25_f32,
|
||||||
|
}
|
||||||
|
|
||||||
|
enum Themes
|
||||||
|
Auto # I.e use the system's settings with media queries
|
||||||
|
Light
|
||||||
|
Dark
|
||||||
|
end
|
||||||
|
|
||||||
|
enum PlayerStyles
|
||||||
|
Invidious
|
||||||
|
Youtube
|
||||||
|
end
|
||||||
|
|
||||||
|
# General
|
||||||
|
enum HomePages
|
||||||
|
Search
|
||||||
|
Popular
|
||||||
|
Trending
|
||||||
|
end
|
||||||
|
|
||||||
|
# Authenticated
|
||||||
|
enum UserHomePages
|
||||||
|
Subscriptions
|
||||||
|
Playlists
|
||||||
|
end
|
||||||
|
|
||||||
|
alias AnyHomePages = HomePages | UserHomePages
|
||||||
|
|
||||||
|
enum SortOptions
|
||||||
|
Alphabetically
|
||||||
|
Alphabetically_Reverse
|
||||||
|
Channel_Name
|
||||||
|
Channel_Name_Reverse
|
||||||
|
Publication_Date
|
||||||
|
Publication_Date_Reverse
|
||||||
|
end
|
||||||
|
|
||||||
|
# Unused for now, reuires merging
|
||||||
|
enum VideoQualities
|
||||||
|
# Normal
|
||||||
|
HD720
|
||||||
|
Medium
|
||||||
|
Small
|
||||||
|
# Dash
|
||||||
|
DASH_Auto
|
||||||
|
DASH_Best
|
||||||
|
DASH_4320p
|
||||||
|
DASH_2160p
|
||||||
|
DASH_1440p
|
||||||
|
DASH_1080p
|
||||||
|
DASH_720p
|
||||||
|
DASH_480p
|
||||||
|
DASH_360p
|
||||||
|
DASH_240p
|
||||||
|
DASH_144p
|
||||||
|
DASH_Worst
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
#
|
||||||
|
# Data structure that stores a user's preferences.
|
||||||
|
#
|
||||||
|
|
||||||
class Preferences
|
class Preferences
|
||||||
include JSON::Serializable
|
include JSON::Serializable
|
||||||
|
@ -12,6 +90,7 @@ class Preferences
|
||||||
|
|
||||||
property annotations : Bool = false
|
property annotations : Bool = false
|
||||||
property annotations_subscribed : Bool = false
|
property annotations_subscribed : Bool = false
|
||||||
|
|
||||||
property autoplay : Bool = false
|
property autoplay : Bool = false
|
||||||
property automatic_instance_redirect : Bool = false
|
property automatic_instance_redirect : Bool = false
|
||||||
|
|
||||||
|
@ -22,12 +101,13 @@ class Preferences
|
||||||
@[JSON::Field(converter: Preferences::StringToArray)]
|
@[JSON::Field(converter: Preferences::StringToArray)]
|
||||||
@[YAML::Field(converter: Preferences::StringToArray)]
|
@[YAML::Field(converter: Preferences::StringToArray)]
|
||||||
property comments : Array(String) = ["youtube", ""]
|
property comments : Array(String) = ["youtube", ""]
|
||||||
|
|
||||||
property continue : Bool = false
|
property continue : Bool = false
|
||||||
property continue_autoplay : Bool = true
|
property continue_autoplay : Bool = true
|
||||||
|
|
||||||
@[JSON::Field(converter: Preferences::BoolToString)]
|
@[JSON::Field(converter: Settings::Converters::Generic(Settings::Themes))]
|
||||||
@[YAML::Field(converter: Preferences::BoolToString)]
|
@[YAML::Field(converter: Settings::Converters::Generic(Settings::Themes))]
|
||||||
property dark_mode : String = ""
|
property dark_mode : Settings::Themes = Settings::Themes::Dark
|
||||||
|
|
||||||
property latest_only : Bool = false
|
property latest_only : Bool = false
|
||||||
|
|
||||||
|
@ -43,20 +123,34 @@ class Preferences
|
||||||
property max_results : Int32 = 40
|
property max_results : Int32 = 40
|
||||||
property notifications_only : Bool = false
|
property notifications_only : Bool = false
|
||||||
|
|
||||||
@[JSON::Field(converter: Preferences::ProcessString)]
|
@[JSON::Field(converter: Settings::Converters::Generic(Settings::PlayerStyles))]
|
||||||
property player_style : String = "invidious"
|
@[YAML::Field(converter: Settings::Converters::Generic(Settings::PlayerStyles))]
|
||||||
|
property player_style : Settings::PlayerStyles = Settings::PlayerStyles::Invidious
|
||||||
|
|
||||||
@[JSON::Field(converter: Preferences::ProcessString)]
|
@[JSON::Field(converter: Preferences::ProcessString)]
|
||||||
property quality : String = "hd720"
|
property quality : String = "hd720"
|
||||||
@[JSON::Field(converter: Preferences::ProcessString)]
|
@[JSON::Field(converter: Preferences::ProcessString)]
|
||||||
property quality_dash : String = "auto"
|
property quality_dash : String = "auto"
|
||||||
|
|
||||||
property default_home : String? = "Popular"
|
@[JSON::Field(converter: Settings::Converters::Generic(Settings::AnyHomePages))]
|
||||||
property feed_menu : Array(String) = ["Popular", "Trending", "Subscriptions", "Playlists"]
|
@[YAML::Field(converter: Settings::Converters::Generic(Settings::AnyHomePages))]
|
||||||
|
property default_home : Settings::AnyHomePages = Settings::HomePages::Popular
|
||||||
|
|
||||||
|
@[JSON::Field(converter: Settings::Converters::Generic(Array(Settings::AnyHomePages)))]
|
||||||
|
@[YAML::Field(converter: Settings::Converters::Generic(Array(Settings::AnyHomePages)))]
|
||||||
|
property feed_menu : Array(Settings::AnyHomePages) = [
|
||||||
|
Settings::HomePages::Popular,
|
||||||
|
Settings::HomePages::Trending,
|
||||||
|
Settings::UserHomePages::Subscriptions,
|
||||||
|
Settings::UserHomePages::Playlists,
|
||||||
|
]
|
||||||
|
|
||||||
property related_videos : Bool = true
|
property related_videos : Bool = true
|
||||||
|
|
||||||
@[JSON::Field(converter: Preferences::ProcessString)]
|
@[JSON::Field(converter: Settings::Converters::Generic(Settings::SortOptions))]
|
||||||
property sort : String = "published"
|
@[YAML::Field(converter: Settings::Converters::Generic(Settings::SortOptions))]
|
||||||
|
property sort : Settings::SortOptions = Settings::SortOptions::Publication_Date
|
||||||
|
|
||||||
property speed : Float32 = 1.0_f32
|
property speed : Float32 = 1.0_f32
|
||||||
|
|
||||||
property thin_mode : Bool = false
|
property thin_mode : Bool = false
|
||||||
|
@ -103,49 +197,9 @@ class Preferences
|
||||||
{% end %}
|
{% end %}
|
||||||
end
|
end
|
||||||
|
|
||||||
module BoolToString
|
def toggle_theme
|
||||||
def self.to_json(value : String, json : JSON::Builder)
|
old = @dark_mode
|
||||||
json.string value
|
@dark_mode = (old.dark?) ? Settings::Themes::Light : Settings::Themes::Dark
|
||||||
end
|
|
||||||
|
|
||||||
def self.from_json(value : JSON::PullParser) : String
|
|
||||||
begin
|
|
||||||
result = value.read_string
|
|
||||||
|
|
||||||
if result.empty?
|
|
||||||
CONFIG.default_user_preferences.dark_mode
|
|
||||||
else
|
|
||||||
result
|
|
||||||
end
|
|
||||||
rescue ex
|
|
||||||
if value.read_bool
|
|
||||||
"dark"
|
|
||||||
else
|
|
||||||
"light"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.to_yaml(value : String, yaml : YAML::Nodes::Builder)
|
|
||||||
yaml.scalar value
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.from_yaml(ctx : YAML::ParseContext, node : YAML::Nodes::Node) : String
|
|
||||||
unless node.is_a?(YAML::Nodes::Scalar)
|
|
||||||
node.raise "Expected scalar, not #{node.class}"
|
|
||||||
end
|
|
||||||
|
|
||||||
case node.value
|
|
||||||
when "true"
|
|
||||||
"dark"
|
|
||||||
when "false"
|
|
||||||
"light"
|
|
||||||
when ""
|
|
||||||
CONFIG.default_user_preferences.dark_mode
|
|
||||||
else
|
|
||||||
node.value
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
module ClampInt
|
module ClampInt
|
||||||
|
@ -247,8 +301,100 @@ class Preferences
|
||||||
}
|
}
|
||||||
{% end %}
|
{% end %}
|
||||||
end
|
end
|
||||||
|
end # class Data
|
||||||
|
|
||||||
|
#
|
||||||
|
# Datatype converters (also act as data validators)
|
||||||
|
#
|
||||||
|
|
||||||
|
module Settings::Converters
|
||||||
|
#
|
||||||
|
# Generic enum conversion
|
||||||
|
#
|
||||||
|
module Generic(T)
|
||||||
|
extend self
|
||||||
|
|
||||||
|
# From/To JSON
|
||||||
|
|
||||||
|
def to_json(value : T, json : JSON::Builder)
|
||||||
|
value.to_json json
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def from_json(value : JSON::PullParser) : T?
|
||||||
|
begin
|
||||||
|
T.new value
|
||||||
|
rescue e : JSON::ParseException
|
||||||
|
# Be silent on invalid data and return nil
|
||||||
|
# This will fallback to the default value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# From/To YAML
|
||||||
|
|
||||||
|
def to_yaml(value : T, yaml : YAML::Nodes::Builder)
|
||||||
|
value.to_yaml yaml
|
||||||
|
end
|
||||||
|
|
||||||
|
def from_yaml(ctx : YAML::ParseContext, node : YAML::Nodes::Node) : T?
|
||||||
|
begin
|
||||||
|
T.new ctx, node
|
||||||
|
rescue e : YAML::ParseException
|
||||||
|
# Be silent on invalid data and return nil
|
||||||
|
# This will fallback to the default value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end # module Generic
|
||||||
|
|
||||||
|
#
|
||||||
|
# Themes enum conversion
|
||||||
|
#
|
||||||
|
module Theme
|
||||||
|
extend self
|
||||||
|
|
||||||
|
# From String (.to_s is native of Enum type)
|
||||||
|
|
||||||
|
def from_s(input : String?) : Themes?
|
||||||
|
return if !input
|
||||||
|
|
||||||
|
case input.downcase
|
||||||
|
when "auto" ; Themes::Auto
|
||||||
|
when "light"; Themes::Light
|
||||||
|
when "dark" ; Themes::Dark
|
||||||
|
# Compatibility with old 'dark_mode' values
|
||||||
|
when "false"; Themes::Light
|
||||||
|
when "true" ; Themes::Dark
|
||||||
|
else
|
||||||
|
# Nothing, use default from initialization
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# From/To JSON
|
||||||
|
|
||||||
|
def to_json(value : Themes, json : JSON::Builder)
|
||||||
|
json.string value.to_s
|
||||||
|
end
|
||||||
|
|
||||||
|
def from_json(value : JSON::PullParser) : Themes?
|
||||||
|
return self.from_s(value.read_string)
|
||||||
|
end
|
||||||
|
|
||||||
|
# From/To YAML
|
||||||
|
|
||||||
|
def to_yaml(value : Themes, yaml : YAML::Nodes::Builder)
|
||||||
|
yaml.scalar value.to_s
|
||||||
|
end
|
||||||
|
|
||||||
|
def from_yaml(ctx : YAML::ParseContext, node : YAML::Nodes::Node) : Themes?
|
||||||
|
unless node.is_a?(YAML::Nodes::Scalar)
|
||||||
|
node.raise "Expected scalar, not #{node.class}"
|
||||||
|
end
|
||||||
|
|
||||||
|
return self.from_s(node.value)
|
||||||
|
end
|
||||||
|
end # module theme
|
||||||
|
|
||||||
|
end # module Settings::Converters
|
||||||
|
|
||||||
struct VideoPreferences
|
struct VideoPreferences
|
||||||
include JSON::Serializable
|
include JSON::Serializable
|
||||||
|
|
||||||
|
@ -305,7 +451,7 @@ def process_video_params(query, preferences)
|
||||||
continue_autoplay ||= preferences.continue_autoplay.to_unsafe
|
continue_autoplay ||= preferences.continue_autoplay.to_unsafe
|
||||||
listen ||= preferences.listen.to_unsafe
|
listen ||= preferences.listen.to_unsafe
|
||||||
local ||= preferences.local.to_unsafe
|
local ||= preferences.local.to_unsafe
|
||||||
player_style ||= preferences.player_style
|
player_style ||= preferences.player_style.to_s
|
||||||
preferred_captions ||= preferences.captions
|
preferred_captions ||= preferences.captions
|
||||||
quality ||= preferences.quality
|
quality ||= preferences.quality
|
||||||
quality_dash ||= preferences.quality_dash
|
quality_dash ||= preferences.quality_dash
|
||||||
|
@ -324,7 +470,7 @@ def process_video_params(query, preferences)
|
||||||
continue_autoplay ||= CONFIG.default_user_preferences.continue_autoplay.to_unsafe
|
continue_autoplay ||= CONFIG.default_user_preferences.continue_autoplay.to_unsafe
|
||||||
listen ||= CONFIG.default_user_preferences.listen.to_unsafe
|
listen ||= CONFIG.default_user_preferences.listen.to_unsafe
|
||||||
local ||= CONFIG.default_user_preferences.local.to_unsafe
|
local ||= CONFIG.default_user_preferences.local.to_unsafe
|
||||||
player_style ||= CONFIG.default_user_preferences.player_style
|
player_style ||= CONFIG.default_user_preferences.player_style.to_s
|
||||||
preferred_captions ||= CONFIG.default_user_preferences.captions
|
preferred_captions ||= CONFIG.default_user_preferences.captions
|
||||||
quality ||= CONFIG.default_user_preferences.quality
|
quality ||= CONFIG.default_user_preferences.quality
|
||||||
quality_dash ||= CONFIG.default_user_preferences.quality_dash
|
quality_dash ||= CONFIG.default_user_preferences.quality_dash
|
||||||
|
|
|
@ -251,15 +251,12 @@ def get_subscription_feed(db, user, max_results = 40, page = 1)
|
||||||
notifications.sort_by! { |video| video.published }.reverse!
|
notifications.sort_by! { |video| video.published }.reverse!
|
||||||
|
|
||||||
case user.preferences.sort
|
case user.preferences.sort
|
||||||
when "alphabetically"
|
when .alphabetically? ; notifications.sort_by! { |video| video.title }
|
||||||
notifications.sort_by! { |video| video.title }
|
when .alphabetically_reverse?; notifications.sort_by! { |video| video.title }.reverse!
|
||||||
when "alphabetically - reverse"
|
when .channel_name? ; notifications.sort_by! { |video| video.author }
|
||||||
notifications.sort_by! { |video| video.title }.reverse!
|
when .channel_name_reverse? ; notifications.sort_by! { |video| video.author }.reverse!
|
||||||
when "channel name"
|
else
|
||||||
notifications.sort_by! { |video| video.author }
|
nil # Ignore
|
||||||
when "channel name - reverse"
|
|
||||||
notifications.sort_by! { |video| video.author }.reverse!
|
|
||||||
else nil # Ignore
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if user.preferences.latest_only
|
if user.preferences.latest_only
|
||||||
|
@ -298,16 +295,13 @@ def get_subscription_feed(db, user, max_results = 40, page = 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
case user.preferences.sort
|
case user.preferences.sort
|
||||||
when "published - reverse"
|
when .alphabetically? ; videos.sort_by! { |video| video.title }
|
||||||
videos.sort_by! { |video| video.published }
|
when .alphabetically_reverse?; videos.sort_by! { |video| video.title }.reverse!
|
||||||
when "alphabetically"
|
when .channel_name? ; videos.sort_by! { |video| video.author }
|
||||||
videos.sort_by! { |video| video.title }
|
when .channel_name_reverse? ; videos.sort_by! { |video| video.author }.reverse!
|
||||||
when "alphabetically - reverse"
|
when .publication_date? ; videos.sort_by! { |video| video.published }
|
||||||
videos.sort_by! { |video| video.title }.reverse!
|
# when .publication_date_reverse?; videos.sort_by! { |video| video.published }.reverse!
|
||||||
when "channel name"
|
# "Date reverse" wasn't here originally (why????)
|
||||||
videos.sort_by! { |video| video.author }
|
|
||||||
when "channel name - reverse"
|
|
||||||
videos.sort_by! { |video| video.author }.reverse!
|
|
||||||
else nil # Ignore
|
else nil # Ignore
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
<div class="feed-menu">
|
<div class="feed-menu">
|
||||||
<% feed_menu = env.get("preferences").as(Preferences).feed_menu.dup %>
|
<% feed_menu = env.get("preferences").as(Preferences).feed_menu.dup %>
|
||||||
<% if !env.get?("user") %>
|
<% if !env.get?("user") %>
|
||||||
<% feed_menu.reject! {|item| {"Subscriptions", "Playlists"}.includes? item} %>
|
<% feed_menu.reject! {|item| Settings::UserHomePages.names.includes? item} %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% feed_menu.each do |feed| %>
|
<% feed_menu.each do |feed| %>
|
||||||
<a href="/feed/<%= feed.downcase %>" class="feed-menu-item pure-menu-heading">
|
<a href="/feed/<%= feed.to_s.downcase %>" class="feed-menu-item pure-menu-heading">
|
||||||
<%= translate(locale, feed) %>
|
<%= translate(locale, feed.to_s) %>
|
||||||
</a>
|
</a>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
<div class="pure-control-group">
|
<div class="pure-control-group">
|
||||||
<label for="speed"><%= translate(locale, "Default speed: ") %></label>
|
<label for="speed"><%= translate(locale, "Default speed: ") %></label>
|
||||||
<select name="speed" id="speed">
|
<select name="speed" id="speed">
|
||||||
<% {2.0, 1.75, 1.5, 1.25, 1.0, 0.75, 0.5, 0.25}.each do |option| %>
|
<% Settings::ALLOWED_SPEED_VALUES.each do |option| %>
|
||||||
<option <% if preferences.speed == option %> selected <% end %>><%= option %></option>
|
<option <% if preferences.speed == option %> selected <% end %>><%= option %></option>
|
||||||
<% end %>
|
<% end %>
|
||||||
</select>
|
</select>
|
||||||
|
@ -130,8 +130,8 @@
|
||||||
<div class="pure-control-group">
|
<div class="pure-control-group">
|
||||||
<label for="player_style"><%= translate(locale, "Player style: ") %></label>
|
<label for="player_style"><%= translate(locale, "Player style: ") %></label>
|
||||||
<select name="player_style" id="player_style">
|
<select name="player_style" id="player_style">
|
||||||
<% {"invidious", "youtube"}.each do |option| %>
|
<% Settings::PlayerStyles.each do |option| %>
|
||||||
<option value="<%= option %>" <% if preferences.player_style == option %> selected <% end %>><%= translate(locale, option) %></option>
|
<option value="<%= option %>" <% if preferences.player_style == option %> selected <% end %>><%= translate(locale, option.to_s.underscore) %></option>
|
||||||
<% end %>
|
<% end %>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
@ -139,8 +139,8 @@
|
||||||
<div class="pure-control-group">
|
<div class="pure-control-group">
|
||||||
<label for="dark_mode"><%= translate(locale, "Theme: ") %></label>
|
<label for="dark_mode"><%= translate(locale, "Theme: ") %></label>
|
||||||
<select name="dark_mode" id="dark_mode">
|
<select name="dark_mode" id="dark_mode">
|
||||||
<% {"", "light", "dark"}.each do |option| %>
|
<% Settings::Themes.each do |option| %>
|
||||||
<option value="<%= option %>" <% if preferences.dark_mode == option %> selected <% end %>><%= translate(locale, option.blank? ? "auto" : option) %></option>
|
<option value="<%= option %>" <% if preferences.dark_mode == option %> selected <% end %>><%= translate(locale, option.to_s.underscore) %></option>
|
||||||
<% end %>
|
<% end %>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
@ -150,17 +150,16 @@
|
||||||
<input name="thin_mode" id="thin_mode" type="checkbox" <% if preferences.thin_mode %>checked<% end %>>
|
<input name="thin_mode" id="thin_mode" type="checkbox" <% if preferences.thin_mode %>checked<% end %>>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<% if env.get?("user") %>
|
<%
|
||||||
<% feed_options = {"", "Popular", "Trending", "Subscriptions", "Playlists"} %>
|
feed_options = Settings::HomePages.names
|
||||||
<% else %>
|
feed_options.concat(Settings::UserHomePages.names) if env.get?("user")
|
||||||
<% feed_options = {"", "Popular", "Trending"} %>
|
%>
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<div class="pure-control-group">
|
<div class="pure-control-group">
|
||||||
<label for="default_home"><%= translate(locale, "Default homepage: ") %></label>
|
<label for="default_home"><%= translate(locale, "Default homepage: ") %></label>
|
||||||
<select name="default_home" id="default_home">
|
<select name="default_home" id="default_home">
|
||||||
<% feed_options.each do |option| %>
|
<% feed_options.each do |option| %>
|
||||||
<option value="<%= option %>" <% if preferences.default_home == option %> selected <% end %>><%= translate(locale, option.blank? ? "Search" : option) %></option>
|
<option value="<%= option %>" <% if preferences.default_home == option %> selected <% end %>><%= translate(locale, option) %></option>
|
||||||
<% end %>
|
<% end %>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
@ -170,11 +169,12 @@
|
||||||
<% (feed_options.size - 1).times do |index| %>
|
<% (feed_options.size - 1).times do |index| %>
|
||||||
<select name="feed_menu[<%= index %>]" id="feed_menu[<%= index %>]">
|
<select name="feed_menu[<%= index %>]" id="feed_menu[<%= index %>]">
|
||||||
<% feed_options.each do |option| %>
|
<% feed_options.each do |option| %>
|
||||||
<option value="<%= option %>" <% if preferences.feed_menu[index]? == option %> selected <% end %>><%= translate(locale, option.blank? ? "Search" : option) %></option>
|
<option value="<%= option %>" <% if preferences.feed_menu[index]? == option %> selected <% end %>><%= translate(locale, option.to_s) %></option>
|
||||||
<% end %>
|
<% end %>
|
||||||
</select>
|
</select>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<% if env.get? "user" %>
|
<% if env.get? "user" %>
|
||||||
<div class="pure-control-group">
|
<div class="pure-control-group">
|
||||||
<label for="show_nick"><%= translate(locale, "Show nickname on top: ") %></label>
|
<label for="show_nick"><%= translate(locale, "Show nickname on top: ") %></label>
|
||||||
|
|
|
@ -20,10 +20,10 @@
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<% locale = LOCALES[env.get("preferences").as(Preferences).locale]? %>
|
<% locale = LOCALES[env.get("preferences").as(Preferences).locale]? %>
|
||||||
<% dark_mode = env.get("preferences").as(Preferences).dark_mode %>
|
<% theme = env.get("preferences").as(Preferences).dark_mode %>
|
||||||
|
|
||||||
<body class="<%= dark_mode.blank? ? "no" : dark_mode %>-theme">
|
<body class="<%= theme == Settings::Themes::Auto ? "no" : theme.to_s %>-theme">
|
||||||
<span style="display:none" id="dark_mode_pref"><%= env.get("preferences").as(Preferences).dark_mode %></span>
|
<span style="display:none" id="dark_mode_pref"><%= theme.to_s %></span>
|
||||||
<div class="pure-g">
|
<div class="pure-g">
|
||||||
<div class="pure-u-1 pure-u-md-2-24"></div>
|
<div class="pure-u-1 pure-u-md-2-24"></div>
|
||||||
<div class="pure-u-1 pure-u-md-20-24" id="contents">
|
<div class="pure-u-1 pure-u-md-20-24" id="contents">
|
||||||
|
@ -45,7 +45,7 @@
|
||||||
<% if env.get? "user" %>
|
<% if env.get? "user" %>
|
||||||
<div class="pure-u-1-4">
|
<div class="pure-u-1-4">
|
||||||
<a id="toggle_theme" href="/toggle_theme?referer=<%= env.get?("current_page") %>" class="pure-menu-heading">
|
<a id="toggle_theme" href="/toggle_theme?referer=<%= env.get?("current_page") %>" class="pure-menu-heading">
|
||||||
<% if env.get("preferences").as(Preferences).dark_mode == "dark" %>
|
<% if theme == Settings::Themes::Dark %>
|
||||||
<i class="icon ion-ios-sunny"></i>
|
<i class="icon ion-ios-sunny"></i>
|
||||||
<% else %>
|
<% else %>
|
||||||
<i class="icon ion-ios-moon"></i>
|
<i class="icon ion-ios-moon"></i>
|
||||||
|
@ -83,7 +83,7 @@
|
||||||
<% else %>
|
<% else %>
|
||||||
<div class="pure-u-1-3">
|
<div class="pure-u-1-3">
|
||||||
<a id="toggle_theme" href="/toggle_theme?referer=<%= env.get?("current_page") %>" class="pure-menu-heading">
|
<a id="toggle_theme" href="/toggle_theme?referer=<%= env.get?("current_page") %>" class="pure-menu-heading">
|
||||||
<% if env.get("preferences").as(Preferences).dark_mode == "dark" %>
|
<% if theme == Settings::Themes::Dark %>
|
||||||
<i class="icon ion-ios-sunny"></i>
|
<i class="icon ion-ios-sunny"></i>
|
||||||
<% else %>
|
<% else %>
|
||||||
<i class="icon ion-ios-moon"></i>
|
<i class="icon ion-ios-moon"></i>
|
||||||
|
|
Loading…
Reference in a new issue