using MediaBrowser.Controller.Drawing; using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Persistence; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Logging; using MediaBrowser.Model.Querying; using ServiceStack; using System; using System.Collections.Generic; using System.Linq; namespace MediaBrowser.Api.DefaultTheme { [Route("/MBT/DefaultTheme/Games", "GET")] public class GetGamesView : IReturn { [ApiMember(Name = "UserId", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")] public Guid UserId { get; set; } [ApiMember(Name = "RecentlyPlayedGamesLimit", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")] public int RecentlyPlayedGamesLimit { get; set; } public string ParentId { get; set; } } [Route("/MBT/DefaultTheme/TV", "GET")] public class GetTvView : IReturn { [ApiMember(Name = "UserId", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")] public Guid UserId { get; set; } [ApiMember(Name = "ComedyGenre", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)] public string ComedyGenre { get; set; } [ApiMember(Name = "RomanceGenre", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)] public string RomanceGenre { get; set; } [ApiMember(Name = "TopCommunityRating", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")] public double TopCommunityRating { get; set; } [ApiMember(Name = "NextUpEpisodeLimit", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")] public int NextUpEpisodeLimit { get; set; } [ApiMember(Name = "ResumableEpisodeLimit", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")] public int ResumableEpisodeLimit { get; set; } [ApiMember(Name = "LatestEpisodeLimit", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")] public int LatestEpisodeLimit { get; set; } public string ParentId { get; set; } } [Route("/MBT/DefaultTheme/Movies", "GET")] public class GetMovieView : IReturn { [ApiMember(Name = "UserId", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")] public Guid UserId { get; set; } [ApiMember(Name = "FamilyGenre", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)] public string FamilyGenre { get; set; } [ApiMember(Name = "ComedyGenre", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)] public string ComedyGenre { get; set; } [ApiMember(Name = "RomanceGenre", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)] public string RomanceGenre { get; set; } [ApiMember(Name = "LatestMoviesLimit", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")] public int LatestMoviesLimit { get; set; } [ApiMember(Name = "LatestTrailersLimit", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")] public int LatestTrailersLimit { get; set; } public string ParentId { get; set; } } [Route("/MBT/DefaultTheme/Favorites", "GET")] public class GetFavoritesView : IReturn { [ApiMember(Name = "UserId", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")] public Guid UserId { get; set; } } public class DefaultThemeService : BaseApiService { private readonly IUserManager _userManager; private readonly IDtoService _dtoService; private readonly ILogger _logger; private readonly ILibraryManager _libraryManager; private readonly IUserDataManager _userDataManager; private readonly IImageProcessor _imageProcessor; private readonly IItemRepository _itemRepo; public DefaultThemeService(IUserManager userManager, IDtoService dtoService, ILogger logger, ILibraryManager libraryManager, IImageProcessor imageProcessor, IUserDataManager userDataManager, IItemRepository itemRepo) { _userManager = userManager; _dtoService = dtoService; _logger = logger; _libraryManager = libraryManager; _imageProcessor = imageProcessor; _userDataManager = userDataManager; _itemRepo = itemRepo; } public object Get(GetFavoritesView request) { var user = _userManager.GetUserById(request.UserId); var allItems = user.RootFolder.GetRecursiveChildren(user) .ToList(); var allFavoriteItems = allItems.Where(i => _userDataManager.GetUserData(user.Id, i.GetUserDataKey()).IsFavorite) .ToList(); var itemsWithImages = allFavoriteItems.Where(i => !string.IsNullOrEmpty(i.PrimaryImagePath)) .ToList(); var itemsWithBackdrops = allFavoriteItems.Where(i => i.GetImages(ImageType.Backdrop).Any()) .ToList(); var view = new FavoritesView(); var fields = new List(); view.BackdropItems = FilterItemsForBackdropDisplay(itemsWithBackdrops) .Randomize("backdrop") .Take(10) .Select(i => _dtoService.GetBaseItemDto(i, fields, user)) .ToList(); var spotlightItems = itemsWithBackdrops.Randomize("spotlight") .Take(10) .ToList(); view.SpotlightItems = spotlightItems .Select(i => _dtoService.GetBaseItemDto(i, fields, user)) .ToList(); fields.Add(ItemFields.PrimaryImageAspectRatio); view.Albums = itemsWithImages .OfType() .Randomize() .Take(4) .Select(i => _dtoService.GetBaseItemDto(i, fields, user)) .ToList(); view.Books = itemsWithImages .OfType() .Randomize() .Take(6) .Select(i => _dtoService.GetBaseItemDto(i, fields, user)) .ToList(); view.Episodes = itemsWithImages .OfType() .Randomize() .Take(6) .Select(i => _dtoService.GetBaseItemDto(i, fields, user)) .ToList(); view.Games = itemsWithImages .OfType() .Randomize() .Take(6) .Select(i => _dtoService.GetBaseItemDto(i, fields, user)) .ToList(); view.Movies = itemsWithImages .OfType() .Randomize() .Take(6) .Select(i => _dtoService.GetBaseItemDto(i, fields, user)) .ToList(); view.Series = itemsWithImages .OfType() .Randomize() .Take(6) .Select(i => _dtoService.GetBaseItemDto(i, fields, user)) .ToList(); view.Songs = itemsWithImages .OfType