diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2015-01-26 11:47:15 -0500 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2015-01-26 11:47:15 -0500 |
| commit | 63f3cf97dada179fc6e9e3a177504d3e7b36321c (patch) | |
| tree | b6810d34b9bc46d61e8565ec4fc0f0c178cd0b35 /MediaBrowser.Api/UserLibrary/UserLibraryService.cs | |
| parent | 91416cb8a83eadde908e810afea981b6e4bed234 (diff) | |
add option to merge metadata and IBN paths
Diffstat (limited to 'MediaBrowser.Api/UserLibrary/UserLibraryService.cs')
| -rw-r--r-- | MediaBrowser.Api/UserLibrary/UserLibraryService.cs | 96 |
1 files changed, 9 insertions, 87 deletions
diff --git a/MediaBrowser.Api/UserLibrary/UserLibraryService.cs b/MediaBrowser.Api/UserLibrary/UserLibraryService.cs index c6ec53018..80ab72db7 100644 --- a/MediaBrowser.Api/UserLibrary/UserLibraryService.cs +++ b/MediaBrowser.Api/UserLibrary/UserLibraryService.cs @@ -228,7 +228,7 @@ namespace MediaBrowser.Api.UserLibrary /// </summary> /// <value>The user id.</value> [ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")] - public Guid UserId { get; set; } + public string UserId { get; set; } [ApiMember(Name = "Limit", Description = "Limit", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")] public int Limit { get; set; } @@ -304,81 +304,15 @@ namespace MediaBrowser.Api.UserLibrary { var user = _userManager.GetUserById(request.UserId); - var includeTypes = string.IsNullOrWhiteSpace(request.IncludeItemTypes) - ? new string[] { } - : request.IncludeItemTypes.Split(','); - - var currentUser = user; - - Func<BaseItem, bool> filter = i => - { - if (includeTypes.Length > 0) - { - if (!includeTypes.Contains(i.GetType().Name, StringComparer.OrdinalIgnoreCase)) - { - return false; - } - } - - if (request.IsPlayed.HasValue) - { - var val = request.IsPlayed.Value; - if (i.IsPlayed(currentUser) != val) - { - return false; - } - } - - return i.LocationType != LocationType.Virtual && !i.IsFolder; - }; - - // Avoid implicitly captured closure - var libraryItems = string.IsNullOrEmpty(request.ParentId) && user != null ? - GetItemsConfiguredForLatest(user, filter) : - GetAllLibraryItems(request.UserId, _userManager, _libraryManager, request.ParentId, filter); - - libraryItems = libraryItems.OrderByDescending(i => i.DateCreated); - - if (request.IsPlayed.HasValue) + var list = _userViewManager.GetLatestItems(new LatestItemsQuery { - var takeLimit = request.Limit * 20; - libraryItems = libraryItems.Take(takeLimit); - } - - // Avoid implicitly captured closure - var items = libraryItems - .ToList(); - - var list = new List<Tuple<BaseItem, List<BaseItem>>>(); - - foreach (var item in items) - { - // Only grab the index container for media - var container = item.IsFolder || !request.GroupItems ? null : item.LatestItemsIndexContainer; - - if (container == null) - { - list.Add(new Tuple<BaseItem, List<BaseItem>>(null, new List<BaseItem> { item })); - } - else - { - var current = list.FirstOrDefault(i => i.Item1 != null && i.Item1.Id == container.Id); - - if (current != null) - { - current.Item2.Add(item); - } - else - { - list.Add(new Tuple<BaseItem, List<BaseItem>>(container, new List<BaseItem> { item })); - } - } - - if (list.Count >= request.Limit) - { - break; - } - } + GroupItems = request.GroupItems, + IncludeItemTypes = (request.IncludeItemTypes ?? string.Empty).Split(',').Where(i => !string.IsNullOrWhiteSpace(i)).ToArray(), + IsPlayed = request.IsPlayed, + Limit = request.Limit, + ParentId = request.ParentId, + UserId = request.UserId + }); var options = GetDtoOptions(request); @@ -403,18 +337,6 @@ namespace MediaBrowser.Api.UserLibrary return ToOptimizedResult(dtos.ToList()); } - private IEnumerable<BaseItem> GetItemsConfiguredForLatest(User user, Func<BaseItem,bool> filter) - { - // Avoid implicitly captured closure - var currentUser = user; - - return user.RootFolder.GetChildren(user, true) - .OfType<Folder>() - .Where(i => !user.Configuration.LatestItemsExcludes.Contains(i.Id.ToString("N"))) - .SelectMany(i => i.GetRecursiveChildren(currentUser, filter)) - .DistinctBy(i => i.Id); - } - public async Task<object> Get(GetUserViews request) { var user = _userManager.GetUserById(request.UserId); |
