From 587d3c1908287c8f6c893355c18a4d5d15541952 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 13 Apr 2013 20:17:25 -0400 Subject: added min/max official rating --- MediaBrowser.Api/UserLibrary/ItemsService.cs | 31 ++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'MediaBrowser.Api/UserLibrary/ItemsService.cs') diff --git a/MediaBrowser.Api/UserLibrary/ItemsService.cs b/MediaBrowser.Api/UserLibrary/ItemsService.cs index cd6bd7854..3b8702e7d 100644 --- a/MediaBrowser.Api/UserLibrary/ItemsService.cs +++ b/MediaBrowser.Api/UserLibrary/ItemsService.cs @@ -2,6 +2,7 @@ using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Localization; using MediaBrowser.Controller.Persistence; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Querying; @@ -124,6 +125,20 @@ namespace MediaBrowser.Api.UserLibrary [ApiMember(Name = "AirDays", Description = "Optional filter by Series Air Days. Allows multiple, comma delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)] public string AirDays { get; set; } + /// + /// Gets or sets the min offical rating. + /// + /// The min offical rating. + [ApiMember(Name = "MinOfficalRating", Description = "Optional filter by minimum official rating (PG, PG-13, TV-MA, etc).", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] + public string MinOfficalRating { get; set; } + + /// + /// Gets or sets the max offical rating. + /// + /// The max offical rating. + [ApiMember(Name = "MaxOfficalRating", Description = "Optional filter by maximum official rating (PG, PG-13, TV-MA, etc).", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] + public string MaxOfficalRating { get; set; } + /// /// Gets the order by. /// @@ -357,6 +372,22 @@ namespace MediaBrowser.Api.UserLibrary /// IEnumerable{BaseItem}. internal static IEnumerable ApplyAdditionalFilters(GetItems request, IEnumerable items) { + // Min official rating + if (!string.IsNullOrEmpty(request.MinOfficalRating)) + { + var level = Ratings.Level(request.MinOfficalRating); + + items = items.Where(i => Ratings.Level(i.CustomRating ?? i.OfficialRating) >= level); + } + + // Max official rating + if (!string.IsNullOrEmpty(request.MaxOfficalRating)) + { + var level = Ratings.Level(request.MaxOfficalRating); + + items = items.Where(i => Ratings.Level(i.CustomRating ?? i.OfficialRating) <= level); + } + // Exclude item types if (!string.IsNullOrEmpty(request.ExcludeItemTypes)) { -- cgit v1.2.3