From 4b7093e923b457f34f717f286ebb08514cfb9067 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 20 Mar 2016 02:46:51 -0400 Subject: [PATCH] get recursive items from db --- MediaBrowser.Api/GamesService.cs | 4 +- MediaBrowser.Api/Library/LibraryService.cs | 10 +- MediaBrowser.Api/Movies/MoviesService.cs | 4 +- MediaBrowser.Api/Reports/ReportsService.cs | 51 +-- MediaBrowser.Api/TvShowsService.cs | 8 +- MediaBrowser.Api/UserLibrary/ItemsService.cs | 63 ++- MediaBrowser.Controller/Entities/Folder.cs | 422 +++++++++++++++++- .../Entities/InternalItemsQuery.cs | 1 + .../Entities/UserRootFolder.cs | 9 +- .../Entities/UserViewBuilder.cs | 40 +- .../Library/ILibraryManager.cs | 21 +- .../ContentDirectory/ControlHandler.cs | 2 +- .../People/TvdbPersonImageProvider.cs | 4 +- .../Channels/ChannelManager.cs | 7 +- .../Dto/DtoService.cs | 5 +- .../Intros/DefaultIntroProvider.cs | 4 +- .../Library/LibraryManager.cs | 43 +- .../Library/LocalTrailerPostScanTask.cs | 7 +- .../Library/MusicManager.cs | 2 +- .../Library/SearchEngine.cs | 2 +- .../Library/UserViewManager.cs | 2 +- .../LiveTv/LiveTvManager.cs | 10 +- .../Persistence/SqliteItemRepository.cs | 104 ++++- .../TV/TVSeriesManager.cs | 4 +- MediaBrowser.XbmcMetadata/EntryPoint.cs | 5 +- 25 files changed, 663 insertions(+), 171 deletions(-) diff --git a/MediaBrowser.Api/GamesService.cs b/MediaBrowser.Api/GamesService.cs index a27c872f1..159a25004 100644 --- a/MediaBrowser.Api/GamesService.cs +++ b/MediaBrowser.Api/GamesService.cs @@ -108,7 +108,7 @@ namespace MediaBrowser.Api IncludeItemTypes = new[] { typeof(GameSystem).Name } }; var parentIds = new string[] { } ; - var gameSystems = _libraryManager.GetItems(query, parentIds) + var gameSystems = _libraryManager.GetItemList(query, parentIds) .Cast() .ToList(); @@ -129,7 +129,7 @@ namespace MediaBrowser.Api IncludeItemTypes = new[] { typeof(Game).Name } }; var parentIds = new string[] { }; - var games = _libraryManager.GetItems(query, parentIds) + var games = _libraryManager.GetItemList(query, parentIds) .Cast() .ToList(); diff --git a/MediaBrowser.Api/Library/LibraryService.cs b/MediaBrowser.Api/Library/LibraryService.cs index 1d7b76c36..871f5e8a8 100644 --- a/MediaBrowser.Api/Library/LibraryService.cs +++ b/MediaBrowser.Api/Library/LibraryService.cs @@ -444,13 +444,11 @@ namespace MediaBrowser.Api.Library public void Post(PostUpdatedSeries request) { - var series = _libraryManager.GetItems(new InternalItemsQuery + var series = _libraryManager.GetItemList(new InternalItemsQuery { IncludeItemTypes = new[] { typeof(Series).Name } - }).Items; - - series = series.Where(i => string.Equals(request.TvdbId, i.GetProviderId(MetadataProviders.Tvdb), StringComparison.OrdinalIgnoreCase)).ToArray(); + }).Where(i => string.Equals(request.TvdbId, i.GetProviderId(MetadataProviders.Tvdb), StringComparison.OrdinalIgnoreCase)).ToArray(); if (series.Length > 0) { @@ -467,11 +465,11 @@ namespace MediaBrowser.Api.Library public void Post(PostUpdatedMovies request) { - var movies = _libraryManager.GetItems(new InternalItemsQuery + var movies = _libraryManager.GetItemList(new InternalItemsQuery { IncludeItemTypes = new[] { typeof(Movie).Name } - }).Items; + }).ToArray(); if (!string.IsNullOrWhiteSpace(request.ImdbId)) { diff --git a/MediaBrowser.Api/Movies/MoviesService.cs b/MediaBrowser.Api/Movies/MoviesService.cs index b60aa0cba..b3d485dc7 100644 --- a/MediaBrowser.Api/Movies/MoviesService.cs +++ b/MediaBrowser.Api/Movies/MoviesService.cs @@ -146,7 +146,7 @@ namespace MediaBrowser.Api.Movies } var parentIds = string.IsNullOrWhiteSpace(request.ParentId) ? new string[] { } : new[] { request.ParentId }; - var movies = _libraryManager.GetItems(query, parentIds); + var movies = _libraryManager.GetItemList(query, parentIds); movies = _libraryManager.ReplaceVideosWithPrimaryVersions(movies); var listEligibleForCategories = new List(); @@ -197,7 +197,7 @@ namespace MediaBrowser.Api.Movies } var parentIds = new string[] { }; - var list = _libraryManager.GetItems(query, parentIds) + var list = _libraryManager.GetItemList(query, parentIds) .Where(i => { // Strip out secondary versions diff --git a/MediaBrowser.Api/Reports/ReportsService.cs b/MediaBrowser.Api/Reports/ReportsService.cs index 6cbe2fd89..d3e9abe69 100644 --- a/MediaBrowser.Api/Reports/ReportsService.cs +++ b/MediaBrowser.Api/Reports/ReportsService.cs @@ -302,6 +302,16 @@ namespace MediaBrowser.Api.Reports } } + 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(); + } + if (request.HasQueryLimit == false) { query.StartIndex = null; @@ -539,50 +549,9 @@ namespace MediaBrowser.Api.Reports } } - if (!string.IsNullOrEmpty(request.MinPremiereDate)) - { - var date = DateTime.Parse(request.MinPremiereDate, null, DateTimeStyles.RoundtripKind).ToUniversalTime(); - - if (!(i.PremiereDate.HasValue && i.PremiereDate.Value >= date)) - { - return false; - } - } - - if (!string.IsNullOrEmpty(request.MaxPremiereDate)) - { - var date = DateTime.Parse(request.MaxPremiereDate, null, DateTimeStyles.RoundtripKind).ToUniversalTime(); - - if (!(i.PremiereDate.HasValue && i.PremiereDate.Value <= date)) - { - return false; - } - } - return true; } - /// Applies the paging. - /// The request. - /// The items. - /// IEnumerable{BaseItem}. - private IEnumerable ApplyPaging(BaseReportRequest request, IEnumerable items) - { - // Start at - if (request.StartIndex.HasValue) - { - items = items.Skip(request.StartIndex.Value); - } - - // Return limit - if (request.Limit.HasValue) - { - items = items.Take(request.Limit.Value); - } - - return items; - } - /// Gets query result. /// The request. /// The query result. diff --git a/MediaBrowser.Api/TvShowsService.cs b/MediaBrowser.Api/TvShowsService.cs index 2873dd8b4..7893ff5bd 100644 --- a/MediaBrowser.Api/TvShowsService.cs +++ b/MediaBrowser.Api/TvShowsService.cs @@ -277,7 +277,7 @@ namespace MediaBrowser.Api var parentIds = string.IsNullOrWhiteSpace(request.ParentId) ? new string[] { } : new[] { request.ParentId }; - var itemsResult = _libraryManager.GetItemsResult(new InternalItemsQuery(user) + var itemsResult = _libraryManager.GetItemList(new InternalItemsQuery(user) { IncludeItemTypes = new[] { typeof(Episode).Name }, SortBy = new[] { "PremiereDate", "AirTime", "SortName" }, @@ -286,15 +286,15 @@ namespace MediaBrowser.Api StartIndex = request.StartIndex, Limit = request.Limit - }, parentIds); + }, parentIds).ToList(); var options = GetDtoOptions(request); - var returnItems = _dtoService.GetBaseItemDtos(itemsResult.Items, options, user).ToArray(); + var returnItems = _dtoService.GetBaseItemDtos(itemsResult, options, user).ToArray(); var result = new ItemsResult { - TotalRecordCount = itemsResult.TotalRecordCount, + TotalRecordCount = itemsResult.Count, Items = returnItems }; diff --git a/MediaBrowser.Api/UserLibrary/ItemsService.cs b/MediaBrowser.Api/UserLibrary/ItemsService.cs index 93e123dea..e739ac7c2 100644 --- a/MediaBrowser.Api/UserLibrary/ItemsService.cs +++ b/MediaBrowser.Api/UserLibrary/ItemsService.cs @@ -85,17 +85,16 @@ namespace MediaBrowser.Api.UserLibrary /// Task{ItemsResult}. private async Task GetItems(GetItems request) { - var parentItem = string.IsNullOrEmpty(request.ParentId) ? null : _libraryManager.GetItemById(request.ParentId); var user = !string.IsNullOrWhiteSpace(request.UserId) ? _userManager.GetUserById(request.UserId) : null; - var result = await GetItemsToSerialize(request, user, parentItem).ConfigureAwait(false); + var result = await GetItemsToSerialize(request, user).ConfigureAwait(false); var dtoOptions = GetDtoOptions(request); return new ItemsResult { - TotalRecordCount = result.Item1.TotalRecordCount, - Items = _dtoService.GetBaseItemDtos(result.Item1.Items, dtoOptions, user).ToArray() + TotalRecordCount = result.TotalRecordCount, + Items = _dtoService.GetBaseItemDtos(result.Items, dtoOptions, user).ToArray() }; } @@ -104,17 +103,16 @@ namespace MediaBrowser.Api.UserLibrary /// /// The request. /// The user. - /// The parent item. /// IEnumerable{BaseItem}. - private async Task, bool>> GetItemsToSerialize(GetItems request, User user, BaseItem parentItem) + private async Task> GetItemsToSerialize(GetItems request, User user) { var item = string.IsNullOrEmpty(request.ParentId) ? user == null ? _libraryManager.RootFolder : user.RootFolder : - parentItem; + _libraryManager.GetItemById(request.ParentId); if (string.Equals(request.IncludeItemTypes, "Playlist", StringComparison.OrdinalIgnoreCase)) { - item = user == null ? _libraryManager.RootFolder : user.RootFolder; + //item = user == null ? _libraryManager.RootFolder : user.RootFolder; } else if (string.Equals(request.IncludeItemTypes, "BoxSet", StringComparison.OrdinalIgnoreCase)) { @@ -137,21 +135,21 @@ namespace MediaBrowser.Api.UserLibrary result.Items = result.Items.OrderBy(i => ids.IndexOf(i.Id.ToString("N"))).ToArray(); } - return new Tuple, bool>(result, true); + return result; } if (request.Recursive) { var result = await ((Folder)item).GetItems(GetItemsQuery(request, user)).ConfigureAwait(false); - return new Tuple, bool>(result, true); + return result; } if (user == null) { var result = await ((Folder)item).GetItems(GetItemsQuery(request, null)).ConfigureAwait(false); - return new Tuple, bool>(result, true); + return result; } var userRoot = item as UserRootFolder; @@ -160,26 +158,24 @@ namespace MediaBrowser.Api.UserLibrary { var result = await ((Folder)item).GetItems(GetItemsQuery(request, user)).ConfigureAwait(false); - return new Tuple, bool>(result, true); + return result; } IEnumerable items = ((Folder)item).GetChildren(user, true); var itemsArray = items.ToArray(); - return new Tuple, bool>(new QueryResult + return new QueryResult { Items = itemsArray, TotalRecordCount = itemsArray.Length - - }, false); + }; } private InternalItemsQuery GetItemsQuery(GetItems request, User user) { - var query = new InternalItemsQuery + var query = new InternalItemsQuery(user) { - User = user, IsPlayed = request.IsPlayed, MediaTypes = request.GetMediaTypes(), IncludeItemTypes = request.GetIncludeItemTypes(), @@ -234,7 +230,8 @@ namespace MediaBrowser.Api.UserLibrary MinPlayers = request.MinPlayers, MaxPlayers = request.MaxPlayers, MinCommunityRating = request.MinCommunityRating, - MinCriticRating = request.MinCriticRating + MinCriticRating = request.MinCriticRating, + ParentId = string.IsNullOrWhiteSpace(request.ParentId) ? (Guid?)null : new Guid(request.ParentId) }; if (!string.IsNullOrWhiteSpace(request.Ids)) @@ -278,6 +275,16 @@ namespace MediaBrowser.Api.UserLibrary } } + 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(); + } + return query; } @@ -500,26 +507,6 @@ namespace MediaBrowser.Api.UserLibrary } } - if (!string.IsNullOrEmpty(request.MinPremiereDate)) - { - var date = DateTime.Parse(request.MinPremiereDate, null, DateTimeStyles.RoundtripKind).ToUniversalTime(); - - if (!(i.PremiereDate.HasValue && i.PremiereDate.Value >= date)) - { - return false; - } - } - - if (!string.IsNullOrEmpty(request.MaxPremiereDate)) - { - var date = DateTime.Parse(request.MaxPremiereDate, null, DateTimeStyles.RoundtripKind).ToUniversalTime(); - - if (!(i.PremiereDate.HasValue && i.PremiereDate.Value <= date)) - { - return false; - } - } - return true; } } diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs index e6db695aa..0cf102d93 100644 --- a/MediaBrowser.Controller/Entities/Folder.cs +++ b/MediaBrowser.Controller/Entities/Folder.cs @@ -15,6 +15,8 @@ using System.Threading; using System.Threading.Tasks; using CommonIO; using MediaBrowser.Common.IO; +using MediaBrowser.Controller.Entities.Movies; +using MediaBrowser.Controller.Playlists; using MediaBrowser.Model.Channels; namespace MediaBrowser.Controller.Entities @@ -795,6 +797,419 @@ namespace MediaBrowser.Controller.Entities return item; } + public QueryResult QueryRecursive(InternalItemsQuery query) + { + var user = query.User; + + if (RequiresPostFiltering(query)) + { + IEnumerable items; + Func filter = i => UserViewBuilder.Filter(i, user, query, UserDataManager, LibraryManager); + + if (query.User == null) + { + items = GetRecursiveChildren(filter); + } + else + { + items = GetRecursiveChildren(user, filter); + } + + return PostFilterAndSort(items, query); + } + + if (!(this is UserRootFolder) && !(this is AggregateFolder)) + { + query.ParentId = query.ParentId ?? Id; + } + + return LibraryManager.GetItemsResult(query); + } + + private bool RequiresPostFiltering(InternalItemsQuery query) + { + if (LinkedChildren.Count > 0) + { + Logger.Debug("Query requires post-filtering due to LinkedChildren"); + return true; + } + + if (query.SortBy != null && query.SortBy.Length > 0) + { + if (query.SortBy.Contains(ItemSortBy.DatePlayed, StringComparer.OrdinalIgnoreCase)) + { + Logger.Debug("Query requires post-filtering due to ItemSortBy.DatePlayed"); + return true; + } + if (query.SortBy.Contains(ItemSortBy.IsFavoriteOrLiked, StringComparer.OrdinalIgnoreCase)) + { + Logger.Debug("Query requires post-filtering due to ItemSortBy.IsFavoriteOrLiked"); + return true; + } + if (query.SortBy.Contains(ItemSortBy.IsPlayed, StringComparer.OrdinalIgnoreCase)) + { + Logger.Debug("Query requires post-filtering due to ItemSortBy.IsPlayed"); + return true; + } + if (query.SortBy.Contains(ItemSortBy.IsUnplayed, StringComparer.OrdinalIgnoreCase)) + { + Logger.Debug("Query requires post-filtering due to ItemSortBy.IsUnplayed"); + return true; + } + if (query.SortBy.Contains(ItemSortBy.AiredEpisodeOrder, StringComparer.OrdinalIgnoreCase)) + { + Logger.Debug("Query requires post-filtering due to ItemSortBy.AiredEpisodeOrder"); + return true; + } + if (query.SortBy.Contains(ItemSortBy.Album, StringComparer.OrdinalIgnoreCase)) + { + Logger.Debug("Query requires post-filtering due to ItemSortBy.Album"); + return true; + } + if (query.SortBy.Contains(ItemSortBy.AlbumArtist, StringComparer.OrdinalIgnoreCase)) + { + Logger.Debug("Query requires post-filtering due to ItemSortBy.AlbumArtist"); + return true; + } + if (query.SortBy.Contains(ItemSortBy.Artist, StringComparer.OrdinalIgnoreCase)) + { + Logger.Debug("Query requires post-filtering due to ItemSortBy.Artist"); + return true; + } + if (query.SortBy.Contains(ItemSortBy.Budget, StringComparer.OrdinalIgnoreCase)) + { + Logger.Debug("Query requires post-filtering due to ItemSortBy.Budget"); + return true; + } + if (query.SortBy.Contains(ItemSortBy.CriticRating, StringComparer.OrdinalIgnoreCase)) + { + Logger.Debug("Query requires post-filtering due to ItemSortBy.CriticRating"); + return true; + } + if (query.SortBy.Contains(ItemSortBy.DateLastContentAdded, StringComparer.OrdinalIgnoreCase)) + { + Logger.Debug("Query requires post-filtering due to ItemSortBy.DateLastContentAdded"); + return true; + } + if (query.SortBy.Contains(ItemSortBy.GameSystem, StringComparer.OrdinalIgnoreCase)) + { + Logger.Debug("Query requires post-filtering due to ItemSortBy.GameSystem"); + return true; + } + if (query.SortBy.Contains(ItemSortBy.Metascore, StringComparer.OrdinalIgnoreCase)) + { + Logger.Debug("Query requires post-filtering due to ItemSortBy.Metascore"); + return true; + } + if (query.SortBy.Contains(ItemSortBy.OfficialRating, StringComparer.OrdinalIgnoreCase)) + { + Logger.Debug("Query requires post-filtering due to ItemSortBy.OfficialRating"); + return true; + } + if (query.SortBy.Contains(ItemSortBy.PlayCount, StringComparer.OrdinalIgnoreCase)) + { + Logger.Debug("Query requires post-filtering due to ItemSortBy.PlayCount"); + return true; + } + if (query.SortBy.Contains(ItemSortBy.Players, StringComparer.OrdinalIgnoreCase)) + { + Logger.Debug("Query requires post-filtering due to ItemSortBy.Players"); + return true; + } + if (query.SortBy.Contains(ItemSortBy.Random, StringComparer.OrdinalIgnoreCase)) + { + Logger.Debug("Query requires post-filtering due to ItemSortBy.Random"); + return true; + } + if (query.SortBy.Contains(ItemSortBy.Revenue, StringComparer.OrdinalIgnoreCase)) + { + Logger.Debug("Query requires post-filtering due to ItemSortBy.Revenue"); + return true; + } + if (query.SortBy.Contains(ItemSortBy.SeriesSortName, StringComparer.OrdinalIgnoreCase)) + { + Logger.Debug("Query requires post-filtering due to ItemSortBy.SeriesSortName"); + return true; + } + if (query.SortBy.Contains(ItemSortBy.StartDate, StringComparer.OrdinalIgnoreCase)) + { + Logger.Debug("Query requires post-filtering due to ItemSortBy.StartDate"); + return true; + } + if (query.SortBy.Contains(ItemSortBy.Studio, StringComparer.OrdinalIgnoreCase)) + { + Logger.Debug("Query requires post-filtering due to ItemSortBy.Studio"); + return true; + } + if (query.SortBy.Contains(ItemSortBy.VideoBitRate, StringComparer.OrdinalIgnoreCase)) + { + Logger.Debug("Query requires post-filtering due to ItemSortBy.VideoBitRate"); + return true; + } + } + + if (query.PersonIds.Length > 0) + { + Logger.Debug("Query requires post-filtering due to PersonIds"); + return true; + } + + if (query.IsLiked.HasValue) + { + Logger.Debug("Query requires post-filtering due to IsLiked"); + return true; + } + + if (query.IsFavoriteOrLiked.HasValue) + { + Logger.Debug("Query requires post-filtering due to IsFavoriteOrLiked"); + return true; + } + + if (query.IsFavorite.HasValue) + { + Logger.Debug("Query requires post-filtering due to IsFavorite"); + return true; + } + + if (query.IsResumable.HasValue) + { + Logger.Debug("Query requires post-filtering due to IsResumable"); + return true; + } + + if (query.IsPlayed.HasValue) + { + Logger.Debug("Query requires post-filtering due to IsPlayed"); + return true; + } + + if (query.IsInBoxSet.HasValue) + { + Logger.Debug("Query requires post-filtering due to IsInBoxSet"); + return true; + } + + // Filter by Video3DFormat + if (query.Is3D.HasValue) + { + Logger.Debug("Query requires post-filtering due to Is3D"); + return true; + } + + if (query.HasOverview.HasValue) + { + Logger.Debug("Query requires post-filtering due to HasOverview"); + return true; + } + + if (query.HasImdbId.HasValue) + { + Logger.Debug("Query requires post-filtering due to HasImdbId"); + return true; + } + + if (query.HasTmdbId.HasValue) + { + Logger.Debug("Query requires post-filtering due to HasTmdbId"); + return true; + } + + if (query.HasTvdbId.HasValue) + { + Logger.Debug("Query requires post-filtering due to HasTvdbId"); + return true; + } + + if (query.IsYearMismatched.HasValue) + { + Logger.Debug("Query requires post-filtering due to IsYearMismatched"); + return true; + } + + if (query.HasOfficialRating.HasValue) + { + Logger.Debug("Query requires post-filtering due to HasOfficialRating"); + return true; + } + + if (query.IsPlaceHolder.HasValue) + { + Logger.Debug("Query requires post-filtering due to IsPlaceHolder"); + return true; + } + + if (query.HasSpecialFeature.HasValue) + { + Logger.Debug("Query requires post-filtering due to HasSpecialFeature"); + return true; + } + + if (query.HasSubtitles.HasValue) + { + Logger.Debug("Query requires post-filtering due to HasSubtitles"); + return true; + } + + if (query.HasTrailer.HasValue) + { + Logger.Debug("Query requires post-filtering due to HasTrailer"); + return true; + } + + if (query.HasThemeSong.HasValue) + { + Logger.Debug("Query requires post-filtering due to HasThemeSong"); + return true; + } + + if (query.HasThemeVideo.HasValue) + { + Logger.Debug("Query requires post-filtering due to HasThemeVideo"); + return true; + } + + // Filter by VideoType + if (query.VideoTypes.Length > 0) + { + Logger.Debug("Query requires post-filtering due to VideoTypes"); + return true; + } + + if (query.ImageTypes.Length > 0) + { + Logger.Debug("Query requires post-filtering due to ImageTypes"); + return true; + } + + // Apply studio filter + if (query.StudioIds.Length > 0) + { + Logger.Debug("Query requires post-filtering due to StudioIds"); + return true; + } + + // Apply genre filter + if (query.GenreIds.Length > 0) + { + Logger.Debug("Query requires post-filtering due to GenreIds"); + return true; + } + + // Apply year filter + if (query.Years.Length > 0) + { + Logger.Debug("Query requires post-filtering due to Years"); + return true; + } + + // Apply official rating filter + if (query.OfficialRatings.Length > 0) + { + Logger.Debug("Query requires post-filtering due to OfficialRatings"); + return true; + } + + // Apply person filter + if (query.ItemIdsFromPersonFilters != null) + { + Logger.Debug("Query requires post-filtering due to ItemIdsFromPersonFilters"); + return true; + } + + if (query.MinPlayers.HasValue) + { + Logger.Debug("Query requires post-filtering due to MinPlayers"); + return true; + } + + if (query.MaxPlayers.HasValue) + { + Logger.Debug("Query requires post-filtering due to MaxPlayers"); + return true; + } + + if (query.MinCommunityRating.HasValue) + { + Logger.Debug("Query requires post-filtering due to MinCommunityRating"); + return true; + } + + if (query.MinIndexNumber.HasValue) + { + Logger.Debug("Query requires post-filtering due to MinIndexNumber"); + return true; + } + + if (query.Years.Length > 0) + { + Logger.Debug("Query requires post-filtering due to Years"); + return true; + } + + if (query.OfficialRatings.Length > 0) + { + Logger.Debug("Query requires post-filtering due to OfficialRatings"); + return true; + } + + if (query.IsMissing.HasValue) + { + Logger.Debug("Query requires post-filtering due to IsMissing"); + return true; + } + + if (query.IsUnaired.HasValue) + { + Logger.Debug("Query requires post-filtering due to IsUnaired"); + return true; + } + + if (query.IsVirtualUnaired.HasValue) + { + Logger.Debug("Query requires post-filtering due to IsVirtualUnaired"); + return true; + } + + if (UserViewBuilder.CollapseBoxSetItems(query, this, query.User)) + { + Logger.Debug("Query requires post-filtering due to CollapseBoxSetItems"); + return true; + } + + if (!string.IsNullOrWhiteSpace(query.AdjacentTo)) + { + Logger.Debug("Query requires post-filtering due to AdjacentTo"); + return true; + } + + if (!string.IsNullOrWhiteSpace(query.NameContains)) + { + Logger.Debug("Query requires post-filtering due to NameContains"); + return true; + } + + if (!string.IsNullOrWhiteSpace(query.NameLessThan)) + { + Logger.Debug("Query requires post-filtering due to NameLessThan"); + return true; + } + + if (!string.IsNullOrWhiteSpace(query.NameStartsWith)) + { + Logger.Debug("Query requires post-filtering due to NameStartsWith"); + return true; + } + + if (!string.IsNullOrWhiteSpace(query.NameStartsWithOrGreater)) + { + Logger.Debug("Query requires post-filtering due to NameStartsWithOrGreater"); + return true; + } + + return false; + } + public virtual async Task> GetItems(InternalItemsQuery query) { if (SourceType == SourceType.Channel) @@ -823,7 +1238,12 @@ namespace MediaBrowser.Controller.Entities }; } } - + + if (query.Recursive) + { + return QueryRecursive(query); + } + var user = query.User; Func filter = i => UserViewBuilder.Filter(i, user, query, UserDataManager, LibraryManager); diff --git a/MediaBrowser.Controller/Entities/InternalItemsQuery.cs b/MediaBrowser.Controller/Entities/InternalItemsQuery.cs index 7b3e51cad..05031691c 100644 --- a/MediaBrowser.Controller/Entities/InternalItemsQuery.cs +++ b/MediaBrowser.Controller/Entities/InternalItemsQuery.cs @@ -83,6 +83,7 @@ namespace MediaBrowser.Controller.Entities public string[] OfficialRatings { get; set; } public DateTime? MinPremiereDate { get; set; } + public DateTime? MaxPremiereDate { get; set; } public DateTime? MinStartDate { get; set; } public DateTime? MaxStartDate { get; set; } public DateTime? MinEndDate { get; set; } diff --git a/MediaBrowser.Controller/Entities/UserRootFolder.cs b/MediaBrowser.Controller/Entities/UserRootFolder.cs index daf590871..104408860 100644 --- a/MediaBrowser.Controller/Entities/UserRootFolder.cs +++ b/MediaBrowser.Controller/Entities/UserRootFolder.cs @@ -19,13 +19,9 @@ namespace MediaBrowser.Controller.Entities { public override async Task> GetItems(InternalItemsQuery query) { - var user = query.User; - Func filter = i => UserViewBuilder.Filter(i, user, query, UserDataManager, LibraryManager); - if (query.Recursive) { - var items = query.User.RootFolder.GetRecursiveChildren(query.User, filter); - return PostFilterAndSort(items, query); + return QueryRecursive(query); } var result = await UserViewManager.GetUserViews(new UserViewQuery @@ -35,6 +31,9 @@ namespace MediaBrowser.Controller.Entities }, CancellationToken.None).ConfigureAwait(false); + var user = query.User; + Func filter = i => UserViewBuilder.Filter(i, user, query, UserDataManager, LibraryManager); + return PostFilterAndSort(result.Where(filter), query); } diff --git a/MediaBrowser.Controller/Entities/UserViewBuilder.cs b/MediaBrowser.Controller/Entities/UserViewBuilder.cs index 721ec3f1b..4439b9c6d 100644 --- a/MediaBrowser.Controller/Entities/UserViewBuilder.cs +++ b/MediaBrowser.Controller/Entities/UserViewBuilder.cs @@ -50,15 +50,15 @@ namespace MediaBrowser.Controller.Entities { var user = query.User; - if (query.IncludeItemTypes != null && - query.IncludeItemTypes.Length == 1 && - string.Equals(query.IncludeItemTypes[0], "Playlist", StringComparison.OrdinalIgnoreCase)) - { - if (!string.Equals(viewType, CollectionType.Playlists, StringComparison.OrdinalIgnoreCase)) - { - return await FindPlaylists(queryParent, user, query).ConfigureAwait(false); - } - } + //if (query.IncludeItemTypes != null && + // query.IncludeItemTypes.Length == 1 && + // string.Equals(query.IncludeItemTypes[0], "Playlist", StringComparison.OrdinalIgnoreCase)) + //{ + // if (!string.Equals(viewType, CollectionType.Playlists, StringComparison.OrdinalIgnoreCase)) + // { + // return await FindPlaylists(queryParent, user, query).ConfigureAwait(false); + // } + //} switch (viewType) { @@ -766,7 +766,7 @@ namespace MediaBrowser.Controller.Entities return items; } - private static bool CollapseBoxSetItems(InternalItemsQuery query, + public static bool CollapseBoxSetItems(InternalItemsQuery query, BaseItem queryParent, User user) { @@ -1689,6 +1689,26 @@ namespace MediaBrowser.Controller.Entities } } + if (query.MinPremiereDate.HasValue) + { + var val = query.MinPremiereDate.Value; + + if (!(item.PremiereDate.HasValue && item.PremiereDate.Value >= val)) + { + return false; + } + } + + if (query.MaxPremiereDate.HasValue) + { + var val = query.MaxPremiereDate.Value; + + if (!(item.PremiereDate.HasValue && item.PremiereDate.Value <= val)) + { + return false; + } + } + return true; } diff --git a/MediaBrowser.Controller/Library/ILibraryManager.cs b/MediaBrowser.Controller/Library/ILibraryManager.cs index ff44953ef..752ac2dad 100644 --- a/MediaBrowser.Controller/Library/ILibraryManager.cs +++ b/MediaBrowser.Controller/Library/ILibraryManager.cs @@ -152,13 +152,6 @@ namespace MediaBrowser.Controller.Library /// BaseItem. BaseItem GetItemById(Guid id); - /// - /// Gets the items. - /// - /// The query. - /// QueryResult<BaseItem>. - QueryResult GetItems(InternalItemsQuery query); - /// /// Gets the memory item by identifier. /// @@ -547,22 +540,28 @@ namespace MediaBrowser.Controller.Library /// Task. Task ConvertImageToLocal(IHasImages item, ItemImageInfo image, int imageIndex); + /// + /// Gets the items. + /// + /// The query. + /// QueryResult<BaseItem>. + IEnumerable GetItemList(InternalItemsQuery query); + /// /// Gets the items. /// /// The query. /// The parent ids. /// List<BaseItem>. - IEnumerable GetItems(InternalItemsQuery query, IEnumerable parentIds); + IEnumerable GetItemList(InternalItemsQuery query, IEnumerable parentIds); /// /// Gets the items result. /// /// The query. - /// The parent ids. /// QueryResult<BaseItem>. - QueryResult GetItemsResult(InternalItemsQuery query, IEnumerable parentIds); - + QueryResult GetItemsResult(InternalItemsQuery query); + /// /// Ignores the file. /// diff --git a/MediaBrowser.Dlna/ContentDirectory/ControlHandler.cs b/MediaBrowser.Dlna/ContentDirectory/ControlHandler.cs index 233f96f65..55b775751 100644 --- a/MediaBrowser.Dlna/ContentDirectory/ControlHandler.cs +++ b/MediaBrowser.Dlna/ContentDirectory/ControlHandler.cs @@ -493,7 +493,7 @@ namespace MediaBrowser.Dlna.ContentDirectory Limit = limit, StartIndex = startIndex - }, new string[] { }); + }); var serverItems = itemsResult.Items.Select(i => new ServerItem { diff --git a/MediaBrowser.Providers/People/TvdbPersonImageProvider.cs b/MediaBrowser.Providers/People/TvdbPersonImageProvider.cs index b5546683b..2d4d484e6 100644 --- a/MediaBrowser.Providers/People/TvdbPersonImageProvider.cs +++ b/MediaBrowser.Providers/People/TvdbPersonImageProvider.cs @@ -59,12 +59,12 @@ namespace MediaBrowser.Providers.People // Avoid implicitly captured closure var itemName = item.Name; - var seriesWithPerson = _libraryManager.GetItems(new InternalItemsQuery + var seriesWithPerson = _libraryManager.GetItemList(new InternalItemsQuery { IncludeItemTypes = new[] { typeof(Series).Name }, Person = itemName - }).Items.Cast() + }).Cast() .Where(i => TvdbSeriesProvider.IsValidSeries(i.ProviderIds)) .ToList(); diff --git a/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs b/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs index e957b9889..240037597 100644 --- a/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs +++ b/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs @@ -510,15 +510,12 @@ namespace MediaBrowser.Server.Implementations.Channels public IEnumerable GetAllChannelFeatures() { - var inputItems = _libraryManager.GetItems(new InternalItemsQuery + return _libraryManager.GetItemList(new InternalItemsQuery { IncludeItemTypes = new[] { typeof(Channel).Name }, SortBy = new[] { ItemSortBy.SortName } - }).Items; - - return inputItems - .Select(i => GetChannelFeatures(i.Id.ToString("N"))); + }).Select(i => GetChannelFeatures(i.Id.ToString("N"))); } public ChannelFeatures GetChannelFeatures(string id) diff --git a/MediaBrowser.Server.Implementations/Dto/DtoService.cs b/MediaBrowser.Server.Implementations/Dto/DtoService.cs index 3ead1a835..5fe9ee434 100644 --- a/MediaBrowser.Server.Implementations/Dto/DtoService.cs +++ b/MediaBrowser.Server.Implementations/Dto/DtoService.cs @@ -183,7 +183,7 @@ namespace MediaBrowser.Server.Implementations.Dto if (person != null) { - var items = _libraryManager.GetItems(new InternalItemsQuery(user) + var items = _libraryManager.GetItemList(new InternalItemsQuery(user) { Person = byName.Name @@ -1655,8 +1655,7 @@ namespace MediaBrowser.Server.Implementations.Dto { IsFolder = false, Recursive = true, - IsVirtualUnaired = false, - IsMissing = false, + ExcludeLocationTypes = new[] { LocationType.Virtual }, User = user }).Result.Items; diff --git a/MediaBrowser.Server.Implementations/Intros/DefaultIntroProvider.cs b/MediaBrowser.Server.Implementations/Intros/DefaultIntroProvider.cs index 5adddd38a..2755a476c 100644 --- a/MediaBrowser.Server.Implementations/Intros/DefaultIntroProvider.cs +++ b/MediaBrowser.Server.Implementations/Intros/DefaultIntroProvider.cs @@ -106,13 +106,13 @@ namespace MediaBrowser.Server.Implementations.Intros if (trailerTypes.Count > 0) { - var trailerResult = _libraryManager.GetItems(new InternalItemsQuery + var trailerResult = _libraryManager.GetItemList(new InternalItemsQuery { IncludeItemTypes = new[] { typeof(Trailer).Name }, TrailerTypes = trailerTypes.ToArray() }); - candidates.AddRange(trailerResult.Items.Select(i => new ItemWithTrailer + candidates.AddRange(trailerResult.Select(i => new ItemWithTrailer { Item = i, Type = i.SourceType == SourceType.Channel ? ItemWithTrailerType.ChannelTrailer : ItemWithTrailerType.ItemWithTrailer, diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index 19b66836b..bf895e5ce 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -813,7 +813,7 @@ namespace MediaBrowser.Server.Implementations.Library { return null; } - + return RootFolder.FindByPath(path); } @@ -1305,7 +1305,7 @@ namespace MediaBrowser.Server.Implementations.Library return item; } - public QueryResult GetItems(InternalItemsQuery query) + public IEnumerable GetItemList(InternalItemsQuery query) { if (query.User != null) { @@ -1314,12 +1314,7 @@ namespace MediaBrowser.Server.Implementations.Library var result = ItemRepository.GetItemIdsList(query); - var items = result.Select(GetItemById).Where(i => i != null).ToArray(); - - return new QueryResult - { - Items = items - }; + return result.Select(GetItemById).Where(i => i != null); } public QueryResult QueryItems(InternalItemsQuery query) @@ -1342,7 +1337,7 @@ namespace MediaBrowser.Server.Implementations.Library return ItemRepository.GetItemIdsList(query); } - public IEnumerable GetItems(InternalItemsQuery query, IEnumerable parentIds) + public IEnumerable GetItemList(InternalItemsQuery query, IEnumerable parentIds) { var parents = parentIds.Select(i => GetItemById(new Guid(i))).Where(i => i != null).ToList(); @@ -1351,13 +1346,39 @@ namespace MediaBrowser.Server.Implementations.Library return GetItemIds(query).Select(GetItemById).Where(i => i != null); } + public QueryResult GetItemsResult(InternalItemsQuery query) + { + if (query.Recursive && query.ParentId.HasValue) + { + var parent = GetItemById(query.ParentId.Value); + if (parent != null) + { + SetTopParentIdsOrAncestors(query, new List { parent }); + query.ParentId = null; + } + } + + if (query.User != null) + { + AddUserToQuery(query, query.User); + } + + var initialResult = ItemRepository.GetItemIds(query); + + return new QueryResult + { + TotalRecordCount = initialResult.TotalRecordCount, + Items = initialResult.Items.Select(GetItemById).Where(i => i != null).ToArray() + }; + } + public QueryResult GetItemsResult(InternalItemsQuery query, IEnumerable parentIds) { var parents = parentIds.Select(i => GetItemById(new Guid(i))).Where(i => i != null).ToList(); SetTopParentIdsOrAncestors(query, parents); - return GetItems(query); + return GetItemsResult(query); } private void SetTopParentIdsOrAncestors(InternalItemsQuery query, List parents) @@ -2545,7 +2566,7 @@ namespace MediaBrowser.Server.Implementations.Library // Remove this image to prevent it from retrying over and over item.RemoveImage(image); await item.UpdateToRepository(ItemUpdateType.ImageUpdate, CancellationToken.None).ConfigureAwait(false); - + throw new InvalidOperationException(); } } diff --git a/MediaBrowser.Server.Implementations/Library/LocalTrailerPostScanTask.cs b/MediaBrowser.Server.Implementations/Library/LocalTrailerPostScanTask.cs index 10263f7d7..4e23b5e93 100644 --- a/MediaBrowser.Server.Implementations/Library/LocalTrailerPostScanTask.cs +++ b/MediaBrowser.Server.Implementations/Library/LocalTrailerPostScanTask.cs @@ -4,6 +4,7 @@ using MediaBrowser.Controller.Library; using MediaBrowser.Model.Channels; using MediaBrowser.Model.Entities; using System; +using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -28,16 +29,14 @@ namespace MediaBrowser.Server.Implementations.Library .Cast() .ToList(); - var trailerResult = _libraryManager.GetItems(new InternalItemsQuery + var trailers = _libraryManager.GetItemList(new InternalItemsQuery { IncludeItemTypes = new[] { typeof(Trailer).Name }, ExcludeTrailerTypes = new[] { TrailerType.LocalTrailer } - - }); - var trailers = trailerResult.Items; + }).ToArray(); var numComplete = 0; diff --git a/MediaBrowser.Server.Implementations/Library/MusicManager.cs b/MediaBrowser.Server.Implementations/Library/MusicManager.cs index 11a1f190a..aad7c112b 100644 --- a/MediaBrowser.Server.Implementations/Library/MusicManager.cs +++ b/MediaBrowser.Server.Implementations/Library/MusicManager.cs @@ -80,7 +80,7 @@ namespace MediaBrowser.Server.Implementations.Library { var genreList = genres.ToList(); - var inputItems = _libraryManager.GetItems(new InternalItemsQuery(user) + var inputItems = _libraryManager.GetItemList(new InternalItemsQuery(user) { IncludeItemTypes = new[] { typeof(Audio).Name }, diff --git a/MediaBrowser.Server.Implementations/Library/SearchEngine.cs b/MediaBrowser.Server.Implementations/Library/SearchEngine.cs index 62392c1c7..276fc329f 100644 --- a/MediaBrowser.Server.Implementations/Library/SearchEngine.cs +++ b/MediaBrowser.Server.Implementations/Library/SearchEngine.cs @@ -157,7 +157,7 @@ namespace MediaBrowser.Server.Implementations.Library AddIfMissing(excludeItemTypes, typeof(CollectionFolder).Name); - var mediaItems = _libraryManager.GetItems(new InternalItemsQuery(user) + var mediaItems = _libraryManager.GetItemList(new InternalItemsQuery(user) { NameContains = searchTerm, ExcludeItemTypes = excludeItemTypes.ToArray(), diff --git a/MediaBrowser.Server.Implementations/Library/UserViewManager.cs b/MediaBrowser.Server.Implementations/Library/UserViewManager.cs index 9d276ada2..37046bfef 100644 --- a/MediaBrowser.Server.Implementations/Library/UserViewManager.cs +++ b/MediaBrowser.Server.Implementations/Library/UserViewManager.cs @@ -278,7 +278,7 @@ namespace MediaBrowser.Server.Implementations.Library } : new string[] { }; - return _libraryManager.GetItems(new InternalItemsQuery(user) + return _libraryManager.GetItemList(new InternalItemsQuery(user) { IncludeItemTypes = includeItemTypes, SortOrder = SortOrder.Descending, diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs index 47379fcb0..22516e7a6 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs @@ -135,11 +135,11 @@ namespace MediaBrowser.Server.Implementations.LiveTv { var user = string.IsNullOrEmpty(query.UserId) ? null : _userManager.GetUserById(query.UserId); - var channels = _libraryManager.GetItems(new InternalItemsQuery + var channels = _libraryManager.GetItemList(new InternalItemsQuery { IncludeItemTypes = new[] { typeof(LiveTvChannel).Name } - }).Items.Cast(); + }).Cast(); if (user != null) { @@ -1430,7 +1430,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv internalQuery.ChannelIds = new[] { query.ChannelId }; } - var queryResult = _libraryManager.GetItems(internalQuery, new string[] { }); + var queryResult = _libraryManager.GetItemList(internalQuery, new string[] { }); IEnumerable recordings = queryResult.Cast(); if (!string.IsNullOrWhiteSpace(query.Id)) @@ -1865,7 +1865,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv var now = DateTime.UtcNow; - var programs = _libraryManager.GetItems(new InternalItemsQuery(user) + var programs = _libraryManager.GetItemList(new InternalItemsQuery(user) { IncludeItemTypes = new[] { typeof(LiveTvProgram).Name }, ChannelIds = new[] { id }, @@ -1889,7 +1889,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv var now = DateTime.UtcNow; - var programs = _libraryManager.GetItems(new InternalItemsQuery(user) + var programs = _libraryManager.GetItemList(new InternalItemsQuery(user) { IncludeItemTypes = new[] { typeof(LiveTvProgram).Name }, ChannelIds = new[] { channel.Id.ToString("N") }, diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs index 50662c90f..12e444017 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs @@ -1583,11 +1583,15 @@ namespace MediaBrowser.Server.Implementations.Persistence private string MapOrderByField(string name) { - if (string.Equals(name, "airtime", StringComparison.OrdinalIgnoreCase)) + if (string.Equals(name, ItemSortBy.AirTime, StringComparison.OrdinalIgnoreCase)) { // TODO return "SortName"; } + if (string.Equals(name, ItemSortBy.Runtime, StringComparison.OrdinalIgnoreCase)) + { + return "RuntimeTicks"; + } return name; } @@ -1783,6 +1787,16 @@ namespace MediaBrowser.Server.Implementations.Persistence } cmd.Parameters.Add(cmd, "@SchemaVersion", DbType.Int32).Value = LatestSchemaVersion; } + if (query.IsHD.HasValue) + { + whereClauses.Add("IsHD=@IsHD"); + cmd.Parameters.Add(cmd, "@IsHD", DbType.Boolean).Value = query.IsHD; + } + if (query.IsLocked.HasValue) + { + whereClauses.Add("IsLocked=@IsLocked"); + cmd.Parameters.Add(cmd, "@IsLocked", DbType.Boolean).Value = query.IsLocked; + } if (query.IsOffline.HasValue) { whereClauses.Add("IsOffline=@IsOffline"); @@ -1861,6 +1875,30 @@ namespace MediaBrowser.Server.Implementations.Persistence cmd.Parameters.Add(cmd, "@Path", DbType.String).Value = query.Path; } + if (query.MinCommunityRating.HasValue) + { + whereClauses.Add("CommunityRating>=@MinCommunityRating"); + cmd.Parameters.Add(cmd, "@MinCommunityRating", DbType.Double).Value = query.MinCommunityRating.Value; + } + + if (query.MinIndexNumber.HasValue) + { + whereClauses.Add("IndexNumber>=@MinIndexNumber"); + cmd.Parameters.Add(cmd, "@MinIndexNumber", DbType.Int32).Value = query.MinIndexNumber.Value; + } + + //if (query.MinPlayers.HasValue) + //{ + // whereClauses.Add("Players>=@MinPlayers"); + // cmd.Parameters.Add(cmd, "@MinPlayers", DbType.Int32).Value = query.MinPlayers.Value; + //} + + //if (query.MaxPlayers.HasValue) + //{ + // whereClauses.Add("Players<=@MaxPlayers"); + // cmd.Parameters.Add(cmd, "@MaxPlayers", DbType.Int32).Value = query.MaxPlayers.Value; + //} + if (query.MinEndDate.HasValue) { whereClauses.Add("EndDate>=@MinEndDate"); @@ -1879,16 +1917,21 @@ namespace MediaBrowser.Server.Implementations.Persistence cmd.Parameters.Add(cmd, "@MinStartDate", DbType.Date).Value = query.MinStartDate.Value; } + if (query.MaxStartDate.HasValue) + { + whereClauses.Add("StartDate<=@MaxStartDate"); + cmd.Parameters.Add(cmd, "@MaxStartDate", DbType.Date).Value = query.MaxStartDate.Value; + } + if (query.MinPremiereDate.HasValue) { whereClauses.Add("PremiereDate>=@MinPremiereDate"); cmd.Parameters.Add(cmd, "@MinPremiereDate", DbType.Date).Value = query.MinPremiereDate.Value; } - - if (query.MaxStartDate.HasValue) + if (query.MaxPremiereDate.HasValue) { - whereClauses.Add("StartDate<=@MaxStartDate"); - cmd.Parameters.Add(cmd, "@MaxStartDate", DbType.Date).Value = query.MaxStartDate.Value; + whereClauses.Add("PremiereDate<=@MaxPremiereDate"); + cmd.Parameters.Add(cmd, "@MaxPremiereDate", DbType.Date).Value = query.MaxPremiereDate.Value; } if (query.SourceTypes.Length == 1) @@ -1972,16 +2015,44 @@ namespace MediaBrowser.Server.Implementations.Persistence if (query.Genres.Length > 0) { - var genres = new List(); + var clauses = new List(); var index = 0; - foreach (var genre in query.Genres) + foreach (var item in query.Genres) { - genres.Add("Genres like @Genres" + index); - cmd.Parameters.Add(cmd, "@Genres" + index, DbType.String).Value = "%" + genre + "%"; + clauses.Add("Genres like @Genres" + index); + cmd.Parameters.Add(cmd, "@Genres" + index, DbType.String).Value = "%" + item + "%"; index++; } - var genreCaluse = "(" + string.Join(" OR ", genres.ToArray()) + ")"; - whereClauses.Add(genreCaluse); + var clause = "(" + string.Join(" OR ", clauses.ToArray()) + ")"; + whereClauses.Add(clause); + } + + if (query.Tags.Length > 0) + { + var clauses = new List(); + var index = 0; + foreach (var item in query.Tags) + { + clauses.Add("Tags like @Tags" + index); + cmd.Parameters.Add(cmd, "@Tags" + index, DbType.String).Value = "%" + item + "%"; + index++; + } + var clause = "(" + string.Join(" OR ", clauses.ToArray()) + ")"; + whereClauses.Add(clause); + } + + if (query.Studios.Length > 0) + { + var clauses = new List(); + var index = 0; + foreach (var item in query.Studios) + { + clauses.Add("Studios like @Studios" + index); + cmd.Parameters.Add(cmd, "@Studios" + index, DbType.String).Value = "%" + item + "%"; + index++; + } + var clause = "(" + string.Join(" OR ", clauses.ToArray()) + ")"; + whereClauses.Add(clause); } if (query.MaxParentalRating.HasValue) @@ -2020,6 +2091,17 @@ namespace MediaBrowser.Server.Implementations.Persistence whereClauses.Add("LocationType not in (" + val + ")"); } + if (query.MediaTypes.Length == 1) + { + whereClauses.Add("MediaType=@MediaTypes"); + cmd.Parameters.Add(cmd, "@MediaTypes", DbType.String).Value = query.MediaTypes[0].ToString(); + } + if (query.MediaTypes.Length > 1) + { + var val = string.Join(",", query.MediaTypes.Select(i => "'" + i + "'").ToArray()); + + whereClauses.Add("MediaType in (" + val + ")"); + } var enableItemsByName = query.IncludeItemsByName ?? query.IncludeItemTypes.Length > 0; diff --git a/MediaBrowser.Server.Implementations/TV/TVSeriesManager.cs b/MediaBrowser.Server.Implementations/TV/TVSeriesManager.cs index 69d1c89fe..3e43ebe9b 100644 --- a/MediaBrowser.Server.Implementations/TV/TVSeriesManager.cs +++ b/MediaBrowser.Server.Implementations/TV/TVSeriesManager.cs @@ -36,7 +36,7 @@ namespace MediaBrowser.Server.Implementations.TV ? new string[] { } : new[] { request.ParentId }; - var items = _libraryManager.GetItems(new InternalItemsQuery(user) + var items = _libraryManager.GetItemList(new InternalItemsQuery(user) { IncludeItemTypes = new[] { typeof(Series).Name }, SortOrder = SortOrder.Ascending @@ -58,7 +58,7 @@ namespace MediaBrowser.Server.Implementations.TV throw new ArgumentException("User not found"); } - var items = _libraryManager.GetItems(new InternalItemsQuery(user) + var items = _libraryManager.GetItemList(new InternalItemsQuery(user) { IncludeItemTypes = new[] { typeof(Series).Name }, SortOrder = SortOrder.Ascending diff --git a/MediaBrowser.XbmcMetadata/EntryPoint.cs b/MediaBrowser.XbmcMetadata/EntryPoint.cs index 1c68a5046..0844f1f74 100644 --- a/MediaBrowser.XbmcMetadata/EntryPoint.cs +++ b/MediaBrowser.XbmcMetadata/EntryPoint.cs @@ -8,6 +8,7 @@ using MediaBrowser.Model.Logging; using MediaBrowser.XbmcMetadata.Configuration; using MediaBrowser.XbmcMetadata.Savers; using System; +using System.Linq; namespace MediaBrowser.XbmcMetadata { @@ -49,11 +50,11 @@ namespace MediaBrowser.XbmcMetadata return; } - var items = _libraryManager.GetItems(new InternalItemsQuery + var items = _libraryManager.GetItemList(new InternalItemsQuery { Person = person.Name - }).Items; + }).ToList(); foreach (var item in items) {