BaseItem.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 IEnumerable<string> Taglines { get; set; }
  44. public IEnumerable<PersonInfo> People { get; set; }
  45. public IEnumerable<string> Studios { get; set; }
  46. public IEnumerable<string> Genres { get; set; }
  47. public string DisplayMediaType { get; set; }
  48. public float? UserRating { get; set; }
  49. public long? RunTimeTicks { get; set; }
  50. public string AspectRatio { get; set; }
  51. public int? ProductionYear { get; set; }
  52. /// <summary>
  53. /// If the item is part of a series, this is it's number in the series.
  54. /// This could be episode number, album track number, etc.
  55. /// </summary>
  56. public int? IndexNumber { get; set; }
  57. /// <summary>
  58. /// For an episode this could be the season number, or for a song this could be the disc number.
  59. /// </summary>
  60. public int? ParentIndexNumber { get; set; }
  61. public IEnumerable<Video> LocalTrailers { get; set; }
  62. public string TrailerUrl { get; set; }
  63. public Dictionary<string, string> ProviderIds { get; set; }
  64. public Dictionary<Guid, UserItemData> UserData { get; set; }
  65. public UserItemData GetUserData(User user)
  66. {
  67. if (UserData == null || !UserData.ContainsKey(user.Id))
  68. {
  69. return null;
  70. }
  71. return UserData[user.Id];
  72. }
  73. public void AddUserData(User user, UserItemData data)
  74. {
  75. if (UserData == null)
  76. {
  77. UserData = new Dictionary<Guid, UserItemData>();
  78. }
  79. UserData[user.Id] = data;
  80. }
  81. /// <summary>
  82. /// Determines if a given user has access to this item
  83. /// </summary>
  84. internal bool IsParentalAllowed(User user)
  85. {
  86. return true;
  87. }
  88. /// <summary>
  89. /// Finds an item by ID, recursively
  90. /// </summary>
  91. public virtual BaseItem FindItemById(Guid id)
  92. {
  93. if (Id == id)
  94. {
  95. return this;
  96. }
  97. if (LocalTrailers != null)
  98. {
  99. return LocalTrailers.FirstOrDefault(i => i.Id == id);
  100. }
  101. return null;
  102. }
  103. public virtual bool IsFolder
  104. {
  105. get
  106. {
  107. return false;
  108. }
  109. }
  110. /// <summary>
  111. /// Determines if the item is considered new based on user settings
  112. /// </summary>
  113. public bool IsRecentlyAdded(User user)
  114. {
  115. return (DateTime.Now - DateCreated).TotalDays < user.RecentItemDays;
  116. }
  117. }
  118. }