Beispiel #1
0
        public IEnumerable <Episode> GetNextUpEpisodes(NextUpQuery request, User user, IEnumerable <Series> series)
        {
            // Avoid implicitly captured closure
            var currentUser = user;

            var allNextUp = series
                            .Select(i => GetNextUp(i, currentUser))
                            .Where(i => i.Item1 != null)
                            // Include if an episode was found, and either the series is not unwatched or the specific series was requested
                            .OrderByDescending(i => i.Item2)
                            .ThenByDescending(i => i.Item1.PremiereDate ?? DateTime.MinValue)
                            .ToList();

            // If viewing all next up for all series, remove first episodes
            if (string.IsNullOrWhiteSpace(request.SeriesId))
            {
                var withoutFirstEpisode = allNextUp
                                          .Where(i => !i.Item3)
                                          .ToList();

                // But if that returns empty, keep those first episodes (avoid completely empty view)
                if (withoutFirstEpisode.Count > 0)
                {
                    allNextUp = withoutFirstEpisode;
                }
            }

            return(allNextUp
                   .Select(i => i.Item1)
                   .Take(request.Limit ?? int.MaxValue));
        }
Beispiel #2
0
        public IEnumerable <Episode> GetNextUpEpisodes(NextUpQuery request, User user, IEnumerable <Series> series)
        {
            // Avoid implicitly captured closure
            var currentUser = user;

            return(FilterSeries(request, series)
                   .AsParallel()
                   .Select(i => GetNextUp(i, currentUser))
                   // Include if an episode was found, and either the series is not unwatched or the specific series was requested
                   .Where(i => i.Item1 != null && (!i.Item3 || !string.IsNullOrWhiteSpace(request.SeriesId)))
                   .OrderByDescending(i =>
            {
                var episode = i.Item1;

                var seriesUserData = _userDataManager.GetUserData(user.Id, episode.Series.GetUserDataKey());

                if (seriesUserData.IsFavorite)
                {
                    return 2;
                }

                if (seriesUserData.Likes.HasValue)
                {
                    return seriesUserData.Likes.Value ? 1 : -1;
                }

                return 0;
            })
                   .ThenByDescending(i => i.Item2)
                   .ThenByDescending(i => i.Item1.PremiereDate ?? DateTime.MinValue)
                   .Select(i => i.Item1));
        }
Beispiel #3
0
        public IEnumerable <Episode> GetNextUpEpisodes(NextUpQuery request, User user, IEnumerable <string> seriesKeys, DtoOptions dtoOptions)
        {
            // Avoid implicitly captured closure
            var currentUser = user;

            var allNextUp = seriesKeys
                            .Select(i => GetNextUp(i, currentUser, dtoOptions));

            //allNextUp = allNextUp.OrderByDescending(i => i.Item1);

            // If viewing all next up for all series, remove first episodes
            // But if that returns empty, keep those first episodes (avoid completely empty view)
            var alwaysEnableFirstEpisode = !string.IsNullOrWhiteSpace(request.SeriesId);
            var anyFound = false;

            return(allNextUp
                   .Where(i =>
            {
                if (alwaysEnableFirstEpisode || i.Item1 != DateTime.MinValue)
                {
                    anyFound = true;
                    return true;
                }

                if (!anyFound && i.Item1 == DateTime.MinValue)
                {
                    return true;
                }

                return false;
            })
                   .Select(i => i.Item2())
                   .Where(i => i != null));
        }
