|
@@ -243,6 +243,43 @@ namespace MediaBrowser.Api.UserLibrary
|
|
|
|
|
|
[ApiMember(Name = "CollapseBoxSetItems", Description = "Whether or not to hide items behind their boxsets.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")]
|
|
[ApiMember(Name = "CollapseBoxSetItems", Description = "Whether or not to hide items behind their boxsets.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")]
|
|
public bool? CollapseBoxSetItems { get; set; }
|
|
public bool? CollapseBoxSetItems { get; set; }
|
|
|
|
+
|
|
|
|
+ public string[] GetAllGenres()
|
|
|
|
+ {
|
|
|
|
+ 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);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public string[] GetPersonTypes()
|
|
|
|
+ {
|
|
|
|
+ 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;
|
|
|
|
+
|
|
|
|
+ if (string.IsNullOrEmpty(val))
|
|
|
|
+ {
|
|
|
|
+ return new VideoType[] { };
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return val.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(v => (VideoType)Enum.Parse(typeof(VideoType), v, true));
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -331,21 +368,21 @@ namespace MediaBrowser.Api.UserLibrary
|
|
items = ApplyFilter(items, filter, user, _userDataRepository);
|
|
items = ApplyFilter(items, filter, user, _userDataRepository);
|
|
}
|
|
}
|
|
|
|
|
|
- items = FilterVirtualEpisodes(request, items, user);
|
|
|
|
|
|
+ items = UserViewBuilder.FilterVirtualEpisodes(items,
|
|
|
|
+ request.IsMissing,
|
|
|
|
+ request.IsVirtualUnaired,
|
|
|
|
+ request.IsUnaired);
|
|
|
|
|
|
- if (CollapseBoxSetItems(request, parentItem, user))
|
|
|
|
- {
|
|
|
|
- items = _collectionManager.CollapseItemsWithinBoxSets(items, user);
|
|
|
|
- }
|
|
|
|
|
|
+ var internalQuery = GetItemsQuery(request, user);
|
|
|
|
|
|
- items = ApplyPostCollectionCollapseFilters(request, items, user);
|
|
|
|
|
|
+ items = UserViewBuilder.CollapseBoxSetItemsIfNeeded(items, internalQuery, parentItem, user);
|
|
|
|
|
|
items = _libraryManager.Sort(items, user, request.GetOrderBy(), request.SortOrder ?? SortOrder.Ascending);
|
|
items = _libraryManager.Sort(items, user, request.GetOrderBy(), request.SortOrder ?? SortOrder.Ascending);
|
|
|
|
|
|
// This must be the last filter
|
|
// This must be the last filter
|
|
if (!string.IsNullOrEmpty(request.AdjacentTo))
|
|
if (!string.IsNullOrEmpty(request.AdjacentTo))
|
|
{
|
|
{
|
|
- items = FilterForAdjacency(items, request.AdjacentTo);
|
|
|
|
|
|
+ items = UserViewBuilder.FilterForAdjacency(items, request.AdjacentTo);
|
|
}
|
|
}
|
|
|
|
|
|
var itemsArray = items.ToList();
|
|
var itemsArray = items.ToList();
|
|
@@ -363,33 +400,6 @@ namespace MediaBrowser.Api.UserLibrary
|
|
};
|
|
};
|
|
}
|
|
}
|
|
|
|
|
|
- private bool CollapseBoxSetItems(GetItems request, BaseItem parentItem, User user)
|
|
|
|
- {
|
|
|
|
- // Could end up stuck in a loop like this
|
|
|
|
- if (parentItem is BoxSet)
|
|
|
|
- {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- var param = request.CollapseBoxSetItems;
|
|
|
|
-
|
|
|
|
- if (!param.HasValue)
|
|
|
|
- {
|
|
|
|
- if (user != null && !user.Configuration.GroupMoviesIntoBoxSets)
|
|
|
|
- {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (!string.IsNullOrWhiteSpace(request.IncludeItemTypes) &&
|
|
|
|
- request.IncludeItemTypes.Split(',').Contains("Movie", StringComparer.OrdinalIgnoreCase))
|
|
|
|
- {
|
|
|
|
- param = true;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return param.HasValue && param.Value && AllowBoxSetCollapsing(request);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Gets the items to serialize.
|
|
/// Gets the items to serialize.
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -486,9 +496,48 @@ namespace MediaBrowser.Api.UserLibrary
|
|
Filter = (i, u) => ApplyAdditionalFilters(request, i, u, true),
|
|
Filter = (i, u) => ApplyAdditionalFilters(request, i, u, true),
|
|
|
|
|
|
Limit = request.Limit,
|
|
Limit = request.Limit,
|
|
- StartIndex = request.StartIndex
|
|
|
|
|
|
+ StartIndex = request.StartIndex,
|
|
|
|
+ IsMissing = request.IsMissing,
|
|
|
|
+ IsVirtualUnaired = request.IsVirtualUnaired,
|
|
|
|
+ IsUnaired = request.IsUnaired,
|
|
|
|
+ CollapseBoxSetItems = request.CollapseBoxSetItems,
|
|
|
|
+ NameLessThan = request.NameLessThan,
|
|
|
|
+ NameStartsWith = request.NameStartsWith,
|
|
|
|
+ NameStartsWithOrGreater = request.NameStartsWithOrGreater,
|
|
|
|
+ HasImdbId = request.HasImdbId,
|
|
|
|
+ IsYearMismatched = request.IsYearMismatched,
|
|
|
|
+ IsUnidentified = request.IsUnidentified,
|
|
|
|
+ IsPlaceHolder = request.IsPlaceHolder,
|
|
|
|
+ IsLocked = request.IsLocked,
|
|
|
|
+ IsInBoxSet = request.IsInBoxSet,
|
|
|
|
+ IsHD = request.IsHD,
|
|
|
|
+ Is3D = request.Is3D,
|
|
|
|
+ HasTvdbId = request.HasTvdbId,
|
|
|
|
+ HasTmdbId = request.HasTmdbId,
|
|
|
|
+ HasOverview = request.HasOverview,
|
|
|
|
+ HasOfficialRating = request.HasOfficialRating,
|
|
|
|
+ HasParentalRating = request.HasParentalRating,
|
|
|
|
+ HasSpecialFeature = request.HasSpecialFeature,
|
|
|
|
+ HasSubtitles = request.HasSubtitles,
|
|
|
|
+ HasThemeSong = request.HasThemeSong,
|
|
|
|
+ HasThemeVideo = request.HasThemeVideo,
|
|
|
|
+ HasTrailer = request.HasTrailer,
|
|
|
|
+ Genres = request.GetGenres(),
|
|
|
|
+ AllGenres = request.GetAllGenres(),
|
|
|
|
+ Studios = request.GetStudios(),
|
|
|
|
+ Person = request.Person,
|
|
|
|
+ PersonTypes = request.GetPersonTypes(),
|
|
|
|
+ Years = request.GetYears(),
|
|
|
|
+ ImageTypes = request.GetImageTypes().ToArray(),
|
|
|
|
+ VideoTypes = request.GetVideoTypes().ToArray(),
|
|
|
|
+ AdjacentTo = request.AdjacentTo
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+ if (!string.IsNullOrWhiteSpace(request.Ids))
|
|
|
|
+ {
|
|
|
|
+ query.CollapseBoxSetItems = false;
|
|
|
|
+ }
|
|
|
|
+
|
|
foreach (var filter in request.GetFilters())
|
|
foreach (var filter in request.GetFilters())
|
|
{
|
|
{
|
|
switch (filter)
|
|
switch (filter)
|
|
@@ -610,121 +659,6 @@ namespace MediaBrowser.Api.UserLibrary
|
|
return items;
|
|
return items;
|
|
}
|
|
}
|
|
|
|
|
|
- private IEnumerable<BaseItem> FilterVirtualEpisodes(GetItems request, IEnumerable<BaseItem> items, User user)
|
|
|
|
- {
|
|
|
|
- items = FilterVirtualSeasons(request, items, user);
|
|
|
|
-
|
|
|
|
- if (request.IsMissing.HasValue)
|
|
|
|
- {
|
|
|
|
- var val = request.IsMissing.Value;
|
|
|
|
- items = items.Where(i =>
|
|
|
|
- {
|
|
|
|
- var e = i as Episode;
|
|
|
|
- if (e != null)
|
|
|
|
- {
|
|
|
|
- return e.IsMissingEpisode == val;
|
|
|
|
- }
|
|
|
|
- return true;
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (request.IsUnaired.HasValue)
|
|
|
|
- {
|
|
|
|
- var val = request.IsUnaired.Value;
|
|
|
|
- items = items.Where(i =>
|
|
|
|
- {
|
|
|
|
- var e = i as Episode;
|
|
|
|
- if (e != null)
|
|
|
|
- {
|
|
|
|
- return e.IsUnaired == val;
|
|
|
|
- }
|
|
|
|
- return true;
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (request.IsVirtualUnaired.HasValue)
|
|
|
|
- {
|
|
|
|
- var val = request.IsVirtualUnaired.Value;
|
|
|
|
- items = items.Where(i =>
|
|
|
|
- {
|
|
|
|
- var e = i as Episode;
|
|
|
|
- if (e != null)
|
|
|
|
- {
|
|
|
|
- return e.IsVirtualUnaired == val;
|
|
|
|
- }
|
|
|
|
- return true;
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return items;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private IEnumerable<BaseItem> FilterVirtualSeasons(GetItems request, IEnumerable<BaseItem> items, User user)
|
|
|
|
- {
|
|
|
|
- if (request.IsMissing.HasValue && request.IsVirtualUnaired.HasValue)
|
|
|
|
- {
|
|
|
|
- var isMissing = request.IsMissing.Value;
|
|
|
|
- var isVirtualUnaired = request.IsVirtualUnaired.Value;
|
|
|
|
-
|
|
|
|
- if (!isMissing && !isVirtualUnaired)
|
|
|
|
- {
|
|
|
|
- return items.Where(i =>
|
|
|
|
- {
|
|
|
|
- var e = i as Season;
|
|
|
|
- if (e != null)
|
|
|
|
- {
|
|
|
|
- return !e.IsMissingOrVirtualUnaired;
|
|
|
|
- }
|
|
|
|
- return true;
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (request.IsMissing.HasValue)
|
|
|
|
- {
|
|
|
|
- var val = request.IsMissing.Value;
|
|
|
|
- items = items.Where(i =>
|
|
|
|
- {
|
|
|
|
- var e = i as Season;
|
|
|
|
- if (e != null)
|
|
|
|
- {
|
|
|
|
- return e.IsMissingSeason == val;
|
|
|
|
- }
|
|
|
|
- return true;
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (request.IsUnaired.HasValue)
|
|
|
|
- {
|
|
|
|
- var val = request.IsUnaired.Value;
|
|
|
|
- items = items.Where(i =>
|
|
|
|
- {
|
|
|
|
- var e = i as Season;
|
|
|
|
- if (e != null)
|
|
|
|
- {
|
|
|
|
- return e.IsUnaired == val;
|
|
|
|
- }
|
|
|
|
- return true;
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (request.IsVirtualUnaired.HasValue)
|
|
|
|
- {
|
|
|
|
- var val = request.IsVirtualUnaired.Value;
|
|
|
|
- items = items.Where(i =>
|
|
|
|
- {
|
|
|
|
- var e = i as Season;
|
|
|
|
- if (e != null)
|
|
|
|
- {
|
|
|
|
- return e.IsVirtualUnaired == val;
|
|
|
|
- }
|
|
|
|
- return true;
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return items;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
private bool ApplyAdditionalFilters(GetItems request, BaseItem i, User user, bool isPreFiltered)
|
|
private bool ApplyAdditionalFilters(GetItems request, BaseItem i, User user, bool isPreFiltered)
|
|
{
|
|
{
|
|
if (!isPreFiltered)
|
|
if (!isPreFiltered)
|
|
@@ -760,130 +694,185 @@ namespace MediaBrowser.Api.UserLibrary
|
|
{
|
|
{
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
|
|
- if (request.MinCommunityRating.HasValue)
|
|
|
|
- {
|
|
|
|
- var val = request.MinCommunityRating.Value;
|
|
|
|
|
|
+ if (request.IsInBoxSet.HasValue)
|
|
|
|
+ {
|
|
|
|
+ var val = request.IsInBoxSet.Value;
|
|
|
|
+ if (i.Parents.OfType<BoxSet>().Any() != val)
|
|
|
|
+ {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- if (!(i.CommunityRating.HasValue && i.CommunityRating >= val))
|
|
|
|
|
|
+ // Filter by Video3DFormat
|
|
|
|
+ if (request.Is3D.HasValue)
|
|
{
|
|
{
|
|
- return false;
|
|
|
|
|
|
+ var val = request.Is3D.Value;
|
|
|
|
+ var video = i as Video;
|
|
|
|
+
|
|
|
|
+ if (video == null || val != video.Video3DFormat.HasValue)
|
|
|
|
+ {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
|
|
- if (request.MinCriticRating.HasValue)
|
|
|
|
- {
|
|
|
|
- var val = request.MinCriticRating.Value;
|
|
|
|
|
|
+ if (request.IsHD.HasValue)
|
|
|
|
+ {
|
|
|
|
+ var val = request.IsHD.Value;
|
|
|
|
+ var video = i as Video;
|
|
|
|
|
|
- var hasCriticRating = i as IHasCriticRating;
|
|
|
|
|
|
+ if (video == null || val != video.IsHD)
|
|
|
|
+ {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- if (hasCriticRating != null)
|
|
|
|
|
|
+ if (request.IsUnidentified.HasValue)
|
|
{
|
|
{
|
|
- if (!(hasCriticRating.CriticRating.HasValue && hasCriticRating.CriticRating >= val))
|
|
|
|
|
|
+ var val = request.IsUnidentified.Value;
|
|
|
|
+ if (i.IsUnidentified != val)
|
|
{
|
|
{
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- else
|
|
|
|
|
|
+
|
|
|
|
+ if (request.IsLocked.HasValue)
|
|
{
|
|
{
|
|
- return false;
|
|
|
|
|
|
+ var val = request.IsLocked.Value;
|
|
|
|
+ if (i.IsLocked != val)
|
|
|
|
+ {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
|
|
- // Artists
|
|
|
|
- if (!string.IsNullOrEmpty(request.Artists))
|
|
|
|
- {
|
|
|
|
- var artists = request.Artists.Split('|');
|
|
|
|
|
|
+ if (request.HasOverview.HasValue)
|
|
|
|
+ {
|
|
|
|
+ var filterValue = request.HasOverview.Value;
|
|
|
|
|
|
- var audio = i as IHasArtist;
|
|
|
|
|
|
+ var hasValue = !string.IsNullOrEmpty(i.Overview);
|
|
|
|
|
|
- if (!(audio != null && artists.Any(audio.HasArtist)))
|
|
|
|
- {
|
|
|
|
- return false;
|
|
|
|
|
|
+ if (hasValue != filterValue)
|
|
|
|
+ {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
|
|
- // Albums
|
|
|
|
- if (!string.IsNullOrEmpty(request.Albums))
|
|
|
|
- {
|
|
|
|
- var albums = request.Albums.Split('|');
|
|
|
|
|
|
+ if (request.HasImdbId.HasValue)
|
|
|
|
+ {
|
|
|
|
+ var filterValue = request.HasImdbId.Value;
|
|
|
|
|
|
- var audio = i as Audio;
|
|
|
|
|
|
+ var hasValue = !string.IsNullOrEmpty(i.GetProviderId(MetadataProviders.Imdb));
|
|
|
|
|
|
- if (audio != null)
|
|
|
|
- {
|
|
|
|
- if (!albums.Any(a => string.Equals(a, audio.Album, StringComparison.OrdinalIgnoreCase)))
|
|
|
|
|
|
+ if (hasValue != filterValue)
|
|
{
|
|
{
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- var album = i as MusicAlbum;
|
|
|
|
-
|
|
|
|
- if (album != null)
|
|
|
|
|
|
+ if (request.HasTmdbId.HasValue)
|
|
{
|
|
{
|
|
- if (!albums.Any(a => string.Equals(a, album.Name, StringComparison.OrdinalIgnoreCase)))
|
|
|
|
|
|
+ var filterValue = request.HasTmdbId.Value;
|
|
|
|
+
|
|
|
|
+ var hasValue = !string.IsNullOrEmpty(i.GetProviderId(MetadataProviders.Tmdb));
|
|
|
|
+
|
|
|
|
+ if (hasValue != filterValue)
|
|
{
|
|
{
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- var musicVideo = i as MusicVideo;
|
|
|
|
-
|
|
|
|
- if (musicVideo != null)
|
|
|
|
|
|
+ if (request.HasTvdbId.HasValue)
|
|
{
|
|
{
|
|
- if (!albums.Any(a => string.Equals(a, musicVideo.Album, StringComparison.OrdinalIgnoreCase)))
|
|
|
|
|
|
+ var filterValue = request.HasTvdbId.Value;
|
|
|
|
+
|
|
|
|
+ var hasValue = !string.IsNullOrEmpty(i.GetProviderId(MetadataProviders.Tvdb));
|
|
|
|
+
|
|
|
|
+ if (hasValue != filterValue)
|
|
{
|
|
{
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // Min index number
|
|
|
|
- if (request.MinIndexNumber.HasValue)
|
|
|
|
- {
|
|
|
|
- if (!(i.IndexNumber.HasValue && i.IndexNumber.Value >= request.MinIndexNumber.Value))
|
|
|
|
|
|
+ if (request.IsYearMismatched.HasValue)
|
|
{
|
|
{
|
|
- return false;
|
|
|
|
|
|
+ var filterValue = request.IsYearMismatched.Value;
|
|
|
|
+
|
|
|
|
+ if (UserViewBuilder.IsYearMismatched(i) != filterValue)
|
|
|
|
+ {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
|
|
- // Min official rating
|
|
|
|
- if (!string.IsNullOrEmpty(request.MinOfficialRating))
|
|
|
|
- {
|
|
|
|
- var level = _localization.GetRatingLevel(request.MinOfficialRating);
|
|
|
|
|
|
+ if (request.HasOfficialRating.HasValue)
|
|
|
|
+ {
|
|
|
|
+ var filterValue = request.HasOfficialRating.Value;
|
|
|
|
|
|
- if (level.HasValue)
|
|
|
|
|
|
+ var hasValue = !string.IsNullOrEmpty(i.OfficialRating);
|
|
|
|
+
|
|
|
|
+ if (hasValue != filterValue)
|
|
|
|
+ {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (request.IsPlaceHolder.HasValue)
|
|
{
|
|
{
|
|
- var rating = i.CustomRating;
|
|
|
|
|
|
+ var filterValue = request.IsPlaceHolder.Value;
|
|
|
|
|
|
- if (string.IsNullOrEmpty(rating))
|
|
|
|
|
|
+ var isPlaceHolder = false;
|
|
|
|
+
|
|
|
|
+ var hasPlaceHolder = i as ISupportsPlaceHolders;
|
|
|
|
+
|
|
|
|
+ if (hasPlaceHolder != null)
|
|
{
|
|
{
|
|
- rating = i.OfficialRating;
|
|
|
|
|
|
+ isPlaceHolder = hasPlaceHolder.IsPlaceHolder;
|
|
}
|
|
}
|
|
|
|
|
|
- if (!string.IsNullOrEmpty(rating))
|
|
|
|
|
|
+ if (isPlaceHolder != filterValue)
|
|
{
|
|
{
|
|
- var itemLevel = _localization.GetRatingLevel(rating);
|
|
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- if (!(!itemLevel.HasValue || itemLevel.Value >= level.Value))
|
|
|
|
|
|
+ if (request.HasSpecialFeature.HasValue)
|
|
|
|
+ {
|
|
|
|
+ var filterValue = request.HasSpecialFeature.Value;
|
|
|
|
+
|
|
|
|
+ var movie = i as IHasSpecialFeatures;
|
|
|
|
+
|
|
|
|
+ if (movie != null)
|
|
|
|
+ {
|
|
|
|
+ var ok = filterValue
|
|
|
|
+ ? movie.SpecialFeatureIds.Count > 0
|
|
|
|
+ : movie.SpecialFeatureIds.Count == 0;
|
|
|
|
+
|
|
|
|
+ if (!ok)
|
|
{
|
|
{
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
|
|
- // Max official rating
|
|
|
|
- if (!string.IsNullOrEmpty(request.MaxOfficialRating))
|
|
|
|
- {
|
|
|
|
- var level = _localization.GetRatingLevel(request.MaxOfficialRating);
|
|
|
|
|
|
+ if (request.HasSubtitles.HasValue)
|
|
|
|
+ {
|
|
|
|
+ var val = request.HasSubtitles.Value;
|
|
|
|
|
|
- if (level.HasValue)
|
|
|
|
|
|
+ var video = i as Video;
|
|
|
|
+
|
|
|
|
+ if (video == null || val != video.HasSubtitles)
|
|
|
|
+ {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (request.HasParentalRating.HasValue)
|
|
{
|
|
{
|
|
|
|
+ var val = request.HasParentalRating.Value;
|
|
|
|
+
|
|
var rating = i.CustomRating;
|
|
var rating = i.CustomRating;
|
|
|
|
|
|
if (string.IsNullOrEmpty(rating))
|
|
if (string.IsNullOrEmpty(rating))
|
|
@@ -891,246 +880,176 @@ namespace MediaBrowser.Api.UserLibrary
|
|
rating = i.OfficialRating;
|
|
rating = i.OfficialRating;
|
|
}
|
|
}
|
|
|
|
|
|
- if (!string.IsNullOrEmpty(rating))
|
|
|
|
|
|
+ if (val)
|
|
{
|
|
{
|
|
- var itemLevel = _localization.GetRatingLevel(rating);
|
|
|
|
-
|
|
|
|
- if (!(!itemLevel.HasValue || itemLevel.Value <= level.Value))
|
|
|
|
|
|
+ if (string.IsNullOrEmpty(rating))
|
|
|
|
+ {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ if (!string.IsNullOrEmpty(rating))
|
|
{
|
|
{
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
|
|
- // LocationTypes
|
|
|
|
- if (!string.IsNullOrEmpty(request.LocationTypes))
|
|
|
|
- {
|
|
|
|
- var vals = request.LocationTypes.Split(',');
|
|
|
|
- if (!vals.Contains(i.LocationType.ToString(), StringComparer.OrdinalIgnoreCase))
|
|
|
|
|
|
+ if (request.HasTrailer.HasValue)
|
|
{
|
|
{
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ var val = request.HasTrailer.Value;
|
|
|
|
+ var trailerCount = 0;
|
|
|
|
|
|
- // ExcludeLocationTypes
|
|
|
|
- if (!string.IsNullOrEmpty(request.ExcludeLocationTypes))
|
|
|
|
- {
|
|
|
|
- var vals = request.ExcludeLocationTypes.Split(',');
|
|
|
|
- if (vals.Contains(i.LocationType.ToString(), StringComparer.OrdinalIgnoreCase))
|
|
|
|
- {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ var hasTrailers = i as IHasTrailers;
|
|
|
|
+ if (hasTrailers != null)
|
|
|
|
+ {
|
|
|
|
+ trailerCount = hasTrailers.LocalTrailerIds.Count;
|
|
|
|
+ }
|
|
|
|
|
|
- if (!string.IsNullOrEmpty(request.AlbumArtistStartsWithOrGreater))
|
|
|
|
- {
|
|
|
|
- var ok = new[] { i }.OfType<IHasAlbumArtist>()
|
|
|
|
- .Any(p => string.Compare(request.AlbumArtistStartsWithOrGreater, p.AlbumArtists.FirstOrDefault(), StringComparison.CurrentCultureIgnoreCase) < 1);
|
|
|
|
|
|
+ var ok = val ? trailerCount > 0 : trailerCount == 0;
|
|
|
|
|
|
- if (!ok)
|
|
|
|
- {
|
|
|
|
- return false;
|
|
|
|
|
|
+ if (!ok)
|
|
|
|
+ {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- }
|
|
|
|
-
|
|
|
|
- // Filter by Series Status
|
|
|
|
- if (!string.IsNullOrEmpty(request.SeriesStatus))
|
|
|
|
- {
|
|
|
|
- var vals = request.SeriesStatus.Split(',');
|
|
|
|
|
|
|
|
- var ok = new[] { i }.OfType<Series>().Any(p => p.Status.HasValue && vals.Contains(p.Status.Value.ToString(), StringComparer.OrdinalIgnoreCase));
|
|
|
|
-
|
|
|
|
- if (!ok)
|
|
|
|
|
|
+ if (request.HasThemeSong.HasValue)
|
|
{
|
|
{
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ var filterValue = request.HasThemeSong.Value;
|
|
|
|
|
|
- // Filter by Series AirDays
|
|
|
|
- if (!string.IsNullOrEmpty(request.AirDays))
|
|
|
|
- {
|
|
|
|
- var days = request.AirDays.Split(',').Select(d => (DayOfWeek)Enum.Parse(typeof(DayOfWeek), d, true));
|
|
|
|
|
|
+ var themeCount = 0;
|
|
|
|
+ var iHasThemeMedia = i as IHasThemeMedia;
|
|
|
|
|
|
- var ok = new[] { i }.OfType<Series>().Any(p => p.AirDays != null && days.Any(d => p.AirDays.Contains(d)));
|
|
|
|
|
|
+ if (iHasThemeMedia != null)
|
|
|
|
+ {
|
|
|
|
+ themeCount = iHasThemeMedia.ThemeSongIds.Count;
|
|
|
|
+ }
|
|
|
|
+ var ok = filterValue ? themeCount > 0 : themeCount == 0;
|
|
|
|
|
|
- if (!ok)
|
|
|
|
- {
|
|
|
|
- return false;
|
|
|
|
|
|
+ if (!ok)
|
|
|
|
+ {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- }
|
|
|
|
-
|
|
|
|
- // Filter by Video3DFormat
|
|
|
|
- if (request.Is3D.HasValue)
|
|
|
|
- {
|
|
|
|
- var val = request.Is3D.Value;
|
|
|
|
- var video = i as Video;
|
|
|
|
|
|
|
|
- if (video == null || val != video.Video3DFormat.HasValue)
|
|
|
|
|
|
+ if (request.HasThemeVideo.HasValue)
|
|
{
|
|
{
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ var filterValue = request.HasThemeVideo.Value;
|
|
|
|
|
|
- // Filter by VideoType
|
|
|
|
- if (!string.IsNullOrEmpty(request.VideoTypes))
|
|
|
|
- {
|
|
|
|
- var types = request.VideoTypes.Split(',');
|
|
|
|
|
|
+ var themeCount = 0;
|
|
|
|
+ var iHasThemeMedia = i as IHasThemeMedia;
|
|
|
|
|
|
- var video = i as Video;
|
|
|
|
- if (video == null || !types.Contains(video.VideoType.ToString(), StringComparer.OrdinalIgnoreCase))
|
|
|
|
- {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ if (iHasThemeMedia != null)
|
|
|
|
+ {
|
|
|
|
+ themeCount = iHasThemeMedia.ThemeVideoIds.Count;
|
|
|
|
+ }
|
|
|
|
+ var ok = filterValue ? themeCount > 0 : themeCount == 0;
|
|
|
|
|
|
- var imageTypes = request.GetImageTypes().ToList();
|
|
|
|
- if (imageTypes.Count > 0)
|
|
|
|
- {
|
|
|
|
- if (!(imageTypes.Any(imageType => HasImage(i, imageType))))
|
|
|
|
- {
|
|
|
|
- return false;
|
|
|
|
|
|
+ if (!ok)
|
|
|
|
+ {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
|
|
- // Apply genre filter
|
|
|
|
- if (!string.IsNullOrEmpty(request.Genres))
|
|
|
|
- {
|
|
|
|
- var vals = request.Genres.Split('|');
|
|
|
|
- if (!(vals.Any(v => i.Genres.Contains(v, StringComparer.OrdinalIgnoreCase))))
|
|
|
|
|
|
+ // Apply genre filter
|
|
|
|
+ var genres = request.GetGenres();
|
|
|
|
+ if (genres.Length > 0 && !(genres.Any(v => i.Genres.Contains(v, StringComparer.OrdinalIgnoreCase))))
|
|
{
|
|
{
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
|
|
- // Apply genre filter
|
|
|
|
- if (!string.IsNullOrEmpty(request.AllGenres))
|
|
|
|
- {
|
|
|
|
- var vals = request.AllGenres.Split('|');
|
|
|
|
- if (!vals.All(v => i.Genres.Contains(v, StringComparer.OrdinalIgnoreCase)))
|
|
|
|
|
|
+ // Apply genre filter
|
|
|
|
+ var allGenres = request.GetAllGenres();
|
|
|
|
+ if (allGenres.Length > 0 && !allGenres.All(v => i.Genres.Contains(v, StringComparer.OrdinalIgnoreCase)))
|
|
{
|
|
{
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
|
|
- // Apply studio filter
|
|
|
|
- if (!string.IsNullOrEmpty(request.Studios))
|
|
|
|
- {
|
|
|
|
- var vals = request.Studios.Split('|');
|
|
|
|
- if (!vals.Any(v => i.Studios.Contains(v, StringComparer.OrdinalIgnoreCase)))
|
|
|
|
|
|
+ // Filter by VideoType
|
|
|
|
+ if (!string.IsNullOrEmpty(request.VideoTypes))
|
|
{
|
|
{
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // Apply year filter
|
|
|
|
- if (!string.IsNullOrEmpty(request.Years))
|
|
|
|
- {
|
|
|
|
- var vals = request.Years.Split(',').Select(int.Parse).ToList();
|
|
|
|
- if (!(i.ProductionYear.HasValue && vals.Contains(i.ProductionYear.Value)))
|
|
|
|
- {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // Apply person filter
|
|
|
|
- if (!string.IsNullOrEmpty(request.Person))
|
|
|
|
- {
|
|
|
|
- var personTypes = request.PersonTypes;
|
|
|
|
|
|
+ var types = request.VideoTypes.Split(',');
|
|
|
|
|
|
- if (string.IsNullOrEmpty(personTypes))
|
|
|
|
- {
|
|
|
|
- if (!(i.People.Any(p => string.Equals(p.Name, request.Person, StringComparison.OrdinalIgnoreCase))))
|
|
|
|
|
|
+ var video = i as Video;
|
|
|
|
+ if (video == null || !types.Contains(video.VideoType.ToString(), StringComparer.OrdinalIgnoreCase))
|
|
{
|
|
{
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- else
|
|
|
|
- {
|
|
|
|
- var types = personTypes.Split(',');
|
|
|
|
|
|
|
|
- var ok = new[] { i }.Any(item =>
|
|
|
|
- item.People != null &&
|
|
|
|
- item.People.Any(p =>
|
|
|
|
- p.Name.Equals(request.Person, StringComparison.OrdinalIgnoreCase) && (types.Contains(p.Type, StringComparer.OrdinalIgnoreCase) || types.Contains(p.Role, StringComparer.OrdinalIgnoreCase))));
|
|
|
|
-
|
|
|
|
- if (!ok)
|
|
|
|
|
|
+ var imageTypes = request.GetImageTypes().ToList();
|
|
|
|
+ if (imageTypes.Count > 0)
|
|
|
|
+ {
|
|
|
|
+ if (!(imageTypes.Any(i.HasImage)))
|
|
{
|
|
{
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }
|
|
|
|
-
|
|
|
|
- if (request.HasTrailer.HasValue)
|
|
|
|
- {
|
|
|
|
- var val = request.HasTrailer.Value;
|
|
|
|
- var trailerCount = 0;
|
|
|
|
|
|
|
|
- var hasTrailers = i as IHasTrailers;
|
|
|
|
- if (hasTrailers != null)
|
|
|
|
|
|
+ // Apply studio filter
|
|
|
|
+ var studios = request.GetStudios();
|
|
|
|
+ if (studios.Length > 0 && !studios.Any(v => i.Studios.Contains(v, StringComparer.OrdinalIgnoreCase)))
|
|
{
|
|
{
|
|
- trailerCount = hasTrailers.LocalTrailerIds.Count;
|
|
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
|
|
|
|
- var ok = val ? trailerCount > 0 : trailerCount == 0;
|
|
|
|
-
|
|
|
|
- if (!ok)
|
|
|
|
|
|
+ // Apply year filter
|
|
|
|
+ var years = request.GetYears();
|
|
|
|
+ if (years.Length > 0 && !(i.ProductionYear.HasValue && years.Contains(i.ProductionYear.Value)))
|
|
{
|
|
{
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
|
|
- if (request.HasThemeSong.HasValue)
|
|
|
|
- {
|
|
|
|
- var filterValue = request.HasThemeSong.Value;
|
|
|
|
|
|
+ // Apply person filter
|
|
|
|
+ if (!string.IsNullOrEmpty(request.Person))
|
|
|
|
+ {
|
|
|
|
+ var personTypes = request.GetPersonTypes();
|
|
|
|
|
|
- var themeCount = 0;
|
|
|
|
- var iHasThemeMedia = i as IHasThemeMedia;
|
|
|
|
|
|
+ if (personTypes.Length == 0)
|
|
|
|
+ {
|
|
|
|
+ if (!(i.People.Any(p => string.Equals(p.Name, request.Person, StringComparison.OrdinalIgnoreCase))))
|
|
|
|
+ {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ var types = personTypes;
|
|
|
|
|
|
- if (iHasThemeMedia != null)
|
|
|
|
- {
|
|
|
|
- themeCount = iHasThemeMedia.ThemeSongIds.Count;
|
|
|
|
- }
|
|
|
|
- var ok = filterValue ? themeCount > 0 : themeCount == 0;
|
|
|
|
|
|
+ var ok = new[] { i }.Any(item =>
|
|
|
|
+ item.People != null &&
|
|
|
|
+ item.People.Any(p =>
|
|
|
|
+ p.Name.Equals(request.Person, StringComparison.OrdinalIgnoreCase) && (types.Contains(p.Type, StringComparer.OrdinalIgnoreCase) || types.Contains(p.Role, StringComparer.OrdinalIgnoreCase))));
|
|
|
|
|
|
- if (!ok)
|
|
|
|
- {
|
|
|
|
- return false;
|
|
|
|
|
|
+ if (!ok)
|
|
|
|
+ {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if (request.HasThemeVideo.HasValue)
|
|
|
|
|
|
+ if (request.MinCommunityRating.HasValue)
|
|
{
|
|
{
|
|
- var filterValue = request.HasThemeVideo.Value;
|
|
|
|
-
|
|
|
|
- var themeCount = 0;
|
|
|
|
- var iHasThemeMedia = i as IHasThemeMedia;
|
|
|
|
-
|
|
|
|
- if (iHasThemeMedia != null)
|
|
|
|
- {
|
|
|
|
- themeCount = iHasThemeMedia.ThemeVideoIds.Count;
|
|
|
|
- }
|
|
|
|
- var ok = filterValue ? themeCount > 0 : themeCount == 0;
|
|
|
|
|
|
+ var val = request.MinCommunityRating.Value;
|
|
|
|
|
|
- if (!ok)
|
|
|
|
|
|
+ if (!(i.CommunityRating.HasValue && i.CommunityRating >= val))
|
|
{
|
|
{
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if (request.MinPlayers.HasValue)
|
|
|
|
|
|
+ if (request.MinCriticRating.HasValue)
|
|
{
|
|
{
|
|
- var filterValue = request.MinPlayers.Value;
|
|
|
|
|
|
+ var val = request.MinCriticRating.Value;
|
|
|
|
|
|
- var game = i as Game;
|
|
|
|
|
|
+ var hasCriticRating = i as IHasCriticRating;
|
|
|
|
|
|
- if (game != null)
|
|
|
|
|
|
+ if (hasCriticRating != null)
|
|
{
|
|
{
|
|
- var players = game.PlayersSupported ?? 1;
|
|
|
|
-
|
|
|
|
- var ok = players >= filterValue;
|
|
|
|
-
|
|
|
|
- if (!ok)
|
|
|
|
|
|
+ if (!(hasCriticRating.CriticRating.HasValue && hasCriticRating.CriticRating >= val))
|
|
{
|
|
{
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
@@ -1141,504 +1060,284 @@ namespace MediaBrowser.Api.UserLibrary
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if (request.MaxPlayers.HasValue)
|
|
|
|
|
|
+ // Artists
|
|
|
|
+ if (!string.IsNullOrEmpty(request.Artists))
|
|
{
|
|
{
|
|
- var filterValue = request.MaxPlayers.Value;
|
|
|
|
-
|
|
|
|
- var game = i as Game;
|
|
|
|
-
|
|
|
|
- if (game != null)
|
|
|
|
- {
|
|
|
|
- var players = game.PlayersSupported ?? 1;
|
|
|
|
|
|
+ var artists = request.Artists.Split('|');
|
|
|
|
|
|
- var ok = players <= filterValue;
|
|
|
|
|
|
+ var audio = i as IHasArtist;
|
|
|
|
|
|
- if (!ok)
|
|
|
|
- {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
|
|
+ if (!(audio != null && artists.Any(audio.HasArtist)))
|
|
{
|
|
{
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if (request.HasSpecialFeature.HasValue)
|
|
|
|
|
|
+ // Albums
|
|
|
|
+ if (!string.IsNullOrEmpty(request.Albums))
|
|
{
|
|
{
|
|
- var filterValue = request.HasSpecialFeature.Value;
|
|
|
|
|
|
+ var albums = request.Albums.Split('|');
|
|
|
|
|
|
- var movie = i as IHasSpecialFeatures;
|
|
|
|
|
|
+ var audio = i as Audio;
|
|
|
|
|
|
- if (movie != null)
|
|
|
|
|
|
+ if (audio != null)
|
|
{
|
|
{
|
|
- var ok = filterValue
|
|
|
|
- ? movie.SpecialFeatureIds.Count > 0
|
|
|
|
- : movie.SpecialFeatureIds.Count == 0;
|
|
|
|
-
|
|
|
|
- if (!ok)
|
|
|
|
|
|
+ if (!albums.Any(a => string.Equals(a, audio.Album, StringComparison.OrdinalIgnoreCase)))
|
|
{
|
|
{
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- else
|
|
|
|
- {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (request.HasSubtitles.HasValue)
|
|
|
|
- {
|
|
|
|
- var val = request.HasSubtitles.Value;
|
|
|
|
-
|
|
|
|
- var video = i as Video;
|
|
|
|
-
|
|
|
|
- if (video == null || val != video.HasSubtitles)
|
|
|
|
- {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
|
|
- if (request.HasParentalRating.HasValue)
|
|
|
|
- {
|
|
|
|
- var val = request.HasParentalRating.Value;
|
|
|
|
-
|
|
|
|
- var rating = i.CustomRating;
|
|
|
|
-
|
|
|
|
- if (string.IsNullOrEmpty(rating))
|
|
|
|
- {
|
|
|
|
- rating = i.OfficialRating;
|
|
|
|
- }
|
|
|
|
|
|
+ var album = i as MusicAlbum;
|
|
|
|
|
|
- if (val)
|
|
|
|
|
|
+ if (album != null)
|
|
{
|
|
{
|
|
- if (string.IsNullOrEmpty(rating))
|
|
|
|
|
|
+ if (!albums.Any(a => string.Equals(a, album.Name, StringComparison.OrdinalIgnoreCase)))
|
|
{
|
|
{
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- else
|
|
|
|
|
|
+
|
|
|
|
+ var musicVideo = i as MusicVideo;
|
|
|
|
+
|
|
|
|
+ if (musicVideo != null)
|
|
{
|
|
{
|
|
- if (!string.IsNullOrEmpty(rating))
|
|
|
|
|
|
+ if (!albums.Any(a => string.Equals(a, musicVideo.Album, StringComparison.OrdinalIgnoreCase)))
|
|
{
|
|
{
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }
|
|
|
|
-
|
|
|
|
- if (request.IsHD.HasValue)
|
|
|
|
- {
|
|
|
|
- var val = request.IsHD.Value;
|
|
|
|
- var video = i as Video;
|
|
|
|
|
|
|
|
- if (video == null || val != video.IsHD)
|
|
|
|
- {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
|
|
|
|
- if (request.IsInBoxSet.HasValue)
|
|
|
|
|
|
+ // Min index number
|
|
|
|
+ if (request.MinIndexNumber.HasValue)
|
|
{
|
|
{
|
|
- var val = request.IsHD.Value;
|
|
|
|
- if (i.Parents.OfType<BoxSet>().Any() != val)
|
|
|
|
|
|
+ if (!(i.IndexNumber.HasValue && i.IndexNumber.Value >= request.MinIndexNumber.Value))
|
|
{
|
|
{
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if (request.IsUnidentified.HasValue)
|
|
|
|
|
|
+ // Min official rating
|
|
|
|
+ if (!string.IsNullOrEmpty(request.MinOfficialRating))
|
|
{
|
|
{
|
|
- var val = request.IsUnidentified.Value;
|
|
|
|
- if (i.IsUnidentified != val)
|
|
|
|
- {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ var level = _localization.GetRatingLevel(request.MinOfficialRating);
|
|
|
|
|
|
- if (request.IsLocked.HasValue)
|
|
|
|
- {
|
|
|
|
- var val = request.IsLocked.Value;
|
|
|
|
- if (i.IsLocked != val)
|
|
|
|
|
|
+ if (level.HasValue)
|
|
{
|
|
{
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (request.ParentIndexNumber.HasValue)
|
|
|
|
- {
|
|
|
|
- var filterValue = request.ParentIndexNumber.Value;
|
|
|
|
-
|
|
|
|
- var episode = i as Episode;
|
|
|
|
|
|
+ var rating = i.CustomRating;
|
|
|
|
|
|
- if (episode != null)
|
|
|
|
- {
|
|
|
|
- if (episode.ParentIndexNumber.HasValue && episode.ParentIndexNumber.Value != filterValue)
|
|
|
|
|
|
+ if (string.IsNullOrEmpty(rating))
|
|
{
|
|
{
|
|
- return false;
|
|
|
|
|
|
+ rating = i.OfficialRating;
|
|
}
|
|
}
|
|
- }
|
|
|
|
-
|
|
|
|
- var song = i as Audio;
|
|
|
|
|
|
|
|
- if (song != null)
|
|
|
|
- {
|
|
|
|
- if (song.ParentIndexNumber.HasValue && song.ParentIndexNumber.Value != filterValue)
|
|
|
|
|
|
+ if (!string.IsNullOrEmpty(rating))
|
|
{
|
|
{
|
|
- return false;
|
|
|
|
|
|
+ var itemLevel = _localization.GetRatingLevel(rating);
|
|
|
|
+
|
|
|
|
+ if (!(!itemLevel.HasValue || itemLevel.Value >= level.Value))
|
|
|
|
+ {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if (request.AiredDuringSeason.HasValue)
|
|
|
|
|
|
+ // Max official rating
|
|
|
|
+ if (!string.IsNullOrEmpty(request.MaxOfficialRating))
|
|
{
|
|
{
|
|
- var episode = i as Episode;
|
|
|
|
|
|
+ var level = _localization.GetRatingLevel(request.MaxOfficialRating);
|
|
|
|
|
|
- if (episode == null)
|
|
|
|
|
|
+ if (level.HasValue)
|
|
{
|
|
{
|
|
- return false;
|
|
|
|
- }
|
|
|
|
|
|
+ var rating = i.CustomRating;
|
|
|
|
|
|
- if (!Series.FilterEpisodesBySeason(new[] { episode }, request.AiredDuringSeason.Value, true).Any())
|
|
|
|
- {
|
|
|
|
- return false;
|
|
|
|
|
|
+ if (string.IsNullOrEmpty(rating))
|
|
|
|
+ {
|
|
|
|
+ rating = i.OfficialRating;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!string.IsNullOrEmpty(rating))
|
|
|
|
+ {
|
|
|
|
+ var itemLevel = _localization.GetRatingLevel(rating);
|
|
|
|
+
|
|
|
|
+ if (!(!itemLevel.HasValue || itemLevel.Value <= level.Value))
|
|
|
|
+ {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if (!string.IsNullOrEmpty(request.MinPremiereDate))
|
|
|
|
|
|
+ // LocationTypes
|
|
|
|
+ if (!string.IsNullOrEmpty(request.LocationTypes))
|
|
{
|
|
{
|
|
- var date = DateTime.Parse(request.MinPremiereDate, null, DateTimeStyles.RoundtripKind).ToUniversalTime();
|
|
|
|
-
|
|
|
|
- if (!(i.PremiereDate.HasValue && i.PremiereDate.Value >= date))
|
|
|
|
|
|
+ var vals = request.LocationTypes.Split(',');
|
|
|
|
+ if (!vals.Contains(i.LocationType.ToString(), StringComparer.OrdinalIgnoreCase))
|
|
{
|
|
{
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if (!string.IsNullOrEmpty(request.MaxPremiereDate))
|
|
|
|
|
|
+ // ExcludeLocationTypes
|
|
|
|
+ if (!string.IsNullOrEmpty(request.ExcludeLocationTypes))
|
|
{
|
|
{
|
|
- var date = DateTime.Parse(request.MaxPremiereDate, null, DateTimeStyles.RoundtripKind).ToUniversalTime();
|
|
|
|
-
|
|
|
|
- if (!(i.PremiereDate.HasValue && i.PremiereDate.Value <= date))
|
|
|
|
|
|
+ var vals = request.ExcludeLocationTypes.Split(',');
|
|
|
|
+ if (vals.Contains(i.LocationType.ToString(), StringComparer.OrdinalIgnoreCase))
|
|
{
|
|
{
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if (request.HasOverview.HasValue)
|
|
|
|
|
|
+ if (!string.IsNullOrEmpty(request.AlbumArtistStartsWithOrGreater))
|
|
{
|
|
{
|
|
- var filterValue = request.HasOverview.Value;
|
|
|
|
-
|
|
|
|
- var hasValue = !string.IsNullOrEmpty(i.Overview);
|
|
|
|
|
|
+ var ok = new[] { i }.OfType<IHasAlbumArtist>()
|
|
|
|
+ .Any(p => string.Compare(request.AlbumArtistStartsWithOrGreater, p.AlbumArtists.FirstOrDefault(), StringComparison.CurrentCultureIgnoreCase) < 1);
|
|
|
|
|
|
- if (hasValue != filterValue)
|
|
|
|
|
|
+ if (!ok)
|
|
{
|
|
{
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if (request.HasImdbId.HasValue)
|
|
|
|
|
|
+ // Filter by Series Status
|
|
|
|
+ if (!string.IsNullOrEmpty(request.SeriesStatus))
|
|
{
|
|
{
|
|
- var filterValue = request.HasImdbId.Value;
|
|
|
|
|
|
+ var vals = request.SeriesStatus.Split(',');
|
|
|
|
|
|
- var hasValue = !string.IsNullOrEmpty(i.GetProviderId(MetadataProviders.Imdb));
|
|
|
|
|
|
+ var ok = new[] { i }.OfType<Series>().Any(p => p.Status.HasValue && vals.Contains(p.Status.Value.ToString(), StringComparer.OrdinalIgnoreCase));
|
|
|
|
|
|
- if (hasValue != filterValue)
|
|
|
|
|
|
+ if (!ok)
|
|
{
|
|
{
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if (request.HasTmdbId.HasValue)
|
|
|
|
|
|
+ // Filter by Series AirDays
|
|
|
|
+ if (!string.IsNullOrEmpty(request.AirDays))
|
|
{
|
|
{
|
|
- var filterValue = request.HasTmdbId.Value;
|
|
|
|
|
|
+ var days = request.AirDays.Split(',').Select(d => (DayOfWeek)Enum.Parse(typeof(DayOfWeek), d, true));
|
|
|
|
|
|
- var hasValue = !string.IsNullOrEmpty(i.GetProviderId(MetadataProviders.Tmdb));
|
|
|
|
|
|
+ var ok = new[] { i }.OfType<Series>().Any(p => p.AirDays != null && days.Any(d => p.AirDays.Contains(d)));
|
|
|
|
|
|
- if (hasValue != filterValue)
|
|
|
|
|
|
+ if (!ok)
|
|
{
|
|
{
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if (request.HasTvdbId.HasValue)
|
|
|
|
|
|
+ if (request.MinPlayers.HasValue)
|
|
{
|
|
{
|
|
- var filterValue = request.HasTvdbId.Value;
|
|
|
|
|
|
+ var filterValue = request.MinPlayers.Value;
|
|
|
|
|
|
- var hasValue = !string.IsNullOrEmpty(i.GetProviderId(MetadataProviders.Tvdb));
|
|
|
|
|
|
+ var game = i as Game;
|
|
|
|
|
|
- if (hasValue != filterValue)
|
|
|
|
|
|
+ if (game != null)
|
|
{
|
|
{
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ var players = game.PlayersSupported ?? 1;
|
|
|
|
|
|
- if (request.IsYearMismatched.HasValue)
|
|
|
|
- {
|
|
|
|
- var filterValue = request.IsYearMismatched.Value;
|
|
|
|
|
|
+ var ok = players >= filterValue;
|
|
|
|
|
|
- if (IsYearMismatched(i) != filterValue)
|
|
|
|
|
|
+ if (!ok)
|
|
|
|
+ {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else
|
|
{
|
|
{
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if (request.HasOfficialRating.HasValue)
|
|
|
|
|
|
+ if (request.MaxPlayers.HasValue)
|
|
{
|
|
{
|
|
- var filterValue = request.HasOfficialRating.Value;
|
|
|
|
|
|
+ var filterValue = request.MaxPlayers.Value;
|
|
|
|
|
|
- var hasValue = !string.IsNullOrEmpty(i.OfficialRating);
|
|
|
|
|
|
+ var game = i as Game;
|
|
|
|
|
|
- if (hasValue != filterValue)
|
|
|
|
|
|
+ if (game != null)
|
|
{
|
|
{
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (request.IsPlaceHolder.HasValue)
|
|
|
|
- {
|
|
|
|
- var filterValue = request.IsPlaceHolder.Value;
|
|
|
|
-
|
|
|
|
- var isPlaceHolder = false;
|
|
|
|
|
|
+ var players = game.PlayersSupported ?? 1;
|
|
|
|
|
|
- var hasPlaceHolder = i as ISupportsPlaceHolders;
|
|
|
|
|
|
+ var ok = players <= filterValue;
|
|
|
|
|
|
- if (hasPlaceHolder != null)
|
|
|
|
- {
|
|
|
|
- isPlaceHolder = hasPlaceHolder.IsPlaceHolder;
|
|
|
|
|
|
+ if (!ok)
|
|
|
|
+ {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
-
|
|
|
|
- if (isPlaceHolder != filterValue)
|
|
|
|
|
|
+ else
|
|
{
|
|
{
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- return true;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private IEnumerable<BaseItem> ApplyPostCollectionCollapseFilters(GetItems request, IEnumerable<BaseItem> items, User user)
|
|
|
|
- {
|
|
|
|
- if (!string.IsNullOrEmpty(request.NameStartsWithOrGreater))
|
|
|
|
- {
|
|
|
|
- items = items.Where(i => string.Compare(request.NameStartsWithOrGreater, i.SortName, StringComparison.CurrentCultureIgnoreCase) < 1);
|
|
|
|
- }
|
|
|
|
- if (!string.IsNullOrEmpty(request.NameStartsWith))
|
|
|
|
- {
|
|
|
|
- items = items.Where(i => string.Compare(request.NameStartsWith, i.SortName.Substring(0, 1), StringComparison.CurrentCultureIgnoreCase) == 0);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (!string.IsNullOrEmpty(request.NameLessThan))
|
|
|
|
|
|
+ if (request.ParentIndexNumber.HasValue)
|
|
{
|
|
{
|
|
- items = items.Where(i => string.Compare(request.NameLessThan, i.SortName, StringComparison.CurrentCultureIgnoreCase) == 1);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return items;
|
|
|
|
- }
|
|
|
|
|
|
+ var filterValue = request.ParentIndexNumber.Value;
|
|
|
|
|
|
- private bool IsYearMismatched(BaseItem item)
|
|
|
|
- {
|
|
|
|
- if (item.ProductionYear.HasValue)
|
|
|
|
- {
|
|
|
|
- var path = item.Path;
|
|
|
|
|
|
+ var episode = i as Episode;
|
|
|
|
|
|
- if (!string.IsNullOrEmpty(path))
|
|
|
|
|
|
+ if (episode != null)
|
|
{
|
|
{
|
|
- int? yearInName;
|
|
|
|
- string name;
|
|
|
|
- NameParser.ParseName(Path.GetFileName(path), out name, out yearInName);
|
|
|
|
-
|
|
|
|
- // Go up a level if we didn't get a year
|
|
|
|
- if (!yearInName.HasValue)
|
|
|
|
|
|
+ if (episode.ParentIndexNumber.HasValue && episode.ParentIndexNumber.Value != filterValue)
|
|
{
|
|
{
|
|
- NameParser.ParseName(Path.GetFileName(Path.GetDirectoryName(path)), out name, out yearInName);
|
|
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
|
|
- if (yearInName.HasValue)
|
|
|
|
|
|
+ var song = i as Audio;
|
|
|
|
+
|
|
|
|
+ if (song != null)
|
|
|
|
+ {
|
|
|
|
+ if (song.ParentIndexNumber.HasValue && song.ParentIndexNumber.Value != filterValue)
|
|
{
|
|
{
|
|
- return yearInName.Value != item.ProductionYear.Value;
|
|
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private bool AllowBoxSetCollapsing(GetItems request)
|
|
|
|
- {
|
|
|
|
- if (!string.IsNullOrWhiteSpace(request.Filters))
|
|
|
|
- {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (!string.IsNullOrWhiteSpace(request.AllGenres))
|
|
|
|
- {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (!string.IsNullOrWhiteSpace(request.Genres))
|
|
|
|
- {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (request.HasImdbId.HasValue)
|
|
|
|
- {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (request.HasOfficialRating.HasValue)
|
|
|
|
- {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (request.HasOverview.HasValue)
|
|
|
|
- {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (request.HasParentalRating.HasValue)
|
|
|
|
- {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (request.HasSpecialFeature.HasValue)
|
|
|
|
- {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (request.HasSubtitles.HasValue)
|
|
|
|
- {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (request.HasThemeSong.HasValue)
|
|
|
|
- {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (request.HasThemeVideo.HasValue)
|
|
|
|
- {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (request.HasTmdbId.HasValue)
|
|
|
|
- {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (request.HasTrailer.HasValue)
|
|
|
|
- {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (!string.IsNullOrWhiteSpace(request.Ids))
|
|
|
|
- {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (!string.IsNullOrWhiteSpace(request.ImageTypes))
|
|
|
|
- {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (request.Is3D.HasValue)
|
|
|
|
- {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (request.IsHD.HasValue)
|
|
|
|
- {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (request.IsInBoxSet.HasValue)
|
|
|
|
- {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (request.IsLocked.HasValue)
|
|
|
|
- {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (request.IsPlaceHolder.HasValue)
|
|
|
|
- {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (request.IsPlayed.HasValue)
|
|
|
|
|
|
+ if (request.AiredDuringSeason.HasValue)
|
|
{
|
|
{
|
|
- return false;
|
|
|
|
- }
|
|
|
|
|
|
+ var episode = i as Episode;
|
|
|
|
|
|
- if (request.IsUnidentified.HasValue)
|
|
|
|
- {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
|
|
+ if (episode == null)
|
|
|
|
+ {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
|
|
- if (request.IsYearMismatched.HasValue)
|
|
|
|
- {
|
|
|
|
- return false;
|
|
|
|
|
|
+ if (!Series.FilterEpisodesBySeason(new[] { episode }, request.AiredDuringSeason.Value, true).Any())
|
|
|
|
+ {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
- if (!string.IsNullOrWhiteSpace(request.Person))
|
|
|
|
|
|
+ if (!string.IsNullOrEmpty(request.MinPremiereDate))
|
|
{
|
|
{
|
|
- return false;
|
|
|
|
- }
|
|
|
|
|
|
+ var date = DateTime.Parse(request.MinPremiereDate, null, DateTimeStyles.RoundtripKind).ToUniversalTime();
|
|
|
|
|
|
- if (!string.IsNullOrWhiteSpace(request.Studios))
|
|
|
|
- {
|
|
|
|
- return false;
|
|
|
|
|
|
+ if (!(i.PremiereDate.HasValue && i.PremiereDate.Value >= date))
|
|
|
|
+ {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
- if (!string.IsNullOrWhiteSpace(request.VideoTypes))
|
|
|
|
|
|
+ if (!string.IsNullOrEmpty(request.MaxPremiereDate))
|
|
{
|
|
{
|
|
- return false;
|
|
|
|
- }
|
|
|
|
|
|
+ var date = DateTime.Parse(request.MaxPremiereDate, null, DateTimeStyles.RoundtripKind).ToUniversalTime();
|
|
|
|
|
|
- if (!string.IsNullOrWhiteSpace(request.Years))
|
|
|
|
- {
|
|
|
|
- return false;
|
|
|
|
|
|
+ if (!(i.PremiereDate.HasValue && i.PremiereDate.Value <= date))
|
|
|
|
+ {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
- internal static IEnumerable<BaseItem> FilterForAdjacency(IEnumerable<BaseItem> items, string adjacentToId)
|
|
|
|
- {
|
|
|
|
- var list = items.ToList();
|
|
|
|
-
|
|
|
|
- var adjacentToIdGuid = new Guid(adjacentToId);
|
|
|
|
- var adjacentToItem = list.FirstOrDefault(i => i.Id == adjacentToIdGuid);
|
|
|
|
-
|
|
|
|
- var index = list.IndexOf(adjacentToItem);
|
|
|
|
-
|
|
|
|
- var previousId = Guid.Empty;
|
|
|
|
- var nextId = Guid.Empty;
|
|
|
|
-
|
|
|
|
- if (index > 0)
|
|
|
|
- {
|
|
|
|
- previousId = list[index - 1].Id;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (index < list.Count - 1)
|
|
|
|
- {
|
|
|
|
- nextId = list[index + 1].Id;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return list.Where(i => i.Id == previousId || i.Id == nextId || i.Id == adjacentToIdGuid);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /// <summary>
|
|
|
|
- /// Determines whether the specified item has image.
|
|
|
|
- /// </summary>
|
|
|
|
- /// <param name="item">The item.</param>
|
|
|
|
- /// <param name="imageType">Type of the image.</param>
|
|
|
|
- /// <returns><c>true</c> if the specified item has image; otherwise, <c>false</c>.</returns>
|
|
|
|
- internal static bool HasImage(BaseItem item, ImageType imageType)
|
|
|
|
- {
|
|
|
|
- return item.HasImage(imageType);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Applies the paging.
|
|
/// Applies the paging.
|
|
/// </summary>
|
|
/// </summary>
|