BaseItem.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace MediaBrowser.Model.Entities
  5. {
  6. public abstract class BaseItem : BaseEntity, IHasProviderIds
  7. {
  8. public string SortName { get; set; }
  9. /// <summary>
  10. /// When the item first debuted. For movies this could be premiere date, episodes would be first aired
  11. /// </summary>
  12. public DateTime? PremiereDate { get; set; }
  13. public string Path { get; set; }
  14. public Folder Parent { get; set; }
  15. public string LogoImagePath { get; set; }
  16. public string ArtImagePath { get; set; }
  17. public string ThumbnailImagePath { get; set; }
  18. public string BannerImagePath { get; set; }
  19. public IEnumerable<string> BackdropImagePaths { get; set; }
  20. public string OfficialRating { get; set; }
  21. public string CustomRating { get; set; }
  22. public string CustomPin { get; set; }
  23. public string Language { get; set; }
  24. public string Overview { get; set; }
  25. public List<string> Taglines { get; set; }
  26. /// <summary>
  27. /// Using a Dictionary to prevent duplicates
  28. /// </summary>
  29. public Dictionary<string,PersonInfo> People { get; set; }
  30. public List<string> Studios { get; set; }
  31. public List<string> Genres { get; set; }
  32. public string DisplayMediaType { get; set; }
  33. public float? UserRating { get; set; }
  34. public long? RunTimeTicks { get; set; }
  35. public string AspectRatio { get; set; }
  36. public int? ProductionYear { get; set; }
  37. /// <summary>
  38. /// If the item is part of a series, this is it's number in the series.
  39. /// This could be episode number, album track number, etc.
  40. /// </summary>
  41. public int? IndexNumber { get; set; }
  42. /// <summary>
  43. /// For an episode this could be the season number, or for a song this could be the disc number.
  44. /// </summary>
  45. public int? ParentIndexNumber { get; set; }
  46. public IEnumerable<Video> LocalTrailers { get; set; }
  47. public string TrailerUrl { get; set; }
  48. public Dictionary<string, string> ProviderIds { get; set; }
  49. public Dictionary<Guid, UserItemData> UserData { get; set; }
  50. public UserItemData GetUserData(User user, bool createIfNull)
  51. {
  52. if (UserData == null || !UserData.ContainsKey(user.Id))
  53. {
  54. if (createIfNull)
  55. {
  56. AddUserData(user, new UserItemData());
  57. }
  58. else
  59. {
  60. return null;
  61. }
  62. }
  63. return UserData[user.Id];
  64. }
  65. private void AddUserData(User user, UserItemData data)
  66. {
  67. if (UserData == null)
  68. {
  69. UserData = new Dictionary<Guid, UserItemData>();
  70. }
  71. UserData[user.Id] = data;
  72. }
  73. /// <summary>
  74. /// Determines if a given user has access to this item
  75. /// </summary>
  76. internal bool IsParentalAllowed(User user)
  77. {
  78. return true;
  79. }
  80. /// <summary>
  81. /// Finds an item by ID, recursively
  82. /// </summary>
  83. public virtual BaseItem FindItemById(Guid id)
  84. {
  85. if (Id == id)
  86. {
  87. return this;
  88. }
  89. if (LocalTrailers != null)
  90. {
  91. return LocalTrailers.FirstOrDefault(i => i.Id == id);
  92. }
  93. return null;
  94. }
  95. public virtual bool IsFolder
  96. {
  97. get
  98. {
  99. return false;
  100. }
  101. }
  102. /// <summary>
  103. /// Determines if the item is considered new based on user settings
  104. /// </summary>
  105. public bool IsRecentlyAdded(User user)
  106. {
  107. return (DateTime.UtcNow - DateCreated).TotalDays < user.RecentItemDays;
  108. }
  109. public void AddPerson(PersonInfo person)
  110. {
  111. if (People == null)
  112. {
  113. People = new Dictionary<string, PersonInfo>(StringComparer.OrdinalIgnoreCase);
  114. }
  115. People[person.Name] = person;
  116. }
  117. /// <summary>
  118. /// Marks the item as either played or unplayed
  119. /// </summary>
  120. public virtual void SetPlayedStatus(User user, bool wasPlayed)
  121. {
  122. UserItemData data = GetUserData(user, true);
  123. if (wasPlayed)
  124. {
  125. data.PlayCount = Math.Max(data.PlayCount, 1);
  126. }
  127. else
  128. {
  129. data.PlayCount = 0;
  130. data.PlaybackPositionTicks = 0;
  131. }
  132. }
  133. }
  134. }