diff --git a/Emby.Dlna/ContentDirectory/ControlHandler.cs b/Emby.Dlna/ContentDirectory/ControlHandler.cs index 47d199e6e6..7db282dc86 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 56b10a7e6a..c99b601c90 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 0b81f7e93b..ec2d8c4fc4 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 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); + var parents = user.RootFolder.GetChildren(user, true) + .Where(i => i is Folder) + .Where(i => !user.Configuration.LatestItemsExcludes.Contains(i.Id.ToString("N"))) + .ToList(); - 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 5919c50d48..5fe386f1ab 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 3ab82a1030..43adc4af68 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 0bcb9ae5b7..fd41094ee4 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 a6d4d4c334..00fd54271c 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); } ///