Ejemplo n.º 1
0
        private QueryResult <BaseItem> GetMusicLatest(Folder parent, User user, UserItemsQuery query)
        {
            query.SortBy    = new[] { ItemSortBy.DateCreated, ItemSortBy.SortName };
            query.SortOrder = SortOrder.Descending;

            return(GetResult(GetRecursiveChildren(parent, user, new[] { CollectionType.Music }).Where(i => i is MusicVideo || i is Audio.Audio), GetSpecialItemsLimit(), query));
        }
Ejemplo n.º 2
0
        public override async Task<QueryResult<BaseItem>> GetUserItems(UserItemsQuery query)
        {
            try
            {
                // Don't blow up here because it could cause parent screens with other content to fail
                return await ChannelManager.GetChannelItemsInternal(new ChannelItemQuery
                {
                    ChannelId = Id.ToString("N"),
                    Limit = query.Limit,
                    StartIndex = query.StartIndex,
                    UserId = query.User.Id.ToString("N"),
                    SortBy = query.SortBy,
                    SortOrder = query.SortOrder

                }, CancellationToken.None);
            }
            catch
            {
                // Already logged at lower levels
                return new QueryResult<BaseItem>
                {

                };
            }
        }
Ejemplo n.º 3
0
        private QueryResult <BaseItem> GetTvLatest(Folder parent, User user, UserItemsQuery query)
        {
            query.SortBy    = new[] { ItemSortBy.DateCreated, ItemSortBy.SortName };
            query.SortOrder = SortOrder.Descending;

            return(GetResult(GetRecursiveChildren(parent, user, new[] { CollectionType.TvShows, string.Empty }).OfType <Episode>(), GetSpecialItemsLimit(), query));
        }
Ejemplo n.º 4
0
 private QueryResult <BaseItem> GetResult <T>(IEnumerable <T> items,
                                              int?totalRecordLimit,
                                              UserItemsQuery query)
     where T : BaseItem
 {
     return(SortAndFilter(items, totalRecordLimit, query, _libraryManager, _userDataManager));
 }
Ejemplo n.º 5
0
        public static QueryResult <BaseItem> Sort(IEnumerable <BaseItem> items,
                                                  int?totalRecordLimit,
                                                  UserItemsQuery query,
                                                  ILibraryManager libraryManager)
        {
            var user = query.User;

            items = libraryManager.ReplaceVideosWithPrimaryVersions(items);

            if (query.SortBy.Length > 0)
            {
                items = libraryManager.Sort(items, user, query.SortBy, query.SortOrder);
            }

            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
            });
        }
Ejemplo n.º 6
0
        private QueryResult <BaseItem> GetMovieLatest(Folder parent, User user, UserItemsQuery query)
        {
            query.SortBy    = new[] { ItemSortBy.DateCreated, ItemSortBy.SortName };
            query.SortOrder = SortOrder.Descending;

            return(GetResult(GetRecursiveChildren(parent, user, new[] { CollectionType.Movies, CollectionType.BoxSets, string.Empty }).Where(i => i is Movie), GetSpecialItemsLimit(), query));
        }
Ejemplo n.º 7
0
        public override async Task <QueryResult <BaseItem> > GetUserItems(UserItemsQuery query)
        {
            var result = await UserViewManager.GetUserViews(new UserViewQuery
            {
                UserId = query.User.Id.ToString("N")
            }, CancellationToken.None).ConfigureAwait(false);

            return(SortAndFilter(result, query));
        }
Ejemplo n.º 8
0
        public override async Task<QueryResult<BaseItem>> GetUserItems(UserItemsQuery query)
        {
            var result = await UserViewManager.GetUserViews(new UserViewQuery
            {
                UserId = query.User.Id.ToString("N")

            }, CancellationToken.None).ConfigureAwait(false);

            return SortAndFilter(result, query);
        }
