using MediaBrowser.Common.Mef; using MediaBrowser.Common.Net; using MediaBrowser.Controller; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; using MediaBrowser.Model.Dto; using MediaBrowser.Model.Entities; using ServiceStack.ServiceHost; using System; using System.Collections.Generic; using System.ComponentModel.Composition; using System.Linq; namespace MediaBrowser.Api { /// /// Class GetPhyscialPaths /// [Route("/Library/PhysicalPaths", "GET")] public class GetPhyscialPaths : IReturn> { } /// /// Class GetItemTypes /// [Route("/Library/ItemTypes", "GET")] public class GetItemTypes : IReturn> { /// /// Gets or sets a value indicating whether this instance has internet provider. /// /// true if this instance has internet provider; otherwise, false. public bool HasInternetProvider { get; set; } } /// /// Class GetPerson /// [Route("/Library/Persons/{Name}", "GET")] public class GetPerson : IReturn { /// /// Gets or sets the name. /// /// The name. public string Name { get; set; } } /// /// Class GetStudio /// [Route("/Library/Studios/{Name}", "GET")] public class GetStudio : IReturn { /// /// Gets or sets the name. /// /// The name. public string Name { get; set; } } /// /// Class GetGenre /// [Route("/Library/Genres/{Name}", "GET")] public class GetGenre : IReturn { /// /// Gets or sets the name. /// /// The name. public string Name { get; set; } } /// /// Class GetYear /// [Route("/Library/Years/{Year}", "GET")] public class GetYear : IReturn { /// /// Gets or sets the year. /// /// The year. public int Year { get; set; } } /// /// Class GetDefaultVirtualFolders /// [Route("/Library/DefaultVirtualFolders", "GET")] public class GetDefaultVirtualFolders : IReturn> { } /// /// Class LibraryService /// [Export(typeof(IRestfulService))] public class LibraryService : BaseRestService { /// /// Gets the specified request. /// /// The request. /// System.Object. public object Get(GetDefaultVirtualFolders request) { var kernel = (Kernel)Kernel; var result = kernel.LibraryManager.GetDefaultVirtualFolders().ToList(); return ToOptimizedResult(result); } /// /// Gets the specified request. /// /// The request. /// System.Object. public object Get(GetPerson request) { var kernel = (Kernel)Kernel; var item = kernel.LibraryManager.GetPerson(request.Name).Result; // Get everything var fields = Enum.GetNames(typeof(ItemFields)).Select(i => (ItemFields)Enum.Parse(typeof(ItemFields), i, true)); var result = DtoBuilder.GetDtoBaseItem(item, fields.ToList()).Result; return ToOptimizedResult(result); } /// /// Gets the specified request. /// /// The request. /// System.Object. public object Get(GetGenre request) { var kernel = (Kernel)Kernel; var item = kernel.LibraryManager.GetGenre(request.Name).Result; // Get everything var fields = Enum.GetNames(typeof(ItemFields)).Select(i => (ItemFields)Enum.Parse(typeof(ItemFields), i, true)); var result = DtoBuilder.GetDtoBaseItem(item, fields.ToList()).Result; return ToOptimizedResult(result); } /// /// Gets the specified request. /// /// The request. /// System.Object. public object Get(GetStudio request) { var kernel = (Kernel)Kernel; var item = kernel.LibraryManager.GetStudio(request.Name).Result; // Get everything var fields = Enum.GetNames(typeof(ItemFields)).Select(i => (ItemFields)Enum.Parse(typeof(ItemFields), i, true)); var result = DtoBuilder.GetDtoBaseItem(item, fields.ToList()).Result; return ToOptimizedResult(result); } /// /// Gets the specified request. /// /// The request. /// System.Object. public object Get(GetYear request) { var kernel = (Kernel)Kernel; var item = kernel.LibraryManager.GetYear(request.Year).Result; // Get everything var fields = Enum.GetNames(typeof(ItemFields)).Select(i => (ItemFields)Enum.Parse(typeof(ItemFields), i, true)); var result = DtoBuilder.GetDtoBaseItem(item, fields.ToList()).Result; return ToOptimizedResult(result); } /// /// Gets the specified request. /// /// The request. /// System.Object. public object Get(GetPhyscialPaths request) { var kernel = (Kernel)Kernel; var result = kernel.RootFolder.Children.SelectMany(c => c.ResolveArgs.PhysicalLocations).ToList(); return ToOptimizedResult(result); } /// /// Gets the specified request. /// /// The request. /// System.Object. public object Get(GetItemTypes request) { var kernel = (Kernel)Kernel; var allTypes = kernel.Assemblies.SelectMany(MefUtils.GetTypes).Where(t => !t.IsAbstract && t.IsSubclassOf(typeof(BaseItem))); if (request.HasInternetProvider) { allTypes = allTypes.Where(t => { if (t == typeof(UserRootFolder) || t == typeof(AggregateFolder) || t == typeof(Folder) || t == typeof(IndexFolder) || t == typeof(CollectionFolder) || t == typeof(Year)) { return false; } if (t == typeof(User)) { return false; } // For now it seems internet providers generally only deal with video subclasses if (t == typeof(Video)) { return false; } if (t.IsSubclassOf(typeof(BasePluginFolder))) { return false; } return true; }); } return allTypes.Select(t => t.Name).OrderBy(s => s).ToList(); } } }