2013-03-04 05:43:06 +00:00
|
|
|
|
using MediaBrowser.Common;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
|
using MediaBrowser.Controller.Library;
|
2013-12-20 16:51:25 +00:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
2013-12-07 15:52:38 +00:00
|
|
|
|
using ServiceStack;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
2013-02-25 03:56:00 +00:00
|
|
|
|
namespace MediaBrowser.Api.Library
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class GetPhyscialPaths
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Route("/Library/PhysicalPaths", "GET")]
|
2013-03-24 02:45:00 +00:00
|
|
|
|
[Api(Description = "Gets a list of physical paths from virtual folders")]
|
2013-02-21 01:33:05 +00:00
|
|
|
|
public class GetPhyscialPaths : IReturn<List<string>>
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class GetItemTypes
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Route("/Library/ItemTypes", "GET")]
|
2013-03-24 02:45:00 +00:00
|
|
|
|
[Api(Description = "Gets a list of BaseItem types")]
|
2013-02-21 01:33:05 +00:00
|
|
|
|
public class GetItemTypes : IReturn<List<string>>
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets a value indicating whether this instance has internet provider.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value><c>true</c> if this instance has internet provider; otherwise, <c>false</c>.</value>
|
2013-03-08 22:41:38 +00:00
|
|
|
|
[ApiMember(Name = "HasInternetProvider", Description = "Optional filter by item types that have internet providers. true/false", IsRequired = false, DataType = "boolean", ParameterType = "query", Verb = "GET")]
|
2013-02-21 01:33:05 +00:00
|
|
|
|
public bool HasInternetProvider { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class LibraryService
|
|
|
|
|
/// </summary>
|
2013-03-16 05:52:33 +00:00
|
|
|
|
public class LibraryService : BaseApiService
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-02-24 21:53:54 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The _app host
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly IApplicationHost _appHost;
|
2013-02-28 19:32:41 +00:00
|
|
|
|
private readonly ILibraryManager _libraryManager;
|
2013-02-24 21:53:54 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="LibraryService" /> class.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="appHost">The app host.</param>
|
2013-04-02 17:37:49 +00:00
|
|
|
|
/// <param name="libraryManager">The library manager.</param>
|
2013-02-24 21:53:54 +00:00
|
|
|
|
/// <exception cref="System.ArgumentNullException">appHost</exception>
|
2013-04-22 04:38:03 +00:00
|
|
|
|
public LibraryService(IApplicationHost appHost, ILibraryManager libraryManager)
|
2013-02-24 21:53:54 +00:00
|
|
|
|
{
|
|
|
|
|
if (appHost == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException("appHost");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_appHost = appHost;
|
2013-02-28 19:32:41 +00:00
|
|
|
|
_libraryManager = libraryManager;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
/// <returns>System.Object.</returns>
|
|
|
|
|
public object Get(GetPhyscialPaths request)
|
|
|
|
|
{
|
2013-12-20 16:51:25 +00:00
|
|
|
|
var result = _libraryManager.RootFolder.Children
|
|
|
|
|
.SelectMany(c =>
|
|
|
|
|
{
|
|
|
|
|
var locationType = c.LocationType;
|
|
|
|
|
|
|
|
|
|
if (locationType != LocationType.Remote && locationType != LocationType.Virtual)
|
|
|
|
|
{
|
2014-02-06 04:39:16 +00:00
|
|
|
|
return c.PhysicalLocations;
|
2013-12-20 16:51:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new List<string>();
|
|
|
|
|
})
|
|
|
|
|
.ToList();
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2014-02-04 04:04:19 +00:00
|
|
|
|
return ToOptimizedSerializedResultUsingCache(result);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
/// <returns>System.Object.</returns>
|
|
|
|
|
public object Get(GetItemTypes request)
|
|
|
|
|
{
|
2013-02-24 21:53:54 +00:00
|
|
|
|
var allTypes = _appHost.AllConcreteTypes.Where(t => t.IsSubclassOf(typeof(BaseItem)));
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
|
|
|
|
if (request.HasInternetProvider)
|
|
|
|
|
{
|
|
|
|
|
allTypes = allTypes.Where(t =>
|
|
|
|
|
{
|
2013-12-11 02:51:26 +00:00
|
|
|
|
if (t == typeof(UserRootFolder) || t == typeof(AggregateFolder) || t == typeof(Folder) || t == typeof(CollectionFolder) || t == typeof(Year))
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|