コード例 #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));
        }
コード例 #2
0
        private IEnumerable <T> FilterItems <T>(IEnumerable <T> items, GetItemCounts request, Guid userId)
            where T : BaseItem
        {
            if (request.IsFavorite.HasValue)
            {
                var val = request.IsFavorite.Value;

                items = items.Where(i => _userDataManager.GetUserData(userId, i.GetUserDataKey()).IsFavorite == val);
            }

            return(items);
        }
コード例 #3
0
        private int GetCount(Type type, User user, GetItemCounts request)
        {
            var query = new InternalItemsQuery(user)
            {
                IncludeItemTypes     = new[] { type.Name },
                Limit                = 0,
                Recursive            = true,
                ExcludeLocationTypes = new[] { LocationType.Virtual },
                SourceTypes          = new[] { SourceType.Library },
                IsFavorite           = request.IsFavorite
            };

            return(_libraryManager.GetItemsResult(query).TotalRecordCount);
        }
コード例 #4
0
        private int GetCount(Type type, User user, GetItemCounts request)
        {
            var query = new InternalItemsQuery(user)
            {
                IncludeItemTypes = new[] { type.Name },
                Limit            = 0,
                Recursive        = true,
                IsVirtualItem    = false,
                IsFavorite       = request.IsFavorite,
                DtoOptions       = new DtoOptions(false)
                {
                    EnableImages = false
                }
            };

            return(_libraryManager.GetItemsResult(query).TotalRecordCount);
        }
コード例 #5
0
ファイル: LibraryService.cs プロジェクト: webcris77/Emby
        private bool FilterItem(BaseItem item, GetItemCounts request, string userId)
        {
            if (!string.IsNullOrWhiteSpace(userId))
            {
                if (request.IsFavorite.HasValue)
                {
                    var val = request.IsFavorite.Value;

                    if (_userDataManager.GetUserData(userId, item.GetUserDataKey()).IsFavorite != val)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
コード例 #6
0
        private bool FilterItem(BaseItem item, GetItemCounts request, Guid?userId)
        {
            if (userId.HasValue)
            {
                if (request.IsFavorite.HasValue)
                {
                    var val = request.IsFavorite.Value;

                    if (_userDataManager.GetUserData(userId.Value, item.GetUserDataKey()).IsFavorite != val)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
コード例 #7
0
        /// <summary>
        /// Gets the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>System.Object.</returns>
        public object Get(GetItemCounts request)
        {
            var user = request.UserId.Equals(Guid.Empty) ? null : _userManager.GetUserById(request.UserId);

            var counts = new ItemCounts
            {
                AlbumCount      = GetCount(typeof(MusicAlbum), user, request),
                EpisodeCount    = GetCount(typeof(Episode), user, request),
                MovieCount      = GetCount(typeof(Movie), user, request),
                SeriesCount     = GetCount(typeof(Series), user, request),
                SongCount       = GetCount(typeof(Audio), user, request),
                MusicVideoCount = GetCount(typeof(MusicVideo), user, request),
                BoxSetCount     = GetCount(typeof(BoxSet), user, request),
                BookCount       = GetCount(typeof(Book), user, request)
            };

            return(ToOptimizedResult(counts));
        }
コード例 #8
0
        /// <summary>
        /// Gets the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>System.Object.</returns>
        public object Get(GetItemCounts request)
        {
            var user = string.IsNullOrWhiteSpace(request.UserId) ? null : _userManager.GetUserById(request.UserId);

            var counts = new ItemCounts
            {
                AlbumCount      = GetCount(typeof(MusicAlbum), user, request),
                EpisodeCount    = GetCount(typeof(Episode), user, request),
                GameCount       = GetCount(typeof(Game), user, request),
                GameSystemCount = GetCount(typeof(GameSystem), user, request),
                MovieCount      = GetCount(typeof(Movie), user, request),
                SeriesCount     = GetCount(typeof(Series), user, request),
                SongCount       = GetCount(typeof(Audio), user, request),
                MusicVideoCount = GetCount(typeof(MusicVideo), user, request),
                BoxSetCount     = GetCount(typeof(BoxSet), user, request),
                BookCount       = GetCount(typeof(Book), user, request)
            };

            return(ToOptimizedSerializedResultUsingCache(counts));
        }
コード例 #9
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 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()
            };

            return(ToOptimizedSerializedResultUsingCache(counts));
        }
コード例 #10
0
ファイル: LibraryService.cs プロジェクト: webcris77/Emby
        /// <summary>
        /// Gets the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>System.Object.</returns>
        public object Get(GetItemCounts request)
        {
            var filteredItems = GetAllLibraryItems(request.UserId, _userManager, _libraryManager, null, i => i.LocationType != LocationType.Virtual && FilterItem(i, request, request.UserId));

            var counts = new ItemCounts
            {
                AlbumCount      = filteredItems.Count(i => i is MusicAlbum),
                EpisodeCount    = filteredItems.Count(i => i is Episode),
                GameCount       = filteredItems.Count(i => i is Game),
                GameSystemCount = filteredItems.Count(i => i is GameSystem),
                MovieCount      = filteredItems.Count(i => i is Movie),
                SeriesCount     = filteredItems.Count(i => i is Series),
                SongCount       = filteredItems.Count(i => i is Audio),
                MusicVideoCount = filteredItems.Count(i => i is MusicVideo),
                BoxSetCount     = filteredItems.Count(i => i is BoxSet),
                BookCount       = filteredItems.Count(i => i is Book),

                UniqueTypes = filteredItems.Select(i => i.GetClientTypeName()).Distinct().ToList()
            };

            return(ToOptimizedSerializedResultUsingCache(counts));
        }