aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/Localization/LocalizationManager.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Emby.Server.Implementations/Localization/LocalizationManager.cs')
-rw-r--r--Emby.Server.Implementations/Localization/LocalizationManager.cs18
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;
}