From 39186cc2da554c0f2bdfc5653bbc71853eb3fa41 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 18 Oct 2013 12:09:47 -0400 Subject: [PATCH] updated mbt endpoints --- .../DefaultTheme/DefaultThemeService.cs | 92 +++++++++++++++---- MediaBrowser.Api/DefaultTheme/Models.cs | 17 ++-- .../Library/Resolvers/TV/SeriesResolver.cs | 2 +- .../ApplicationHost.cs | 4 +- 4 files changed, 88 insertions(+), 27 deletions(-) diff --git a/MediaBrowser.Api/DefaultTheme/DefaultThemeService.cs b/MediaBrowser.Api/DefaultTheme/DefaultThemeService.cs index 08ddc764c..6c7ba96ec 100644 --- a/MediaBrowser.Api/DefaultTheme/DefaultThemeService.cs +++ b/MediaBrowser.Api/DefaultTheme/DefaultThemeService.cs @@ -64,16 +64,18 @@ namespace MediaBrowser.Api.DefaultTheme 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) + 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(GetHomeView request) @@ -124,6 +126,7 @@ namespace MediaBrowser.Api.DefaultTheme .ToList(); var gamesWithImages = items.OfType().Where(i => !string.IsNullOrEmpty(i.PrimaryImagePath)).ToList(); + var itemsWithBackdrops = FilterItemsForBackdropDisplay(items.Where(i => i.BackdropImagePaths.Count > 0)).ToList(); var view = new GamesView(); @@ -143,8 +146,15 @@ namespace MediaBrowser.Api.DefaultTheme .OrderBy(i => Guid.NewGuid()) .Select(i => GetItemStub(i, ImageType.Primary)) .Where(i => i != null) - .Take(3) + .Take(1) .ToList(); + + view.MiniSpotlights = itemsWithBackdrops + .OfType() + .OrderBy(i => Guid.NewGuid()) + .Take(3) + .Select(i => _dtoService.GetBaseItemDto(i, fields, user)) + .ToList(); return view; } @@ -190,7 +200,7 @@ namespace MediaBrowser.Api.DefaultTheme .OrderBy(i => Guid.NewGuid()) .Select(i => GetItemStub(i, ImageType.Backdrop)) .Where(i => i != null) - .Take(3) + .Take(1) .ToList(); var romanceGenres = request.RomanceGenre.Split(',').ToDictionary(i => i, StringComparer.OrdinalIgnoreCase); @@ -201,7 +211,7 @@ namespace MediaBrowser.Api.DefaultTheme .OrderBy(i => Guid.NewGuid()) .Select(i => GetItemStub(i, ImageType.Backdrop)) .Where(i => i != null) - .Take(3) + .Take(1) .ToList(); view.ComedyItems = seriesWithBackdrops @@ -209,11 +219,17 @@ namespace MediaBrowser.Api.DefaultTheme .OrderBy(i => Guid.NewGuid()) .Select(i => GetItemStub(i, ImageType.Backdrop)) .Where(i => i != null) - .Take(3) + .Take(1) .ToList(); - view.ActorItems = GetActors(series); + view.ActorItems = GetActors(series, user.Id); + view.MiniSpotlights = seriesWithBackdrops + .OrderBy(i => Guid.NewGuid()) + .Take(3) + .Select(i => _dtoService.GetBaseItemDto(i, fields, user)) + .ToList(); + return view; } @@ -262,7 +278,7 @@ namespace MediaBrowser.Api.DefaultTheme .OrderBy(i => Guid.NewGuid()) .Select(i => GetItemStub(i, ImageType.Backdrop)) .Where(i => i != null) - .Take(3) + .Take(1) .ToList(); view.TrailerItems = items @@ -271,7 +287,7 @@ namespace MediaBrowser.Api.DefaultTheme .OrderBy(i => Guid.NewGuid()) .Select(i => GetItemStub(i, ImageType.Primary)) .Where(i => i != null) - .Take(3) + .Take(1) .ToList(); view.BoxSetItems = items @@ -280,7 +296,7 @@ namespace MediaBrowser.Api.DefaultTheme .OrderBy(i => Guid.NewGuid()) .Select(i => GetItemStub(i, ImageType.Backdrop)) .Where(i => i != null) - .Take(3) + .Take(1) .ToList(); view.ThreeDItems = moviesWithBackdrops @@ -288,7 +304,7 @@ namespace MediaBrowser.Api.DefaultTheme .OrderBy(i => Guid.NewGuid()) .Select(i => GetItemStub(i, ImageType.Backdrop)) .Where(i => i != null) - .Take(3) + .Take(1) .ToList(); var romanceGenres = request.RomanceGenre.Split(',').ToDictionary(i => i, StringComparer.OrdinalIgnoreCase); @@ -299,7 +315,7 @@ namespace MediaBrowser.Api.DefaultTheme .OrderBy(i => Guid.NewGuid()) .Select(i => GetItemStub(i, ImageType.Backdrop)) .Where(i => i != null) - .Take(3) + .Take(1) .ToList(); view.ComedyItems = moviesWithBackdrops @@ -307,7 +323,7 @@ namespace MediaBrowser.Api.DefaultTheme .OrderBy(i => Guid.NewGuid()) .Select(i => GetItemStub(i, ImageType.Backdrop)) .Where(i => i != null) - .Take(3) + .Take(1) .ToList(); view.HDItems = hdMovies @@ -315,7 +331,7 @@ namespace MediaBrowser.Api.DefaultTheme .OrderBy(i => Guid.NewGuid()) .Select(i => GetItemStub(i, ImageType.Backdrop)) .Where(i => i != null) - .Take(3) + .Take(1) .ToList(); view.FamilyMovies = familyMovies @@ -323,10 +339,16 @@ namespace MediaBrowser.Api.DefaultTheme .OrderBy(i => Guid.NewGuid()) .Select(i => GetItemStub(i, ImageType.Backdrop)) .Where(i => i != null) - .Take(3) + .Take(1) .ToList(); - view.PeopleItems = GetActors(items); + view.PeopleItems = GetActors(items, user.Id); + + view.MiniSpotlights = moviesWithBackdrops + .OrderBy(i => Guid.NewGuid()) + .Take(3) + .Select(i => _dtoService.GetBaseItemDto(i, fields, user)) + .ToList(); return view; } @@ -366,7 +388,7 @@ namespace MediaBrowser.Api.DefaultTheme } } - private List GetActors(IEnumerable mediaItems) + private List GetActors(IEnumerable mediaItems, Guid userId) { var actors = mediaItems.SelectMany(i => i.People) .Select(i => i.Name) @@ -374,7 +396,7 @@ namespace MediaBrowser.Api.DefaultTheme .OrderBy(i => Guid.NewGuid()) .ToList(); - return actors.Select(actor => + var result = actors.Select(actor => { try { @@ -382,7 +404,12 @@ namespace MediaBrowser.Api.DefaultTheme if (!string.IsNullOrEmpty(person.PrimaryImagePath)) { - return GetItemStub(person, ImageType.Primary); + var userdata = _userDataManager.GetUserData(userId, person.GetUserDataKey()); + + if (userdata.IsFavorite || (userdata.Likes ?? false)) + { + return GetItemStub(person, ImageType.Primary); + } } } catch (Exception ex) @@ -393,8 +420,35 @@ namespace MediaBrowser.Api.DefaultTheme return null; }) .Where(i => i != null) - .Take(3) + .Take(1) .ToList(); + + if (result.Count == 0) + { + result = actors.Select(actor => + { + try + { + var person = _libraryManager.GetPerson(actor); + + if (!string.IsNullOrEmpty(person.PrimaryImagePath)) + { + return GetItemStub(person, ImageType.Primary); + } + } + catch (Exception ex) + { + _logger.ErrorException("Error getting person {0}", ex, actor); + } + + return null; + }) + .Where(i => i != null) + .Take(1) + .ToList(); + } + + return result; } private ItemStub GetItemStub(BaseItem item, ImageType imageType) diff --git a/MediaBrowser.Api/DefaultTheme/Models.cs b/MediaBrowser.Api/DefaultTheme/Models.cs index 6b0c39ae7..1fc230fd4 100644 --- a/MediaBrowser.Api/DefaultTheme/Models.cs +++ b/MediaBrowser.Api/DefaultTheme/Models.cs @@ -13,9 +13,8 @@ namespace MediaBrowser.Api.DefaultTheme public ImageType ImageType { get; set; } } - public class MoviesView + public class MoviesView : BaseView { - public List SpotlightItems { get; set; } public List MovieItems { get; set; } public List PeopleItems { get; set; } @@ -34,9 +33,8 @@ namespace MediaBrowser.Api.DefaultTheme public double HDMoviePercentage { get; set; } } - public class TvView + public class TvView : BaseView { - public List SpotlightItems { get; set; } public List ShowsItems { get; set; } public List ActorItems { get; set; } @@ -44,10 +42,17 @@ namespace MediaBrowser.Api.DefaultTheme public List ComedyItems { get; set; } } - public class GamesView + public class GamesView : BaseView + { + public List MultiPlayerItems { get; set; } + + } + + public class BaseView { public List SpotlightItems { get; set; } - public List MultiPlayerItems { get; set; } + + public List MiniSpotlights { get; set; } } public class HomeView diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/SeriesResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/SeriesResolver.cs index 38a3d44bb..9a2f6c637 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/SeriesResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/SeriesResolver.cs @@ -43,7 +43,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV } // Optimization to avoid running these tests against Seasons - if (args.Parent is Series || args.Parent is MusicArtist || args.Parent is MusicAlbum || args.Parent is BoxSet) + if (args.Parent is Series || args.Parent is MusicArtist || args.Parent is MusicAlbum) { return null; } diff --git a/MediaBrowser.ServerApplication/ApplicationHost.cs b/MediaBrowser.ServerApplication/ApplicationHost.cs index ae4f09d3e..25a254fa9 100644 --- a/MediaBrowser.ServerApplication/ApplicationHost.cs +++ b/MediaBrowser.ServerApplication/ApplicationHost.cs @@ -459,8 +459,10 @@ namespace MediaBrowser.ServerApplication { ServerManager.Start(HttpServerUrlPrefix, ServerConfigurationManager.Configuration.EnableHttpLevelLogging); } - catch + catch (Exception ex) { + Logger.ErrorException("Error starting http server", ex); + if (retryOnFailure) { RegisterServerWithAdministratorAccess();