Beispiel #4
0
        /// <summary>
        /// Gets the next up.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <returns>System.String.</returns>
        /// <exception cref="System.ArgumentNullException">query</exception>
        protected string GetNextUpUrl(NextUpQuery query)
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }

            var dict = new QueryStringDictionary {
            };

            if (query.Fields != null)
            {
                dict.Add("fields", query.Fields.Select(f => f.ToString()));
            }

            dict.Add("ParentId", query.ParentId);

            dict.AddIfNotNull("Limit", query.Limit);

            dict.AddIfNotNull("StartIndex", query.StartIndex);

            dict.AddIfNotNullOrEmpty("SeriesId", query.SeriesId);

            dict.Add("UserId", query.UserId);

            dict.AddIfNotNull("EnableImages", query.EnableImages);
            if (query.EnableImageTypes != null)
            {
                dict.Add("EnableImageTypes", query.EnableImageTypes.Select(f => f.ToString()));
            }
            dict.AddIfNotNull("ImageTypeLimit", query.ImageTypeLimit);

            return(GetApiUrl("Shows/NextUp", dict));
        }
Beispiel #5
0
        private QueryResult <BaseItem> GetResult(IEnumerable <BaseItem> items, NextUpQuery query)
        {
            int totalCount = 0;

            if (query.EnableTotalRecordCount)
            {
                var list = items.ToList();
                totalCount = list.Count;
                items      = list;
            }

            if (query.StartIndex.HasValue)
            {
                items = items.Skip(query.StartIndex.Value);
            }
            if (query.Limit.HasValue)
            {
                items = items.Take(query.Limit.Value);
            }

            return(new QueryResult <BaseItem>
            {
                TotalRecordCount = totalCount,
                Items = items.ToArray()
            });
        }
        private async Task <bool> GetNextUp()
        {
            try
            {
                SetProgressBar("Getting next up items...");

                var query = new NextUpQuery
                {
                    UserId = AuthenticationService.Current.LoggedInUser.Id
                };

                Log.Info("Getting next up items");

                var itemResponse = await _apiClient.GetNextUpAsync(query);

                return(SetNextUpItems(itemResponse));
            }
            catch (HttpException ex)
            {
                Log.ErrorException("GetNextUp()", ex);
            }

            SetProgressBar();

            return(false);
        }
        /// <summary>
        /// Gets the next up.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <returns>System.String.</returns>
        /// <exception cref="System.ArgumentNullException">query</exception>
        protected Uri GetNextUpUrl(NextUpQuery query)
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }

            var dict = new NameValueCollection {
            };

            if (query.Fields != null)
            {
                dict.Add("fields", query.Fields.Select(f => f.ToString()));
            }

            dict.Add("ParentId", query.ParentId);

            dict.AddIfNotNull("Limit", query.Limit);

            dict.AddIfNotNull("StartIndex", query.StartIndex);

            dict.AddIfNotNullOrEmpty("SeriesId", query.SeriesId);

            dict.Add("UserId", query.UserId.ToString("N", CultureInfo.InvariantCulture));

            dict.AddIfNotNull("EnableImages", query.EnableImages);
            if (query.EnableImageTypes != null)
            {
                dict.Add("EnableImageTypes", query.EnableImageTypes.Select(f => f.ToString()));
            }
            dict.AddIfNotNull("ImageTypeLimit", query.ImageTypeLimit);

            return(GetApiUrl(new Uri("Shows/NextUp", UriKind.Relative), dict));
        }
        public IEnumerable <Episode> GetNextUpEpisodes(NextUpQuery request, User user, IEnumerable <Series> series)
        {
            // Avoid implicitly captured closure
            var currentUser = user;

            return(FilterSeries(request, series)
                   .AsParallel()
                   .Select(i => GetNextUp(i, currentUser))
                   .Where(i => i.Item1 != null)
                   .OrderByDescending(i =>
            {
                var episode = i.Item1;

                var seriesUserData = _userDataManager.GetUserData(user.Id, episode.Series.GetUserDataKey());

                if (seriesUserData.IsFavorite)
                {
                    return 2;
                }

                if (seriesUserData.Likes.HasValue)
                {
                    return seriesUserData.Likes.Value ? 1 : -1;
                }

                return 0;
            })
                   .ThenByDescending(i => i.Item2)
                   .ThenByDescending(i => i.Item1.PremiereDate ?? DateTime.MinValue)
                   .Select(i => i.Item1));
        }
        private async Task <bool> GetNextUp()
        {
            try
            {
                SetProgressBar(AppResources.SysTrayGettingNextUp);

                var query = new NextUpQuery
                {
                    ParentId         = _parentId,
                    UserId           = AuthenticationService.Current.LoggedInUserId,
                    Fields           = new[] { ItemFields.PrimaryImageAspectRatio, ItemFields.ParentId, ItemFields.MediaSources, ItemFields.SyncInfo },
                    ImageTypeLimit   = 1,
                    EnableImageTypes = new[] { ImageType.Backdrop, ImageType.Primary }
                };

                Log.Info("Getting next up items");

                var itemResponse = await ApiClient.GetNextUpEpisodesAsync(query);

                return(SetNextUpItems(itemResponse));
            }
            catch (HttpException ex)
            {
                Utils.HandleHttpException("GetNextUp()", ex, NavigationService, Log);
            }

            SetProgressBar();

            return(false);
        }
