LibraryService.cs 3.9 KB

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