diff options
| author | Shadowghost <Ghost_of_Stone@web.de> | 2022-10-09 22:56:23 +0200 |
|---|---|---|
| committer | Shadowghost <Ghost_of_Stone@web.de> | 2023-02-20 11:53:20 +0100 |
| commit | ed2280a0605c7e971d151b9b2239d332ee204579 (patch) | |
| tree | 45f11791e6a090a6f525e5469816de5263bc1cbc /Emby.Server.Implementations/Localization/LocalizationManager.cs | |
| parent | 720852f7087e32053407cd849470d3f13f57159c (diff) | |
Overhaul content ratings
Diffstat (limited to 'Emby.Server.Implementations/Localization/LocalizationManager.cs')
| -rw-r--r-- | Emby.Server.Implementations/Localization/LocalizationManager.cs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/Emby.Server.Implementations/Localization/LocalizationManager.cs b/Emby.Server.Implementations/Localization/LocalizationManager.cs index b418c7877..5e22e7886 100644 --- a/Emby.Server.Implementations/Localization/LocalizationManager.cs +++ b/Emby.Server.Implementations/Localization/LocalizationManager.cs @@ -3,6 +3,7 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Globalization; using System.IO; +using System.Linq; using System.Reflection; using System.Text.Json; using System.Threading.Tasks; @@ -25,7 +26,7 @@ namespace Emby.Server.Implementations.Localization private const string CulturesPath = "Emby.Server.Implementations.Localization.iso6392.txt"; private const string CountriesPath = "Emby.Server.Implementations.Localization.countries.json"; private static readonly Assembly _assembly = typeof(LocalizationManager).Assembly; - private static readonly string[] _unratedValues = { "n/a", "unrated", "not rated" }; + private static readonly string[] _unratedValues = { "n/a", "unrated", "not rated", "nr" }; private readonly IServerConfigurationManager _configurationManager; private readonly ILogger<LocalizationManager> _logger; @@ -194,6 +195,7 @@ namespace Emby.Server.Implementations.Localization { var countryCode = _configurationManager.Configuration.MetadataCountryCode; + // Fall back to US ratings if no country code is specified or country code does not exist. if (string.IsNullOrEmpty(countryCode)) { countryCode = "us"; @@ -221,12 +223,14 @@ namespace Emby.Server.Implementations.Localization { ArgumentException.ThrowIfNullOrEmpty(rating); + // Handle unrated content if (_unratedValues.Contains(rating.AsSpan(), StringComparison.OrdinalIgnoreCase)) { return null; } // Fairly common for some users to have "Rated R" in their rating field + rating = rating.Replace("Rated :", string.Empty, StringComparison.OrdinalIgnoreCase); rating = rating.Replace("Rated ", string.Empty, StringComparison.OrdinalIgnoreCase); var ratingsDictionary = GetParentalRatingsDictionary(); @@ -257,6 +261,18 @@ namespace Emby.Server.Implementations.Localization } } + // Remove prefix country code to handle "DE-18" + index = rating.IndexOf('-', StringComparison.Ordinal); + if (index != -1) + { + var trimmedRating = rating.AsSpan(index).TrimStart('-').Trim(); + + if (!trimmedRating.IsEmpty) + { + return GetRatingLevel(trimmedRating.ToString()); + } + } + // TODO: Further improve by normalizing out all spaces and dashes return null; } |
