private IEnumerable <Episode> FilterItems(GetNextUpEpisodes request, IEnumerable <Episode> items) { // Make this configurable when needed items = items.Where(i => i.LocationType != LocationType.Virtual); return(items); }
public IEnumerable <Episode> GetNextUpEpisodes(GetNextUpEpisodes request, IEnumerable <Series> series) { var user = _userManager.GetUserById(request.UserId); // Avoid implicitly captured closure var currentUser = user; return(FilterSeries(request, series) .AsParallel() .Select(i => GetNextUp(i, currentUser, request).Item1) .Where(i => i != null) .OrderByDescending(i => { var seriesUserData = _userDataManager.GetUserData(user.Id, i.Series.GetUserDataKey()); if (seriesUserData.IsFavorite) { return 2; } if (seriesUserData.Likes.HasValue) { return seriesUserData.Likes.Value ? 1 : -1; } return 0; }) .ThenByDescending(i => i.PremiereDate ?? DateTime.MinValue)); }
/// <summary> /// Gets the specified request. /// </summary> /// <param name="request">The request.</param> /// <returns>System.Object.</returns> public async Task <object> Get(GetNextUpEpisodes request) { var options = GetDtoOptions(_authContext, request); var result = _tvSeriesManager.GetNextUp(new NextUpQuery { Limit = request.Limit, ParentId = request.ParentId, SeriesId = request.SeriesId, StartIndex = request.StartIndex, UserId = request.UserId, EnableTotalRecordCount = request.EnableTotalRecordCount }, options); var user = _userManager.GetUserById(request.UserId); var returnList = (await _dtoService.GetBaseItemDtos(result.Items, options, user).ConfigureAwait(false)); var returnItems = returnList.ToArray(returnList.Count); return(ToOptimizedSerializedResultUsingCache(new ItemsResult { TotalRecordCount = result.TotalRecordCount, Items = returnItems })); }
public IEnumerable <Episode> GetNextUpEpisodes(GetNextUpEpisodes request) { var items = GetAllLibraryItems(request.UserId, _userManager, _libraryManager, request.ParentId) .OfType <Series>(); // Avoid implicitly captured closure return(GetNextUpEpisodes(request, items)); }
private IEnumerable <Series> FilterSeries(GetNextUpEpisodes request, IEnumerable <Series> items) { if (!string.IsNullOrWhiteSpace(request.SeriesId)) { var id = new Guid(request.SeriesId); items = items.Where(i => i.Id == id); } return(items); }
public IEnumerable <Episode> GetNextUpEpisodes(GetNextUpEpisodes request) { var user = _userManager.GetUserById(request.UserId); var items = user.RootFolder .GetRecursiveChildren(user) .OfType <Series>(); // Avoid implicitly captured closure return(GetNextUpEpisodes(request, items)); }
/// <summary> /// Applies the paging. /// </summary> /// <param name="request">The request.</param> /// <param name="items">The items.</param> /// <returns>IEnumerable{BaseItem}.</returns> private IEnumerable <BaseItem> ApplyPaging(GetNextUpEpisodes request, IEnumerable <BaseItem> 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); }
/// <summary> /// Gets the next up episodes. /// </summary> /// <param name="request">The request.</param> /// <returns>Task{ItemsResult}.</returns> private async Task <ItemsResult> GetNextUpEpisodes(GetNextUpEpisodes request) { var user = _userManager.GetUserById(request.UserId); var itemsArray = user.RootFolder .GetRecursiveChildren(user) .OfType <Series>() .AsParallel() .Select(i => GetNextUp(i, user)) .ToArray(); itemsArray = itemsArray .Where(i => i.Item1 != null) .OrderByDescending(i => { var seriesUserData = _userDataRepository.GetUserData(user.Id, i.Item1.Series.GetUserDataKey()); if (seriesUserData.IsFavorite) { return(2); } if (seriesUserData.Likes.HasValue) { return(seriesUserData.Likes.Value ? 1 : -1); } return(0); }) .ThenByDescending(i => i.Item1.PremiereDate ?? DateTime.MinValue) .ToArray(); var pagedItems = ApplyPaging(request, itemsArray.Select(i => i.Item1)); var fields = request.GetItemFields().ToList(); var returnItems = await GetItemDtos(pagedItems, user, fields).ConfigureAwait(false); return(new ItemsResult { TotalRecordCount = itemsArray.Length, Items = returnItems }); }
/// <summary> /// Gets the next up. /// </summary> /// <param name="series">The series.</param> /// <param name="user">The user.</param> /// <param name="request">The request.</param> /// <returns>Task{Episode}.</returns> private Tuple <Episode, DateTime> GetNextUp(Series series, User user, GetNextUpEpisodes request) { // Get them in display order, then reverse var allEpisodes = series.GetSeasons(user, true, true) .SelectMany(i => i.GetEpisodes(user, true, true)) .Reverse() .ToList(); Episode lastWatched = null; var lastWatchedDate = DateTime.MinValue; Episode nextUp = null; // Go back starting with the most recent episodes foreach (var episode in allEpisodes) { var userData = _userDataManager.GetUserData(user.Id, episode.GetUserDataKey()); if (userData.Played) { if (lastWatched != null || nextUp == null) { break; } lastWatched = episode; lastWatchedDate = userData.LastPlayedDate ?? DateTime.MinValue; } else { if (episode.LocationType != LocationType.Virtual) { nextUp = episode; } } } if (lastWatched != null) { return(new Tuple <Episode, DateTime>(nextUp, lastWatchedDate)); } return(new Tuple <Episode, DateTime>(null, lastWatchedDate)); }
/// <summary> /// Gets the next up episodes. /// </summary> /// <param name="request">The request.</param> /// <returns>Task{ItemsResult}.</returns> private ItemsResult GetNextUpEpisodeItemsResult(GetNextUpEpisodes request) { var user = _userManager.GetUserById(request.UserId); var itemsList = GetNextUpEpisodes(request) .ToList(); var pagedItems = ApplyPaging(request, itemsList); var fields = request.GetItemFields().ToList(); var returnItems = pagedItems.Select(i => _dtoService.GetBaseItemDto(i, fields, user)).ToArray(); return(new ItemsResult { TotalRecordCount = itemsList.Count, Items = returnItems }); }
/// <summary> /// Gets the next up. /// </summary> /// <param name="series">The series.</param> /// <param name="user">The user.</param> /// <param name="request">The request.</param> /// <returns>Task{Episode}.</returns> private Tuple <Episode, DateTime> GetNextUp(Series series, User user, GetNextUpEpisodes request) { var allEpisodes = series.GetRecursiveChildren(user) .OfType <Episode>() .OrderByDescending(i => i.PremiereDate ?? DateTime.MinValue) .ThenByDescending(i => i.IndexNumber ?? 0) .ToList(); allEpisodes = FilterItems(request, allEpisodes).ToList(); Episode lastWatched = null; var lastWatchedDate = DateTime.MinValue; Episode nextUp = null; // Go back starting with the most recent episodes foreach (var episode in allEpisodes) { var userData = _userDataManager.GetUserData(user.Id, episode.GetUserDataKey()); if (userData.Played) { if (lastWatched != null || nextUp == null) { break; } lastWatched = episode; lastWatchedDate = userData.LastPlayedDate ?? DateTime.MinValue; } else { nextUp = episode; } } if (lastWatched != null) { return(new Tuple <Episode, DateTime>(nextUp, lastWatchedDate)); } return(new Tuple <Episode, DateTime>(null, lastWatchedDate)); }
/// <summary> /// Gets the specified request. /// </summary> /// <param name="request">The request.</param> /// <returns>System.Object.</returns> public object Get(GetNextUpEpisodes request) { var user = _userManager.GetUserById(request.UserId); var itemsList = GetNextUpEpisodes(request) .ToList(); var pagedItems = ApplyPaging(itemsList, request.StartIndex, request.Limit); var fields = request.GetItemFields().ToList(); var returnItems = pagedItems.Select(i => _dtoService.GetBaseItemDto(i, fields, user)).ToArray(); var result = new ItemsResult { TotalRecordCount = itemsList.Count, Items = returnItems }; return(ToOptimizedSerializedResultUsingCache(result)); }
/// <summary> /// Gets the specified request. /// </summary> /// <param name="request">The request.</param> /// <returns>System.Object.</returns> public object Get(GetNextUpEpisodes request) { var result = _tvSeriesManager.GetNextUp(new NextUpQuery { Limit = request.Limit, ParentId = request.ParentId, SeriesId = request.SeriesId, StartIndex = request.StartIndex, UserId = request.UserId }); var user = _userManager.GetUserById(new Guid(request.UserId)); var fields = request.GetItemFields().ToList(); var returnItems = result.Items.Select(i => _dtoService.GetBaseItemDto(i, fields, user)).ToArray(); return(ToOptimizedSerializedResultUsingCache(new ItemsResult { TotalRecordCount = result.TotalRecordCount, Items = returnItems })); }
/// <summary> /// Gets the specified request. /// </summary> /// <param name="request">The request.</param> /// <returns>System.Object.</returns> public object Get(GetNextUpEpisodes request) { var result = _tvSeriesManager.GetNextUp(new NextUpQuery { Limit = request.Limit, ParentId = request.ParentId, SeriesId = request.SeriesId, StartIndex = request.StartIndex, UserId = request.UserId }); var user = _userManager.GetUserById(request.UserId); var options = GetDtoOptions(request); var returnItems = _dtoService.GetBaseItemDtos(result.Items, options, user).ToArray(); return(ToOptimizedSerializedResultUsingCache(new ItemsResult { TotalRecordCount = result.TotalRecordCount, Items = returnItems })); }
/// <summary> /// Gets the specified request. /// </summary> /// <param name="request">The request.</param> /// <returns>System.Object.</returns> public object Get(GetNextUpEpisodes request) { var options = GetDtoOptions(_authContext, request); var result = _tvSeriesManager.GetNextUp(new NextUpQuery { Limit = request.Limit, ParentId = request.ParentId, SeriesId = request.SeriesId, StartIndex = request.StartIndex, UserId = request.UserId, EnableTotalRecordCount = request.EnableTotalRecordCount }, options); var user = _userManager.GetUserById(request.UserId); var returnItems = _dtoService.GetBaseItemDtos(result.Items, options, user); return(ToOptimizedResult(new QueryResult <BaseItemDto> { TotalRecordCount = result.TotalRecordCount, Items = returnItems })); }
/// <summary> /// Gets the specified request. /// </summary> /// <param name="request">The request.</param> /// <returns>System.Object.</returns> public object Get(GetNextUpEpisodes request) { var result = GetNextUpEpisodes(request).Result; return(ToOptimizedResult(result)); }