private InternalItemsQuery GetItemsQuery(BaseReportRequest request, User user) { var query = new InternalItemsQuery(user) { IsPlayed = request.IsPlayed, MediaTypes = request.GetMediaTypes(), IncludeItemTypes = request.GetIncludeItemTypes(), ExcludeItemTypes = request.GetExcludeItemTypes(), Recursive = request.Recursive, OrderBy = request.GetOrderBy(), Limit = request.Limit, StartIndex = request.StartIndex, IsMissing = request.IsMissing, IsUnaired = request.IsUnaired, CollapseBoxSetItems = request.CollapseBoxSetItems, NameLessThan = request.NameLessThan, NameStartsWith = request.NameStartsWith, NameStartsWithOrGreater = request.NameStartsWithOrGreater, HasImdbId = request.HasImdbId, IsPlaceHolder = request.IsPlaceHolder, IsLocked = request.IsLocked, 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, Tags = request.GetTags(), OfficialRatings = request.GetOfficialRatings(), Genres = request.GetGenres(), GenreIds = request.GetGenreIds(), StudioIds = request.GetStudioIds(), Person = request.Person, PersonIds = request.GetPersonIds(), PersonTypes = request.GetPersonTypes(), Years = request.GetYears(), ImageTypes = request.GetImageTypes().ToArray(), VideoTypes = request.GetVideoTypes().ToArray(), AdjacentTo = request.AdjacentTo, ItemIds = request.GetItemIds(), MinPlayers = request.MinPlayers, MaxPlayers = request.MaxPlayers, MinCommunityRating = request.MinCommunityRating, MinCriticRating = request.MinCriticRating, ParentId = string.IsNullOrWhiteSpace(request.ParentId) ? Guid.Empty : new Guid(request.ParentId), ParentIndexNumber = request.ParentIndexNumber, EnableTotalRecordCount = request.EnableTotalRecordCount }; if (request.Limit == -1) { query.Limit = null; } if (!string.IsNullOrWhiteSpace(request.Ids)) { query.CollapseBoxSetItems = false; } query.IsFavorite = null; if (request.IsFavorite == true) { query.IsFavorite = true; } else if (request.IsNotFavorite == true) { query.IsFavorite = false; } foreach (var filter in request.GetFilters()) { switch (filter) { case ItemFilter.Dislikes: query.IsLiked = false; break; case ItemFilter.IsFavoriteOrLikes: query.IsFavoriteOrLiked = true; break; case ItemFilter.IsFolder: query.IsFolder = true; break; case ItemFilter.IsNotFolder: query.IsFolder = false; break; case ItemFilter.IsPlayed: query.IsPlayed = true; break; case ItemFilter.IsResumable: query.IsResumable = true; break; case ItemFilter.IsUnplayed: query.IsPlayed = false; break; case ItemFilter.Likes: query.IsLiked = true; break; } } if (!string.IsNullOrEmpty(request.MinPremiereDate)) { query.MinPremiereDate = DateTime.Parse(request.MinPremiereDate, null, DateTimeStyles.RoundtripKind).ToUniversalTime(); } if (!string.IsNullOrEmpty(request.MaxPremiereDate)) { query.MaxPremiereDate = DateTime.Parse(request.MaxPremiereDate, null, DateTimeStyles.RoundtripKind).ToUniversalTime(); } // Filter by Series Status if (!string.IsNullOrEmpty(request.SeriesStatus)) { query.SeriesStatuses = request.SeriesStatus.Split(',').Select(d => (SeriesStatus)Enum.Parse(typeof(SeriesStatus), d, true)).ToArray(); } // ExcludeLocationTypes if (!string.IsNullOrEmpty(request.ExcludeLocationTypes)) { var excludeLocationTypes = request.ExcludeLocationTypes.Split(',').Select(d => (LocationType)Enum.Parse(typeof(LocationType), d, true)).ToArray(); if (excludeLocationTypes.Contains(LocationType.Virtual)) { query.IsVirtualItem = false; } } // Min official rating if (!string.IsNullOrWhiteSpace(request.MinOfficialRating)) { query.MinParentalRating = _localization.GetRatingLevel(request.MinOfficialRating); } // Max official rating if (!string.IsNullOrWhiteSpace(request.MaxOfficialRating)) { query.MaxParentalRating = _localization.GetRatingLevel(request.MaxOfficialRating); } query.CollapseBoxSetItems = false; return(query); }
private InternalItemsQuery GetItemsQuery(BaseReportRequest request, DtoOptions dtoOptions, User user) { var query = new InternalItemsQuery(user) { IsPlayed = request.IsPlayed, MediaTypes = request.GetMediaTypes(), IncludeItemTypes = request.GetIncludeItemTypes(), ExcludeItemTypes = request.GetExcludeItemTypes(), Recursive = request.Recursive, OrderBy = request.GetOrderBy(), IsFavorite = request.IsFavorite, StartIndex = request.StartIndex, IsVirtualItem = request.IsMissing, IsUnaired = request.IsUnaired, NameLessThan = request.NameLessThan, NameStartsWith = request.NameStartsWith, NameStartsWithOrGreater = request.NameStartsWithOrGreater, IsLocked = request.IsLocked, MinWidth = request.MinWidth, MinHeight = request.MinHeight, MaxWidth = request.MaxWidth, MaxHeight = request.MaxHeight, Is3D = request.Is3D, HasOverview = request.HasOverview, HasOfficialRating = request.HasOfficialRating, HasParentalRating = request.HasParentalRating, HasExtra = request.HasSpecialFeature, HasSubtitles = request.HasSubtitles, HasThemeSong = request.HasThemeSong, HasThemeVideo = request.HasThemeVideo, HasTrailer = request.HasTrailer, IsHD = request.IsHD, Is4K = request.Is4K, Tags = request.GetTags(), OfficialRatings = request.GetOfficialRatings(), Genres = request.GetGenres(), ArtistIds = ParseIds(request.ArtistIds, _libraryManager), AlbumArtistIds = ParseIds(request.AlbumArtistIds, _libraryManager), ContributingArtistIds = ParseIds(request.ContributingArtistIds, _libraryManager), GenreIds = ParseIds(request.GenreIds, _libraryManager), StudioIds = ParseIds(request.StudioIds, _libraryManager), PersonIds = ParseIds(request.PersonIds, _libraryManager), PersonTypes = request.GetPersonTypes(), Years = request.GetYears(), ImageTypes = request.GetImageTypes(), Containers = request.GetContainers(), AdjacentTo = _libraryManager.GetInternalId(request.AdjacentTo), ItemIds = ParseIds(request.Ids, _libraryManager), MinPlayers = request.MinPlayers, MaxPlayers = request.MaxPlayers, MinCommunityRating = request.MinCommunityRating, MinCriticRating = request.MinCriticRating, ParentIds = ParseIds(request.ParentId, _libraryManager), ParentIndexNumber = request.ParentIndexNumber, EnableTotalRecordCount = request.EnableTotalRecordCount, ExcludeItemIds = ParseIds(request.ExcludeItemIds, _libraryManager), DtoOptions = dtoOptions, SearchTerm = request.SearchTerm, IsMovie = request.IsMovie, IsSports = request.IsSports, IsKids = request.IsKids, IsNews = request.IsNews, IsSeries = request.IsSeries }; var hasAnyProviderId = new List <string>(); var missingAnyProviderId = new List <string>(); if (request.HasImdbId.HasValue) { if (request.HasImdbId.Value) { hasAnyProviderId.Add(MetadataProviders.Imdb.ToString()); } else { missingAnyProviderId.Add(MetadataProviders.Imdb.ToString()); } } if (request.HasTvdbId.HasValue) { if (request.HasTvdbId.Value) { hasAnyProviderId.Add(MetadataProviders.Tvdb.ToString()); } else { missingAnyProviderId.Add(MetadataProviders.Tvdb.ToString()); } } if (request.HasTmdbId.HasValue) { if (request.HasTmdbId.Value) { hasAnyProviderId.Add(MetadataProviders.Tmdb.ToString()); } else { missingAnyProviderId.Add(MetadataProviders.Tmdb.ToString()); } } query.HasAnyProviderId = hasAnyProviderId.ToArray(); query.MissingAnyProviderId = missingAnyProviderId.ToArray(); foreach (var filter in request.GetFilters()) { switch (filter) { case ItemFilter.Dislikes: query.IsLiked = false; break; case ItemFilter.IsFavorite: query.IsFavorite = true; break; case ItemFilter.IsFavoriteOrLikes: query.IsFavorite = true; break; case ItemFilter.IsFolder: query.IsFolder = true; break; case ItemFilter.IsNotFolder: query.IsFolder = false; break; case ItemFilter.IsPlayed: query.IsPlayed = true; break; case ItemFilter.IsResumable: query.IsResumable = true; break; case ItemFilter.IsUnplayed: query.IsPlayed = false; break; case ItemFilter.Likes: query.IsLiked = true; break; } } if (!string.IsNullOrEmpty(request.MinDateLastSaved)) { query.MinDateLastSaved = DateTime.Parse(request.MinDateLastSaved, null, DateTimeStyles.RoundtripKind).ToUniversalTime(); } if (!string.IsNullOrEmpty(request.MinDateLastSavedForUser)) { query.MinDateLastSavedForUser = DateTime.Parse(request.MinDateLastSavedForUser, null, DateTimeStyles.RoundtripKind).ToUniversalTime(); } if (!string.IsNullOrEmpty(request.MinPremiereDate)) { query.MinPremiereDate = DateTime.Parse(request.MinPremiereDate, null, DateTimeStyles.RoundtripKind).ToUniversalTime(); } if (!string.IsNullOrEmpty(request.MaxPremiereDate)) { query.MaxPremiereDate = DateTime.Parse(request.MaxPremiereDate, null, DateTimeStyles.RoundtripKind).ToUniversalTime(); } // Filter by Series Status if (!string.IsNullOrEmpty(request.SeriesStatus)) { query.SeriesStatuses = request.SeriesStatus.Split(',').Select(d => (SeriesStatus)Enum.Parse(typeof(SeriesStatus), d, true)).ToArray(); } // ExcludeLocationTypes if (!string.IsNullOrEmpty(request.ExcludeLocationTypes)) { var excludeLocationTypes = request.ExcludeLocationTypes.Split(',').Select(d => (LocationType)Enum.Parse(typeof(LocationType), d, true)).ToArray(); if (excludeLocationTypes.Contains(LocationType.Virtual)) { query.IsVirtualItem = false; } } if (!string.IsNullOrEmpty(request.LocationTypes)) { var requestedLocationTypes = request.LocationTypes.Split(','); if (requestedLocationTypes.Length > 0 && requestedLocationTypes.Length < 4) { query.IsVirtualItem = requestedLocationTypes.Contains(LocationType.Virtual.ToString()); } } // Min official rating if (!string.IsNullOrWhiteSpace(request.MinOfficialRating)) { query.MinParentalRating = _localization.GetRatingLevel(request.MinOfficialRating.AsSpan()); } // Max official rating if (!string.IsNullOrWhiteSpace(request.MaxOfficialRating)) { query.MaxParentalRating = _localization.GetRatingLevel(request.MaxOfficialRating.AsSpan()); } // ExcludeArtistIds if (!string.IsNullOrWhiteSpace(request.ExcludeArtistIds)) { query.ExcludeArtistIds = ParseIds(request.ExcludeArtistIds, _libraryManager); } if (!string.IsNullOrWhiteSpace(request.AlbumIds)) { query.AlbumIds = ParseIds(request.AlbumIds, _libraryManager); } // Apply default sorting if none requested if (query.OrderBy.Length == 0) { // Albums by artist if ((query.ArtistIds.Length > 0) && query.IncludeItemTypes.Length == 1 && string.Equals(query.IncludeItemTypes[0], "MusicAlbum", StringComparison.OrdinalIgnoreCase)) { query.OrderBy = new[] { new ValueTuple <string, SortOrder>(ItemSortBy.ProductionYear, SortOrder.Descending), new ValueTuple <string, SortOrder>(ItemSortBy.SortName, SortOrder.Ascending) }; } } if (request.Limit > -1 && request.Limit < int.MaxValue) { query.Limit = request.Limit; } return(query); }