BaseItem.cs 4.0 KB

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