using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Persistence; using ServiceStack.ServiceHost; namespace MediaBrowser.Api { /// /// Class GetSimilarMovies /// [Route("/Movies/{Id}/Similar", "GET")] [Api(Description = "Finds movies and trailers similar to a given movie.")] public class GetSimilarMovies : BaseGetSimilarItems { [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; } } /// /// Class MoviesService /// public class MoviesService : BaseApiService { /// /// The _user manager /// private readonly IUserManager _userManager; /// /// The _user data repository /// private readonly IUserDataRepository _userDataRepository; /// /// The _library manager /// private readonly ILibraryManager _libraryManager; private readonly IItemRepository _itemRepo; /// /// Initializes a new instance of the class. /// /// The user manager. /// The user data repository. /// The library manager. public MoviesService(IUserManager userManager, IUserDataRepository userDataRepository, ILibraryManager libraryManager, IItemRepository itemRepo) { _userManager = userManager; _userDataRepository = userDataRepository; _libraryManager = libraryManager; _itemRepo = itemRepo; } /// /// Gets the specified request. /// /// The request. /// System.Object. public object Get(GetSimilarMovies request) { var result = SimilarItemsHelper.GetSimilarItemsResult(_userManager, _itemRepo, _libraryManager, _userDataRepository, Logger, request, item => item is Movie || (item is Trailer && request.IncludeTrailers), SimilarItemsHelper.GetSimiliarityScore); return ToOptimizedResult(result); } } }