UserItemData.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #nullable disable
  2. #pragma warning disable CS1591
  3. using System;
  4. using System.Text.Json.Serialization;
  5. namespace MediaBrowser.Controller.Entities
  6. {
  7. /// <summary>
  8. /// Class UserItemData.
  9. /// </summary>
  10. public class UserItemData
  11. {
  12. public const double MinLikeValue = 6.5;
  13. /// <summary>
  14. /// The _rating.
  15. /// </summary>
  16. private double? _rating;
  17. /// <summary>
  18. /// Gets or sets the user id.
  19. /// </summary>
  20. /// <value>The user id.</value>
  21. public Guid UserId { get; set; }
  22. /// <summary>
  23. /// Gets or sets the key.
  24. /// </summary>
  25. /// <value>The key.</value>
  26. public string Key { get; set; }
  27. /// <summary>
  28. /// Gets or sets the users 0-10 rating.
  29. /// </summary>
  30. /// <value>The rating.</value>
  31. /// <exception cref="ArgumentOutOfRangeException">Rating;A 0 to 10 rating is required for UserItemData.</exception>
  32. public double? Rating
  33. {
  34. get => _rating;
  35. set
  36. {
  37. if (value.HasValue)
  38. {
  39. if (value.Value < 0 || value.Value > 10)
  40. {
  41. throw new ArgumentOutOfRangeException(nameof(value), "A 0 to 10 rating is required for UserItemData.");
  42. }
  43. }
  44. _rating = value;
  45. }
  46. }
  47. /// <summary>
  48. /// Gets or sets the playback position ticks.
  49. /// </summary>
  50. /// <value>The playback position ticks.</value>
  51. public long PlaybackPositionTicks { get; set; }
  52. /// <summary>
  53. /// Gets or sets the play count.
  54. /// </summary>
  55. /// <value>The play count.</value>
  56. public int PlayCount { get; set; }
  57. /// <summary>
  58. /// Gets or sets a value indicating whether this instance is favorite.
  59. /// </summary>
  60. /// <value><c>true</c> if this instance is favorite; otherwise, <c>false</c>.</value>
  61. public bool IsFavorite { get; set; }
  62. /// <summary>
  63. /// Gets or sets the last played date.
  64. /// </summary>
  65. /// <value>The last played date.</value>
  66. public DateTime? LastPlayedDate { get; set; }
  67. /// <summary>
  68. /// Gets or sets a value indicating whether this <see cref="UserItemData" /> is played.
  69. /// </summary>
  70. /// <value><c>true</c> if played; otherwise, <c>false</c>.</value>
  71. public bool Played { get; set; }
  72. /// <summary>
  73. /// Gets or sets the index of the audio stream.
  74. /// </summary>
  75. /// <value>The index of the audio stream.</value>
  76. public int? AudioStreamIndex { get; set; }
  77. /// <summary>
  78. /// Gets or sets the index of the subtitle stream.
  79. /// </summary>
  80. /// <value>The index of the subtitle stream.</value>
  81. public int? SubtitleStreamIndex { get; set; }
  82. /// <summary>
  83. /// Gets or sets a value indicating whether the item is liked or not.
  84. /// This should never be serialized.
  85. /// </summary>
  86. /// <value><c>null</c> if [likes] contains no value, <c>true</c> if [likes]; otherwise, <c>false</c>.</value>
  87. [JsonIgnore]
  88. public bool? Likes
  89. {
  90. get
  91. {
  92. if (Rating != null)
  93. {
  94. return Rating >= MinLikeValue;
  95. }
  96. return null;
  97. }
  98. set
  99. {
  100. if (value.HasValue)
  101. {
  102. Rating = value.Value ? 10 : 1;
  103. }
  104. else
  105. {
  106. Rating = null;
  107. }
  108. }
  109. }
  110. }
  111. }