diff options
| author | Dmitry Sandalov <dmitry@sandalov.org> | 2021-10-21 14:54:15 +0300 |
|---|---|---|
| committer | Dmitry Sandalov <dmitry@sandalov.org> | 2021-10-21 14:54:15 +0300 |
| commit | d9c58c48370debbbfecf76370b5ea0526277bb5a (patch) | |
| tree | be22470c81768fffabf04c3fa3cfa87a5c6e9a52 /src | |
| parent | 129779a7573cab465a6975fa527ec5e9d7e0ee92 (diff) | |
| download | invidious-d9c58c48370debbbfecf76370b5ea0526277bb5a.tar.gz invidious-d9c58c48370debbbfecf76370b5ea0526277bb5a.tar.bz2 invidious-d9c58c48370debbbfecf76370b5ea0526277bb5a.zip | |
Feature Request: Localization for trending iv-org#331
Diffstat (limited to 'src')
| -rw-r--r-- | src/invidious/config.cr | 2 | ||||
| -rw-r--r-- | src/invidious/routes/feeds.cr | 2 | ||||
| -rw-r--r-- | src/invidious/routes/preferences.cr | 3 | ||||
| -rw-r--r-- | src/invidious/user/preferences.cr | 1 | ||||
| -rw-r--r-- | src/invidious/videos.cr | 2 | ||||
| -rw-r--r-- | src/invidious/views/preferences.ecr | 9 |
6 files changed, 18 insertions, 1 deletions
diff --git a/src/invidious/config.cr b/src/invidious/config.cr index e2bc5722..baf2702a 100644 --- a/src/invidious/config.cr +++ b/src/invidious/config.cr @@ -31,6 +31,7 @@ struct ConfigPreferences property default_home : String? = "Popular" property feed_menu : Array(String) = ["Popular", "Trending", "Subscriptions", "Playlists"] property automatic_instance_redirect : Bool = false + property region : String = "US" property related_videos : Bool = true property sort : String = "published" property speed : Float32 = 1.0_f32 @@ -72,6 +73,7 @@ class Config property captcha_enabled : Bool = true property login_enabled : Bool = true property registration_enabled : Bool = true + property region : String? property statistics_enabled : Bool = false property admins : Array(String) = [] of String property external_port : Int32? = nil diff --git a/src/invidious/routes/feeds.cr b/src/invidious/routes/feeds.cr index d9280529..40c41dc1 100644 --- a/src/invidious/routes/feeds.cr +++ b/src/invidious/routes/feeds.cr @@ -48,7 +48,7 @@ module Invidious::Routes::Feeds trending_type ||= "Default" region = env.params.query["region"]? - region ||= "US" + region ||= env.get("preferences").as(Preferences).region begin trending, plid = fetch_trending(trending_type, region, locale) diff --git a/src/invidious/routes/preferences.cr b/src/invidious/routes/preferences.cr index ae5407dc..8793d4e9 100644 --- a/src/invidious/routes/preferences.cr +++ b/src/invidious/routes/preferences.cr @@ -102,6 +102,8 @@ module Invidious::Routes::PreferencesRoute automatic_instance_redirect ||= "off" automatic_instance_redirect = automatic_instance_redirect == "on" + region = env.params.body["region"]?.try &.as(String) + locale = env.params.body["locale"]?.try &.as(String) locale ||= CONFIG.default_user_preferences.locale @@ -152,6 +154,7 @@ module Invidious::Routes::PreferencesRoute default_home: default_home, feed_menu: feed_menu, automatic_instance_redirect: automatic_instance_redirect, + region: region, related_videos: related_videos, sort: sort, speed: speed, diff --git a/src/invidious/user/preferences.cr b/src/invidious/user/preferences.cr index 453a635e..fd7b4763 100644 --- a/src/invidious/user/preferences.cr +++ b/src/invidious/user/preferences.cr @@ -28,6 +28,7 @@ struct Preferences @[JSON::Field(converter: Preferences::ProcessString)] property locale : String = CONFIG.default_user_preferences.locale + property region : String? = CONFIG.region != nil ? CONFIG.region : CONFIG.default_user_preferences.region @[JSON::Field(converter: Preferences::ClampInt)] property max_results : Int32 = CONFIG.default_user_preferences.max_results diff --git a/src/invidious/videos.cr b/src/invidious/videos.cr index 0e6bd77c..4c200409 100644 --- a/src/invidious/videos.cr +++ b/src/invidious/videos.cr @@ -110,6 +110,8 @@ CAPTION_LANGUAGES = { REGIONS = {"AD", "AE", "AF", "AG", "AI", "AL", "AM", "AO", "AQ", "AR", "AS", "AT", "AU", "AW", "AX", "AZ", "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BL", "BM", "BN", "BO", "BQ", "BR", "BS", "BT", "BV", "BW", "BY", "BZ", "CA", "CC", "CD", "CF", "CG", "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", "CU", "CV", "CW", "CX", "CY", "CZ", "DE", "DJ", "DK", "DM", "DO", "DZ", "EC", "EE", "EG", "EH", "ER", "ES", "ET", "FI", "FJ", "FK", "FM", "FO", "FR", "GA", "GB", "GD", "GE", "GF", "GG", "GH", "GI", "GL", "GM", "GN", "GP", "GQ", "GR", "GS", "GT", "GU", "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", "ID", "IE", "IL", "IM", "IN", "IO", "IQ", "IR", "IS", "IT", "JE", "JM", "JO", "JP", "KE", "KG", "KH", "KI", "KM", "KN", "KP", "KR", "KW", "KY", "KZ", "LA", "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", "LV", "LY", "MA", "MC", "MD", "ME", "MF", "MG", "MH", "MK", "ML", "MM", "MN", "MO", "MP", "MQ", "MR", "MS", "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA", "NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", "NR", "NU", "NZ", "OM", "PA", "PE", "PF", "PG", "PH", "PK", "PL", "PM", "PN", "PR", "PS", "PT", "PW", "PY", "QA", "RE", "RO", "RS", "RU", "RW", "SA", "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SJ", "SK", "SL", "SM", "SN", "SO", "SR", "SS", "ST", "SV", "SX", "SY", "SZ", "TC", "TD", "TF", "TG", "TH", "TJ", "TK", "TL", "TM", "TN", "TO", "TR", "TT", "TV", "TW", "TZ", "UA", "UG", "UM", "US", "UY", "UZ", "VA", "VC", "VE", "VG", "VI", "VN", "VU", "WF", "WS", "YE", "YT", "ZA", "ZM", "ZW"} +TRENDING_REGIONS = {"AE", "AR", "AT", "AU", "AZ", "BA", "BD", "BE", "BG", "BH", "BO", "BR", "BY", "CA", "CH", "CL", "CO", "CR", "CY", "CZ", "DE", "DK", "DO", "DZ", "EC", "EE", "EG", "ES", "FI", "FR", "GB", "GE", "GH", "GR", "GT", "HK", "HN", "HR", "HU", "ID", "IE", "IL", "IN", "IQ", "IS", "IT", "JM", "JO", "JP", "KE", "KR", "KW", "KZ", "LB", "LI", "LK", "LT", "LU", "LV", "LY", "MA", "ME", "MK", "MT", "MX", "MY", "NG", "NI", "NL", "NO", "NP", "NZ", "OM", "PA", "PE", "PG", "PH", "PK", "PL", "PR", "PT", "PY", "QA", "RO", "RS", "RU", "SA", "SE", "SG", "SI", "SK", "SN", "SV", "TH", "TN", "TR", "TW", "TZ", "UA", "UG", "US", "UY", "VE", "VN", "YE", "ZA", "ZW"} + # See https://github.com/rg3/youtube-dl/blob/master/youtube_dl/extractor/youtube.py#L380-#L476 VIDEO_FORMATS = { "5" => {"ext" => "flv", "width" => 400, "height" => 240, "acodec" => "mp3", "abr" => 64, "vcodec" => "h263"}, diff --git a/src/invidious/views/preferences.ecr b/src/invidious/views/preferences.ecr index 401c15ea..ad9cb089 100644 --- a/src/invidious/views/preferences.ecr +++ b/src/invidious/views/preferences.ecr @@ -128,6 +128,15 @@ </div> <div class="pure-control-group"> + <label for="region"><%= translate(locale, "Content country: ") %></label> + <select name="region" id="region"> + <% TRENDING_REGIONS.each do |option| %> + <option value="<%= option %>" <% if preferences.region == option %> selected <% end %>><%= option %></option> + <% end %> + </select> + </div> + + <div class="pure-control-group"> <label for="player_style"><%= translate(locale, "Player style: ") %></label> <select name="player_style" id="player_style"> <% {"invidious", "youtube"}.each do |option| %> |
