private IEnumerable <RecommendationDto> GetSimilarTo(User user, List <BaseItem> baselineItems, int itemLimit, DtoOptions dtoOptions, RecommendationType type)
        {
            var itemTypes = new List <string> {
                typeof(Movie).Name
            };

            if (_config.Configuration.EnableExternalContentInSuggestions)
            {
                itemTypes.Add(typeof(Trailer).Name);
                itemTypes.Add(typeof(LiveTvProgram).Name);
            }

            foreach (var item in baselineItems)
            {
                var similar = _libraryManager.GetItemList(new InternalItemsQuery(user)
                {
                    Limit                    = itemLimit,
                    IncludeItemTypes         = itemTypes.ToArray(),
                    IsMovie                  = true,
                    SimilarTo                = item,
                    EnableGroupByMetadataKey = true,
                    DtoOptions               = dtoOptions
                }).ToList();

                if (similar.Count > 0)
                {
                    yield return(new RecommendationDto
                    {
                        BaselineItemName = item.Name,
                        CategoryId = item.Id.ToString("N"),
                        RecommendationType = type,
                        Items = _dtoService.GetBaseItemDtos(similar, dtoOptions, user).Result.ToArray()
                    });
                }
            }
        }
Esempio n. 2
0
        private IEnumerable <RecommendationDto> GetWithDirector(User user, List <BaseItem> allMovies, IEnumerable <string> directors, int itemLimit, DtoOptions dtoOptions, RecommendationType type)
        {
            var userId = user.Id;

            foreach (var director in directors)
            {
                var items = allMovies
                            .Where(i => _libraryManager.GetPeople(i).Any(p => string.Equals(p.Type, PersonType.Director, StringComparison.OrdinalIgnoreCase) && string.Equals(p.Name, director, StringComparison.OrdinalIgnoreCase)))
                            .Take(itemLimit)
                            .ToList();

                if (items.Count > 0)
                {
                    yield return(new RecommendationDto
                    {
                        BaselineItemName = director,
                        CategoryId = director.GetMD5().ToString("N"),
                        RecommendationType = type,
                        Items = _dtoService.GetBaseItemDtos(items, dtoOptions, user).ToArray()
                    });
                }
            }
        }
        private IEnumerable <RecommendationDto> GetWithActor(User user, IEnumerable <string> names, int itemLimit, DtoOptions dtoOptions, RecommendationType type)
        {
            var itemTypes = new List <string> {
                typeof(Movie).Name
            };

            if (_config.Configuration.EnableExternalContentInSuggestions)
            {
                itemTypes.Add(typeof(Trailer).Name);
                itemTypes.Add(typeof(LiveTvProgram).Name);
            }

            foreach (var name in names)
            {
                var items = _libraryManager.GetItemList(new InternalItemsQuery(user)
                {
                    Person = name,
                    // Account for duplicates by imdb id, since the database doesn't support this yet
                    Limit                    = itemLimit + 2,
                    IncludeItemTypes         = itemTypes.ToArray(),
                    IsMovie                  = true,
                    EnableGroupByMetadataKey = true,
                    DtoOptions               = dtoOptions
                }).DistinctBy(i => i.GetProviderId(MetadataProviders.Imdb) ?? Guid.NewGuid().ToString("N"))
                            .Take(itemLimit)
                            .ToList();

                if (items.Count > 0)
                {
                    yield return(new RecommendationDto
                    {
                        BaselineItemName = name,
                        CategoryId = name.GetMD5().ToString("N"),
                        RecommendationType = type,
                        Items = _dtoService.GetBaseItemDtos(items, dtoOptions, user).Result.ToArray()
                    });
                }
            }
        }
