diff --git a/config/config.example.yml b/config/config.example.yml index 8bb19fcc..554c0d46 100644 --- a/config/config.example.yml +++ b/config/config.example.yml @@ -504,6 +504,21 @@ default_user_preferences: ## #locale: en-US + ## + ## Default language for content. + ## + ## Accepted values: + ## 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 + ## + ## Default: US + ## + #region: US + ## ## Top 3 prefered languages for video captions. ## diff --git a/locales/en-US.json b/locales/en-US.json index 230d96ad..11aecff4 100644 --- a/locales/en-US.json +++ b/locales/en-US.json @@ -80,6 +80,7 @@ "Automatically extend video description: ": "Automatically extend video description: ", "Interactive 360 degree videos: ": "Interactive 360 degree videos: ", "Visual preferences": "Visual preferences", + "Content country: ": "Content country: ", "Player style: ": "Player style: ", "Dark mode: ": "Dark mode: ", "Theme: ": "Theme: ", 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 @@ -127,6 +127,15 @@ +
+ + +
+