BaseItem.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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)
  51. {
  52. if (UserData == null || !UserData.ContainsKey(user.Id))
  53. {
  54. return null;
  55. }
  56. return UserData[user.Id];
  57. }
  58. public void AddUserData(User user, UserItemData data)
  59. {
  60. if (UserData == null)
  61. {
  62. UserData = new Dictionary<Guid, UserItemData>();
  63. }
  64. UserData[user.Id] = data;
  65. }
  66. /// <summary>
  67. /// Determines if a given user has access to this item
  68. /// </summary>
  69. internal bool IsParentalAllowed(User user)
  70. {
  71. return true;
  72. }
  73. /// <summary>
  74. /// Finds an item by ID, recursively
  75. /// </summary>
  76. public virtual BaseItem FindItemById(Guid id)
  77. {
  78. if (Id == id)
  79. {
  80. return this;
  81. }
  82. if (LocalTrailers != null)
  83. {
  84. return LocalTrailers.FirstOrDefault(i => i.Id == id);
  85. }
  86. return null;
  87. }
  88. public virtual bool IsFolder
  89. {
  90. get
  91. {
  92. return false;
  93. }
  94. }
  95. /// <summary>
  96. /// Determines if the item is considered new based on user settings
  97. /// </summary>
  98. public bool IsRecentlyAdded(User user)
  99. {
  100. return (DateTime.UtcNow - DateCreated).TotalDays < user.RecentItemDays;
  101. }
  102. public void AddPerson(PersonInfo person)
  103. {
  104. if (People == null)
  105. {
  106. People = new Dictionary<string, PersonInfo>(StringComparer.OrdinalIgnoreCase);
  107. }
  108. People[person.Name] = person;
  109. }
  110. }
  111. }