Beispiel #10
0
        public QueryResult <BaseItem> GetNextUp(NextUpQuery request, DtoOptions dtoOptions)
        {
            var user = _userManager.GetUserById(request.UserId);

            if (user == null)
            {
                throw new ArgumentException("User not found");
            }

            var parentIdGuid = string.IsNullOrWhiteSpace(request.ParentId) ? (Guid?)null : new Guid(request.ParentId);

            string presentationUniqueKey = null;
            int?   limit = null;

            if (!string.IsNullOrWhiteSpace(request.SeriesId))
            {
                var series = _libraryManager.GetItemById(request.SeriesId) as Series;

                if (series != null)
                {
                    presentationUniqueKey = GetUniqueSeriesKey(series);
                    limit = 1;
                }
            }

            if (!string.IsNullOrWhiteSpace(presentationUniqueKey))
            {
                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 },
                SortBy                      = new[] { ItemSortBy.DatePlayed },
                SortOrder                   = SortOrder.Descending,
                SeriesPresentationUniqueKey = presentationUniqueKey,
                Limit      = limit,
                ParentId   = parentIdGuid,
                Recursive  = true,
                DtoOptions = new MediaBrowser.Controller.Dto.DtoOptions
                {
                    Fields = new List <ItemFields>
                    {
                        ItemFields.SeriesPresentationUniqueKey
                    }
                },
                GroupBySeriesPresentationUniqueKey = true
            }).Cast <Episode>().Select(GetUniqueSeriesKey);

            // Avoid implicitly captured closure
            var episodes = GetNextUpEpisodes(request, user, items, dtoOptions);

            return(GetResult(episodes, request));
        }
Beispiel #11
0
        public QueryResult <BaseItem> GetNextUp(NextUpQuery request, BaseItem[] parentsFolders, DtoOptions dtoOptions)
        {
            var user = _userManager.GetUserById(request.UserId);

            if (user == null)
            {
                throw new ArgumentException("User not found");
            }

            string presentationUniqueKey = null;
            int?   limit = null;

            if (!string.IsNullOrEmpty(request.SeriesId))
            {
                var series = _libraryManager.GetItemById(request.SeriesId) as Series;

                if (series != null)
                {
                    presentationUniqueKey = GetUniqueSeriesKey(series);
                    limit = 1;
                }
            }

            if (!string.IsNullOrEmpty(presentationUniqueKey))
            {
                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[] { nameof(Episode) },
                OrderBy                     = new[] { new ValueTuple <string, SortOrder>(ItemSortBy.DatePlayed, SortOrder.Descending) },
                SeriesPresentationUniqueKey = presentationUniqueKey,
                Limit      = limit,
                DtoOptions = new DtoOptions {
                    Fields = new[] { ItemFields.SeriesPresentationUniqueKey }, EnableImages = false
                },
                GroupBySeriesPresentationUniqueKey = true
            }, parentsFolders.ToList())
                        .Cast <Episode>()
                        .Where(episode => !string.IsNullOrEmpty(episode.SeriesPresentationUniqueKey))
                        .Select(GetUniqueSeriesKey);

            // Avoid implicitly captured closure
            var episodes = GetNextUpEpisodes(request, user, items, dtoOptions);

            return(GetResult(episodes, request));
        }
