update default theme api

pull/702/head
Luke Pulverenti 11 years ago
parent 8d6a7a9992
commit d770a8af7c

@ -41,7 +41,7 @@ namespace MediaBrowser.Api.DefaultTheme
private readonly ILibraryManager _libraryManager; private readonly ILibraryManager _libraryManager;
private readonly ILocalizationManager _localization; private readonly ILocalizationManager _localization;
public DefaultThemeService(IUserManager userManager, IDtoService dtoService, ILogger logger, ILibraryManager libraryManager, ILocalizationManager localization) public DefaultThemeService(IUserManager userManager, IDtoService dtoService, ILogger logger, ILibraryManager libraryManager, ILocalizationManager localization)
{ {
_userManager = userManager; _userManager = userManager;
@ -70,21 +70,20 @@ namespace MediaBrowser.Api.DefaultTheme
var view = new TvView(); var view = new TvView();
var fields = Enum.GetNames(typeof(ItemFields)) var fields = new List<ItemFields>();
.Select(i => (ItemFields)Enum.Parse(typeof(ItemFields), i, true))
.ToList();
var spotlightItemTasks = seriesWithBackdrops var spotlightItemTasks = seriesWithBackdrops
.OrderByDescending(i => GetResolution(i, i.BackdropImagePaths[0]))
.Take(60)
.OrderBy(i => Guid.NewGuid()) .OrderBy(i => Guid.NewGuid())
.Take(30)
.Select(i => _dtoService.GetBaseItemDto(i, fields, user)); .Select(i => _dtoService.GetBaseItemDto(i, fields, user));
view.SpotlightItems = await Task.WhenAll(spotlightItemTasks).ConfigureAwait(false); view.SpotlightItems = await Task.WhenAll(spotlightItemTasks).ConfigureAwait(false);
view.ShowsItems = series view.ShowsItems = series
.Where(i => !string.IsNullOrEmpty(i.PrimaryImagePath)) .Where(i => i.BackdropImagePaths.Count > 0)
.OrderBy(i => Guid.NewGuid()) .OrderBy(i => Guid.NewGuid())
.Select(i => GetItemStub(i, ImageType.Primary)) .Select(i => GetItemStub(i, ImageType.Backdrop))
.Where(i => i != null) .Where(i => i != null)
.Take(3) .Take(3)
.ToArray(); .ToArray();
@ -131,25 +130,24 @@ namespace MediaBrowser.Api.DefaultTheme
view.FamilyMoviePercentage = 100 * familyMovies.Count; view.FamilyMoviePercentage = 100 * familyMovies.Count;
view.FamilyMoviePercentage /= movies.Count; view.FamilyMoviePercentage /= movies.Count;
var moviesWithImages = movies
.Where(i => !string.IsNullOrEmpty(i.PrimaryImagePath))
.ToList();
var fields = Enum.GetNames(typeof(ItemFields)) var moviesWithBackdrops = movies
.Select(i => (ItemFields)Enum.Parse(typeof(ItemFields), i, true)) .Where(i => i.BackdropImagePaths.Count > 0)
.ToList(); .ToList();
var fields = new List<ItemFields>();
var spotlightItemTasks = itemsWithBackdrops var spotlightItemTasks = itemsWithBackdrops
.OrderByDescending(i => GetResolution(i, i.BackdropImagePaths[0]))
.Take(60)
.OrderBy(i => Guid.NewGuid()) .OrderBy(i => Guid.NewGuid())
.Take(30)
.Select(i => _dtoService.GetBaseItemDto(i, fields, user)); .Select(i => _dtoService.GetBaseItemDto(i, fields, user));
view.SpotlightItems = await Task.WhenAll(spotlightItemTasks).ConfigureAwait(false); view.SpotlightItems = await Task.WhenAll(spotlightItemTasks).ConfigureAwait(false);
view.MovieItems = moviesWithImages view.MovieItems = moviesWithBackdrops
.OrderBy(i => Guid.NewGuid()) .OrderBy(i => Guid.NewGuid())
.Select(i => GetItemStub(i, ImageType.Primary)) .Select(i => GetItemStub(i, ImageType.Backdrop))
.Where(i => i != null) .Where(i => i != null)
.Take(3) .Take(3)
.ToArray(); .ToArray();
@ -165,33 +163,33 @@ namespace MediaBrowser.Api.DefaultTheme
view.BoxSetItems = items view.BoxSetItems = items
.OfType<BoxSet>() .OfType<BoxSet>()
.Where(i => !string.IsNullOrEmpty(i.PrimaryImagePath)) .Where(i => i.BackdropImagePaths.Count > 0)
.OrderBy(i => Guid.NewGuid()) .OrderBy(i => Guid.NewGuid())
.Select(i => GetItemStub(i, ImageType.Primary)) .Select(i => GetItemStub(i, ImageType.Backdrop))
.Where(i => i != null) .Where(i => i != null)
.Take(3) .Take(3)
.ToArray(); .ToArray();
view.ThreeDItems = moviesWithImages view.ThreeDItems = moviesWithBackdrops
.Where(i => i.Is3D) .Where(i => i.Is3D)
.OrderBy(i => Guid.NewGuid()) .OrderBy(i => Guid.NewGuid())
.Select(i => GetItemStub(i, ImageType.Primary)) .Select(i => GetItemStub(i, ImageType.Backdrop))
.Where(i => i != null) .Where(i => i != null)
.Take(3) .Take(3)
.ToArray(); .ToArray();
view.HDItems = hdMovies view.HDItems = hdMovies
.Where(i => !string.IsNullOrEmpty(i.PrimaryImagePath)) .Where(i => i.BackdropImagePaths.Count > 0)
.OrderBy(i => Guid.NewGuid()) .OrderBy(i => Guid.NewGuid())
.Select(i => GetItemStub(i, ImageType.Primary)) .Select(i => GetItemStub(i, ImageType.Backdrop))
.Where(i => i != null) .Where(i => i != null)
.Take(3) .Take(3)
.ToArray(); .ToArray();
view.FamilyMovies = familyMovies view.FamilyMovies = familyMovies
.Where(i => !string.IsNullOrEmpty(i.PrimaryImagePath)) .Where(i => i.BackdropImagePaths.Count > 0)
.OrderBy(i => Guid.NewGuid()) .OrderBy(i => Guid.NewGuid())
.Select(i => GetItemStub(i, ImageType.Primary)) .Select(i => GetItemStub(i, ImageType.Backdrop))
.Where(i => i != null) .Where(i => i != null)
.Take(3) .Take(3)
.ToArray(); .ToArray();
@ -201,6 +199,22 @@ namespace MediaBrowser.Api.DefaultTheme
return view; return view;
} }
private double GetResolution(BaseItem item, string path)
{
try
{
var date = Kernel.Instance.ImageManager.GetImageDateModified(item, path);
var size = Kernel.Instance.ImageManager.GetImageSize(path, date).Result;
return size.Width;
}
catch
{
return 0;
}
}
private bool IsFamilyMovie(BaseItem item, int? baselineRating) private bool IsFamilyMovie(BaseItem item, int? baselineRating)
{ {
var ratingString = item.CustomRating; var ratingString = item.CustomRating;

@ -509,7 +509,7 @@ namespace MediaBrowser.Api.UserLibrary
// Max official rating // Max official rating
if (!string.IsNullOrEmpty(request.MaxOfficialRating)) if (!string.IsNullOrEmpty(request.MaxOfficialRating))
{ {
var level = _localization.GetRatingLevel(request.MinOfficialRating); var level = _localization.GetRatingLevel(request.MaxOfficialRating);
if (level.HasValue) if (level.HasValue)
{ {

Loading…
Cancel
Save