BaseItem.cs 4.1 KB

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