Beispiel #12
0
        private IEnumerable <Series> FilterSeries(NextUpQuery request, IEnumerable <Series> items)
        {
            if (!string.IsNullOrWhiteSpace(request.SeriesId))
            {
                var id = new Guid(request.SeriesId);

                items = items.Where(i => i.Id == id);
            }

            return(items);
        }
Beispiel #13
0
        public QueryResult <BaseItem> GetNextUp(NextUpQuery request, DtoOptions dtoOptions)
        {
            var user = _userManager.GetUserById(request.UserId);

            if (user == null)
            {
                throw new ArgumentException("User not found");
            }

            string presentationUniqueKey = null;

            if (!string.IsNullOrEmpty(request.SeriesId))
            {
                var series = _libraryManager.GetItemById(request.SeriesId) as Series;

                if (series != null)
                {
                    presentationUniqueKey = GetUniqueSeriesKey(series);
                }
            }

            if (!string.IsNullOrEmpty(presentationUniqueKey))
            {
                return(GetResult(GetNextUpEpisodes(request, user, new[] { presentationUniqueKey }, dtoOptions), request));
            }

            var parentIdGuid = string.IsNullOrEmpty(request.ParentId) ? (Guid?)null : new Guid(request.ParentId);

            BaseItem[] parents;

            if (parentIdGuid.HasValue)
            {
                var parent = _libraryManager.GetItemById(parentIdGuid.Value);

                if (parent != null)
                {
                    parents = new[] { parent };
                }
                else
                {
                    parents = Array.Empty <BaseItem>();
                }
            }
            else
            {
                parents = _libraryManager.GetUserRootFolder().GetChildren(user, true)
                          .Where(i => i is Folder)
                          .Where(i => !user.GetPreference(PreferenceKind.LatestItemExcludes)
                                 .Contains(i.Id.ToString("N", CultureInfo.InvariantCulture)))
                          .ToArray();
            }

            return(GetNextUp(request, parents, dtoOptions));
        }
Beispiel #14
0
        public IEnumerable <Episode> GetNextUpEpisodes(NextUpQuery request, User user, IEnumerable <Series> series)
        {
            // Avoid implicitly captured closure
            var currentUser = user;

            return(series
                   .Select(i => GetNextUp(i, currentUser))
                   // Include if an episode was found, and either the series is not unwatched or the specific series was requested
                   .Where(i => i.Item1 != null && (!i.Item3 || !string.IsNullOrWhiteSpace(request.SeriesId)))
                   .OrderByDescending(i => i.Item2)
                   .ThenByDescending(i => i.Item1.PremiereDate ?? DateTime.MinValue)
                   .Select(i => i.Item1));
        }
Beispiel #15
0
        public QueryResult <BaseItem> GetNextUp(NextUpQuery request, DtoOptions dtoOptions)
        {
            var user = _userManager.GetUserById(request.UserId);

            if (user == null)
            {
                throw new ArgumentException("User not found");
            }

            string presentationUniqueKey = null;
            int?   limit = null;

            if (!string.IsNullOrWhiteSpace(request.SeriesId))
            {
                var series = _libraryManager.GetItemById(request.SeriesId) as Series;

                if (series != null)
                {
                    presentationUniqueKey = GetUniqueSeriesKey(series);
                    limit = 1;
                }
            }

            if (!string.IsNullOrWhiteSpace(presentationUniqueKey))
            {
                return(GetResult(GetNextUpEpisodes(request, user, new[] { presentationUniqueKey }, dtoOptions), request));
            }

            var parentIdGuid = string.IsNullOrWhiteSpace(request.ParentId) ? (Guid?)null : new Guid(request.ParentId);

            List <BaseItem> parents;

            if (parentIdGuid.HasValue)
            {
                var parent = _libraryManager.GetItemById(parentIdGuid.Value);
                parents = new List <BaseItem>();
                if (parent != null)
                {
                    parents.Add(parent);
                }
            }
            else
            {
                parents = user.RootFolder.GetChildren(user, true)
                          .Where(i => i is Folder)
                          .Where(i => !user.Configuration.LatestItemsExcludes.Contains(i.Id.ToString("N")))
                          .ToList();
            }

            return(GetNextUp(request, parents, dtoOptions));
        }
