BaseItem.cs 4.6 KB

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