Esempio n. 4
0
        private IEnumerable <RecommendationDto> GetWithActor(User?user, IEnumerable <string> names, int itemLimit, DtoOptions dtoOptions, RecommendationType type)
        {
            var itemTypes = new List <string> {
                nameof(Movie)
            };

            if (_serverConfigurationManager.Configuration.EnableExternalContentInSuggestions)
            {
                itemTypes.Add(nameof(Trailer));
                itemTypes.Add(nameof(LiveTvProgram));
            }

            foreach (var name in names)
            {
                var items = _libraryManager.GetItemList(new InternalItemsQuery(user)
                {
                    Person = name,
                    // Account for duplicates by imdb id, since the database doesn't support this yet
                    Limit                    = itemLimit + 2,
                    IncludeItemTypes         = itemTypes.ToArray(),
                    IsMovie                  = true,
                    EnableGroupByMetadataKey = true,
                    DtoOptions               = dtoOptions
                }).GroupBy(i => i.GetProviderId(MediaBrowser.Model.Entities.MetadataProvider.Imdb) ?? Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture))
                            .Select(x => x.First())
                            .Take(itemLimit)
                            .ToList();

                if (items.Count > 0)
                {
                    var returnItems = _dtoService.GetBaseItemDtos(items, dtoOptions, user);

                    yield return(new RecommendationDto
                    {
                        BaselineItemName = name,
                        CategoryId = name.GetMD5(),
                        RecommendationType = type,
                        Items = returnItems
                    });
                }
            }
        }
Esempio n. 5
0
        private IEnumerable <RecommendationDto> GetSimilarTo(User user, List <BaseItem> allMovies, IEnumerable <BaseItem> baselineItems, int itemLimit, DtoOptions dtoOptions, RecommendationType type)
        {
            foreach (var item in baselineItems)
            {
                var similar = SimilarItemsHelper
                              .GetSimilaritems(item, _libraryManager, allMovies, SimilarItemsHelper.GetSimiliarityScore)
                              .Take(itemLimit)
                              .ToList();

                if (similar.Count > 0)
                {
                    yield return(new RecommendationDto
                    {
                        BaselineItemName = item.Name,
                        CategoryId = item.Id.ToString("N"),
                        RecommendationType = type,
                        Items = _dtoService.GetBaseItemDtos(similar, dtoOptions, user).ToArray()
                    });
                }
            }
        }
Esempio n. 6
0
        private IEnumerable <RecommendationDto> GetWithActor(User user, List <BaseItem> allMovies, IEnumerable <string> names, int itemLimit, DtoOptions dtoOptions, RecommendationType type)
        {
            foreach (var name in names)
            {
                var itemsWithActor = _libraryManager.GetItemIds(new InternalItemsQuery
                {
                    Person = name
                });

                var items = allMovies
                            .Where(i => itemsWithActor.Contains(i.Id))
                            .Take(itemLimit)
                            .ToList();

                if (items.Count > 0)
                {
                    yield return(new RecommendationDto
                    {
                        BaselineItemName = name,
                        CategoryId = name.GetMD5().ToString("N"),
                        RecommendationType = type,
                        Items = _dtoService.GetBaseItemDtos(items, dtoOptions, user).ToArray()
                    });
                }
            }
        }
Esempio n. 7
0
        private IEnumerable <RecommendationDto> GetWithActor(User user, List <BaseItem> allMovies, IEnumerable <string> names, int itemLimit, DtoOptions dtoOptions, RecommendationType type)
        {
            var userId = user.Id;

            foreach (var name in names)
            {
                var items = allMovies
                            .Where(i => i.People.Any(p => string.Equals(p.Name, name, StringComparison.OrdinalIgnoreCase)))
                            .Take(itemLimit)
                            .ToList();

                if (items.Count > 0)
                {
                    yield return(new RecommendationDto
                    {
                        BaselineItemName = name,
                        CategoryId = name.GetMD5().ToString("N"),
                        RecommendationType = type,
                        Items = items.Select(i => _dtoService.GetBaseItemDto(i, dtoOptions, user)).ToArray()
                    });
                }
            }
        }