Ejemplo n.º 9
0
        public static QueryResult <BaseItem> SortAndFilter(IEnumerable <BaseItem> items,
                                                           int?totalRecordLimit,
                                                           UserItemsQuery query,
                                                           ILibraryManager libraryManager,
                                                           IUserDataManager userDataManager)
        {
            var user = query.User;

            items = items.Where(i => Filter(i, user, query, userDataManager));

            return(Sort(items, totalRecordLimit, query, libraryManager));
        }
Ejemplo n.º 10
0
        public virtual Task <QueryResult <BaseItem> > GetUserItems(UserItemsQuery query)
        {
            var user = query.User;

            var items = query.Recursive
                ? GetRecursiveChildren(user)
                : GetChildren(user, true);

            var result = SortAndFilter(items, query);

            return(Task.FromResult(result));
        }
Ejemplo n.º 11
0
        private QueryResult <BaseItem> GetTvNextUp(Folder parent, UserItemsQuery query)
        {
            var parentFolders = GetMediaFolders(parent, query.User, new[] { CollectionType.TvShows, string.Empty });

            var result = _tvSeriesManager.GetNextUp(new NextUpQuery
            {
                Limit      = query.Limit,
                StartIndex = query.StartIndex,
                UserId     = query.User.Id.ToString("N")
            }, parentFolders);

            return(result);
        }
