LibraryService.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. using MediaBrowser.Common;
  2. using MediaBrowser.Controller.Entities;
  3. using MediaBrowser.Controller.Library;
  4. using MediaBrowser.Model.Entities;
  5. using ServiceStack;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. namespace MediaBrowser.Api.Library
  10. {
  11. /// <summary>
  12. /// Class GetPhyscialPaths
  13. /// </summary>
  14. [Route("/Library/PhysicalPaths", "GET")]
  15. [Api(Description = "Gets a list of physical paths from virtual folders")]
  16. public class GetPhyscialPaths : IReturn<List<string>>
  17. {
  18. }
  19. /// <summary>
  20. /// Class GetItemTypes
  21. /// </summary>
  22. [Route("/Library/ItemTypes", "GET")]
  23. [Api(Description = "Gets a list of BaseItem types")]
  24. public class GetItemTypes : IReturn<List<string>>
  25. {
  26. /// <summary>
  27. /// Gets or sets a value indicating whether this instance has internet provider.
  28. /// </summary>
  29. /// <value><c>true</c> if this instance has internet provider; otherwise, <c>false</c>.</value>
  30. [ApiMember(Name = "HasInternetProvider", Description = "Optional filter by item types that have internet providers. true/false", IsRequired = false, DataType = "boolean", ParameterType = "query", Verb = "GET")]
  31. public bool HasInternetProvider { get; set; }
  32. }
  33. /// <summary>
  34. /// Class LibraryService
  35. /// </summary>
  36. public class LibraryService : BaseApiService
  37. {
  38. /// <summary>
  39. /// The _app host
  40. /// </summary>
  41. private readonly IApplicationHost _appHost;
  42. private readonly ILibraryManager _libraryManager;
  43. /// <summary>
  44. /// Initializes a new instance of the <see cref="LibraryService" /> class.
  45. /// </summary>
  46. /// <param name="appHost">The app host.</param>
  47. /// <param name="libraryManager">The library manager.</param>
  48. /// <exception cref="System.ArgumentNullException">appHost</exception>
  49. public LibraryService(IApplicationHost appHost, ILibraryManager libraryManager)
  50. {
  51. if (appHost == null)
  52. {
  53. throw new ArgumentNullException("appHost");
  54. }
  55. _appHost = appHost;
  56. _libraryManager = libraryManager;
  57. }
  58. /// <summary>
  59. /// Gets the specified request.
  60. /// </summary>
  61. /// <param name="request">The request.</param>
  62. /// <returns>System.Object.</returns>
  63. public object Get(GetPhyscialPaths request)
  64. {
  65. var result = _libraryManager.RootFolder.Children
  66. .SelectMany(c => c.PhysicalLocations)
  67. .ToList();
  68. return ToOptimizedSerializedResultUsingCache(result);
  69. }
  70. /// <summary>
  71. /// Gets the specified request.
  72. /// </summary>
  73. /// <param name="request">The request.</param>
  74. /// <returns>System.Object.</returns>
  75. public object Get(GetItemTypes request)
  76. {
  77. var allTypes = _appHost.AllConcreteTypes.Where(t => t.IsSubclassOf(typeof(BaseItem)));
  78. if (request.HasInternetProvider)
  79. {
  80. allTypes = allTypes.Where(t =>
  81. {
  82. if (t == typeof(UserRootFolder) || t == typeof(AggregateFolder) || t == typeof(Folder) || t == typeof(CollectionFolder) || t == typeof(Year))
  83. {
  84. return false;
  85. }
  86. if (t == typeof(User))
  87. {
  88. return false;
  89. }
  90. // For now it seems internet providers generally only deal with video subclasses
  91. if (t == typeof(Video))
  92. {
  93. return false;
  94. }
  95. if (t.IsSubclassOf(typeof(BasePluginFolder)))
  96. {
  97. return false;
  98. }
  99. return true;
  100. });
  101. }
  102. return allTypes.Select(t => t.Name).OrderBy(s => s).ToList();
  103. }
  104. }
  105. }