2013-09-18 18:49:06 +00:00
|
|
|
|
using MediaBrowser.Controller.Drawing;
|
2013-09-10 03:13:12 +00:00
|
|
|
|
using MediaBrowser.Controller.Dto;
|
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2013-09-15 17:34:48 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities.Audio;
|
2013-09-10 03:13:12 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities.Movies;
|
|
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
|
|
|
|
using MediaBrowser.Controller.Library;
|
2013-09-11 17:54:59 +00:00
|
|
|
|
using MediaBrowser.Controller.Localization;
|
2013-09-10 03:13:12 +00:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
using MediaBrowser.Model.Logging;
|
2013-09-11 17:54:59 +00:00
|
|
|
|
using MediaBrowser.Model.Querying;
|
2013-09-10 03:13:12 +00:00
|
|
|
|
using ServiceStack.ServiceHost;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Api.DefaultTheme
|
|
|
|
|
{
|
2013-09-15 21:53:18 +00:00
|
|
|
|
[Route("/MBT/DefaultTheme/Games", "GET")]
|
|
|
|
|
public class GetGamesView : IReturn<GamesView>
|
|
|
|
|
{
|
|
|
|
|
[ApiMember(Name = "UserId", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
|
|
|
|
|
public Guid UserId { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-10 03:13:12 +00:00
|
|
|
|
[Route("/MBT/DefaultTheme/TV", "GET")]
|
|
|
|
|
public class GetTvView : IReturn<TvView>
|
|
|
|
|
{
|
|
|
|
|
[ApiMember(Name = "UserId", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
|
|
|
|
|
public Guid UserId { get; set; }
|
2013-09-15 17:34:48 +00:00
|
|
|
|
|
|
|
|
|
[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; }
|
2013-09-10 03:13:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Route("/MBT/DefaultTheme/Movies", "GET")]
|
|
|
|
|
public class GetMovieView : IReturn<MoviesView>
|
|
|
|
|
{
|
|
|
|
|
[ApiMember(Name = "UserId", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
|
|
|
|
|
public Guid UserId { get; set; }
|
2013-09-11 17:54:59 +00:00
|
|
|
|
|
2013-09-15 19:33:23 +00:00
|
|
|
|
[ApiMember(Name = "FamilyGenre", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
|
|
|
|
|
public string FamilyGenre { get; set; }
|
2013-09-15 17:34:48 +00:00
|
|
|
|
|
|
|
|
|
[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/Home", "GET")]
|
|
|
|
|
public class GetHomeView : IReturn<HomeView>
|
|
|
|
|
{
|
|
|
|
|
[ApiMember(Name = "UserId", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
|
|
|
|
|
public Guid UserId { get; set; }
|
2013-09-10 03:13:12 +00:00
|
|
|
|
}
|
2013-09-11 17:54:59 +00:00
|
|
|
|
|
2013-09-10 03:13:12 +00:00
|
|
|
|
public class DefaultThemeService : BaseApiService
|
|
|
|
|
{
|
|
|
|
|
private readonly IUserManager _userManager;
|
|
|
|
|
private readonly IDtoService _dtoService;
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
private readonly ILibraryManager _libraryManager;
|
|
|
|
|
|
2013-09-18 18:49:06 +00:00
|
|
|
|
private readonly IImageProcessor _imageProcessor;
|
2013-09-12 01:35:18 +00:00
|
|
|
|
|
2013-10-04 20:08:45 +00:00
|
|
|
|
public DefaultThemeService(IUserManager userManager, IDtoService dtoService, ILogger logger, ILibraryManager libraryManager, IImageProcessor imageProcessor)
|
2013-09-10 03:13:12 +00:00
|
|
|
|
{
|
|
|
|
|
_userManager = userManager;
|
|
|
|
|
_dtoService = dtoService;
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_libraryManager = libraryManager;
|
2013-09-18 18:49:06 +00:00
|
|
|
|
_imageProcessor = imageProcessor;
|
2013-09-10 03:13:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-15 17:34:48 +00:00
|
|
|
|
public object Get(GetHomeView request)
|
|
|
|
|
{
|
2013-09-18 18:49:06 +00:00
|
|
|
|
var result = GetHomeView(request);
|
2013-09-15 17:34:48 +00:00
|
|
|
|
|
|
|
|
|
return ToOptimizedResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-18 18:49:06 +00:00
|
|
|
|
private HomeView GetHomeView(GetHomeView request)
|
2013-09-15 17:34:48 +00:00
|
|
|
|
{
|
|
|
|
|
var user = _userManager.GetUserById(request.UserId);
|
|
|
|
|
|
|
|
|
|
var allItems = user.RootFolder.GetRecursiveChildren(user)
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
var itemsWithBackdrops = allItems.Where(i => i.BackdropImagePaths.Count > 0).ToList();
|
|
|
|
|
|
|
|
|
|
var view = new HomeView();
|
|
|
|
|
|
|
|
|
|
var fields = new List<ItemFields>();
|
|
|
|
|
|
|
|
|
|
var eligibleSpotlightItems = itemsWithBackdrops
|
|
|
|
|
.Where(i => i is Game || i is Movie || i is Series || i is MusicArtist);
|
|
|
|
|
|
2013-09-17 02:44:06 +00:00
|
|
|
|
var dtos = FilterItemsForBackdropDisplay(eligibleSpotlightItems)
|
2013-09-15 17:34:48 +00:00
|
|
|
|
.OrderBy(i => Guid.NewGuid())
|
|
|
|
|
.Take(50)
|
|
|
|
|
.Select(i => _dtoService.GetBaseItemDto(i, fields, user));
|
|
|
|
|
|
2013-09-20 00:53:18 +00:00
|
|
|
|
view.SpotlightItems = dtos.ToList();
|
2013-09-15 17:34:48 +00:00
|
|
|
|
|
|
|
|
|
return view;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-15 21:53:18 +00:00
|
|
|
|
public object Get(GetGamesView request)
|
|
|
|
|
{
|
2013-09-18 18:49:06 +00:00
|
|
|
|
var result = GetGamesView(request);
|
2013-09-15 21:53:18 +00:00
|
|
|
|
|
|
|
|
|
return ToOptimizedResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-18 18:49:06 +00:00
|
|
|
|
private GamesView GetGamesView(GetGamesView request)
|
2013-09-15 21:53:18 +00:00
|
|
|
|
{
|
|
|
|
|
var user = _userManager.GetUserById(request.UserId);
|
|
|
|
|
|
2013-10-05 14:17:27 +00:00
|
|
|
|
var items = user.RootFolder.GetRecursiveChildren(user, i => i is Game || i is GameSystem)
|
2013-09-15 21:53:18 +00:00
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
var itemsWithBackdrops = FilterItemsForBackdropDisplay(items.Where(i => i.BackdropImagePaths.Count > 0)).ToList();
|
|
|
|
|
|
|
|
|
|
var view = new GamesView();
|
|
|
|
|
|
|
|
|
|
var fields = new List<ItemFields>();
|
|
|
|
|
|
2013-09-17 02:44:06 +00:00
|
|
|
|
var dtos = itemsWithBackdrops
|
2013-09-15 21:53:18 +00:00
|
|
|
|
.OfType<Game>()
|
|
|
|
|
.OrderBy(i => Guid.NewGuid())
|
|
|
|
|
.Take(50)
|
|
|
|
|
.Select(i => _dtoService.GetBaseItemDto(i, fields, user));
|
|
|
|
|
|
2013-09-20 00:53:18 +00:00
|
|
|
|
view.SpotlightItems = dtos.ToList();
|
2013-09-17 02:08:18 +00:00
|
|
|
|
|
2013-09-15 21:53:18 +00:00
|
|
|
|
return view;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public object Get(GetMovieView request)
|
|
|
|
|
{
|
2013-09-18 18:49:06 +00:00
|
|
|
|
var result = GetMovieView(request);
|
2013-09-15 21:53:18 +00:00
|
|
|
|
|
|
|
|
|
return ToOptimizedResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-10 03:13:12 +00:00
|
|
|
|
public object Get(GetTvView request)
|
|
|
|
|
{
|
2013-09-18 18:49:06 +00:00
|
|
|
|
var result = GetTvView(request);
|
2013-09-10 03:13:12 +00:00
|
|
|
|
|
|
|
|
|
return ToOptimizedResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-18 18:49:06 +00:00
|
|
|
|
private TvView GetTvView(GetTvView request)
|
2013-09-10 03:13:12 +00:00
|
|
|
|
{
|
|
|
|
|
var user = _userManager.GetUserById(request.UserId);
|
|
|
|
|
|
|
|
|
|
var series = user.RootFolder.GetRecursiveChildren(user)
|
|
|
|
|
.OfType<Series>()
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
var seriesWithBackdrops = series.Where(i => i.BackdropImagePaths.Count > 0).ToList();
|
|
|
|
|
|
|
|
|
|
var view = new TvView();
|
|
|
|
|
|
2013-09-12 01:35:18 +00:00
|
|
|
|
var fields = new List<ItemFields>();
|
2013-09-11 17:54:59 +00:00
|
|
|
|
|
2013-09-17 02:44:06 +00:00
|
|
|
|
var dtos = FilterItemsForBackdropDisplay(seriesWithBackdrops)
|
2013-09-10 03:13:12 +00:00
|
|
|
|
.OrderBy(i => Guid.NewGuid())
|
2013-09-15 17:34:48 +00:00
|
|
|
|
.Take(50)
|
2013-09-19 17:45:48 +00:00
|
|
|
|
.AsParallel()
|
2013-09-11 17:54:59 +00:00
|
|
|
|
.Select(i => _dtoService.GetBaseItemDto(i, fields, user));
|
2013-09-10 03:13:12 +00:00
|
|
|
|
|
2013-09-20 00:53:18 +00:00
|
|
|
|
view.SpotlightItems = dtos.ToList();
|
2013-09-10 03:13:12 +00:00
|
|
|
|
|
|
|
|
|
view.ShowsItems = series
|
2013-09-12 01:35:18 +00:00
|
|
|
|
.Where(i => i.BackdropImagePaths.Count > 0)
|
2013-09-10 03:13:12 +00:00
|
|
|
|
.OrderBy(i => Guid.NewGuid())
|
2013-09-12 01:35:18 +00:00
|
|
|
|
.Select(i => GetItemStub(i, ImageType.Backdrop))
|
2013-09-10 03:13:12 +00:00
|
|
|
|
.Where(i => i != null)
|
|
|
|
|
.Take(3)
|
2013-09-20 00:53:18 +00:00
|
|
|
|
.ToList();
|
2013-09-10 03:13:12 +00:00
|
|
|
|
|
2013-09-15 17:34:48 +00:00
|
|
|
|
var romanceGenres = request.RomanceGenre.Split(',').ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);
|
|
|
|
|
var comedyGenres = request.ComedyGenre.Split(',').ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);
|
|
|
|
|
|
|
|
|
|
view.RomanceItems = seriesWithBackdrops
|
|
|
|
|
.Where(i => i.Genres.Any(romanceGenres.ContainsKey))
|
|
|
|
|
.OrderBy(i => Guid.NewGuid())
|
|
|
|
|
.Select(i => GetItemStub(i, ImageType.Backdrop))
|
|
|
|
|
.Where(i => i != null)
|
|
|
|
|
.Take(3)
|
2013-09-20 00:53:18 +00:00
|
|
|
|
.ToList();
|
2013-09-15 17:34:48 +00:00
|
|
|
|
|
|
|
|
|
view.ComedyItems = seriesWithBackdrops
|
|
|
|
|
.Where(i => i.Genres.Any(comedyGenres.ContainsKey))
|
|
|
|
|
.OrderBy(i => Guid.NewGuid())
|
|
|
|
|
.Select(i => GetItemStub(i, ImageType.Backdrop))
|
|
|
|
|
.Where(i => i != null)
|
|
|
|
|
.Take(3)
|
2013-09-20 00:53:18 +00:00
|
|
|
|
.ToList();
|
2013-09-15 17:34:48 +00:00
|
|
|
|
|
2013-09-17 02:08:18 +00:00
|
|
|
|
view.ActorItems = GetActors(series);
|
2013-09-10 03:13:12 +00:00
|
|
|
|
|
|
|
|
|
return view;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-18 18:49:06 +00:00
|
|
|
|
private MoviesView GetMovieView(GetMovieView request)
|
2013-09-10 03:13:12 +00:00
|
|
|
|
{
|
|
|
|
|
var user = _userManager.GetUserById(request.UserId);
|
|
|
|
|
|
2013-10-05 14:17:27 +00:00
|
|
|
|
var items = user.RootFolder.GetRecursiveChildren(user, i => i is Movie || i is Trailer || i is BoxSet)
|
2013-09-10 03:13:12 +00:00
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
// Exclude trailers from backdrops because they're not always 1080p
|
|
|
|
|
var itemsWithBackdrops = items.Where(i => i.BackdropImagePaths.Count > 0 && !(i is Trailer))
|
|
|
|
|
.ToList();
|
|
|
|
|
|
2013-09-11 17:54:59 +00:00
|
|
|
|
var view = new MoviesView();
|
|
|
|
|
|
|
|
|
|
var movies = items.OfType<Movie>()
|
|
|
|
|
.ToList();
|
|
|
|
|
|
2013-09-30 00:51:04 +00:00
|
|
|
|
var hdMovies = movies.Where(i => i.IsHD).ToList();
|
2013-09-11 17:54:59 +00:00
|
|
|
|
|
2013-09-15 19:33:23 +00:00
|
|
|
|
var familyGenres = request.FamilyGenre.Split(',').ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);
|
|
|
|
|
|
|
|
|
|
var familyMovies = movies.Where(i => i.Genres.Any(familyGenres.ContainsKey)).ToList();
|
2013-09-10 03:13:12 +00:00
|
|
|
|
|
2013-09-11 17:54:59 +00:00
|
|
|
|
view.HDMoviePercentage = 100 * hdMovies.Count;
|
|
|
|
|
view.HDMoviePercentage /= movies.Count;
|
|
|
|
|
|
|
|
|
|
view.FamilyMoviePercentage = 100 * familyMovies.Count;
|
|
|
|
|
view.FamilyMoviePercentage /= movies.Count;
|
2013-09-10 03:13:12 +00:00
|
|
|
|
|
2013-09-12 01:35:18 +00:00
|
|
|
|
var moviesWithBackdrops = movies
|
|
|
|
|
.Where(i => i.BackdropImagePaths.Count > 0)
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
var fields = new List<ItemFields>();
|
2013-09-10 03:13:12 +00:00
|
|
|
|
|
2013-09-17 02:44:06 +00:00
|
|
|
|
var dtos = FilterItemsForBackdropDisplay(itemsWithBackdrops)
|
2013-09-10 03:13:12 +00:00
|
|
|
|
.OrderBy(i => Guid.NewGuid())
|
2013-09-15 17:34:48 +00:00
|
|
|
|
.Take(50)
|
2013-09-11 17:54:59 +00:00
|
|
|
|
.Select(i => _dtoService.GetBaseItemDto(i, fields, user));
|
2013-09-10 03:13:12 +00:00
|
|
|
|
|
2013-09-20 00:53:18 +00:00
|
|
|
|
view.SpotlightItems = dtos.ToList();
|
2013-09-10 03:13:12 +00:00
|
|
|
|
|
2013-09-12 01:35:18 +00:00
|
|
|
|
view.MovieItems = moviesWithBackdrops
|
2013-09-10 03:13:12 +00:00
|
|
|
|
.OrderBy(i => Guid.NewGuid())
|
2013-09-12 01:35:18 +00:00
|
|
|
|
.Select(i => GetItemStub(i, ImageType.Backdrop))
|
2013-09-10 03:13:12 +00:00
|
|
|
|
.Where(i => i != null)
|
|
|
|
|
.Take(3)
|
2013-09-20 00:53:18 +00:00
|
|
|
|
.ToList();
|
2013-09-10 03:13:12 +00:00
|
|
|
|
|
|
|
|
|
view.TrailerItems = items
|
|
|
|
|
.OfType<Trailer>()
|
|
|
|
|
.Where(i => !string.IsNullOrEmpty(i.PrimaryImagePath))
|
|
|
|
|
.OrderBy(i => Guid.NewGuid())
|
|
|
|
|
.Select(i => GetItemStub(i, ImageType.Primary))
|
|
|
|
|
.Where(i => i != null)
|
|
|
|
|
.Take(3)
|
2013-09-20 00:53:18 +00:00
|
|
|
|
.ToList();
|
2013-09-10 03:13:12 +00:00
|
|
|
|
|
|
|
|
|
view.BoxSetItems = items
|
|
|
|
|
.OfType<BoxSet>()
|
2013-09-12 01:35:18 +00:00
|
|
|
|
.Where(i => i.BackdropImagePaths.Count > 0)
|
2013-09-10 03:13:12 +00:00
|
|
|
|
.OrderBy(i => Guid.NewGuid())
|
2013-09-12 01:35:18 +00:00
|
|
|
|
.Select(i => GetItemStub(i, ImageType.Backdrop))
|
2013-09-10 03:13:12 +00:00
|
|
|
|
.Where(i => i != null)
|
|
|
|
|
.Take(3)
|
2013-09-20 00:53:18 +00:00
|
|
|
|
.ToList();
|
2013-09-10 03:13:12 +00:00
|
|
|
|
|
2013-09-12 01:35:18 +00:00
|
|
|
|
view.ThreeDItems = moviesWithBackdrops
|
2013-09-10 03:13:12 +00:00
|
|
|
|
.Where(i => i.Is3D)
|
|
|
|
|
.OrderBy(i => Guid.NewGuid())
|
2013-09-12 01:35:18 +00:00
|
|
|
|
.Select(i => GetItemStub(i, ImageType.Backdrop))
|
2013-09-10 03:13:12 +00:00
|
|
|
|
.Where(i => i != null)
|
|
|
|
|
.Take(3)
|
2013-09-20 00:53:18 +00:00
|
|
|
|
.ToList();
|
2013-09-10 03:13:12 +00:00
|
|
|
|
|
2013-09-15 17:34:48 +00:00
|
|
|
|
var romanceGenres = request.RomanceGenre.Split(',').ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);
|
|
|
|
|
var comedyGenres = request.ComedyGenre.Split(',').ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);
|
2013-09-14 01:56:03 +00:00
|
|
|
|
|
2013-09-15 17:34:48 +00:00
|
|
|
|
view.RomanceItems = moviesWithBackdrops
|
2013-09-14 01:56:03 +00:00
|
|
|
|
.Where(i => i.Genres.Any(romanceGenres.ContainsKey))
|
|
|
|
|
.OrderBy(i => Guid.NewGuid())
|
|
|
|
|
.Select(i => GetItemStub(i, ImageType.Backdrop))
|
|
|
|
|
.Where(i => i != null)
|
|
|
|
|
.Take(3)
|
2013-09-20 00:53:18 +00:00
|
|
|
|
.ToList();
|
2013-09-14 01:56:03 +00:00
|
|
|
|
|
2013-09-15 17:34:48 +00:00
|
|
|
|
view.ComedyItems = moviesWithBackdrops
|
|
|
|
|
.Where(i => i.Genres.Any(comedyGenres.ContainsKey))
|
|
|
|
|
.OrderBy(i => Guid.NewGuid())
|
|
|
|
|
.Select(i => GetItemStub(i, ImageType.Backdrop))
|
|
|
|
|
.Where(i => i != null)
|
|
|
|
|
.Take(3)
|
2013-09-20 00:53:18 +00:00
|
|
|
|
.ToList();
|
2013-09-15 17:34:48 +00:00
|
|
|
|
|
2013-09-11 17:54:59 +00:00
|
|
|
|
view.HDItems = hdMovies
|
2013-09-12 01:35:18 +00:00
|
|
|
|
.Where(i => i.BackdropImagePaths.Count > 0)
|
2013-09-11 17:54:59 +00:00
|
|
|
|
.OrderBy(i => Guid.NewGuid())
|
2013-09-12 01:35:18 +00:00
|
|
|
|
.Select(i => GetItemStub(i, ImageType.Backdrop))
|
2013-09-11 17:54:59 +00:00
|
|
|
|
.Where(i => i != null)
|
|
|
|
|
.Take(3)
|
2013-09-20 00:53:18 +00:00
|
|
|
|
.ToList();
|
2013-09-11 17:54:59 +00:00
|
|
|
|
|
|
|
|
|
view.FamilyMovies = familyMovies
|
2013-09-12 01:35:18 +00:00
|
|
|
|
.Where(i => i.BackdropImagePaths.Count > 0)
|
2013-09-10 03:13:12 +00:00
|
|
|
|
.OrderBy(i => Guid.NewGuid())
|
2013-09-12 01:35:18 +00:00
|
|
|
|
.Select(i => GetItemStub(i, ImageType.Backdrop))
|
2013-09-10 03:13:12 +00:00
|
|
|
|
.Where(i => i != null)
|
|
|
|
|
.Take(3)
|
2013-09-20 00:53:18 +00:00
|
|
|
|
.ToList();
|
2013-09-10 03:13:12 +00:00
|
|
|
|
|
2013-09-17 02:08:18 +00:00
|
|
|
|
view.PeopleItems = GetActors(items);
|
2013-09-11 17:54:59 +00:00
|
|
|
|
|
2013-09-10 03:13:12 +00:00
|
|
|
|
return view;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-15 17:34:48 +00:00
|
|
|
|
private IEnumerable<BaseItem> FilterItemsForBackdropDisplay(IEnumerable<BaseItem> items)
|
|
|
|
|
{
|
|
|
|
|
var tuples = items
|
|
|
|
|
.Select(i => new Tuple<BaseItem, double>(i, GetResolution(i, i.BackdropImagePaths[0])))
|
|
|
|
|
.Where(i => i.Item2 > 0)
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
var topItems = tuples
|
|
|
|
|
.Where(i => i.Item2 >= 1920)
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
if (topItems.Count >= 10)
|
|
|
|
|
{
|
|
|
|
|
return topItems.Select(i => i.Item1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return tuples.Select(i => i.Item1);
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-12 01:35:18 +00:00
|
|
|
|
private double GetResolution(BaseItem item, string path)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2013-09-18 18:49:06 +00:00
|
|
|
|
var date = item.GetImageDateModified(path);
|
2013-09-12 01:35:18 +00:00
|
|
|
|
|
2013-09-18 18:49:06 +00:00
|
|
|
|
var size = _imageProcessor.GetImageSize(path, date);
|
2013-09-12 01:35:18 +00:00
|
|
|
|
|
|
|
|
|
return size.Width;
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-20 00:53:18 +00:00
|
|
|
|
private List<ItemStub> GetActors(IEnumerable<BaseItem> mediaItems)
|
2013-09-10 03:13:12 +00:00
|
|
|
|
{
|
|
|
|
|
var actors = mediaItems.SelectMany(i => i.People)
|
|
|
|
|
.Select(i => i.Name)
|
|
|
|
|
.Distinct(StringComparer.OrdinalIgnoreCase)
|
2013-09-11 17:54:59 +00:00
|
|
|
|
.OrderBy(i => Guid.NewGuid())
|
2013-09-10 03:13:12 +00:00
|
|
|
|
.ToList();
|
|
|
|
|
|
2013-09-17 02:08:18 +00:00
|
|
|
|
return actors.Select(actor =>
|
2013-09-10 03:13:12 +00:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2013-09-17 02:08:18 +00:00
|
|
|
|
var person = _libraryManager.GetPerson(actor);
|
2013-09-10 03:13:12 +00:00
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(person.PrimaryImagePath))
|
|
|
|
|
{
|
2013-09-17 02:08:18 +00:00
|
|
|
|
return GetItemStub(person, ImageType.Primary);
|
2013-09-10 03:13:12 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.ErrorException("Error getting person {0}", ex, actor);
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-17 02:08:18 +00:00
|
|
|
|
return null;
|
|
|
|
|
})
|
|
|
|
|
.Where(i => i != null)
|
|
|
|
|
.Take(3)
|
2013-09-20 00:53:18 +00:00
|
|
|
|
.ToList();
|
2013-09-10 03:13:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ItemStub GetItemStub(BaseItem item, ImageType imageType)
|
|
|
|
|
{
|
|
|
|
|
var stub = new ItemStub
|
|
|
|
|
{
|
|
|
|
|
Id = _dtoService.GetDtoId(item),
|
2013-09-14 01:56:03 +00:00
|
|
|
|
Name = item.Name,
|
|
|
|
|
ImageType = imageType
|
2013-09-10 03:13:12 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2013-09-18 18:49:06 +00:00
|
|
|
|
var imagePath = item.GetImagePath(imageType, 0);
|
2013-09-10 03:13:12 +00:00
|
|
|
|
|
2013-09-18 18:49:06 +00:00
|
|
|
|
stub.ImageTag = _imageProcessor.GetImageCacheTag(item, imageType, imagePath);
|
2013-09-10 03:13:12 +00:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.ErrorException("Error getting image tag for {0}", ex, item.Path);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return stub;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|