Beispiel #16
0
        public QueryResult <BaseItem> GetNextUp(NextUpQuery request, List <Folder> parentsFolders, DtoOptions dtoOptions)
        {
            var user = _userManager.GetUserById(request.UserId);

            if (user == null)
            {
                throw new ArgumentException("User not found");
            }

            string presentationUniqueKey = null;
            int?   limit = null;

            if (!string.IsNullOrWhiteSpace(request.SeriesId))
            {
                var series = _libraryManager.GetItemById(request.SeriesId);

                if (series != null)
                {
                    presentationUniqueKey = GetUniqueSeriesKey(series);
                    limit = 1;
                }
            }

            if (string.IsNullOrWhiteSpace(presentationUniqueKey) && limit.HasValue)
            {
                limit = limit.Value + 10;
            }

            var items = _libraryManager.GetItemList(new InternalItemsQuery(user)
            {
                IncludeItemTypes      = new[] { typeof(Series).Name },
                SortBy                = new[] { ItemSortBy.SeriesDatePlayed },
                SortOrder             = SortOrder.Descending,
                PresentationUniqueKey = presentationUniqueKey,
                Limit      = limit,
                DtoOptions = new MediaBrowser.Controller.Dto.DtoOptions
                {
                    Fields = new List <ItemFields>
                    {
                        ItemFields.PresentationUniqueKey
                    },
                    EnableImages = false
                }
            }, parentsFolders.Cast <BaseItem>().ToList()).Cast <Series>().Select(GetUniqueSeriesKey);

            // Avoid implicitly captured closure
            var episodes = GetNextUpEpisodes(request, user, items, dtoOptions);

            return(GetResult(episodes, request));
        }
Beispiel #17
0
        public QueryResult <BaseItem> GetNextUp(NextUpQuery query, DtoOptions options)
        {
            var user = _userManager.GetUserById(query.UserId);

            if (user == null)
            {
                throw new ArgumentException("User not found");
            }

            string presentationUniqueKey = null;

            if (!string.IsNullOrEmpty(query.SeriesId))
            {
                if (_libraryManager.GetItemById(query.SeriesId) is Series series)
                {
                    presentationUniqueKey = GetUniqueSeriesKey(series);
                }
            }

            if (!string.IsNullOrEmpty(presentationUniqueKey))
            {
                return(GetResult(GetNextUpEpisodes(query, user, new[] { presentationUniqueKey }, options), query));
            }

            BaseItem[] parents;

            if (query.ParentId.HasValue)
            {
                var parent = _libraryManager.GetItemById(query.ParentId.Value);

                if (parent != null)
                {
                    parents = new[] { parent };
                }
                else
                {
                    parents = Array.Empty <BaseItem>();
                }
            }
            else
            {
                parents = _libraryManager.GetUserRootFolder().GetChildren(user, true)
                          .Where(i => i is Folder)
                          .Where(i => !user.GetPreferenceValues <Guid>(PreferenceKind.LatestItemExcludes).Contains(i.Id))
                          .ToArray();
            }

            return(GetNextUp(query, parents, options));
        }
