mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
Add default rating selections
This commit is contained in:
parent
4ed97a4593
commit
9d21f078c7
@ -87,12 +87,10 @@ namespace Emby.Server.Implementations.Localization
|
|||||||
var name = parts[0];
|
var name = parts[0];
|
||||||
dict.Add(name, new ParentalRating(name, value));
|
dict.Add(name, new ParentalRating(name, value));
|
||||||
}
|
}
|
||||||
#if DEBUG
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Malformed line in ratings file for country {CountryCode}", countryCode);
|
_logger.LogWarning("Malformed line in ratings file for country {CountryCode}", countryCode);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_allParentalRatings[countryCode] = dict;
|
_allParentalRatings[countryCode] = dict;
|
||||||
@ -185,7 +183,56 @@ namespace Emby.Server.Implementations.Localization
|
|||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public IEnumerable<ParentalRating> GetParentalRatings()
|
public IEnumerable<ParentalRating> GetParentalRatings()
|
||||||
=> GetParentalRatingsDictionary().Values;
|
{
|
||||||
|
var ratings = GetParentalRatingsDictionary().Values.ToList();
|
||||||
|
|
||||||
|
// Add common ratings to ensure them being available for selection.
|
||||||
|
// Based on the US rating system due to it being the main source of rating in the metadata providers
|
||||||
|
// Minimum rating possible
|
||||||
|
if (!ratings.Any(x => x.Value == 0))
|
||||||
|
{
|
||||||
|
ratings.Add(new ParentalRating("Approved", 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Matches PG (this has differnet age restrictions depending on country)
|
||||||
|
if (!ratings.Any(x => x.Value == 10))
|
||||||
|
{
|
||||||
|
ratings.Add(new ParentalRating("10", 10));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Matches PG-13
|
||||||
|
if (!ratings.Any(x => x.Value == 13))
|
||||||
|
{
|
||||||
|
ratings.Add(new ParentalRating("13", 13));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Matches TV-14
|
||||||
|
if (!ratings.Any(x => x.Value == 14))
|
||||||
|
{
|
||||||
|
ratings.Add(new ParentalRating("14", 14));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Catchall if max rating of country is less than 21
|
||||||
|
// Using 21 instead of 18 to be sure to allow access to all rated content except adult and banned
|
||||||
|
if (!ratings.Any(x => x.Value >= 21))
|
||||||
|
{
|
||||||
|
ratings.Add(new ParentalRating("21", 21));
|
||||||
|
}
|
||||||
|
|
||||||
|
// A lot of countries don't excplicitly have a seperate rating for adult content
|
||||||
|
if (!ratings.Any(x => x.Value == 1000))
|
||||||
|
{
|
||||||
|
ratings.Add(new ParentalRating("XXX", 1000));
|
||||||
|
}
|
||||||
|
|
||||||
|
// A lot of countries don't excplicitly have a seperate rating for banned content
|
||||||
|
if (!ratings.Any(x => x.Value == 1001))
|
||||||
|
{
|
||||||
|
ratings.Add(new ParentalRating("Banned", 1001));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ratings.OrderBy(r => r.Value);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the parental ratings dictionary.
|
/// Gets the parental ratings dictionary.
|
||||||
@ -207,15 +254,15 @@ namespace Emby.Server.Implementations.Localization
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the ratings.
|
/// Gets the ratings for a country.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="countryCode">The country code.</param>
|
/// <param name="countryCode">The country code.</param>
|
||||||
/// <returns>The ratings.</returns>
|
/// <returns>The ratings.</returns>
|
||||||
private Dictionary<string, ParentalRating>? GetRatings(string countryCode)
|
private Dictionary<string, ParentalRating>? GetRatings(string countryCode)
|
||||||
{
|
{
|
||||||
_allParentalRatings.TryGetValue(countryCode, out var value);
|
_allParentalRatings.TryGetValue(countryCode, out var countryValue);
|
||||||
|
|
||||||
return value;
|
return countryValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
@ -12,7 +12,7 @@ namespace MediaBrowser.Model.Entities
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public ParentalRating(string name, int value)
|
public ParentalRating(string name, int? value)
|
||||||
{
|
{
|
||||||
Name = name;
|
Name = name;
|
||||||
Value = value;
|
Value = value;
|
||||||
@ -28,6 +28,6 @@ namespace MediaBrowser.Model.Entities
|
|||||||
/// Gets or sets the value.
|
/// Gets or sets the value.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The value.</value>
|
/// <value>The value.</value>
|
||||||
public int Value { get; set; }
|
public int? Value { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,7 @@ namespace Jellyfin.Server.Implementations.Tests.Localization
|
|||||||
await localizationManager.LoadAll();
|
await localizationManager.LoadAll();
|
||||||
var ratings = localizationManager.GetParentalRatings().ToList();
|
var ratings = localizationManager.GetParentalRatings().ToList();
|
||||||
|
|
||||||
Assert.Equal(50, ratings.Count);
|
Assert.Equal(53, ratings.Count);
|
||||||
|
|
||||||
var tvma = ratings.FirstOrDefault(x => x.Name.Equals("TV-MA", StringComparison.Ordinal));
|
var tvma = ratings.FirstOrDefault(x => x.Name.Equals("TV-MA", StringComparison.Ordinal));
|
||||||
Assert.NotNull(tvma);
|
Assert.NotNull(tvma);
|
||||||
@ -100,7 +100,7 @@ namespace Jellyfin.Server.Implementations.Tests.Localization
|
|||||||
await localizationManager.LoadAll();
|
await localizationManager.LoadAll();
|
||||||
var ratings = localizationManager.GetParentalRatings().ToList();
|
var ratings = localizationManager.GetParentalRatings().ToList();
|
||||||
|
|
||||||
Assert.Equal(12, ratings.Count);
|
Assert.Equal(18, ratings.Count);
|
||||||
|
|
||||||
var fsk = ratings.FirstOrDefault(x => x.Name.Equals("FSK-12", StringComparison.Ordinal));
|
var fsk = ratings.FirstOrDefault(x => x.Name.Equals("FSK-12", StringComparison.Ordinal));
|
||||||
Assert.NotNull(fsk);
|
Assert.NotNull(fsk);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user