Example #1
0
        /// <summary>
        /// Gets the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>System.Object.</returns>
        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));
        }
Example #2
0
        /// <summary>
        /// Gets the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>System.Object.</returns>
        public object Get(GetSimilarShows request)
        {
            var result = SimilarItemsHelper.GetSimilarItems(_userManager,
                                                            _itemRepo,
                                                            _libraryManager,
                                                            _userDataRepository,
                                                            Logger,
                                                            request, item => item is Series,
                                                            SimilarItemsHelper.GetSimiliarityScore);

            return(ToOptimizedResult(result));
        }
Example #3
0
        /// <summary>
        /// Gets the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>System.Object.</returns>
        public object Get(GetSimilarAlbums request)
        {
            var result = SimilarItemsHelper.GetSimilarItemsResult(_userManager,
                                                                  _itemRepo,
                                                                  _libraryManager,
                                                                  _userDataRepository,
                                                                  Logger,
                                                                  request, item => item is MusicAlbum,
                                                                  GetAlbumSimilarityScore);

            return(ToOptimizedResult(result));
        }
Example #4
0
        /// <summary>
        /// Gets the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>System.Object.</returns>
        public object Get(GetSimilarShows request)
        {
            var result = SimilarItemsHelper.GetSimilarItemsResult(_userManager,
                                                                  _itemRepo,
                                                                  _libraryManager,
                                                                  _userDataManager,
                                                                  _dtoService,
                                                                  Logger,
                                                                  request, item => item is Series,
                                                                  SimilarItemsHelper.GetSimiliarityScore);

            return(ToOptimizedSerializedResultUsingCache(result));
        }
Example #5
0
        /// <summary>
        /// Gets the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>System.Object.</returns>
        public object Get(GetSimilarGames request)
        {
            var result = SimilarItemsHelper.GetSimilarItemsResult(_userManager,
                                                                  _itemRepo,
                                                                  _libraryManager,
                                                                  _userDataRepository,
                                                                  _dtoService,
                                                                  Logger,
                                                                  request, item => item is Game,
                                                                  SimilarItemsHelper.GetSimiliarityScore);

            return(ToOptimizedResult(result));
        }
Example #6
0
        /// <summary>
        /// Gets the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>System.Object.</returns>
        public object Get(GetSimilarGames request)
        {
            var dtoOptions = GetDtoOptions(request);

            var result = SimilarItemsHelper.GetSimilarItemsResult(dtoOptions, _userManager,
                                                                  _itemRepo,
                                                                  _libraryManager,
                                                                  _userDataRepository,
                                                                  _dtoService,
                                                                  Logger,
                                                                  request, new[] { typeof(Game) },
                                                                  SimilarItemsHelper.GetSimiliarityScore);

            return(ToOptimizedSerializedResultUsingCache(result));
        }
Example #7
0
        /// <summary>
        /// Gets the album similarity score.
        /// </summary>
        /// <param name="item1">The item1.</param>
        /// <param name="item2">The item2.</param>
        /// <returns>System.Int32.</returns>
        private int GetAlbumSimilarityScore(BaseItem item1, BaseItem item2)
        {
            var points = SimilarItemsHelper.GetSimiliarityScore(item1, item2);

            var album1 = (MusicAlbum)item1;
            var album2 = (MusicAlbum)item2;

            var artists1 = album1.GetRecursiveChildren()
                           .OfType <Audio>()
                           .SelectMany(i =>
            {
                var list = new List <string>();

                if (!string.IsNullOrEmpty(i.AlbumArtist))
                {
                    list.Add(i.AlbumArtist);
                }
                list.AddRange(i.Artists);

                return(list);
            })
                           .Distinct(StringComparer.OrdinalIgnoreCase)
                           .ToList();

            var artists2 = album2.GetRecursiveChildren()
                           .OfType <Audio>()
                           .SelectMany(i =>
            {
                var list = new List <string>();

                if (!string.IsNullOrEmpty(i.AlbumArtist))
                {
                    list.Add(i.AlbumArtist);
                }
                list.AddRange(i.Artists);

                return(list);
            })
                           .Distinct(StringComparer.OrdinalIgnoreCase)
                           .ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);

            return(points + artists1.Where(artists2.ContainsKey).Sum(i => 5));
        }
Example #8
0
        /// <summary>
        /// Gets the album similarity score.
        /// </summary>
        /// <param name="item1">The item1.</param>
        /// <param name="item2">The item2.</param>
        /// <returns>System.Int32.</returns>
        private int GetAlbumSimilarityScore(BaseItem item1, BaseItem item2)
        {
            var points = SimilarItemsHelper.GetSimiliarityScore(item1, item2);

            var album1 = (MusicAlbum)item1;
            var album2 = (MusicAlbum)item2;

            var artists1 = album1.RecursiveChildren
                           .OfType <Audio>()
                           .SelectMany(i => new[] { i.AlbumArtist, i.Artist })
                           .Where(i => !string.IsNullOrEmpty(i))
                           .Distinct(StringComparer.OrdinalIgnoreCase)
                           .ToList();

            var artists2 = album2.RecursiveChildren
                           .OfType <Audio>()
                           .SelectMany(i => new[] { i.AlbumArtist, i.Artist })
                           .Where(i => !string.IsNullOrEmpty(i))
                           .Distinct(StringComparer.OrdinalIgnoreCase)
                           .ToList();

            return(points + artists1.Where(i => artists2.Contains(i, StringComparer.OrdinalIgnoreCase)).Sum(i => 5));
        }