2014-03-17 18:45:41 -07:00
using MediaBrowser.Controller.Channels ;
2014-07-01 21:57:18 -07:00
using MediaBrowser.Controller.Net ;
2014-03-17 18:45:41 -07:00
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 ;
2014-08-16 22:38:13 -07:00
using System.Threading.Tasks ;
2014-03-17 18:45:41 -07:00
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-06-17 09:03:14 -07:00
[ApiMember(Name = "SupportsLatestItems", Description = "Optional. Filter by channels that support getting latest items.", IsRequired = false, DataType = "boolean", ParameterType = "query", Verb = "GET")]
public bool? SupportsLatestItems { get ; set ; }
2014-06-23 09:05:19 -07:00
/// <summary>
/// Gets or sets a value indicating whether this instance is favorite.
/// </summary>
/// <value><c>null</c> if [is favorite] contains no value, <c>true</c> if [is favorite]; otherwise, <c>false</c>.</value>
public bool? IsFavorite { get ; set ; }
2014-03-17 18:45:41 -07:00
}
2014-05-27 10:09:48 -07:00
[Route("/Channels/{Id}/Features", "GET", Summary = "Gets features for a channel")]
public class GetChannelFeatures : IReturn < ChannelFeatures >
{
[ApiMember(Name = "Id", Description = "Channel Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
public string Id { get ; set ; }
}
2014-06-02 12:32:41 -07:00
[Route("/Channels/Features", "GET", Summary = "Gets features for a channel")]
public class GetAllChannelFeatures : IReturn < List < ChannelFeatures > >
{
}
2014-03-26 09:10:46 -07:00
[Route("/Channels/{Id}/Items", "GET", Summary = "Gets channel items")]
2014-06-07 14:06:01 -07:00
public class GetChannelItems : IReturn < QueryResult < BaseItemDto > > , IHasItemFields
2014-03-18 10:05:57 -07:00
{
2014-05-27 10:09:48 -07:00
[ApiMember(Name = "Id", Description = "Channel Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
2014-03-18 10:05:57 -07:00
public string Id { get ; set ; }
2014-05-27 10:09:48 -07:00
[ApiMember(Name = "FolderId", Description = "Folder Id", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
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>
2014-05-27 10:09:48 -07:00
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = false, DataType = "string", ParameterType = "query", 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 ; }
2014-06-07 14:06:01 -07:00
[ApiMember(Name = "Fields", Description = "Optional. Specify additional fields of information to return in the output. This allows multiple, comma delimeted. Options: Budget, Chapters, CriticRatingSummary, DateCreated, Genres, HomePageUrl, IndexOptions, MediaStreams, Overview, ParentId, Path, People, ProviderIds, PrimaryImageAspectRatio, Revenue, SortName, Studios, Taglines", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
public string Fields { get ; set ; }
2014-05-02 21:20:04 -07:00
/// <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-06-15 16:30:04 -07:00
[Route("/Channels/Items/Latest", "GET", Summary = "Gets channel items")]
public class GetLatestChannelItems : IReturn < QueryResult < BaseItemDto > > , IHasItemFields
{
/// <summary>
/// Gets or sets the user id.
/// </summary>
/// <value>The user id.</value>
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public string UserId { get ; set ; }
/// <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")]
public int? StartIndex { get ; set ; }
/// <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")]
public int? Limit { get ; set ; }
[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)]
public string Filters { get ; set ; }
[ApiMember(Name = "Fields", Description = "Optional. Specify additional fields of information to return in the output. This allows multiple, comma delimeted. Options: Budget, Chapters, CriticRatingSummary, DateCreated, Genres, HomePageUrl, IndexOptions, MediaStreams, Overview, ParentId, Path, People, ProviderIds, PrimaryImageAspectRatio, Revenue, SortName, Studios, Taglines", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
public string Fields { get ; set ; }
2014-06-17 09:03:14 -07:00
[ApiMember(Name = "ChannelIds", Description = "Optional. Specify one or more channel id's, comma delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
public string ChannelIds { get ; set ; }
2014-06-15 16:30:04 -07:00
/// <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-06-07 12:46:24 -07:00
[Route("/Channels/Folder", "GET", Summary = "Gets the users channel folder, along with configured images")]
public class GetChannelFolder : IReturn < BaseItemDto >
{
[ApiMember(Name = "UserId", Description = "Optional attach user data.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public string UserId { get ; set ; }
}
2014-07-01 21:57:18 -07:00
[Authenticated]
2014-03-17 18:45:41 -07:00
public class ChannelService : BaseApiService
{
private readonly IChannelManager _channelManager ;
public ChannelService ( IChannelManager channelManager )
{
_channelManager = channelManager ;
}
2014-06-02 12:32:41 -07:00
public object Get ( GetAllChannelFeatures request )
{
var result = _channelManager . GetAllChannelFeatures ( ) . ToList ( ) ;
return ToOptimizedResult ( result ) ;
}
2014-05-27 10:09:48 -07:00
public object Get ( GetChannelFeatures request )
{
var result = _channelManager . GetChannelFeatures ( request . Id ) ;
return ToOptimizedResult ( result ) ;
}
2014-08-16 22:38:13 -07:00
public async Task < object > Get ( GetChannelFolder request )
2014-06-07 12:46:24 -07:00
{
2014-08-16 22:38:13 -07:00
return ToOptimizedResult ( await _channelManager . GetChannelFolder ( request . UserId , CancellationToken . None ) . ConfigureAwait ( false ) ) ;
2014-06-07 12:46:24 -07:00
}
2014-08-16 22:38:13 -07:00
public async Task < object > Get ( GetChannels request )
2014-03-17 18:45:41 -07:00
{
2014-08-16 22:38:13 -07:00
var result = await _channelManager . GetChannels ( new ChannelQuery
2014-03-17 18:45:41 -07:00
{
Limit = request . Limit ,
StartIndex = request . StartIndex ,
UserId = request . UserId ,
2014-06-23 09:05:19 -07:00
SupportsLatestItems = request . SupportsLatestItems ,
IsFavorite = request . IsFavorite
2014-03-17 18:45:41 -07:00
2014-08-16 22:38:13 -07:00
} , CancellationToken . None ) . ConfigureAwait ( false ) ;
2014-03-17 18:45:41 -07:00
return ToOptimizedResult ( result ) ;
}
2014-03-18 10:05:57 -07:00
2014-08-16 22:38:13 -07:00
public async Task < object > Get ( GetChannelItems request )
2014-03-18 10:05:57 -07:00
{
2014-08-16 22:38:13 -07:00
var result = await _channelManager . GetChannelItems ( new ChannelItemQuery
2014-03-18 10:05:57 -07:00
{
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 ( ) ,
2014-06-07 14:06:01 -07:00
Filters = request . GetFilters ( ) . ToArray ( ) ,
2014-08-10 15:13:17 -07:00
Fields = request . GetItemFields ( ) . ToArray ( )
2014-03-18 10:05:57 -07:00
2014-08-16 22:38:13 -07:00
} , CancellationToken . None ) . ConfigureAwait ( false ) ;
2014-03-18 10:05:57 -07:00
return ToOptimizedResult ( result ) ;
}
2014-06-15 16:30:04 -07:00
2014-08-16 22:38:13 -07:00
public async Task < object > Get ( GetLatestChannelItems request )
2014-06-15 16:30:04 -07:00
{
2014-08-16 22:38:13 -07:00
var result = await _channelManager . GetLatestChannelItems ( new AllChannelMediaQuery
2014-06-15 16:30:04 -07:00
{
Limit = request . Limit ,
StartIndex = request . StartIndex ,
2014-06-17 09:03:14 -07:00
ChannelIds = ( request . ChannelIds ? ? string . Empty ) . Split ( ',' ) . Where ( i = > ! string . IsNullOrWhiteSpace ( i ) ) . ToArray ( ) ,
2014-06-15 16:30:04 -07:00
UserId = request . UserId ,
Filters = request . GetFilters ( ) . ToArray ( ) ,
Fields = request . GetItemFields ( ) . ToList ( )
2014-08-16 22:38:13 -07:00
} , CancellationToken . None ) . ConfigureAwait ( false ) ;
2014-06-15 16:30:04 -07:00
return ToOptimizedResult ( result ) ;
}
2014-03-17 18:45:41 -07:00
}
}