Exemplo n.º 1
0
        /// <summary>
        /// Gets the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>System.Object.</returns>
        public object Get(GetItemCounts request)
        {
            var items = GetAllLibraryItems(request.UserId, _userManager, _libraryManager)
                        .Where(i => i.LocationType != LocationType.Virtual)
                        .ToList();

            var filteredItems = request.UserId.HasValue ? FilterItems(items, request, request.UserId.Value).ToList() : items;

            var albums      = filteredItems.OfType <MusicAlbum>().ToList();
            var episodes    = filteredItems.OfType <Episode>().ToList();
            var games       = filteredItems.OfType <Game>().ToList();
            var movies      = filteredItems.OfType <Movie>().ToList();
            var musicVideos = filteredItems.OfType <MusicVideo>().ToList();
            var adultVideos = filteredItems.OfType <AdultVideo>().ToList();
            var boxsets     = filteredItems.OfType <BoxSet>().ToList();
            var books       = filteredItems.OfType <Book>().ToList();
            var songs       = filteredItems.OfType <Audio>().ToList();
            var series      = filteredItems.OfType <Series>().ToList();

            var channelCount = 0;

            try
            {
                channelCount = _channelManager.GetChannels(new ChannelQuery
                {
                    UserId = request.UserId.HasValue ? request.UserId.Value.ToString("N") : null
                }, CancellationToken.None).Result.TotalRecordCount;
            }
            catch (Exception ex)
            {
                Logger.ErrorException("Error getting channels", ex);
            }

            var counts = new ItemCounts
            {
                AlbumCount      = albums.Count,
                EpisodeCount    = episodes.Count,
                GameCount       = games.Count,
                GameSystemCount = filteredItems.OfType <GameSystem>().Count(),
                MovieCount      = movies.Count,
                SeriesCount     = series.Count,
                SongCount       = songs.Count,
                TrailerCount    = filteredItems.OfType <Trailer>().Count(),
                MusicVideoCount = musicVideos.Count,
                AdultVideoCount = adultVideos.Count,
                BoxSetCount     = boxsets.Count,
                BookCount       = books.Count,

                UniqueTypes = items.Select(i => i.GetClientTypeName()).Distinct().ToList(),

                ChannelCount = channelCount
            };

            return(ToOptimizedSerializedResultUsingCache(counts));
        }
Exemplo n.º 2
0
        public object Get(GetChannels request)
        {
            var result = _channelManager.GetChannels(new ChannelQuery
            {
                Limit      = request.Limit,
                StartIndex = request.StartIndex,
                UserId     = request.UserId,
            }, CancellationToken.None).Result;

            return(ToOptimizedResult(result));
        }
Exemplo n.º 3
0
        public async Task <object> Get(GetChannels request)
        {
            var result = await _channelManager.GetChannels(new ChannelQuery
            {
                Limit               = request.Limit,
                StartIndex          = request.StartIndex,
                UserId              = request.UserId,
                SupportsLatestItems = request.SupportsLatestItems,
                IsFavorite          = request.IsFavorite
            }, CancellationToken.None).ConfigureAwait(false);

            return(ToOptimizedResult(result));
        }
Exemplo n.º 4
0
        public object Get(GetChannels request)
        {
            var result = _channelManager.GetChannels(new ChannelQuery
            {
                Limit                 = request.Limit,
                StartIndex            = request.StartIndex,
                UserId                = request.UserId,
                SupportsLatestItems   = request.SupportsLatestItems,
                SupportsMediaDeletion = request.SupportsMediaDeletion,
                IsFavorite            = request.IsFavorite
            });

            return(ToOptimizedResult(result));
        }
Exemplo n.º 5
0
 public ActionResult <QueryResult <BaseItemDto> > GetChannels(
     [FromQuery] Guid?userId,
     [FromQuery] int?startIndex,
     [FromQuery] int?limit,
     [FromQuery] bool?supportsLatestItems,
     [FromQuery] bool?supportsMediaDeletion,
     [FromQuery] bool?isFavorite)
 {
     return(_channelManager.GetChannels(new ChannelQuery
     {
         Limit = limit,
         StartIndex = startIndex,
         UserId = userId ?? Guid.Empty,
         SupportsLatestItems = supportsLatestItems,
         SupportsMediaDeletion = supportsMediaDeletion,
         IsFavorite = isFavorite
     }));
 }
