2
0

UserItemData.cs 3.6 KB

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