Beispiel #18
0
        public IEnumerable <Episode> GetNextUpEpisodes(NextUpQuery request, User user, IEnumerable <string> seriesKeys, DtoOptions dtoOptions)
        {
            // Avoid implicitly captured closure
            var currentUser = user;

            var allNextUp = seriesKeys
                            .Select(i => GetNextUp(i, currentUser, dtoOptions));

            return(allNextUp
                   .Where(i =>
            {
                return i.Item1 != DateTime.MinValue;
            })
                   .Select(i => i.Item2())
                   .Where(i => i != null));
        }
        public QueryResult <BaseItem> GetNextUp(NextUpQuery request, IEnumerable <Folder> parentsFolders)
        {
            var user = _userManager.GetUserById(request.UserId);

            if (user == null)
            {
                throw new ArgumentException("User not found");
            }

            var items = parentsFolders.SelectMany(i => i.GetRecursiveChildren(user))
                        .OfType <Series>();

            // Avoid implicitly captured closure
            var episodes = GetNextUpEpisodes(request, user, items);

            return(GetResult(episodes, null, request));
        }
Beispiel #20
0
        public QueryResult <BaseItem> GetNextUp(NextUpQuery request)
        {
            var user = _userManager.GetUserById(request.UserId);

            if (user == null)
            {
                throw new ArgumentException("User not found");
            }

            var parentIdGuid = string.IsNullOrWhiteSpace(request.ParentId) ? (Guid?)null : new Guid(request.ParentId);

            string presentationUniqueKey = null;
            int?   limit = null;

            if (!string.IsNullOrWhiteSpace(request.SeriesId))
            {
                var series = _libraryManager.GetItemById(request.SeriesId);

                if (series != null)
                {
                    presentationUniqueKey = GetUniqueSeriesKey(series);
                    limit = 1;
                }
            }

            if (string.IsNullOrWhiteSpace(presentationUniqueKey) && limit.HasValue)
            {
                limit = limit.Value + 10;
            }

            var items = _libraryManager.GetItemList(new InternalItemsQuery(user)
            {
                IncludeItemTypes      = new[] { typeof(Series).Name },
                SortOrder             = SortOrder.Ascending,
                PresentationUniqueKey = presentationUniqueKey,
                Limit     = limit,
                ParentId  = parentIdGuid,
                Recursive = true
            }).Cast <Series>();

            // Avoid implicitly captured closure
            var episodes = GetNextUpEpisodes(request, user, items);

            return(GetResult(episodes, null, request));
        }
Beispiel #21
0
        public QueryResult <BaseItem> GetNextUp(NextUpQuery request, IEnumerable <Folder> parentsFolders)
        {
            var user = _userManager.GetUserById(request.UserId);

            if (user == null)
            {
                throw new ArgumentException("User not found");
            }

            var items = _libraryManager.GetItemList(new InternalItemsQuery(user)
            {
                IncludeItemTypes = new[] { typeof(Series).Name },
                SortOrder        = SortOrder.Ascending
            }, parentsFolders.Select(i => i.Id.ToString("N"))).Cast <Series>();

            // Avoid implicitly captured closure
            var episodes = GetNextUpEpisodes(request, user, items);

            return(GetResult(episodes, null, request));
        }
        public QueryResult <BaseItem> GetNextUp(NextUpQuery request)
        {
            var user = _userManager.GetUserById(request.UserId);

            if (user == null)
            {
                throw new ArgumentException("User not found");
            }

            var parentIds = string.IsNullOrEmpty(request.ParentId)
                ? new string[] { }
                : new[] { request.ParentId };

            var items = GetAllLibraryItems(user, parentIds)
                        .OfType <Series>();

            // Avoid implicitly captured closure
            var episodes = GetNextUpEpisodes(request, user, items);

            return(GetResult(episodes, null, request));
        }
