mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-01-15 23:58:57 +00:00
Rework parental ratings (#12615)
Some checks are pending
CodeQL / Analyze (csharp) (push) Waiting to run
OpenAPI / OpenAPI - HEAD (push) Waiting to run
OpenAPI / OpenAPI - BASE (push) Waiting to run
OpenAPI / OpenAPI - Difference (push) Blocked by required conditions
OpenAPI / OpenAPI - Publish Unstable Spec (push) Blocked by required conditions
OpenAPI / OpenAPI - Publish Stable Spec (push) Blocked by required conditions
Tests / run-tests (macos-latest) (push) Waiting to run
Tests / run-tests (ubuntu-latest) (push) Waiting to run
Tests / run-tests (windows-latest) (push) Waiting to run
Project Automation / Project board (push) Waiting to run
Merge Conflict Labeler / Labeling (push) Waiting to run
Some checks are pending
CodeQL / Analyze (csharp) (push) Waiting to run
OpenAPI / OpenAPI - HEAD (push) Waiting to run
OpenAPI / OpenAPI - BASE (push) Waiting to run
OpenAPI / OpenAPI - Difference (push) Blocked by required conditions
OpenAPI / OpenAPI - Publish Unstable Spec (push) Blocked by required conditions
OpenAPI / OpenAPI - Publish Stable Spec (push) Blocked by required conditions
Tests / run-tests (macos-latest) (push) Waiting to run
Tests / run-tests (ubuntu-latest) (push) Waiting to run
Tests / run-tests (windows-latest) (push) Waiting to run
Project Automation / Project board (push) Waiting to run
Merge Conflict Labeler / Labeling (push) Waiting to run
This commit is contained in:
@@ -581,6 +581,9 @@ namespace MediaBrowser.Controller.Entities
|
||||
[JsonIgnore]
|
||||
public int? InheritedParentalRatingValue { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public int? InheritedParentalRatingSubValue { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the critic rating.
|
||||
/// </summary>
|
||||
@@ -1540,7 +1543,8 @@ namespace MediaBrowser.Controller.Entities
|
||||
return false;
|
||||
}
|
||||
|
||||
var maxAllowedRating = user.MaxParentalAgeRating;
|
||||
var maxAllowedRating = user.MaxParentalRatingScore;
|
||||
var maxAllowedSubRating = user.MaxParentalRatingSubScore;
|
||||
var rating = CustomRatingForComparison;
|
||||
|
||||
if (string.IsNullOrEmpty(rating))
|
||||
@@ -1554,10 +1558,10 @@ namespace MediaBrowser.Controller.Entities
|
||||
return !GetBlockUnratedValue(user);
|
||||
}
|
||||
|
||||
var value = LocalizationManager.GetRatingLevel(rating);
|
||||
var ratingScore = LocalizationManager.GetRatingScore(rating);
|
||||
|
||||
// Could not determine rating level
|
||||
if (!value.HasValue)
|
||||
if (ratingScore is null)
|
||||
{
|
||||
var isAllowed = !GetBlockUnratedValue(user);
|
||||
|
||||
@@ -1569,10 +1573,15 @@ namespace MediaBrowser.Controller.Entities
|
||||
return isAllowed;
|
||||
}
|
||||
|
||||
return !maxAllowedRating.HasValue || value.Value <= maxAllowedRating.Value;
|
||||
if (maxAllowedSubRating is not null)
|
||||
{
|
||||
return (ratingScore.SubScore ?? 0) <= maxAllowedSubRating && ratingScore.Score <= maxAllowedRating.Value;
|
||||
}
|
||||
|
||||
return !maxAllowedRating.HasValue || ratingScore.Score <= maxAllowedRating.Value;
|
||||
}
|
||||
|
||||
public int? GetInheritedParentalRatingValue()
|
||||
public ParentalRatingScore GetParentalRatingScore()
|
||||
{
|
||||
var rating = CustomRatingForComparison;
|
||||
|
||||
@@ -1586,7 +1595,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
return null;
|
||||
}
|
||||
|
||||
return LocalizationManager.GetRatingLevel(rating);
|
||||
return LocalizationManager.GetRatingScore(rating);
|
||||
}
|
||||
|
||||
public List<string> GetInheritedTags()
|
||||
@@ -2518,11 +2527,29 @@ namespace MediaBrowser.Controller.Entities
|
||||
|
||||
var item = this;
|
||||
|
||||
var inheritedParentalRatingValue = item.GetInheritedParentalRatingValue() ?? null;
|
||||
if (inheritedParentalRatingValue != item.InheritedParentalRatingValue)
|
||||
var rating = item.GetParentalRatingScore();
|
||||
if (rating is not null)
|
||||
{
|
||||
item.InheritedParentalRatingValue = inheritedParentalRatingValue;
|
||||
updateType |= ItemUpdateType.MetadataImport;
|
||||
if (rating.Score != item.InheritedParentalRatingValue)
|
||||
{
|
||||
item.InheritedParentalRatingValue = rating.Score;
|
||||
updateType |= ItemUpdateType.MetadataImport;
|
||||
}
|
||||
|
||||
if (rating.SubScore != item.InheritedParentalRatingSubValue)
|
||||
{
|
||||
item.InheritedParentalRatingSubValue = rating.SubScore;
|
||||
updateType |= ItemUpdateType.MetadataImport;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (item.InheritedParentalRatingValue is not null)
|
||||
{
|
||||
item.InheritedParentalRatingValue = null;
|
||||
item.InheritedParentalRatingSubValue = null;
|
||||
updateType |= ItemUpdateType.MetadataImport;
|
||||
}
|
||||
}
|
||||
|
||||
return updateType;
|
||||
@@ -2542,8 +2569,9 @@ namespace MediaBrowser.Controller.Entities
|
||||
.Select(i => i.OfficialRating)
|
||||
.Where(i => !string.IsNullOrEmpty(i))
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase)
|
||||
.Select(rating => (rating, LocalizationManager.GetRatingLevel(rating)))
|
||||
.OrderBy(i => i.Item2 ?? 1000)
|
||||
.Select(rating => (rating, LocalizationManager.GetRatingScore(rating)))
|
||||
.OrderBy(i => i.Item2 is null ? 1001 : i.Item2.Score)
|
||||
.ThenBy(i => i.Item2 is null ? 1001 : i.Item2.SubScore)
|
||||
.Select(i => i.rating);
|
||||
|
||||
OfficialRating = ratings.FirstOrDefault() ?? currentOfficialRating;
|
||||
|
||||
Reference in New Issue
Block a user