Ejemplo n.º 12
0
        private static bool Filter(BaseItem item, User user, UserItemsQuery query, IUserDataManager userDataManager)
        {
            if (query.MediaTypes.Length > 0 && !query.MediaTypes.Contains(item.MediaType ?? string.Empty, StringComparer.OrdinalIgnoreCase))
            {
                return(false);
            }

            if (query.IsFolder.HasValue && query.IsFolder.Value != item.IsFolder)
            {
                return(false);
            }

            if (query.Filter != null && !query.Filter(item, user))
            {
                return(false);
            }

            UserItemData userData = null;

            if (query.IsFavorite.HasValue)
            {
                userData = userData ?? userDataManager.GetUserData(user.Id, item.GetUserDataKey());

                if (userData.IsFavorite != query.IsFavorite.Value)
                {
                    return(false);
                }
            }

            if (query.IsResumable.HasValue)
            {
                userData = userData ?? userDataManager.GetUserData(user.Id, item.GetUserDataKey());
                var isResumable = userData.PlaybackPositionTicks > 0;

                if (isResumable != query.IsResumable.Value)
                {
                    return(false);
                }
            }

            if (query.IsPlayed.HasValue)
            {
                if (item.IsPlayed(user) != query.IsPlayed.Value)
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 13
0
        private QueryResult <BaseItem> GetFavoriteArtists(Folder parent, User user, UserItemsQuery query)
        {
            var artists = GetRecursiveChildren(parent, user, new[] { CollectionType.Music })
                          .Where(i => !i.IsFolder)
                          .OfType <IHasAlbumArtist>()
                          .SelectMany(i => i.AlbumArtists)
                          .Distinct(StringComparer.OrdinalIgnoreCase)
                          .Select(i =>
            {
                try
                {
                    return(_libraryManager.GetArtist(i));
                }
                catch
                {
                    // Already logged at lower levels
                    return(null);
                }
            })
                          .Where(i => i != null && _userDataManager.GetUserData(user.Id, i.GetUserDataKey()).IsFavorite);

            return(GetResult(artists, query));
        }
Ejemplo n.º 14
0
        private QueryResult <BaseItem> GetGameGenres(Folder parent, User user, UserItemsQuery query)
        {
            var genres = GetRecursiveChildren(parent, user, new[] { CollectionType.Games })
                         .OfType <Game>()
                         .SelectMany(i => i.Genres)
                         .Distinct(StringComparer.OrdinalIgnoreCase)
                         .Select(i =>
            {
                try
                {
                    return(_libraryManager.GetGameGenre(i));
                }
                catch
                {
                    // Full exception logged at lower levels
                    _logger.Error("Error getting game genre");
                    return(null);
                }
            })
                         .Where(i => i != null);

            return(GetResult(genres, query));
        }
Ejemplo n.º 15
0
 private QueryResult <BaseItem> GetTvSeries(Folder parent, User user, UserItemsQuery query)
 {
     return(GetResult(GetRecursiveChildren(parent, user, new[] { CollectionType.TvShows, string.Empty }).OfType <Series>(), query));
 }
Ejemplo n.º 16
0
 protected QueryResult<BaseItem> SortAndFilter(IEnumerable<BaseItem> items, UserItemsQuery query)
 {
     return UserViewBuilder.SortAndFilter(items, null, query, LibraryManager, UserDataManager);
 }
Ejemplo n.º 17
0
 private QueryResult <BaseItem> GetMusicSongs(Folder parent, User user, UserItemsQuery query)
 {
     return(GetResult(GetRecursiveChildren(parent, user, new[] { CollectionType.Music }).Where(i => i is Audio.Audio), query));
 }
Ejemplo n.º 18
0
        private async Task <QueryResult <BaseItem> > GetMusicFavorites(Folder parent, User user, UserItemsQuery query)
        {
            var list = new List <BaseItem>();

            var category = "music";

            list.Add(await GetUserView(category, CollectionType.MusicFavoriteAlbums, user, "0", parent).ConfigureAwait(false));
            list.Add(await GetUserView(category, CollectionType.MusicFavoriteArtists, user, "1", parent).ConfigureAwait(false));
            list.Add(await GetUserView(category, CollectionType.MusicFavoriteSongs, user, "2", parent).ConfigureAwait(false));

            return(GetResult(list, query));
        }
Ejemplo n.º 19
0
        private QueryResult <BaseItem> GetFavoriteGames(Folder parent, User user, UserItemsQuery query)
        {
            query.IsFavorite = true;

            return(GetResult(GetRecursiveChildren(parent, user, new[] { CollectionType.Games }).OfType <Game>(), query));
        }
Ejemplo n.º 20
0
        private async Task <QueryResult <BaseItem> > GetMovieFolders(Folder parent, User user, UserItemsQuery query)
        {
            if (query.Recursive)
            {
                return(GetResult(GetRecursiveChildren(parent, user, new[] { CollectionType.Movies, CollectionType.BoxSets, string.Empty }).Where(i => i is Movie || i is BoxSet), query));
            }

            var list = new List <BaseItem>();

            var category = "movies";

            list.Add(await GetUserView(category, CollectionType.MovieResume, user, "0", parent).ConfigureAwait(false));
            list.Add(await GetUserView(category, CollectionType.MovieLatest, user, "1", parent).ConfigureAwait(false));
            list.Add(await GetUserView(category, CollectionType.MovieMovies, user, "2", parent).ConfigureAwait(false));
            list.Add(await GetUserView(category, CollectionType.MovieCollections, user, "3", parent).ConfigureAwait(false));
            list.Add(await GetUserView(category, CollectionType.MovieFavorites, user, "4", parent).ConfigureAwait(false));
            //list.Add(await GetUserView(CollectionType.MovieGenres, user, "5", parent).ConfigureAwait(false));

            return(GetResult(list, query));
        }
Ejemplo n.º 21
0
 public override Task<QueryResult<BaseItem>> GetUserItems(UserItemsQuery query)
 {
     return new UserViewBuilder(UserViewManager, LiveTvManager, ChannelManager, LibraryManager, Logger, UserDataManager, TVSeriesManager)
         .GetUserItems(this, ViewType, query);
 }
Ejemplo n.º 22
0
 private QueryResult <BaseItem> GetResult <T>(IEnumerable <T> items,
                                              UserItemsQuery query)
     where T : BaseItem
 {
     return(GetResult(items, null, query));
 }
Ejemplo n.º 23
0
 private QueryResult <BaseItem> GetGameSystems(Folder parent, User user, UserItemsQuery query)
 {
     return(GetResult(GetRecursiveChildren(parent, user, new[] { CollectionType.Games }).OfType <GameSystem>(), query));
 }
Ejemplo n.º 24
0
 private QueryResult <BaseItem> GetMovieCollections(Folder parent, User user, UserItemsQuery query)
 {
     return(GetResult(GetRecursiveChildren(parent, user, new[] { CollectionType.Movies, CollectionType.BoxSets, string.Empty }).Where(i => i is BoxSet), query));
 }
Ejemplo n.º 25
0
        private QueryResult <BaseItem> GetFavoriteAlbums(Folder parent, User user, UserItemsQuery query)
        {
            query.IsFavorite = true;

            return(GetResult(GetRecursiveChildren(parent, user, new[] { CollectionType.Music }).Where(i => i is MusicAlbum), query));
        }
Ejemplo n.º 26
0
        private QueryResult <BaseItem> GetFavoriteEpisodes(Folder parent, User user, UserItemsQuery query)
        {
            query.IsFavorite = true;

            return(GetResult(GetRecursiveChildren(parent, user, new[] { CollectionType.TvShows, string.Empty }).Where(i => i is Episode), query));
        }
Ejemplo n.º 27
0
        public async Task <QueryResult <BaseItem> > GetUserItems(Folder parent, string viewType, UserItemsQuery query)
        {
            var user = query.User;

            switch (viewType)
            {
            case CollectionType.Channels:
            {
                var result = await _channelManager.GetChannelsInternal(new ChannelQuery
                    {
                        UserId     = user.Id.ToString("N"),
                        Limit      = query.Limit,
                        StartIndex = query.StartIndex
                    }, CancellationToken.None).ConfigureAwait(false);

                return(GetResult(result));
            }

            case CollectionType.LiveTvChannels:
            {
                var result = await _liveTvManager.GetInternalChannels(new LiveTvChannelQuery
                    {
                        UserId     = query.User.Id.ToString("N"),
                        Limit      = query.Limit,
                        StartIndex = query.StartIndex
                    }, CancellationToken.None).ConfigureAwait(false);

                return(GetResult(result));
            }

            case CollectionType.LiveTvNowPlaying:
            {
                var result = await _liveTvManager.GetRecommendedProgramsInternal(new RecommendedProgramQuery
                    {
                        UserId   = query.User.Id.ToString("N"),
                        Limit    = query.Limit,
                        IsAiring = true
                    }, CancellationToken.None).ConfigureAwait(false);

                return(GetResult(result));
            }

            case CollectionType.LiveTvRecordingGroups:
            {
                var result = await _liveTvManager.GetInternalRecordings(new RecordingQuery
                    {
                        UserId     = query.User.Id.ToString("N"),
                        Status     = RecordingStatus.Completed,
                        Limit      = query.Limit,
                        StartIndex = query.StartIndex
                    }, CancellationToken.None).ConfigureAwait(false);

                return(GetResult(result));
            }

            case CollectionType.LiveTv:
            {
                var result = await GetLiveTvFolders(user).ConfigureAwait(false);

                return(GetResult(result, query));
            }

            case CollectionType.Folders:
                return(GetResult(user.RootFolder.GetChildren(user, true), query));

            case CollectionType.Games:
                return(await GetGameView(user, parent, query).ConfigureAwait(false));

            case CollectionType.BoxSets:
                return(GetResult(GetMediaFolders(user).SelectMany(i => i.GetRecursiveChildren(user)).OfType <BoxSet>(), query));

            case CollectionType.TvShows:
                return(await GetTvView(parent, user, query).ConfigureAwait(false));

            case CollectionType.Music:
                return(await GetMusicFolders(parent, user, query).ConfigureAwait(false));

            case CollectionType.Movies:
                return(await GetMovieFolders(parent, user, query).ConfigureAwait(false));

            case CollectionType.GameGenres:
                return(GetGameGenres(parent, user, query));

            case CollectionType.GameSystems:
                return(GetGameSystems(parent, user, query));

            case CollectionType.LatestGames:
                return(GetLatestGames(parent, user, query));

            case CollectionType.RecentlyPlayedGames:
                return(GetRecentlyPlayedGames(parent, user, query));

            case CollectionType.GameFavorites:
                return(GetFavoriteGames(parent, user, query));

            case CollectionType.TvShowSeries:
                return(GetTvSeries(parent, user, query));

            case CollectionType.TvGenres:
                return(GetTvGenres(parent, user, query));

            case CollectionType.TvResume:
                return(GetTvResume(parent, user, query));

            case CollectionType.TvNextUp:
                return(GetTvNextUp(parent, query));

            case CollectionType.TvLatest:
                return(GetTvLatest(parent, user, query));

            case CollectionType.MovieFavorites:
                return(GetFavoriteMovies(parent, user, query));

            case CollectionType.MovieLatest:
                return(GetMovieLatest(parent, user, query));

            case CollectionType.MovieGenres:
                return(GetMovieGenres(parent, user, query));

            case CollectionType.MovieResume:
                return(GetMovieResume(parent, user, query));

            case CollectionType.MovieMovies:
                return(GetMovieMovies(parent, user, query));

            case CollectionType.MovieCollections:
                return(GetMovieCollections(parent, user, query));

            case CollectionType.MusicLatest:
                return(GetMusicLatest(parent, user, query));

            case CollectionType.MusicAlbums:
                return(GetMusicAlbums(parent, user, query));

            case CollectionType.MusicAlbumArtists:
                return(GetMusicAlbumArtists(parent, user, query));

            case CollectionType.MusicArtists:
                return(GetMusicArtists(parent, user, query));

            case CollectionType.MusicSongs:
                return(GetMusicSongs(parent, user, query));

            case CollectionType.TvFavoriteEpisodes:
                return(GetFavoriteEpisodes(parent, user, query));

            case CollectionType.TvFavoriteSeries:
                return(GetFavoriteSeries(parent, user, query));

            case CollectionType.MusicFavorites:
                return(await GetMusicFavorites(parent, user, query).ConfigureAwait(false));

            case CollectionType.MusicFavoriteAlbums:
                return(GetFavoriteAlbums(parent, user, query));

            case CollectionType.MusicFavoriteArtists:
                return(GetFavoriteArtists(parent, user, query));

            case CollectionType.MusicFavoriteSongs:
                return(GetFavoriteSongs(parent, user, query));

            default:
                return(GetResult(GetMediaFolders(user).SelectMany(i => i.GetChildren(user, true)), query));
            }
        }
Ejemplo n.º 28
0
        private async Task <QueryResult <BaseItem> > GetTvView(Folder parent, User user, UserItemsQuery query)
        {
            if (query.Recursive)
            {
                return(GetResult(GetRecursiveChildren(parent, user, new[] { CollectionType.TvShows, string.Empty }).Where(i => i is Series || i is Season || i is Episode), query));
            }

            var list = new List <BaseItem>();

            var category = "tvshows";

            list.Add(await GetUserView(category, CollectionType.TvResume, user, "0", parent).ConfigureAwait(false));
            list.Add(await GetUserView(category, CollectionType.TvNextUp, user, "1", parent).ConfigureAwait(false));
            list.Add(await GetUserView(category, CollectionType.TvLatest, user, "2", parent).ConfigureAwait(false));
            list.Add(await GetUserView(category, CollectionType.TvShowSeries, user, "3", parent).ConfigureAwait(false));
            list.Add(await GetUserView(category, CollectionType.TvFavoriteSeries, user, "4", parent).ConfigureAwait(false));
            list.Add(await GetUserView(category, CollectionType.TvFavoriteEpisodes, user, "5", parent).ConfigureAwait(false));
            //list.Add(await GetUserView(CollectionType.TvGenres, user, "5", parent).ConfigureAwait(false));

            return(GetResult(list, query));
        }
Ejemplo n.º 29
0
        public virtual Task<QueryResult<BaseItem>> GetUserItems(UserItemsQuery query)
        {
            var user = query.User;

            var items = query.Recursive
                ? GetRecursiveChildren(user)
                : GetChildren(user, true);

            var result = SortAndFilter(items, query);

            return Task.FromResult(result);
        }
Ejemplo n.º 30
0
        private async Task <QueryResult <BaseItem> > GetGameView(User user, Folder parent, UserItemsQuery query)
        {
            if (query.Recursive)
            {
                return(GetResult(GetRecursiveChildren(parent, user, new[] { CollectionType.Games }), query));
            }

            var list = new List <BaseItem>();

            var category = "games";

            list.Add(await GetUserView(category, CollectionType.LatestGames, user, "0", parent).ConfigureAwait(false));
            list.Add(await GetUserView(category, CollectionType.RecentlyPlayedGames, user, "1", parent).ConfigureAwait(false));
            list.Add(await GetUserView(category, CollectionType.GameFavorites, user, "2", parent).ConfigureAwait(false));
            list.Add(await GetUserView(category, CollectionType.GameSystems, user, "3", parent).ConfigureAwait(false));
            //list.Add(await GetUserView(CollectionType.GameGenres, user, "4", parent).ConfigureAwait(false));

            return(GetResult(list, query));
        }
Ejemplo n.º 31
0
 protected QueryResult <BaseItem> SortAndFilter(IEnumerable <BaseItem> items, UserItemsQuery query)
 {
     return(UserViewBuilder.SortAndFilter(items, null, query, LibraryManager, UserDataManager));
 }
Ejemplo n.º 32
0
        private QueryResult <BaseItem> GetRecentlyPlayedGames(Folder parent, User user, UserItemsQuery query)
        {
            query.IsPlayed  = true;
            query.SortBy    = new[] { ItemSortBy.DatePlayed, ItemSortBy.SortName };
            query.SortOrder = SortOrder.Descending;

            return(GetResult(GetRecursiveChildren(parent, user, new[] { CollectionType.Games }).OfType <Game>(), GetSpecialItemsLimit(), query));
        }
Ejemplo n.º 33
0
 public override Task <QueryResult <BaseItem> > GetUserItems(UserItemsQuery query)
 {
     return(new UserViewBuilder(UserViewManager, LiveTvManager, ChannelManager, LibraryManager, Logger, UserDataManager, TVSeriesManager)
            .GetUserItems(this, ViewType, query));
 }
Ejemplo n.º 34
0
        private async Task <QueryResult <BaseItem> > GetMusicFolders(Folder parent, User user, UserItemsQuery query)
        {
            if (query.Recursive)
            {
                return(GetResult(GetRecursiveChildren(parent, user, new[] { CollectionType.Music }), query));
            }

            var list = new List <BaseItem>();

            var category = "music";

            list.Add(await GetUserView(category, CollectionType.MusicLatest, user, "0", parent).ConfigureAwait(false));
            list.Add(await GetUserView(category, CollectionType.MusicAlbums, user, "1", parent).ConfigureAwait(false));
            list.Add(await GetUserView(category, CollectionType.MusicAlbumArtists, user, "2", parent).ConfigureAwait(false));
            list.Add(await GetUserView(category, CollectionType.MusicSongs, user, "3", parent).ConfigureAwait(false));
            //list.Add(await GetUserView(CollectionType.MusicArtists, user, "3", parent).ConfigureAwait(false));
            //list.Add(await GetUserView(CollectionType.MusicGenres, user, "5", parent).ConfigureAwait(false));
            list.Add(await GetUserView(category, CollectionType.MusicFavorites, user, "6", parent).ConfigureAwait(false));

            return(GetResult(list, query));
        }