From 085470394e60fa919581b2f19dc234eeb985993a Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 1 Oct 2017 13:26:09 -0400 Subject: [PATCH] update home screen sections --- Emby.Dlna/ContentDirectory/ControlHandler.cs | 2 +- .../IO/LibraryMonitor.cs | 8 +-- .../TV/TVSeriesManager.cs | 36 +++---------- MediaBrowser.Api/UserLibrary/ItemsService.cs | 52 +++++++++++++++++++ .../Entities/UserViewBuilder.cs | 15 +++--- .../TV/ITVSeriesManager.cs | 2 +- .../Manager/ItemImageProvider.cs | 4 +- 7 files changed, 69 insertions(+), 50 deletions(-) diff --git a/Emby.Dlna/ContentDirectory/ControlHandler.cs b/Emby.Dlna/ContentDirectory/ControlHandler.cs index 47d199e6e..7db282dc8 100644 --- a/Emby.Dlna/ContentDirectory/ControlHandler.cs +++ b/Emby.Dlna/ContentDirectory/ControlHandler.cs @@ -1101,7 +1101,7 @@ namespace Emby.Dlna.ContentDirectory StartIndex = query.StartIndex, UserId = query.User.Id.ToString("N") - }, new List { (Folder)parent }, query.DtoOptions); + }, new List { parent }, query.DtoOptions); return ToResult(result); } diff --git a/Emby.Server.Implementations/IO/LibraryMonitor.cs b/Emby.Server.Implementations/IO/LibraryMonitor.cs index 56b10a7e6..c99b601c9 100644 --- a/Emby.Server.Implementations/IO/LibraryMonitor.cs +++ b/Emby.Server.Implementations/IO/LibraryMonitor.cs @@ -333,13 +333,7 @@ namespace Emby.Server.Implementations.IO NotifyFilters.Attributes; newWatcher.Created += watcher_Changed; - - // Seeing mono crashes on background threads we can't catch, testing if this might help - if (_environmentInfo.OperatingSystem == MediaBrowser.Model.System.OperatingSystem.Windows) - { - newWatcher.Deleted += watcher_Changed; - } - + newWatcher.Deleted += watcher_Changed; newWatcher.Renamed += watcher_Changed; newWatcher.Changed += watcher_Changed; diff --git a/Emby.Server.Implementations/TV/TVSeriesManager.cs b/Emby.Server.Implementations/TV/TVSeriesManager.cs index 0b81f7e93..ec2d8c4fc 100644 --- a/Emby.Server.Implementations/TV/TVSeriesManager.cs +++ b/Emby.Server.Implementations/TV/TVSeriesManager.cs @@ -56,37 +56,15 @@ namespace Emby.Server.Implementations.TV return GetResult(GetNextUpEpisodes(request, user, new[] { presentationUniqueKey }, dtoOptions), request); } - if (limit.HasValue) - { - limit = limit.Value + 10; - } + var parents = user.RootFolder.GetChildren(user, true) + .Where(i => i is Folder) + .Where(i => !user.Configuration.LatestItemsExcludes.Contains(i.Id.ToString("N"))) + .ToList(); - var items = _libraryManager.GetItemList(new InternalItemsQuery(user) - { - IncludeItemTypes = new[] { typeof(Episode).Name }, - OrderBy = new[] { new Tuple(ItemSortBy.DatePlayed, SortOrder.Descending) }, - SeriesPresentationUniqueKey = presentationUniqueKey, - Limit = limit, - ParentId = parentIdGuid, - Recursive = true, - DtoOptions = new MediaBrowser.Controller.Dto.DtoOptions - { - Fields = new ItemFields[] - { - ItemFields.SeriesPresentationUniqueKey - } - }, - GroupBySeriesPresentationUniqueKey = true - - }).Cast().Select(GetUniqueSeriesKey); - - // Avoid implicitly captured closure - var episodes = GetNextUpEpisodes(request, user, items, dtoOptions); - - return GetResult(episodes, request); + return GetNextUp(request, parents, dtoOptions); } - public QueryResult GetNextUp(NextUpQuery request, List parentsFolders, DtoOptions dtoOptions) + public QueryResult GetNextUp(NextUpQuery request, List parentsFolders, DtoOptions dtoOptions) { var user = _userManager.GetUserById(request.UserId); @@ -134,7 +112,7 @@ namespace Emby.Server.Implementations.TV }, GroupBySeriesPresentationUniqueKey = true - }, parentsFolders.Cast().ToList()).Cast().Select(GetUniqueSeriesKey); + }, parentsFolders).Cast().Select(GetUniqueSeriesKey); // Avoid implicitly captured closure var episodes = GetNextUpEpisodes(request, user, items, dtoOptions); diff --git a/MediaBrowser.Api/UserLibrary/ItemsService.cs b/MediaBrowser.Api/UserLibrary/ItemsService.cs index 5919c50d4..5fe386f1a 100644 --- a/MediaBrowser.Api/UserLibrary/ItemsService.cs +++ b/MediaBrowser.Api/UserLibrary/ItemsService.cs @@ -26,6 +26,11 @@ namespace MediaBrowser.Api.UserLibrary { } + [Route("/Users/{UserId}/Items/Resume", "GET", Summary = "Gets items based on a query.")] + public class GetResumeItems : BaseItemsRequest, IReturn> + { + } + /// /// Class ItemsService /// @@ -79,6 +84,53 @@ namespace MediaBrowser.Api.UserLibrary _authContext = authContext; } + public object Get(GetResumeItems request) + { + var user = _userManager.GetUserById(request.UserId); + + var parentIdGuid = string.IsNullOrWhiteSpace(request.ParentId) ? (Guid?)null : new Guid(request.ParentId); + + var options = GetDtoOptions(_authContext, request); + + var ancestorIds = new List(); + + var excludeFolderIds = user.Configuration.LatestItemsExcludes; + if (!parentIdGuid.HasValue && excludeFolderIds.Length > 0) + { + ancestorIds = user.RootFolder.GetChildren(user, true) + .Where(i => i is Folder) + .Where(i => !excludeFolderIds.Contains(i.Id.ToString("N"))) + .Select(i => i.Id.ToString("N")) + .ToList(); + } + + var itemsResult = _libraryManager.GetItemsResult(new InternalItemsQuery(user) + { + OrderBy = new[] { ItemSortBy.DatePlayed }.Select(i => new Tuple(i, SortOrder.Descending)).ToArray(), + IsResumable = true, + StartIndex = request.StartIndex, + Limit = request.Limit, + ParentId = parentIdGuid, + Recursive = true, + DtoOptions = options, + MediaTypes = request.GetMediaTypes(), + IsVirtualItem = false, + CollapseBoxSetItems = false, + EnableTotalRecordCount = request.EnableTotalRecordCount, + AncestorIds = ancestorIds.ToArray() + }); + + var returnItems = _dtoService.GetBaseItemDtos(itemsResult.Items, options, user); + + var result = new QueryResult + { + TotalRecordCount = itemsResult.TotalRecordCount, + Items = returnItems + }; + + return ToOptimizedSerializedResultUsingCache(result); + } + /// /// Gets the specified request. /// diff --git a/MediaBrowser.Controller/Entities/UserViewBuilder.cs b/MediaBrowser.Controller/Entities/UserViewBuilder.cs index 3ab82a103..43adc4af6 100644 --- a/MediaBrowser.Controller/Entities/UserViewBuilder.cs +++ b/MediaBrowser.Controller/Entities/UserViewBuilder.cs @@ -238,12 +238,9 @@ namespace MediaBrowser.Controller.Entities { if (queryParent is UserView) { - return GetResult(GetMediaFolders(user).SelectMany(i => i.GetChildren(user, true)), queryParent, query); - } - else - { - return GetResult(queryParent.GetChildren(user, true), queryParent, query); + return GetResult(GetMediaFolders(user).OfType().SelectMany(i => i.GetChildren(user, true)), queryParent, query); } + return GetResult(queryParent.GetChildren(user, true), queryParent, query); } } } @@ -1681,7 +1678,7 @@ namespace MediaBrowser.Controller.Entities return true; } - private IEnumerable GetMediaFolders(User user) + private IEnumerable GetMediaFolders(User user) { if (user == null) { @@ -1696,7 +1693,7 @@ namespace MediaBrowser.Controller.Entities .Where(i => user.IsFolderGrouped(i.Id) && UserView.IsEligibleForGrouping(i)); } - private List GetMediaFolders(User user, IEnumerable viewTypes) + private List GetMediaFolders(User user, IEnumerable viewTypes) { if (user == null) { @@ -1717,14 +1714,14 @@ namespace MediaBrowser.Controller.Entities }).ToList(); } - private List GetMediaFolders(Folder parent, User user, IEnumerable viewTypes) + private List GetMediaFolders(Folder parent, User user, IEnumerable viewTypes) { if (parent == null || parent is UserView) { return GetMediaFolders(user, viewTypes); } - return new List { parent }; + return new List { parent }; } private async Task> GetLiveTvView(Folder queryParent, User user, InternalItemsQuery query) diff --git a/MediaBrowser.Controller/TV/ITVSeriesManager.cs b/MediaBrowser.Controller/TV/ITVSeriesManager.cs index 0bcb9ae5b..fd41094ee 100644 --- a/MediaBrowser.Controller/TV/ITVSeriesManager.cs +++ b/MediaBrowser.Controller/TV/ITVSeriesManager.cs @@ -15,6 +15,6 @@ namespace MediaBrowser.Controller.TV /// /// Gets the next up. /// - QueryResult GetNextUp(NextUpQuery request, List parentsFolders, DtoOptions options); + QueryResult GetNextUp(NextUpQuery request, List parentsFolders, DtoOptions options); } } diff --git a/MediaBrowser.Providers/Manager/ItemImageProvider.cs b/MediaBrowser.Providers/Manager/ItemImageProvider.cs index a6d4d4c33..00fd54271 100644 --- a/MediaBrowser.Providers/Manager/ItemImageProvider.cs +++ b/MediaBrowser.Providers/Manager/ItemImageProvider.cs @@ -204,9 +204,7 @@ namespace MediaBrowser.Providers.Manager private bool HasImage(IHasMetadata item, ImageType type) { - var image = item.GetImageInfo(type, 0); - - return image != null; + return item.HasImage(type); } ///