|
|
@ -397,7 +397,7 @@ namespace MediaBrowser.Api.Library
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (item is Series || (program != null && program.IsSeries) )
|
|
|
|
if (item is Series || (program != null && program.IsSeries))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return new TvShowsService(_userManager, _userDataManager, _libraryManager, _itemRepo, _dtoService, _tvManager)
|
|
|
|
return new TvShowsService(_userManager, _userDataManager, _libraryManager, _itemRepo, _dtoService, _tvManager)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -659,87 +659,38 @@ namespace MediaBrowser.Api.Library
|
|
|
|
/// <returns>System.Object.</returns>
|
|
|
|
/// <returns>System.Object.</returns>
|
|
|
|
public object Get(GetItemCounts request)
|
|
|
|
public object Get(GetItemCounts request)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var filteredItems = GetAllLibraryItems(request.UserId, _userManager, _libraryManager, null, i => i.LocationType != LocationType.Virtual && FilterItem(i, request, request.UserId));
|
|
|
|
var user = string.IsNullOrWhiteSpace(request.UserId) ? null : _userManager.GetUserById(request.UserId);
|
|
|
|
|
|
|
|
|
|
|
|
var counts = new ItemCounts
|
|
|
|
var counts = new ItemCounts
|
|
|
|
{
|
|
|
|
{
|
|
|
|
AlbumCount = filteredItems.Count(i => i is MusicAlbum),
|
|
|
|
AlbumCount = GetCount(typeof(MusicAlbum), user, request),
|
|
|
|
EpisodeCount = filteredItems.Count(i => i is Episode),
|
|
|
|
EpisodeCount = GetCount(typeof(Episode), user, request),
|
|
|
|
GameCount = filteredItems.Count(i => i is Game),
|
|
|
|
GameCount = GetCount(typeof(Game), user, request),
|
|
|
|
GameSystemCount = filteredItems.Count(i => i is GameSystem),
|
|
|
|
GameSystemCount = GetCount(typeof(GameSystem), user, request),
|
|
|
|
MovieCount = filteredItems.Count(i => i is Movie),
|
|
|
|
MovieCount = GetCount(typeof(Movie), user, request),
|
|
|
|
SeriesCount = filteredItems.Count(i => i is Series),
|
|
|
|
SeriesCount = GetCount(typeof(Series), user, request),
|
|
|
|
SongCount = filteredItems.Count(i => i is Audio),
|
|
|
|
SongCount = GetCount(typeof(Audio), user, request),
|
|
|
|
MusicVideoCount = filteredItems.Count(i => i is MusicVideo),
|
|
|
|
MusicVideoCount = GetCount(typeof(MusicVideo), user, request),
|
|
|
|
BoxSetCount = filteredItems.Count(i => i is BoxSet),
|
|
|
|
BoxSetCount = GetCount(typeof(BoxSet), user, request),
|
|
|
|
BookCount = filteredItems.Count(i => i is Book),
|
|
|
|
BookCount = GetCount(typeof(Book), user, request)
|
|
|
|
|
|
|
|
|
|
|
|
UniqueTypes = filteredItems.Select(i => i.GetClientTypeName()).Distinct().ToList()
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return ToOptimizedSerializedResultUsingCache(counts);
|
|
|
|
return ToOptimizedSerializedResultUsingCache(counts);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private IList<BaseItem> GetAllLibraryItems(string userId, IUserManager userManager, ILibraryManager libraryManager, string parentId, Func<BaseItem, bool> filter)
|
|
|
|
private int GetCount(Type type, User user, GetItemCounts request)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!string.IsNullOrEmpty(parentId))
|
|
|
|
var query = new InternalItemsQuery(user)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var folder = (Folder)libraryManager.GetItemById(new Guid(parentId));
|
|
|
|
IncludeItemTypes = new[] { type.Name },
|
|
|
|
|
|
|
|
Limit = 0,
|
|
|
|
if (!string.IsNullOrWhiteSpace(userId))
|
|
|
|
Recursive = true,
|
|
|
|
{
|
|
|
|
ExcludeLocationTypes = new[] { LocationType.Virtual },
|
|
|
|
var user = userManager.GetUserById(userId);
|
|
|
|
SourceTypes = new[] { SourceType.Library },
|
|
|
|
|
|
|
|
IsFavorite = request.IsFavorite
|
|
|
|
if (user == null)
|
|
|
|
};
|
|
|
|
{
|
|
|
|
|
|
|
|
throw new ArgumentException("User not found");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return folder
|
|
|
|
|
|
|
|
.GetRecursiveChildren(user, filter)
|
|
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return folder
|
|
|
|
|
|
|
|
.GetRecursiveChildren(filter);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(userId))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var user = userManager.GetUserById(userId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (user == null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw new ArgumentException("User not found");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return userManager
|
|
|
|
|
|
|
|
.GetUserById(userId)
|
|
|
|
|
|
|
|
.RootFolder
|
|
|
|
|
|
|
|
.GetRecursiveChildren(user, filter)
|
|
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return libraryManager
|
|
|
|
|
|
|
|
.RootFolder
|
|
|
|
|
|
|
|
.GetRecursiveChildren(filter);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
return _libraryManager.GetItemsResult(query).TotalRecordCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
@ -980,20 +931,15 @@ namespace MediaBrowser.Api.Library
|
|
|
|
? new string[] { }
|
|
|
|
? new string[] { }
|
|
|
|
: request.IncludeItemTypes.Split(',');
|
|
|
|
: request.IncludeItemTypes.Split(',');
|
|
|
|
|
|
|
|
|
|
|
|
Func<BaseItem, bool> filter = i =>
|
|
|
|
var user = !string.IsNullOrWhiteSpace(request.UserId) ? _userManager.GetUserById(request.UserId) : null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var query = new InternalItemsQuery(user)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (includeTypes.Length > 0)
|
|
|
|
IncludeItemTypes = includeTypes,
|
|
|
|
{
|
|
|
|
Recursive = true
|
|
|
|
if (!includeTypes.Contains(i.GetType().Name, StringComparer.OrdinalIgnoreCase))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
IEnumerable<BaseItem> items = GetAllLibraryItems(request.UserId, _userManager, _libraryManager, null, filter);
|
|
|
|
var items = _libraryManager.GetItemList(query);
|
|
|
|
|
|
|
|
|
|
|
|
var lookup = items
|
|
|
|
var lookup = items
|
|
|
|
.ToLookup(i => i.ProductionYear ?? -1)
|
|
|
|
.ToLookup(i => i.ProductionYear ?? -1)
|
|
|
|