Exemplo n.º 6
0
        public async Task <IEnumerable <Folder> > GetUserViews(UserViewQuery query, CancellationToken cancellationToken)
        {
            var user = _userManager.GetUserById(query.UserId);

            var folders = user.RootFolder
                          .GetChildren(user, true)
                          .OfType <Folder>()
                          .ToList();

            var list = new List <Folder>();

            var excludeFolderIds = user.Configuration.ExcludeFoldersFromGrouping.Select(i => new Guid(i)).ToList();

            var standaloneFolders = folders.Where(i => UserView.IsExcludedFromGrouping(i) || excludeFolderIds.Contains(i.Id)).ToList();

            var foldersWithViewTypes = folders
                                       .Except(standaloneFolders)
                                       .OfType <ICollectionFolder>()
                                       .ToList();

            list.AddRange(standaloneFolders);

            if (foldersWithViewTypes.Any(i => string.Equals(i.CollectionType, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase)) ||
                foldersWithViewTypes.Any(i => string.IsNullOrWhiteSpace(i.CollectionType)))
            {
                list.Add(await GetUserView(CollectionType.TvShows, string.Empty, cancellationToken).ConfigureAwait(false));
            }

            if (foldersWithViewTypes.Any(i => string.Equals(i.CollectionType, CollectionType.Music, StringComparison.OrdinalIgnoreCase)) ||
                foldersWithViewTypes.Any(i => string.Equals(i.CollectionType, CollectionType.MusicVideos, StringComparison.OrdinalIgnoreCase)))
            {
                list.Add(await GetUserView(CollectionType.Music, string.Empty, cancellationToken).ConfigureAwait(false));
            }

            if (foldersWithViewTypes.Any(i => string.Equals(i.CollectionType, CollectionType.Movies, StringComparison.OrdinalIgnoreCase)) ||
                foldersWithViewTypes.Any(i => string.IsNullOrWhiteSpace(i.CollectionType)))
            {
                list.Add(await GetUserView(CollectionType.Movies, string.Empty, cancellationToken).ConfigureAwait(false));
            }

            if (foldersWithViewTypes.Any(i => string.Equals(i.CollectionType, CollectionType.Games, StringComparison.OrdinalIgnoreCase)))
            {
                list.Add(await GetUserView(CollectionType.Games, string.Empty, cancellationToken).ConfigureAwait(false));
            }

            if (user.Configuration.DisplayCollectionsView &&
                folders
                .Except(standaloneFolders)
                .SelectMany(i => i.GetRecursiveChildren(user, false)).OfType <BoxSet>().Any())
            {
                list.Add(await GetUserView(CollectionType.BoxSets, string.Empty, cancellationToken).ConfigureAwait(false));
            }

            if (foldersWithViewTypes.Any(i => string.Equals(i.CollectionType, CollectionType.Playlists, StringComparison.OrdinalIgnoreCase)))
            {
                list.Add(_playlists.GetPlaylistsFolder(user.Id.ToString("N")));
            }

            if (user.Configuration.DisplayFoldersView)
            {
                list.Add(await GetUserView(CollectionType.Folders, "zz_" + CollectionType.Folders, cancellationToken).ConfigureAwait(false));
            }

            if (query.IncludeExternalContent)
            {
                var channelResult = await _channelManager.GetChannels(new ChannelQuery
                {
                    UserId = query.UserId
                }, cancellationToken).ConfigureAwait(false);

                var channels = channelResult.Items;

                var embeddedChannels = channels
                                       .Where(i => user.Configuration.DisplayChannelsWithinViews.Contains(i.Id))
                                       .ToList();

                list.AddRange(embeddedChannels.Select(i => _channelManager.GetChannel(i.Id)));

                if (channels.Length > embeddedChannels.Count)
                {
                    list.Add(await _channelManager.GetInternalChannelFolder(query.UserId, cancellationToken).ConfigureAwait(false));
                }

                if (_liveTvManager.GetEnabledUsers().Select(i => i.Id.ToString("N")).Contains(query.UserId))
                {
                    list.Add(await _liveTvManager.GetInternalLiveTvFolder(query.UserId, cancellationToken).ConfigureAwait(false));
                }
            }

            var sorted = _libraryManager.Sort(list, user, new[] { ItemSortBy.SortName }, SortOrder.Ascending).ToList();

            var orders = user.Configuration.OrderedViews.ToList();

            return(list
                   .OrderBy(i =>
            {
                var index = orders.IndexOf(i.Id.ToString("N"));

                return index == -1 ? int.MaxValue : index;
            })
                   .ThenBy(sorted.IndexOf)
                   .ThenBy(i => i.SortName));
        }
