2014-03-17 18:45:41 -07:00
using MediaBrowser.Controller.Channels ;
using MediaBrowser.Model.Channels ;
using MediaBrowser.Model.Dto ;
2014-05-02 21:20:04 -07:00
using MediaBrowser.Model.Entities ;
2014-03-17 18:45:41 -07:00
using MediaBrowser.Model.Querying ;
using ServiceStack ;
2014-05-02 21:20:04 -07:00
using System ;
using System.Collections.Generic ;
using System.Linq ;
2014-03-17 18:45:41 -07:00
using System.Threading ;
namespace MediaBrowser.Api
{
2014-03-26 09:10:46 -07:00
[Route("/Channels", "GET", Summary = "Gets available channels")]
2014-03-17 18:45:41 -07:00
public class GetChannels : IReturn < QueryResult < BaseItemDto > >
{
2014-05-02 21:20:04 -07:00
/// <summary>
/// Gets or sets the user id.
/// </summary>
/// <value>The user id.</value>
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = false, DataType = "string", ParameterType = "path", Verb = "GET")]
2014-03-17 18:45:41 -07:00
public string UserId { get ; set ; }
2014-05-02 21:20:04 -07:00
/// <summary>
/// Skips over a given number of items within the results. Use for paging.
/// </summary>
/// <value>The start index.</value>
[ApiMember(Name = "StartIndex", Description = "Optional. The record index to start at. All items with a lower index will be dropped from the results.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
2014-03-17 18:45:41 -07:00
public int? StartIndex { get ; set ; }
2014-05-02 21:20:04 -07:00
/// <summary>
/// The maximum number of items to return
/// </summary>
/// <value>The limit.</value>
[ApiMember(Name = "Limit", Description = "Optional. The maximum number of records to return", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
2014-03-17 18:45:41 -07:00
public int? Limit { get ; set ; }
}
2014-03-26 09:10:46 -07:00
[Route("/Channels/{Id}/Items", "GET", Summary = "Gets channel items")]
2014-03-18 10:05:57 -07:00
public class GetChannelItems : IReturn < QueryResult < BaseItemDto > >
{
public string Id { get ; set ; }
2014-05-23 07:09:58 -07:00
public string FolderId { get ; set ; }
2014-03-18 10:05:57 -07:00
2014-05-02 21:20:04 -07:00
/// <summary>
/// Gets or sets the user id.
/// </summary>
/// <value>The user id.</value>
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = false, DataType = "string", ParameterType = "path", Verb = "GET")]
2014-03-18 10:05:57 -07:00
public string UserId { get ; set ; }
2014-05-02 21:20:04 -07:00
/// <summary>
/// Skips over a given number of items within the results. Use for paging.
/// </summary>
/// <value>The start index.</value>
[ApiMember(Name = "StartIndex", Description = "Optional. The record index to start at. All items with a lower index will be dropped from the results.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
2014-03-18 10:05:57 -07:00
public int? StartIndex { get ; set ; }
2014-05-02 21:20:04 -07:00
/// <summary>
/// The maximum number of items to return
/// </summary>
/// <value>The limit.</value>
[ApiMember(Name = "Limit", Description = "Optional. The maximum number of records to return", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
2014-03-18 10:05:57 -07:00
public int? Limit { get ; set ; }
2014-05-02 21:20:04 -07:00
[ApiMember(Name = "SortOrder", Description = "Sort Order - Ascending,Descending", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public SortOrder ? SortOrder { get ; set ; }
2014-05-06 19:28:19 -07:00
[ApiMember(Name = "Filters", Description = "Optional. Specify additional filters to apply. This allows multiple, comma delimeted. Options: IsFolder, IsNotFolder, IsUnplayed, IsPlayed, IsFavorite, IsResumable, Likes, Dislikes", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
2014-05-02 21:20:04 -07:00
public string Filters { get ; set ; }
[ApiMember(Name = "SortBy", Description = "Optional. Specify one or more sort orders, comma delimeted. Options: Album, AlbumArtist, Artist, Budget, CommunityRating, CriticRating, DateCreated, DatePlayed, PlayCount, PremiereDate, ProductionYear, SortName, Random, Revenue, Runtime", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
public string SortBy { get ; set ; }
/// <summary>
/// Gets the filters.
/// </summary>
/// <returns>IEnumerable{ItemFilter}.</returns>
public IEnumerable < ItemFilter > GetFilters ( )
{
var val = Filters ;
if ( string . IsNullOrEmpty ( val ) )
{
return new ItemFilter [ ] { } ;
}
return val . Split ( ',' ) . Select ( v = > ( ItemFilter ) Enum . Parse ( typeof ( ItemFilter ) , v , true ) ) ;
}
2014-03-18 10:05:57 -07:00
}
2014-03-17 18:45:41 -07:00
public class ChannelService : BaseApiService
{
private readonly IChannelManager _channelManager ;
public ChannelService ( IChannelManager channelManager )
{
_channelManager = channelManager ;
}
public object Get ( GetChannels request )
{
var result = _channelManager . GetChannels ( new ChannelQuery
{
Limit = request . Limit ,
StartIndex = request . StartIndex ,
UserId = request . UserId ,
} , CancellationToken . None ) . Result ;
return ToOptimizedResult ( result ) ;
}
2014-03-18 10:05:57 -07:00
public object Get ( GetChannelItems request )
{
var result = _channelManager . GetChannelItems ( new ChannelItemQuery
{
Limit = request . Limit ,
StartIndex = request . StartIndex ,
UserId = request . UserId ,
ChannelId = request . Id ,
2014-05-23 07:09:58 -07:00
FolderId = request . FolderId ,
2014-05-02 21:20:04 -07:00
SortOrder = request . SortOrder ,
SortBy = ( request . SortBy ? ? string . Empty ) . Split ( ',' ) . Where ( i = > ! string . IsNullOrWhiteSpace ( i ) ) . ToArray ( ) ,
Filters = request . GetFilters ( ) . ToArray ( )
2014-03-18 10:05:57 -07:00
} , CancellationToken . None ) . Result ;
return ToOptimizedResult ( result ) ;
}
2014-03-17 18:45:41 -07:00
}
}