|
|
|
@ -146,21 +146,12 @@ namespace MediaBrowser.Api.Movies
|
|
|
|
|
var movies = _libraryManager.GetItemList(query, parentIds)
|
|
|
|
|
.OrderBy(i => (int)i.SourceType);
|
|
|
|
|
|
|
|
|
|
var listEligibleForCategories = new List<BaseItem>();
|
|
|
|
|
var listEligibleForSuggestion = new List<BaseItem>();
|
|
|
|
|
|
|
|
|
|
var list = movies.ToList();
|
|
|
|
|
|
|
|
|
|
listEligibleForCategories.AddRange(list);
|
|
|
|
|
listEligibleForSuggestion.AddRange(list);
|
|
|
|
|
|
|
|
|
|
listEligibleForCategories = listEligibleForCategories
|
|
|
|
|
// Exclude trailers from the suggestion categories
|
|
|
|
|
.Where(i => i is Movie)
|
|
|
|
|
.DistinctBy(i => i.Name, StringComparer.OrdinalIgnoreCase)
|
|
|
|
|
.DistinctBy(i => i.GetProviderId(MetadataProviders.Imdb) ?? Guid.NewGuid().ToString(), StringComparer.OrdinalIgnoreCase)
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
listEligibleForSuggestion = listEligibleForSuggestion
|
|
|
|
|
.DistinctBy(i => i.Name, StringComparer.OrdinalIgnoreCase)
|
|
|
|
|
.DistinctBy(i => i.GetProviderId(MetadataProviders.Imdb) ?? Guid.NewGuid().ToString(), StringComparer.OrdinalIgnoreCase)
|
|
|
|
@ -170,7 +161,7 @@ namespace MediaBrowser.Api.Movies
|
|
|
|
|
|
|
|
|
|
dtoOptions.Fields = request.GetItemFields().ToList();
|
|
|
|
|
|
|
|
|
|
var result = GetRecommendationCategories(user, listEligibleForCategories, listEligibleForSuggestion, request.CategoryLimit, request.ItemLimit, dtoOptions);
|
|
|
|
|
var result = GetRecommendationCategories(user, request.ParentId, listEligibleForSuggestion, request.CategoryLimit, request.ItemLimit, dtoOptions);
|
|
|
|
|
|
|
|
|
|
return ToOptimizedResult(result);
|
|
|
|
|
}
|
|
|
|
@ -233,44 +224,43 @@ namespace MediaBrowser.Api.Movies
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IEnumerable<RecommendationDto> GetRecommendationCategories(User user, List<BaseItem> allMoviesForCategories, List<BaseItem> allMovies, int categoryLimit, int itemLimit, DtoOptions dtoOptions)
|
|
|
|
|
private IEnumerable<RecommendationDto> GetRecommendationCategories(User user, string parentId, List<BaseItem> allMovies, int categoryLimit, int itemLimit, DtoOptions dtoOptions)
|
|
|
|
|
{
|
|
|
|
|
var categories = new List<RecommendationDto>();
|
|
|
|
|
|
|
|
|
|
var recentlyPlayedMovies = allMoviesForCategories
|
|
|
|
|
.Select(i =>
|
|
|
|
|
var parentIds = string.IsNullOrWhiteSpace(parentId) ? new string[] { } : new[] { parentId };
|
|
|
|
|
var query = new InternalItemsQuery(user)
|
|
|
|
|
{
|
|
|
|
|
var userdata = _userDataRepository.GetUserData(user, i);
|
|
|
|
|
return new Tuple<BaseItem, bool, DateTime>(i, userdata.Played, userdata.LastPlayedDate ?? DateTime.MinValue);
|
|
|
|
|
})
|
|
|
|
|
.Where(i => i.Item2)
|
|
|
|
|
.OrderByDescending(i => i.Item3)
|
|
|
|
|
.Select(i => i.Item1)
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
var excludeFromLiked = recentlyPlayedMovies.Take(10);
|
|
|
|
|
var likedMovies = allMovies
|
|
|
|
|
.Select(i =>
|
|
|
|
|
IncludeItemTypes = new[]
|
|
|
|
|
{
|
|
|
|
|
var score = 0;
|
|
|
|
|
var userData = _userDataRepository.GetUserData(user, i);
|
|
|
|
|
typeof(Movie).Name,
|
|
|
|
|
//typeof(Trailer).Name,
|
|
|
|
|
//typeof(LiveTvProgram).Name
|
|
|
|
|
},
|
|
|
|
|
// IsMovie = true
|
|
|
|
|
SortBy = new[] { ItemSortBy.DatePlayed, ItemSortBy.Random },
|
|
|
|
|
SortOrder = SortOrder.Descending,
|
|
|
|
|
Limit = 7
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (userData.IsFavorite)
|
|
|
|
|
var recentlyPlayedMovies = _libraryManager.GetItemList(query, parentIds).ToList();
|
|
|
|
|
|
|
|
|
|
var likedMovies = _libraryManager.GetItemList(new InternalItemsQuery(user)
|
|
|
|
|
{
|
|
|
|
|
score = 2;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
IncludeItemTypes = new[]
|
|
|
|
|
{
|
|
|
|
|
score = userData.Likes.HasValue ? userData.Likes.Value ? 1 : -1 : 0;
|
|
|
|
|
}
|
|
|
|
|
typeof(Movie).Name,
|
|
|
|
|
typeof(Trailer).Name,
|
|
|
|
|
typeof(LiveTvProgram).Name
|
|
|
|
|
},
|
|
|
|
|
IsMovie = true,
|
|
|
|
|
SortBy = new[] { ItemSortBy.Random },
|
|
|
|
|
SortOrder = SortOrder.Descending,
|
|
|
|
|
Limit = 10,
|
|
|
|
|
IsFavoriteOrLiked = true,
|
|
|
|
|
ExcludeItemIds = recentlyPlayedMovies.Select(i => i.Id.ToString("N")).ToArray()
|
|
|
|
|
|
|
|
|
|
return new Tuple<BaseItem, int>(i, score);
|
|
|
|
|
})
|
|
|
|
|
.OrderByDescending(i => i.Item2)
|
|
|
|
|
.ThenBy(i => Guid.NewGuid())
|
|
|
|
|
.Where(i => i.Item2 > 0)
|
|
|
|
|
.Select(i => i.Item1)
|
|
|
|
|
.Where(i => !excludeFromLiked.Contains(i));
|
|
|
|
|
}, parentIds);
|
|
|
|
|
|
|
|
|
|
var mostRecentMovies = recentlyPlayedMovies.Take(6).ToList();
|
|
|
|
|
// Get recently played directors
|
|
|
|
@ -286,8 +276,8 @@ namespace MediaBrowser.Api.Movies
|
|
|
|
|
var similarToRecentlyPlayed = GetSimilarTo(user, allMovies, recentlyPlayedMovies.Take(7).OrderBy(i => Guid.NewGuid()), itemLimit, dtoOptions, RecommendationType.SimilarToRecentlyPlayed).GetEnumerator();
|
|
|
|
|
var similarToLiked = GetSimilarTo(user, allMovies, likedMovies, itemLimit, dtoOptions, RecommendationType.SimilarToLikedItem).GetEnumerator();
|
|
|
|
|
|
|
|
|
|
var hasDirectorFromRecentlyPlayed = GetWithDirector(user, allMovies, recentDirectors, itemLimit, dtoOptions, RecommendationType.HasDirectorFromRecentlyPlayed).GetEnumerator();
|
|
|
|
|
var hasActorFromRecentlyPlayed = GetWithActor(user, allMovies, recentActors, itemLimit, dtoOptions, RecommendationType.HasActorFromRecentlyPlayed).GetEnumerator();
|
|
|
|
|
var hasDirectorFromRecentlyPlayed = GetWithDirector(user, recentDirectors, itemLimit, dtoOptions, RecommendationType.HasDirectorFromRecentlyPlayed).GetEnumerator();
|
|
|
|
|
var hasActorFromRecentlyPlayed = GetWithActor(user, recentActors, itemLimit, dtoOptions, RecommendationType.HasActorFromRecentlyPlayed).GetEnumerator();
|
|
|
|
|
|
|
|
|
|
var categoryTypes = new List<IEnumerator<RecommendationDto>>
|
|
|
|
|
{
|
|
|
|
@ -330,14 +320,25 @@ namespace MediaBrowser.Api.Movies
|
|
|
|
|
return categories.OrderBy(i => i.RecommendationType).ThenBy(i => Guid.NewGuid());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IEnumerable<RecommendationDto> GetWithDirector(User user, List<BaseItem> allMovies, IEnumerable<string> directors, int itemLimit, DtoOptions dtoOptions, RecommendationType type)
|
|
|
|
|
private IEnumerable<RecommendationDto> GetWithDirector(User user, IEnumerable<string> names, int itemLimit, DtoOptions dtoOptions, RecommendationType type)
|
|
|
|
|
{
|
|
|
|
|
var userId = user.Id;
|
|
|
|
|
|
|
|
|
|
foreach (var director in directors)
|
|
|
|
|
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,
|
|
|
|
|
PersonTypes = new[] { PersonType.Director },
|
|
|
|
|
IncludeItemTypes = new[]
|
|
|
|
|
{
|
|
|
|
|
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)))
|
|
|
|
|
typeof(Movie).Name,
|
|
|
|
|
typeof(Trailer).Name,
|
|
|
|
|
typeof(LiveTvProgram).Name
|
|
|
|
|
},
|
|
|
|
|
IsMovie = true
|
|
|
|
|
|
|
|
|
|
}).DistinctBy(i => i.GetProviderId(MetadataProviders.Imdb) ?? Guid.NewGuid().ToString("N"))
|
|
|
|
|
.Take(itemLimit)
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
@ -345,8 +346,8 @@ namespace MediaBrowser.Api.Movies
|
|
|
|
|
{
|
|
|
|
|
yield return new RecommendationDto
|
|
|
|
|
{
|
|
|
|
|
BaselineItemName = director,
|
|
|
|
|
CategoryId = director.GetMD5().ToString("N"),
|
|
|
|
|
BaselineItemName = name,
|
|
|
|
|
CategoryId = name.GetMD5().ToString("N"),
|
|
|
|
|
RecommendationType = type,
|
|
|
|
|
Items = _dtoService.GetBaseItemDtos(items, dtoOptions, user).ToArray()
|
|
|
|
|
};
|
|
|
|
@ -354,18 +355,24 @@ namespace MediaBrowser.Api.Movies
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IEnumerable<RecommendationDto> GetWithActor(User user, List<BaseItem> allMovies, IEnumerable<string> names, int itemLimit, DtoOptions dtoOptions, RecommendationType type)
|
|
|
|
|
private IEnumerable<RecommendationDto> GetWithActor(User user, IEnumerable<string> names, int itemLimit, DtoOptions dtoOptions, RecommendationType type)
|
|
|
|
|
{
|
|
|
|
|
foreach (var name in names)
|
|
|
|
|
{
|
|
|
|
|
var itemsWithActor = _libraryManager.GetItemIds(new InternalItemsQuery(user)
|
|
|
|
|
var items = _libraryManager.GetItemList(new InternalItemsQuery(user)
|
|
|
|
|
{
|
|
|
|
|
Person = name
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
Person = name,
|
|
|
|
|
// Account for duplicates by imdb id, since the database doesn't support this yet
|
|
|
|
|
Limit = itemLimit + 2,
|
|
|
|
|
IncludeItemTypes = new[]
|
|
|
|
|
{
|
|
|
|
|
typeof(Movie).Name,
|
|
|
|
|
typeof(Trailer).Name,
|
|
|
|
|
typeof(LiveTvProgram).Name
|
|
|
|
|
},
|
|
|
|
|
IsMovie = true
|
|
|
|
|
|
|
|
|
|
var items = allMovies
|
|
|
|
|
.Where(i => itemsWithActor.Contains(i.Id))
|
|
|
|
|
}).DistinctBy(i => i.GetProviderId(MetadataProviders.Imdb) ?? Guid.NewGuid().ToString("N"))
|
|
|
|
|
.Take(itemLimit)
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|