added players filter to games view

This commit is contained in:
Luke Pulverenti 2013-09-15 15:33:23 -04:00
parent 7ecbf44590
commit d2b6b91ab6
4 changed files with 35 additions and 32 deletions

View File

@ -36,8 +36,8 @@ namespace MediaBrowser.Api.DefaultTheme
[ApiMember(Name = "UserId", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
public Guid UserId { get; set; }
[ApiMember(Name = "FamilyRating", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public string FamilyRating { 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; }
@ -185,8 +185,6 @@ namespace MediaBrowser.Api.DefaultTheme
var itemsWithBackdrops = items.Where(i => i.BackdropImagePaths.Count > 0 && !(i is Trailer))
.ToList();
var baselineRating = _localization.GetRatingLevel(request.FamilyRating ?? "PG");
var view = new MoviesView();
var movies = items.OfType<Movie>()
@ -194,7 +192,9 @@ namespace MediaBrowser.Api.DefaultTheme
var hdMovies = movies.Where(i => i.IsHd).ToList();
var familyMovies = movies.Where(i => IsFamilyMovie(i, baselineRating)).ToList();
var familyGenres = request.FamilyGenre.Split(',').ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);
var familyMovies = movies.Where(i => i.Genres.Any(familyGenres.ContainsKey)).ToList();
view.HDMoviePercentage = 100 * hdMovies.Count;
view.HDMoviePercentage /= movies.Count;
@ -323,30 +323,6 @@ namespace MediaBrowser.Api.DefaultTheme
}
}
private bool IsFamilyMovie(BaseItem item, int? baselineRating)
{
var ratingString = item.CustomRating;
if (string.IsNullOrEmpty(ratingString))
{
ratingString = item.OfficialRating;
}
if (string.IsNullOrEmpty(ratingString))
{
return false;
}
var rating = _localization.GetRatingLevel(ratingString);
if (!baselineRating.HasValue || !rating.HasValue)
{
return false;
}
return rating.Value <= baselineRating.Value;
}
private async Task<ItemStub[]> GetActors(IEnumerable<BaseItem> mediaItems)
{
var actorStubs = new List<ItemStub>();

View File

@ -43,6 +43,11 @@ namespace MediaBrowser.Api.DefaultTheme
public ItemStub[] ComedyItems { get; set; }
}
public class GamesView
{
public BaseItemDto[] SpotlightItems { get; set; }
}
public class HomeView
{
public BaseItemDto[] SpotlightItems { get; set; }

View File

@ -164,6 +164,9 @@ namespace MediaBrowser.Api.UserLibrary
[ApiMember(Name = "MinIndexNumber", Description = "Optional filter by minimum index number.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
public int? MinIndexNumber { get; set; }
[ApiMember(Name = "MinPlayers", Description = "Optional filter by minimum number of game players.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
public int? MinPlayers { get; set; }
[ApiMember(Name = "ParentIndexNumber", Description = "Optional filter by parent index number.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
public int? ParentIndexNumber { get; set; }
@ -670,6 +673,25 @@ namespace MediaBrowser.Api.UserLibrary
items = items.Where(i => request.HasThemeVideo.Value ? i.ThemeVideoIds.Count > 0 : i.ThemeVideoIds.Count == 0);
}
if (request.MinPlayers.HasValue)
{
var filterValue = request.MinPlayers.Value;
items = items.Where(i =>
{
var game = i as Game;
if (game != null)
{
var players = game.PlayersSupported ?? 1;
return players >= filterValue;
}
return false;
});
}
if (request.HasSpecialFeature.HasValue)
{
var filterValue = request.HasSpecialFeature.Value;

View File

@ -1,5 +1,4 @@
using System.Collections.Generic;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
@ -10,6 +9,7 @@ using MediaBrowser.Model.Entities;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Logging;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
@ -149,7 +149,7 @@ namespace MediaBrowser.Providers.TV
{
get
{
return "1";
return "2";
}
}