diff options
Diffstat (limited to 'MediaBrowser.Controller')
| -rw-r--r-- | MediaBrowser.Controller/Entities/BaseItem.cs | 41 |
1 files changed, 37 insertions, 4 deletions
diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index 022f8f0fbf..a1e955f33f 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -102,6 +102,14 @@ namespace MediaBrowser.Controller.Entities private string _originalLanguage; + private float? _lufs; + + private float? _normalizationGain; + + private float? _criticRating; + + private float? _communityRating; + public const char SlugChar = '-'; protected BaseItem() @@ -154,14 +162,22 @@ namespace MediaBrowser.Controller.Entities /// </summary> /// <value>The LUFS Value.</value> [JsonIgnore] - public float? LUFS { get; set; } + public float? LUFS + { + get => _lufs; + set => _lufs = FiniteOrNull(value); + } /// <summary> /// Gets or sets the gain required for audio normalization. /// </summary> /// <value>The gain required for audio normalization.</value> [JsonIgnore] - public float? NormalizationGain { get; set; } + public float? NormalizationGain + { + get => _normalizationGain; + set => _normalizationGain = FiniteOrNull(value); + } /// <summary> /// Gets or sets the channel identifier. @@ -610,7 +626,11 @@ namespace MediaBrowser.Controller.Entities /// </summary> /// <value>The critic rating.</value> [JsonIgnore] - public float? CriticRating { get; set; } + public float? CriticRating + { + get => _criticRating; + set => _criticRating = FiniteOrNull(value); + } /// <summary> /// Gets or sets the custom rating. @@ -662,7 +682,11 @@ namespace MediaBrowser.Controller.Entities /// </summary> /// <value>The community rating.</value> [JsonIgnore] - public float? CommunityRating { get; set; } + public float? CommunityRating + { + get => _communityRating; + set => _communityRating = FiniteOrNull(value); + } /// <summary> /// Gets or sets the run time ticks. @@ -1376,6 +1400,15 @@ namespace MediaBrowser.Controller.Entities } /// <summary> + /// Treats a rating or gain that is not a finite number as no value, since NaN and infinity + /// cannot be stored by every database or written as JSON. + /// </summary> + /// <param name="value">The value to check.</param> + /// <returns><paramref name="value"/> when it is finite or has no value, otherwise <see langword="null"/>.</returns> + private static float? FiniteOrNull(float? value) + => value.HasValue && !float.IsFinite(value.Value) ? null : value; + + /// <summary> /// Derives the prefix shared by the supplied media source items' file names, used to strip the /// common part and surface a short version label per source. Returns null when there are fewer /// than two file-based sources, since there is nothing to differentiate. |
