update user view builder
This commit is contained in:
parent
35449735be
commit
e70782a478
|
@ -125,7 +125,6 @@ namespace MediaBrowser.Controller.Entities
|
|||
case CollectionType.HomeVideos:
|
||||
case CollectionType.Games:
|
||||
case CollectionType.MusicVideos:
|
||||
case CollectionType.Music:
|
||||
{
|
||||
if (query.Recursive)
|
||||
{
|
||||
|
@ -194,6 +193,45 @@ namespace MediaBrowser.Controller.Entities
|
|||
case SpecialFolder.TvFavoriteSeries:
|
||||
return GetFavoriteSeries(queryParent, user, query);
|
||||
|
||||
case CollectionType.Music:
|
||||
return await GetMusicFolders(queryParent, user, query).ConfigureAwait(false);
|
||||
|
||||
case SpecialFolder.MusicGenres:
|
||||
return await GetMusicGenres(queryParent, user, query).ConfigureAwait(false);
|
||||
|
||||
case SpecialFolder.MusicGenre:
|
||||
return await GetMusicGenreItems(queryParent, displayParent, user, query).ConfigureAwait(false);
|
||||
|
||||
case SpecialFolder.MusicLatest:
|
||||
return GetMusicLatest(queryParent, user, query);
|
||||
|
||||
case SpecialFolder.MusicPlaylists:
|
||||
return await GetMusicPlaylists(queryParent, user, query).ConfigureAwait(false);
|
||||
|
||||
case SpecialFolder.MusicAlbums:
|
||||
return GetMusicAlbums(queryParent, user, query);
|
||||
|
||||
case SpecialFolder.MusicAlbumArtists:
|
||||
return GetMusicAlbumArtists(queryParent, user, query);
|
||||
|
||||
case SpecialFolder.MusicArtists:
|
||||
return GetMusicArtists(queryParent, user, query);
|
||||
|
||||
case SpecialFolder.MusicSongs:
|
||||
return GetMusicSongs(queryParent, user, query);
|
||||
|
||||
case SpecialFolder.MusicFavorites:
|
||||
return await GetMusicFavorites(queryParent, user, query).ConfigureAwait(false);
|
||||
|
||||
case SpecialFolder.MusicFavoriteAlbums:
|
||||
return GetFavoriteAlbums(queryParent, user, query);
|
||||
|
||||
case SpecialFolder.MusicFavoriteArtists:
|
||||
return GetFavoriteArtists(queryParent, user, query);
|
||||
|
||||
case SpecialFolder.MusicFavoriteSongs:
|
||||
return GetFavoriteSongs(queryParent, user, query);
|
||||
|
||||
default:
|
||||
{
|
||||
if (queryParent is UserView)
|
||||
|
@ -208,6 +246,172 @@ namespace MediaBrowser.Controller.Entities
|
|||
}
|
||||
}
|
||||
|
||||
private async Task<QueryResult<BaseItem>> GetMusicFolders(Folder parent, User user, InternalItemsQuery query)
|
||||
{
|
||||
if (query.Recursive)
|
||||
{
|
||||
var items = GetRecursiveChildren(parent, user, new[] { CollectionType.Music, CollectionType.MusicVideos }, i => FilterItem(i, query));
|
||||
|
||||
return PostFilterAndSort(items, parent, null, query);
|
||||
}
|
||||
|
||||
var list = new List<BaseItem>();
|
||||
|
||||
list.Add(await GetUserView(SpecialFolder.MusicLatest, "0", parent).ConfigureAwait(false));
|
||||
list.Add(await GetUserView(SpecialFolder.MusicPlaylists, "1", parent).ConfigureAwait(false));
|
||||
list.Add(await GetUserView(SpecialFolder.MusicAlbums, "2", parent).ConfigureAwait(false));
|
||||
list.Add(await GetUserView(SpecialFolder.MusicAlbumArtists, "3", parent).ConfigureAwait(false));
|
||||
//list.Add(await GetUserView(SpecialFolder.MusicArtists, user, "4", parent).ConfigureAwait(false));
|
||||
list.Add(await GetUserView(SpecialFolder.MusicSongs, "5", parent).ConfigureAwait(false));
|
||||
list.Add(await GetUserView(SpecialFolder.MusicGenres, "6", parent).ConfigureAwait(false));
|
||||
list.Add(await GetUserView(SpecialFolder.MusicFavorites, "7", parent).ConfigureAwait(false));
|
||||
|
||||
return GetResult(list, parent, query);
|
||||
}
|
||||
|
||||
private async Task<QueryResult<BaseItem>> GetMusicFavorites(Folder parent, User user, InternalItemsQuery query)
|
||||
{
|
||||
var list = new List<BaseItem>();
|
||||
|
||||
list.Add(await GetUserView(SpecialFolder.MusicFavoriteAlbums, "0", parent).ConfigureAwait(false));
|
||||
list.Add(await GetUserView(SpecialFolder.MusicFavoriteArtists, "1", parent).ConfigureAwait(false));
|
||||
list.Add(await GetUserView(SpecialFolder.MusicFavoriteSongs, "2", parent).ConfigureAwait(false));
|
||||
|
||||
return GetResult(list, parent, query);
|
||||
}
|
||||
|
||||
private async Task<QueryResult<BaseItem>> GetMusicGenres(Folder parent, User user, InternalItemsQuery query)
|
||||
{
|
||||
var tasks = GetRecursiveChildren(parent, user, new[] { CollectionType.Music, CollectionType.MusicVideos })
|
||||
.Where(i => !i.IsFolder)
|
||||
.SelectMany(i => i.Genres)
|
||||
.DistinctNames()
|
||||
.Select(i =>
|
||||
{
|
||||
try
|
||||
{
|
||||
return _libraryManager.GetMusicGenre(i);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Full exception logged at lower levels
|
||||
_logger.Error("Error getting genre");
|
||||
return null;
|
||||
}
|
||||
|
||||
})
|
||||
.Where(i => i != null)
|
||||
.Select(i => GetUserView(i.Name, SpecialFolder.MusicGenre, i.SortName, parent));
|
||||
|
||||
var genres = await Task.WhenAll(tasks).ConfigureAwait(false);
|
||||
|
||||
return GetResult(genres, parent, query);
|
||||
}
|
||||
|
||||
private async Task<QueryResult<BaseItem>> GetMusicGenreItems(Folder queryParent, Folder displayParent, User user, InternalItemsQuery query)
|
||||
{
|
||||
var items = GetRecursiveChildren(queryParent, user, new[] { CollectionType.Music, CollectionType.MusicVideos })
|
||||
.Where(i => !i.IsFolder)
|
||||
.Where(i => i.Genres.Contains(displayParent.Name, StringComparer.OrdinalIgnoreCase))
|
||||
.OfType<IHasAlbumArtist>();
|
||||
|
||||
var artists = _libraryManager.GetAlbumArtists(items);
|
||||
|
||||
return GetResult(artists, queryParent, query);
|
||||
}
|
||||
|
||||
private QueryResult<BaseItem> GetMusicAlbumArtists(Folder parent, User user, InternalItemsQuery query)
|
||||
{
|
||||
var items = GetRecursiveChildren(parent, user, new[] { CollectionType.Music, CollectionType.MusicVideos })
|
||||
.Where(i => !i.IsFolder)
|
||||
.OfType<IHasAlbumArtist>();
|
||||
|
||||
var artists = _libraryManager.GetAlbumArtists(items);
|
||||
|
||||
return GetResult(artists, parent, query);
|
||||
}
|
||||
|
||||
private QueryResult<BaseItem> GetMusicArtists(Folder parent, User user, InternalItemsQuery query)
|
||||
{
|
||||
var items = GetRecursiveChildren(parent, user, new[] { CollectionType.Music, CollectionType.MusicVideos })
|
||||
.Where(i => !i.IsFolder)
|
||||
.OfType<IHasArtist>();
|
||||
|
||||
var artists = _libraryManager.GetArtists(items);
|
||||
|
||||
return GetResult(artists, parent, query);
|
||||
}
|
||||
|
||||
private QueryResult<BaseItem> GetFavoriteArtists(Folder parent, User user, InternalItemsQuery query)
|
||||
{
|
||||
var items = GetRecursiveChildren(parent, user, new[] { CollectionType.Music, CollectionType.MusicVideos })
|
||||
.Where(i => !i.IsFolder)
|
||||
.OfType<IHasAlbumArtist>();
|
||||
|
||||
var artists = _libraryManager.GetAlbumArtists(items).Where(i => _userDataManager.GetUserData(user.Id, i.GetUserDataKey()).IsFavorite);
|
||||
|
||||
return GetResult(artists, parent, query);
|
||||
}
|
||||
|
||||
private Task<QueryResult<BaseItem>> GetMusicPlaylists(Folder parent, User user, InternalItemsQuery query)
|
||||
{
|
||||
query.IncludeItemTypes = new[] { "Playlist" };
|
||||
query.Recursive = true;
|
||||
|
||||
return parent.GetItems(query);
|
||||
}
|
||||
|
||||
private QueryResult<BaseItem> GetMusicAlbums(Folder parent, User user, InternalItemsQuery query)
|
||||
{
|
||||
var items = GetRecursiveChildren(parent, user, new[] { CollectionType.Music, CollectionType.MusicVideos }, i => (i is MusicAlbum) && FilterItem(i, query));
|
||||
|
||||
return PostFilterAndSort(items, parent, null, query);
|
||||
}
|
||||
|
||||
private QueryResult<BaseItem> GetMusicSongs(Folder parent, User user, InternalItemsQuery query)
|
||||
{
|
||||
var items = GetRecursiveChildren(parent, user, new[] { CollectionType.Music, CollectionType.MusicVideos }, i => (i is Audio.Audio) && FilterItem(i, query));
|
||||
|
||||
return PostFilterAndSort(items, parent, null, query);
|
||||
}
|
||||
|
||||
private QueryResult<BaseItem> GetMusicLatest(Folder parent, User user, InternalItemsQuery query)
|
||||
{
|
||||
var items = _userViewManager.GetLatestItems(new LatestItemsQuery
|
||||
{
|
||||
UserId = user.Id.ToString("N"),
|
||||
Limit = GetSpecialItemsLimit(),
|
||||
IncludeItemTypes = new[] { typeof(Audio.Audio).Name },
|
||||
ParentId = (parent == null ? null : parent.Id.ToString("N")),
|
||||
GroupItems = true
|
||||
|
||||
}).Select(i => i.Item1 ?? i.Item2.FirstOrDefault()).Where(i => i != null);
|
||||
|
||||
query.SortBy = new string[] { };
|
||||
|
||||
//var items = GetRecursiveChildren(parent, user, new[] { CollectionType.Music, CollectionType.MusicVideos }, i => i is MusicVideo || i is Audio.Audio && FilterItem(i, query));
|
||||
|
||||
return PostFilterAndSort(items, parent, null, query);
|
||||
}
|
||||
|
||||
private QueryResult<BaseItem> GetFavoriteSongs(Folder parent, User user, InternalItemsQuery query)
|
||||
{
|
||||
query.IsFavorite = true;
|
||||
|
||||
var items = GetRecursiveChildren(parent, user, new[] { CollectionType.Music }, i => (i is Audio.Audio) && FilterItem(i, query));
|
||||
|
||||
return PostFilterAndSort(items, parent, null, query);
|
||||
}
|
||||
|
||||
private QueryResult<BaseItem> GetFavoriteAlbums(Folder parent, User user, InternalItemsQuery query)
|
||||
{
|
||||
query.IsFavorite = true;
|
||||
|
||||
var items = GetRecursiveChildren(parent, user, new[] { CollectionType.Music }, i => (i is MusicAlbum) && FilterItem(i, query));
|
||||
|
||||
return PostFilterAndSort(items, parent, null, query);
|
||||
}
|
||||
|
||||
private async Task<QueryResult<BaseItem>> FindPlaylists(Folder parent, User user, InternalItemsQuery query)
|
||||
{
|
||||
var list = _playlistManager.GetPlaylists(user.Id.ToString("N"));
|
||||
|
|
Loading…
Reference in New Issue
Block a user