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.Model.Entities; using MediaBrowser.Model.Logging; using MediaBrowser.Model.Querying; using ServiceStack.ServiceHost; 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; } } [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; } } [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; } } [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; public DefaultThemeService(IUserManager userManager, IDtoService dtoService, ILogger logger, ILibraryManager libraryManager, IImageProcessor imageProcessor, IUserDataManager userDataManager) { _userManager = userManager; _dtoService = dtoService; _logger = logger; _libraryManager = libraryManager; _imageProcessor = imageProcessor; _userDataManager = userDataManager; } public object Get(GetFavoritesView request) { var user = _userManager.GetUserById(request.UserId); var allItems = user.RootFolder.GetRecursiveChildren(user, i => _userDataManager.GetUserData(user.Id, i.GetUserDataKey()).IsFavorite) .ToList(); var itemsWithImages = allItems.Where(i => !string.IsNullOrEmpty(i.PrimaryImagePath)) .ToList(); var itemsWithBackdrops = allItems.Where(i => i.BackdropImagePaths.Count > 0) .ToList(); var view = new FavoritesView(); var fields = new List(); view.BackdropItems = FilterItemsForBackdropDisplay(itemsWithBackdrops.OrderBy(i => Guid.NewGuid())) .Take(10) .Select(i => _dtoService.GetBaseItemDto(i, fields, user)) .ToList(); var spotlightItems = itemsWithBackdrops.OrderBy(i => Guid.NewGuid()) .Take(10) .ToList(); view.SpotlightItems = spotlightItems .Select(i => _dtoService.GetBaseItemDto(i, fields, user)) .ToList(); view.Albums = itemsWithImages .OfType() .OrderBy(i => Guid.NewGuid()) .Take(4) .Select(i => _dtoService.GetBaseItemDto(i, fields, user)) .ToList(); view.Books = itemsWithImages .OfType() .OrderBy(i => Guid.NewGuid()) .Take(6) .Select(i => _dtoService.GetBaseItemDto(i, fields, user)) .ToList(); view.Episodes = itemsWithImages .OfType() .OrderBy(i => Guid.NewGuid()) .Take(6) .Select(i => _dtoService.GetBaseItemDto(i, fields, user)) .ToList(); view.Games = itemsWithImages .OfType() .OrderBy(i => Guid.NewGuid()) .Take(6) .Select(i => _dtoService.GetBaseItemDto(i, fields, user)) .ToList(); view.Movies = itemsWithImages .OfType() .OrderBy(i => Guid.NewGuid()) .Take(6) .Select(i => _dtoService.GetBaseItemDto(i, fields, user)) .ToList(); view.Series = itemsWithImages .OfType() .OrderBy(i => Guid.NewGuid()) .Take(6) .Select(i => _dtoService.GetBaseItemDto(i, fields, user)) .ToList(); view.Songs = itemsWithImages .OfType