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. /// <summary>
  13. /// Gets or sets the user id.
  14. /// </summary>
  15. /// <value>The user id.</value>
  16. public Guid UserId { get; set; }
  17. /// <summary>
  18. /// Gets or sets the key.
  19. /// </summary>
  20. /// <value>The key.</value>
  21. public string Key { get; set; }
  22. /// <summary>
  23. /// The _rating.
  24. /// </summary>
  25. private double? _rating;
  26. /// <summary>
  27. /// Gets or sets the users 0-10 rating.
  28. /// </summary>
  29. /// <value>The rating.</value>
  30. /// <exception cref="ArgumentOutOfRangeException">Rating;A 0 to 10 rating is required for UserItemData.</exception>
  31. public double? Rating
  32. {
  33. get => _rating;
  34. set
  35. {
  36. if (value.HasValue)
  37. {
  38. if (value.Value < 0 || value.Value > 10)
  39. {
  40. throw new ArgumentOutOfRangeException(nameof(value), "A 0 to 10 rating is required for UserItemData.");
  41. }
  42. }
  43. _rating = value;
  44. }
  45. }
  46. /// <summary>
  47. /// Gets or sets the playback position ticks.
  48. /// </summary>
  49. /// <value>The playback position ticks.</value>
  50. public long PlaybackPositionTicks { get; set; }
  51. /// <summary>
  52. /// Gets or sets the play count.
  53. /// </summary>
  54. /// <value>The play count.</value>
  55. public int PlayCount { get; set; }
  56. /// <summary>
  57. /// Gets or sets a value indicating whether this instance is favorite.
  58. /// </summary>
  59. /// <value><c>true</c> if this instance is favorite; otherwise, <c>false</c>.</value>
  60. public bool IsFavorite { get; set; }
  61. /// <summary>
  62. /// Gets or sets the last played date.
  63. /// </summary>
  64. /// <value>The last played date.</value>
  65. public DateTime? LastPlayedDate { get; set; }
  66. /// <summary>
  67. /// Gets or sets a value indicating whether this <see cref="UserItemData" /> is played.
  68. /// </summary>
  69. /// <value><c>true</c> if played; otherwise, <c>false</c>.</value>
  70. public bool Played { get; set; }
  71. /// <summary>
  72. /// Gets or sets the index of the audio stream.
  73. /// </summary>
  74. /// <value>The index of the audio stream.</value>
  75. public int? AudioStreamIndex { get; set; }
  76. /// <summary>
  77. /// Gets or sets the index of the subtitle stream.
  78. /// </summary>
  79. /// <value>The index of the subtitle stream.</value>
  80. public int? SubtitleStreamIndex { get; set; }
  81. public const double MinLikeValue = 6.5;
  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. }