UserView.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. #nullable disable
  2. #pragma warning disable CS1591
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text.Json.Serialization;
  7. using System.Threading.Tasks;
  8. using Jellyfin.Data.Entities;
  9. using Jellyfin.Data.Enums;
  10. using Jellyfin.Extensions;
  11. using MediaBrowser.Controller.TV;
  12. using MediaBrowser.Model.Querying;
  13. namespace MediaBrowser.Controller.Entities
  14. {
  15. public class UserView : Folder, IHasCollectionType
  16. {
  17. private static readonly CollectionType?[] _viewTypesEligibleForGrouping =
  18. {
  19. Jellyfin.Data.Enums.CollectionType.Movies,
  20. Jellyfin.Data.Enums.CollectionType.TvShows,
  21. null
  22. };
  23. private static readonly CollectionType?[] _originalFolderViewTypes =
  24. {
  25. Jellyfin.Data.Enums.CollectionType.Books,
  26. Jellyfin.Data.Enums.CollectionType.MusicVideos,
  27. Jellyfin.Data.Enums.CollectionType.HomeVideos,
  28. Jellyfin.Data.Enums.CollectionType.Photos,
  29. Jellyfin.Data.Enums.CollectionType.Music,
  30. Jellyfin.Data.Enums.CollectionType.BoxSets
  31. };
  32. public static ITVSeriesManager TVSeriesManager { get; set; }
  33. /// <summary>
  34. /// Gets or sets the view type.
  35. /// </summary>
  36. public CollectionType? ViewType { get; set; }
  37. /// <summary>
  38. /// Gets or sets the display parent id.
  39. /// </summary>
  40. public new Guid DisplayParentId { get; set; }
  41. /// <summary>
  42. /// Gets or sets the user id.
  43. /// </summary>
  44. public Guid? UserId { get; set; }
  45. /// <inheritdoc />
  46. [JsonIgnore]
  47. public CollectionType? CollectionType => ViewType;
  48. /// <inheritdoc />
  49. [JsonIgnore]
  50. public override bool SupportsInheritedParentImages => false;
  51. /// <inheritdoc />
  52. [JsonIgnore]
  53. public override bool SupportsPlayedStatus => false;
  54. /// <inheritdoc />
  55. [JsonIgnore]
  56. public override bool SupportsPeople => false;
  57. /// <inheritdoc />
  58. public override IEnumerable<Guid> GetIdsForAncestorQuery()
  59. {
  60. if (!DisplayParentId.Equals(default))
  61. {
  62. yield return DisplayParentId;
  63. }
  64. else if (!ParentId.Equals(default))
  65. {
  66. yield return ParentId;
  67. }
  68. else
  69. {
  70. yield return Id;
  71. }
  72. }
  73. /// <inheritdoc />
  74. public override int GetChildCount(User user)
  75. {
  76. return GetChildren(user, true).Count;
  77. }
  78. /// <inheritdoc />
  79. protected override QueryResult<BaseItem> GetItemsInternal(InternalItemsQuery query)
  80. {
  81. var parent = this as Folder;
  82. if (!DisplayParentId.Equals(default))
  83. {
  84. parent = LibraryManager.GetItemById(DisplayParentId) as Folder ?? parent;
  85. }
  86. else if (!ParentId.Equals(default))
  87. {
  88. parent = LibraryManager.GetItemById(ParentId) as Folder ?? parent;
  89. }
  90. return new UserViewBuilder(UserViewManager, LibraryManager, Logger, UserDataManager, TVSeriesManager)
  91. .GetUserItems(parent, this, CollectionType, query);
  92. }
  93. /// <inheritdoc />
  94. public override List<BaseItem> GetChildren(User user, bool includeLinkedChildren, InternalItemsQuery query)
  95. {
  96. query ??= new InternalItemsQuery(user);
  97. query.EnableTotalRecordCount = false;
  98. var result = GetItemList(query);
  99. return result.ToList();
  100. }
  101. /// <inheritdoc />
  102. public override bool CanDelete()
  103. {
  104. return false;
  105. }
  106. /// <inheritdoc />
  107. public override bool IsSaveLocalMetadataEnabled()
  108. {
  109. return true;
  110. }
  111. /// <inheritdoc />
  112. public override IEnumerable<BaseItem> GetRecursiveChildren(User user, InternalItemsQuery query)
  113. {
  114. query.SetUser(user);
  115. query.Recursive = true;
  116. query.EnableTotalRecordCount = false;
  117. query.ForceDirect = true;
  118. return GetItemList(query);
  119. }
  120. /// <inheritdoc />
  121. protected override IEnumerable<BaseItem> GetEligibleChildrenForRecursiveChildren(User user)
  122. {
  123. return GetChildren(user, false);
  124. }
  125. public static bool IsUserSpecific(Folder folder)
  126. {
  127. if (folder is not ICollectionFolder collectionFolder)
  128. {
  129. return false;
  130. }
  131. if (folder is ISupportsUserSpecificView supportsUserSpecific
  132. && supportsUserSpecific.EnableUserSpecificView)
  133. {
  134. return true;
  135. }
  136. return collectionFolder.CollectionType == Jellyfin.Data.Enums.CollectionType.Playlists;
  137. }
  138. public static bool IsEligibleForGrouping(Folder folder)
  139. {
  140. return folder is ICollectionFolder collectionFolder
  141. && IsEligibleForGrouping(collectionFolder.CollectionType);
  142. }
  143. public static bool IsEligibleForGrouping(CollectionType? viewType)
  144. {
  145. return _viewTypesEligibleForGrouping.Contains(viewType);
  146. }
  147. public static bool EnableOriginalFolder(CollectionType? viewType)
  148. {
  149. return _originalFolderViewTypes.Contains(viewType);
  150. }
  151. protected override Task ValidateChildrenInternal(IProgress<double> progress, bool recursive, bool refreshChildMetadata, Providers.MetadataRefreshOptions refreshOptions, Providers.IDirectoryService directoryService, System.Threading.CancellationToken cancellationToken)
  152. {
  153. return Task.CompletedTask;
  154. }
  155. }
  156. }