Exemplo n.º 7
0
        public async Task <IEnumerable <Folder> > GetUserViews(UserViewQuery query, CancellationToken cancellationToken)
        {
            var user = _userManager.GetUserById(new Guid(query.UserId));

            var folders = user.RootFolder
                          .GetChildren(user, true)
                          .OfType <Folder>()
                          .ToList();

            var list = new List <Folder>();

            var excludeFolderIds = user.Configuration.ExcludeFoldersFromGrouping.Select(i => new Guid(i)).ToList();

            var standaloneFolders = folders.Where(i => UserView.IsExcludedFromGrouping(i) || excludeFolderIds.Contains(i.Id)).ToList();

            list.AddRange(standaloneFolders);

            var recursiveChildren = folders
                                    .Except(standaloneFolders)
                                    .SelectMany(i => i.GetRecursiveChildren(user, false))
                                    .ToList();

            if (recursiveChildren.OfType <Series>().Any())
            {
                list.Add(await GetUserView(CollectionType.TvShows, user, cancellationToken).ConfigureAwait(false));
            }

            if (recursiveChildren.OfType <MusicAlbum>().Any() ||
                recursiveChildren.OfType <MusicVideo>().Any())
            {
                list.Add(await GetUserView(CollectionType.Music, user, cancellationToken).ConfigureAwait(false));
            }

            if (recursiveChildren.OfType <Movie>().Any())
            {
                list.Add(await GetUserView(CollectionType.Movies, user, cancellationToken).ConfigureAwait(false));
            }

            if (recursiveChildren.OfType <Game>().Any())
            {
                list.Add(await GetUserView(CollectionType.Games, user, cancellationToken).ConfigureAwait(false));
            }

            if (recursiveChildren.OfType <BoxSet>().Any())
            {
                list.Add(await GetUserView(CollectionType.BoxSets, user, cancellationToken).ConfigureAwait(false));
            }

            if (query.IncludeExternalContent)
            {
                var channelResult = await _channelManager.GetChannels(new ChannelQuery
                {
                    Limit  = 0,
                    UserId = query.UserId
                }, cancellationToken).ConfigureAwait(false);

                if (channelResult.TotalRecordCount > 0)
                {
                    list.Add(await _channelManager.GetInternalChannelFolder(query.UserId, cancellationToken).ConfigureAwait(false));
                }

                if (_liveTvManager.GetEnabledUsers().Select(i => i.Id.ToString("N")).Contains(query.UserId))
                {
                    list.Add(await _liveTvManager.GetInternalLiveTvFolder(query.UserId, cancellationToken).ConfigureAwait(false));
                }
            }

            return(list.OrderBy(i => i.SortName));
        }
Exemplo n.º 8
0
        public async Task <IEnumerable <Folder> > GetUserViews(UserViewQuery query, CancellationToken cancellationToken)
        {
            var user = _userManager.GetUserById(new Guid(query.UserId));

            var folders = user.RootFolder
                          .GetChildren(user, true)
                          .OfType <Folder>()
                          .ToList();

            var list = new List <Folder>();

            var excludeFolderIds = user.Configuration.ExcludeFoldersFromGrouping.Select(i => new Guid(i)).ToList();

            var standaloneFolders = folders.Where(i => UserView.IsExcludedFromGrouping(i) || excludeFolderIds.Contains(i.Id)).ToList();

            list.AddRange(standaloneFolders);

            var recursiveChildren = folders
                                    .Except(standaloneFolders)
                                    .SelectMany(i => i.GetRecursiveChildren(user, false))
                                    .ToList();

            if (recursiveChildren.OfType <Series>().Any())
            {
                list.Add(await GetUserView(CollectionType.TvShows, user, string.Empty, cancellationToken).ConfigureAwait(false));
            }

            if (recursiveChildren.OfType <MusicAlbum>().Any() ||
                recursiveChildren.OfType <MusicVideo>().Any())
            {
                list.Add(await GetUserView(CollectionType.Music, user, string.Empty, cancellationToken).ConfigureAwait(false));
            }

            if (recursiveChildren.OfType <Movie>().Any())
            {
                list.Add(await GetUserView(CollectionType.Movies, user, string.Empty, cancellationToken).ConfigureAwait(false));
            }

            if (recursiveChildren.OfType <Game>().Any())
            {
                list.Add(await GetUserView(CollectionType.Games, user, string.Empty, cancellationToken).ConfigureAwait(false));
            }

            if (user.Configuration.DisplayCollectionsView &&
                recursiveChildren.OfType <BoxSet>().Any())
            {
                list.Add(await GetUserView(CollectionType.BoxSets, user, string.Empty, cancellationToken).ConfigureAwait(false));
            }

            if (recursiveChildren.OfType <Playlist>().Any())
            {
                list.Add(_playlists.GetPlaylistsFolder(user.Id.ToString("N")));
            }

            if (user.Configuration.DisplayFoldersView)
            {
                list.Add(await GetUserView(CollectionType.Folders, user, "zz_" + CollectionType.Folders, cancellationToken).ConfigureAwait(false));
            }

            if (query.IncludeExternalContent)
            {
                var channelResult = await _channelManager.GetChannels(new ChannelQuery
                {
                    UserId = query.UserId
                }, cancellationToken).ConfigureAwait(false);

                var channels = channelResult.Items;

                var embeddedChannels = channels
                                       .Where(i => user.Configuration.DisplayChannelsWithinViews.Contains(i.Id))
                                       .ToList();

                list.AddRange(embeddedChannels.Select(i => _channelManager.GetChannel(i.Id)));

                if (channels.Length > embeddedChannels.Count)
                {
                    list.Add(await _channelManager.GetInternalChannelFolder(query.UserId, cancellationToken).ConfigureAwait(false));
                }

                if (_liveTvManager.GetEnabledUsers().Select(i => i.Id.ToString("N")).Contains(query.UserId))
                {
                    list.Add(await _liveTvManager.GetInternalLiveTvFolder(query.UserId, cancellationToken).ConfigureAwait(false));
                }
            }

            return(_libraryManager.Sort(list, user, new[] { ItemSortBy.SortName }, SortOrder.Ascending).Cast <Folder>());
        }