2013-05-25 23:52:41 +00:00
using MediaBrowser.Controller.Entities ;
using MediaBrowser.Controller.Entities.Movies ;
using MediaBrowser.Controller.Library ;
using MediaBrowser.Controller.Persistence ;
using ServiceStack.ServiceHost ;
namespace MediaBrowser.Api
{
/// <summary>
/// Class GetSimilarMovies
/// </summary>
[Route("/Movies/{Id}/Similar", "GET")]
[Api(Description = "Finds movies and trailers similar to a given movie.")]
public class GetSimilarMovies : BaseGetSimilarItems
{
2013-06-13 15:59:09 +00:00
[ApiMember(Name = "IncludeTrailers", Description = "Whether or not to include trailers within the results. Defaults to true.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")]
public bool IncludeTrailers { get ; set ; }
public GetSimilarMovies ( )
{
IncludeTrailers = true ;
}
2013-05-25 23:52:41 +00:00
}
/// <summary>
/// Class MoviesService
/// </summary>
public class MoviesService : BaseApiService
{
/// <summary>
/// The _user manager
/// </summary>
private readonly IUserManager _userManager ;
/// <summary>
/// The _user data repository
/// </summary>
private readonly IUserDataRepository _userDataRepository ;
/// <summary>
/// The _library manager
/// </summary>
private readonly ILibraryManager _libraryManager ;
2013-06-18 19:16:27 +00:00
private readonly IItemRepository _itemRepo ;
2013-05-25 23:52:41 +00:00
/// <summary>
/// Initializes a new instance of the <see cref="MoviesService"/> class.
/// </summary>
/// <param name="userManager">The user manager.</param>
/// <param name="userDataRepository">The user data repository.</param>
/// <param name="libraryManager">The library manager.</param>
2013-06-18 19:16:27 +00:00
public MoviesService ( IUserManager userManager , IUserDataRepository userDataRepository , ILibraryManager libraryManager , IItemRepository itemRepo )
2013-05-25 23:52:41 +00:00
{
_userManager = userManager ;
_userDataRepository = userDataRepository ;
_libraryManager = libraryManager ;
2013-06-18 19:16:27 +00:00
_itemRepo = itemRepo ;
2013-05-25 23:52:41 +00:00
}
/// <summary>
/// Gets the specified request.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>System.Object.</returns>
public object Get ( GetSimilarMovies request )
{
var result = SimilarItemsHelper . GetSimilarItems ( _userManager ,
2013-06-18 19:16:27 +00:00
_itemRepo ,
2013-05-25 23:52:41 +00:00
_libraryManager ,
_userDataRepository ,
Logger ,
2013-06-13 15:59:09 +00:00
request , item = > item is Movie | | ( item is Trailer & & request . IncludeTrailers ) ,
2013-05-25 23:52:41 +00:00
SimilarItemsHelper . GetSimiliarityScore ) ;
return ToOptimizedResult ( result ) ;
}
}
}