Beispiel #23
0
        public QueryResult <BaseItem> GetNextUp(NextUpQuery request)
        {
            var user = _userManager.GetUserById(request.UserId);

            if (user == null)
            {
                throw new ArgumentException("User not found");
            }

            var parentIds = string.IsNullOrEmpty(request.ParentId)
                ? new string[] { }
                : new[] { request.ParentId };

            string presentationUniqueKey = null;
            int?   limit = null;

            if (!string.IsNullOrWhiteSpace(request.SeriesId))
            {
                var series = _libraryManager.GetItemById(request.SeriesId);

                if (series != null)
                {
                    presentationUniqueKey = series.PresentationUniqueKey;
                    limit = 1;
                }
            }

            var items = _libraryManager.GetItemList(new InternalItemsQuery(user)
            {
                IncludeItemTypes      = new[] { typeof(Series).Name },
                SortOrder             = SortOrder.Ascending,
                PresentationUniqueKey = presentationUniqueKey,
                Limit = limit
            }, parentIds).Cast <Series>();

            // Avoid implicitly captured closure
            var episodes = GetNextUpEpisodes(request, user, items);

            return(GetResult(episodes, null, request));
        }
        private async Task <ItemsResult> GetNextUpAsync(ItemListViewModel viewModel)
        {
            var query = new NextUpQuery
            {
                Fields = new[]
                {
                    ItemFields.PrimaryImageAspectRatio,
                    ItemFields.DateCreated,
                    ItemFields.DisplayPreferencesId
                },

                UserId = _sessionManager.CurrentUser.Id,

                Limit = 15
            };

            var result = await ApiClient.GetNextUpAsync(query);

            ShowNextUp = result.TotalRecordCount > 0;

            return(result);
        }
Beispiel #25
0
        public QueryResult <BaseItem> GetNextUp(NextUpQuery request, BaseItem[] parentsFolders, DtoOptions options)
        {
            var user = _userManager.GetUserById(request.UserId);

            if (user == null)
            {
                throw new ArgumentException("User not found");
            }

            string presentationUniqueKey = null;
            int?   limit = null;

            if (!string.IsNullOrEmpty(request.SeriesId))
            {
                if (_libraryManager.GetItemById(request.SeriesId) is Series series)
                {
                    presentationUniqueKey = GetUniqueSeriesKey(series);
                    limit = 1;
                }
            }

            if (!string.IsNullOrEmpty(presentationUniqueKey))
            {
                return(GetResult(GetNextUpEpisodes(request, user, new[] { presentationUniqueKey }, options), request));
            }

            if (limit.HasValue)
            {
                limit = limit.Value + 10;
            }

            var items = _libraryManager
                        .GetItemList(
                new InternalItemsQuery(user)
            {
                IncludeItemTypes            = new[] { BaseItemKind.Episode },
                OrderBy                     = new[] { (ItemSortBy.DatePlayed, SortOrder.Descending) },
Beispiel #26
0
        public QueryResult <BaseItem> GetNextUp(NextUpQuery request)
        {
            var user = _userManager.GetUserById(request.UserId);

            if (user == null)
            {
                throw new ArgumentException("User not found");
            }

            var parentIds = string.IsNullOrEmpty(request.ParentId)
                ? new string[] { }
                : new[] { request.ParentId };

            var items = _libraryManager.GetItemList(new InternalItemsQuery(user)
            {
                IncludeItemTypes = new[] { typeof(Series).Name },
                SortOrder        = SortOrder.Ascending
            }, parentIds).Cast <Series>();

            // Avoid implicitly captured closure
            var episodes = GetNextUpEpisodes(request, user, items);

            return(GetResult(episodes, null, request));
        }
Beispiel #27
0
        private QueryResult <BaseItem> GetResult(IEnumerable <BaseItem> items, int?totalRecordLimit, NextUpQuery query)
        {
            var itemsArray = totalRecordLimit.HasValue ? items.Take(totalRecordLimit.Value).ToArray() : items.ToArray();
            var totalCount = itemsArray.Length;

            if (query.Limit.HasValue)
            {
                itemsArray = itemsArray.Skip(query.StartIndex ?? 0).Take(query.Limit.Value).ToArray();
            }
            else if (query.StartIndex.HasValue)
            {
                itemsArray = itemsArray.Skip(query.StartIndex.Value).ToArray();
            }

            return(new QueryResult <BaseItem>
            {
                TotalRecordCount = totalCount,
                Items = itemsArray
            });
        }