aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Api/UserLibrary
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Api/UserLibrary')
-rw-r--r--MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs56
-rw-r--r--MediaBrowser.Api/UserLibrary/BaseItemsRequest.cs40
-rw-r--r--MediaBrowser.Api/UserLibrary/ItemsService.cs48
3 files changed, 112 insertions, 32 deletions
diff --git a/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs b/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs
index 458cf8bae..3ae53daf8 100644
--- a/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs
+++ b/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs
@@ -193,13 +193,6 @@ namespace MediaBrowser.Api.UserLibrary
var filters = request.GetFilters().ToList();
- if (filters.Count == 0)
- {
- return items;
- }
-
- items = items.AsParallel();
-
if (filters.Contains(ItemFilter.Dislikes))
{
items = items.Where(i =>
@@ -243,9 +236,56 @@ namespace MediaBrowser.Api.UserLibrary
});
}
- return items.AsEnumerable();
+ // Avoid implicitly captured closure
+ var currentRequest = request;
+ return items.Where(i => ApplyAdditionalFilters(currentRequest, i, user, false));
+ }
+
+ private bool ApplyAdditionalFilters(BaseItemsRequest request, BaseItem i, User user, bool isPreFiltered)
+ {
+ if (!isPreFiltered)
+ {
+ // Apply tag filter
+ var tags = request.GetTags();
+ if (tags.Length > 0)
+ {
+ var hasTags = i as IHasTags;
+ if (hasTags == null)
+ {
+ return false;
+ }
+ if (!(tags.Any(v => hasTags.Tags.Contains(v, StringComparer.OrdinalIgnoreCase))))
+ {
+ return false;
+ }
+ }
+
+ // Apply official rating filter
+ var officialRatings = request.GetOfficialRatings();
+ if (officialRatings.Length > 0 && !officialRatings.Contains(i.OfficialRating ?? string.Empty))
+ {
+ return false;
+ }
+
+ // Apply genre filter
+ var genres = request.GetGenres();
+ if (genres.Length > 0 && !(genres.Any(v => i.Genres.Contains(v, StringComparer.OrdinalIgnoreCase))))
+ {
+ return false;
+ }
+
+ // Apply year filter
+ var years = request.GetYears();
+ if (years.Length > 0 && !(i.ProductionYear.HasValue && years.Contains(i.ProductionYear.Value)))
+ {
+ return false;
+ }
+ }
+
+ return true;
}
+
/// <summary>
/// Filters the items.
/// </summary>
diff --git a/MediaBrowser.Api/UserLibrary/BaseItemsRequest.cs b/MediaBrowser.Api/UserLibrary/BaseItemsRequest.cs
index 3dcd4efbd..6b0c64b79 100644
--- a/MediaBrowser.Api/UserLibrary/BaseItemsRequest.cs
+++ b/MediaBrowser.Api/UserLibrary/BaseItemsRequest.cs
@@ -96,6 +96,41 @@ namespace MediaBrowser.Api.UserLibrary
[ApiMember(Name = "IsPlayed", Description = "Optional filter by items that are played, or not.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")]
public bool? IsPlayed { get; set; }
+ /// <summary>
+ /// Limit results to items containing specific genres
+ /// </summary>
+ /// <value>The genres.</value>
+ [ApiMember(Name = "Genres", Description = "Optional. If specified, results will be filtered based on genre. This allows multiple, pipe delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
+ public string Genres { get; set; }
+
+ [ApiMember(Name = "OfficialRatings", Description = "Optional. If specified, results will be filtered based on OfficialRating. This allows multiple, pipe delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
+ public string OfficialRatings { get; set; }
+
+ [ApiMember(Name = "Tags", Description = "Optional. If specified, results will be filtered based on tag. This allows multiple, pipe delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
+ public string Tags { get; set; }
+
+ /// <summary>
+ /// Limit results to items containing specific years
+ /// </summary>
+ /// <value>The years.</value>
+ [ApiMember(Name = "Years", Description = "Optional. If specified, results will be filtered based on production year. This allows multiple, comma delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
+ public string Years { get; set; }
+
+ public string[] GetGenres()
+ {
+ return (Genres ?? string.Empty).Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
+ }
+
+ public string[] GetTags()
+ {
+ return (Tags ?? string.Empty).Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
+ }
+
+ public string[] GetOfficialRatings()
+ {
+ return (OfficialRatings ?? string.Empty).Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
+ }
+
public string[] GetMediaTypes()
{
return (MediaTypes ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
@@ -110,6 +145,11 @@ namespace MediaBrowser.Api.UserLibrary
{
return (ExcludeItemTypes ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
}
+
+ public int[] GetYears()
+ {
+ return (Years ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
+ }
/// <summary>
/// Gets the filters.
diff --git a/MediaBrowser.Api/UserLibrary/ItemsService.cs b/MediaBrowser.Api/UserLibrary/ItemsService.cs
index f2da135c2..18996e0d9 100644
--- a/MediaBrowser.Api/UserLibrary/ItemsService.cs
+++ b/MediaBrowser.Api/UserLibrary/ItemsService.cs
@@ -46,13 +46,6 @@ namespace MediaBrowser.Api.UserLibrary
[ApiMember(Name = "PersonTypes", Description = "Optional. If specified, along with Person, results will be filtered to include only those containing the specified person and PersonType. Allows multiple, comma-delimited", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public string PersonTypes { get; set; }
- /// <summary>
- /// Limit results to items containing specific genres
- /// </summary>
- /// <value>The genres.</value>
- [ApiMember(Name = "Genres", Description = "Optional. If specified, results will be filtered based on genre. This allows multiple, pipe delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
- public string Genres { get; set; }
-
[ApiMember(Name = "AllGenres", Description = "Optional. If specified, results will be filtered based on genre. This allows multiple, pipe delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
public string AllGenres { get; set; }
@@ -74,13 +67,6 @@ namespace MediaBrowser.Api.UserLibrary
public string Albums { get; set; }
/// <summary>
- /// Limit results to items containing specific years
- /// </summary>
- /// <value>The years.</value>
- [ApiMember(Name = "Years", Description = "Optional. If specified, results will be filtered based on production year. This allows multiple, comma delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
- public string Years { get; set; }
-
- /// <summary>
/// Gets or sets the item ids.
/// </summary>
/// <value>The item ids.</value>
@@ -247,11 +233,6 @@ namespace MediaBrowser.Api.UserLibrary
return (AllGenres ?? string.Empty).Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
}
- public string[] GetGenres()
- {
- return (Genres ?? string.Empty).Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
- }
-
public string[] GetStudios()
{
return (Studios ?? string.Empty).Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
@@ -262,11 +243,6 @@ namespace MediaBrowser.Api.UserLibrary
return (PersonTypes ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
}
- public int[] GetYears()
- {
- return (Years ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
- }
-
public IEnumerable<VideoType> GetVideoTypes()
{
var val = VideoTypes;
@@ -520,6 +496,8 @@ namespace MediaBrowser.Api.UserLibrary
HasThemeSong = request.HasThemeSong,
HasThemeVideo = request.HasThemeVideo,
HasTrailer = request.HasTrailer,
+ Tags = request.GetTags(),
+ OfficialRatings = request.GetOfficialRatings(),
Genres = request.GetGenres(),
AllGenres = request.GetAllGenres(),
Studios = request.GetStudios(),
@@ -951,6 +929,28 @@ namespace MediaBrowser.Api.UserLibrary
}
}
+ // Apply tag filter
+ var tags = request.GetTags();
+ if (tags.Length > 0)
+ {
+ var hasTags = i as IHasTags;
+ if (hasTags == null)
+ {
+ return false;
+ }
+ if (!(tags.Any(v => hasTags.Tags.Contains(v, StringComparer.OrdinalIgnoreCase))))
+ {
+ return false;
+ }
+ }
+
+ // Apply official rating filter
+ var officialRatings = request.GetOfficialRatings();
+ if (officialRatings.Length > 0 && !officialRatings.Contains(i.OfficialRating ?? string.Empty))
+ {
+ return false;
+ }
+
// Apply genre filter
var genres = request.GetGenres();
if (genres.Length > 0 && !(genres.Any(v => i.Genres.Contains(v, StringComparer.OrdinalIgnoreCase))))