From 74ec6e5a06679e5360b9e8daf00fea40de4c699a Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 20 Dec 2016 02:31:30 -0500 Subject: [PATCH] update dlna music genres --- Emby.Dlna/ContentDirectory/ControlHandler.cs | 63 +++++++++++++++---- .../Entities/UserViewBuilder.cs | 15 ----- MediaBrowser.Model/Entities/CollectionType.cs | 8 --- 3 files changed, 50 insertions(+), 36 deletions(-) diff --git a/Emby.Dlna/ContentDirectory/ControlHandler.cs b/Emby.Dlna/ContentDirectory/ControlHandler.cs index bba8c53d9..55d662e64 100644 --- a/Emby.Dlna/ContentDirectory/ControlHandler.cs +++ b/Emby.Dlna/ContentDirectory/ControlHandler.cs @@ -23,6 +23,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using System.Xml; +using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.MediaEncoding; using MediaBrowser.Model.Globalization; using MediaBrowser.Model.Xml; @@ -492,29 +493,53 @@ namespace Emby.Dlna.ContentDirectory return ApplyPaging(new QueryResult(), startIndex, limit); } - var folder = (Folder)item; - - var sortOrders = new List(); - if (!folder.IsPreSorted) + if (item is MusicGenre) { - sortOrders.Add(ItemSortBy.SortName); + return GetMusicGenreItems(item, null, user, sort, startIndex, limit); } - var queryResult = await folder.GetItems(new InternalItemsQuery + var folder = (Folder)item; + + var query = new InternalItemsQuery { Limit = limit, StartIndex = startIndex, - SortBy = sortOrders.ToArray(), - SortOrder = sort.SortOrder, User = user, IsMissing = false, - PresetViews = new[] { CollectionType.Movies, CollectionType.TvShows, CollectionType.Music }, - ExcludeItemTypes = new[] { typeof(Game).Name, typeof(Book).Name }, + PresetViews = new[] {CollectionType.Movies, CollectionType.TvShows, CollectionType.Music}, + ExcludeItemTypes = new[] {typeof (Game).Name, typeof (Book).Name}, IsPlaceHolder = false + }; - }).ConfigureAwait(false); + SetSorting(query, sort, folder.IsPreSorted); - var serverItems = queryResult + var queryResult = await folder.GetItems(query).ConfigureAwait(false); + + return ToResult(queryResult); + } + + private QueryResult GetMusicGenreItems(BaseItem item, Guid? parentId, User user, SortCriteria sort, int? startIndex, int? limit) + { + var query = new InternalItemsQuery(user) + { + Recursive = true, + ParentId = parentId, + GenreIds = new[] {item.Id.ToString("N")}, + IncludeItemTypes = new[] {typeof (MusicAlbum).Name}, + Limit = limit, + StartIndex = startIndex + }; + + SetSorting(query, sort, false); + + var result = _libraryManager.GetItemsResult(query); + + return ToResult(result); + } + + private QueryResult ToResult(QueryResult result) + { + var serverItems = result .Items .Select(i => new ServerItem { @@ -524,11 +549,23 @@ namespace Emby.Dlna.ContentDirectory return new QueryResult { - TotalRecordCount = queryResult.TotalRecordCount, + TotalRecordCount = result.TotalRecordCount, Items = serverItems }; } + private void SetSorting(InternalItemsQuery query, SortCriteria sort, bool isPreSorted) + { + var sortOrders = new List(); + if (!isPreSorted) + { + sortOrders.Add(ItemSortBy.SortName); + } + + query.SortBy = sortOrders.ToArray(); + query.SortOrder = sort.SortOrder; + } + private QueryResult GetItemsFromPerson(Person person, User user, int? startIndex, int? limit) { var itemsResult = _libraryManager.GetItemsResult(new InternalItemsQuery(user) diff --git a/MediaBrowser.Controller/Entities/UserViewBuilder.cs b/MediaBrowser.Controller/Entities/UserViewBuilder.cs index d5781d21e..abaf43fd5 100644 --- a/MediaBrowser.Controller/Entities/UserViewBuilder.cs +++ b/MediaBrowser.Controller/Entities/UserViewBuilder.cs @@ -203,9 +203,6 @@ namespace MediaBrowser.Controller.Entities case SpecialFolder.MusicGenres: return GetMusicGenres(queryParent, user, query); - case SpecialFolder.MusicGenre: - return await GetMusicGenreItems(queryParent, displayParent, user, query).ConfigureAwait(false); - case SpecialFolder.MusicLatest: return GetMusicLatest(queryParent, user, query); @@ -306,18 +303,6 @@ namespace MediaBrowser.Controller.Entities }; } - private async Task> GetMusicGenreItems(Folder queryParent, Folder displayParent, User user, InternalItemsQuery query) - { - query.Recursive = true; - query.ParentId = queryParent.Id; - query.Genres = new[] { displayParent.Name }; - query.SetUser(user); - - query.IncludeItemTypes = new[] { typeof(MusicAlbum).Name }; - - return _libraryManager.GetItemsResult(query); - } - private QueryResult GetMusicAlbumArtists(Folder parent, User user, InternalItemsQuery query) { var artists = _libraryManager.GetAlbumArtists(new InternalItemsQuery(user) diff --git a/MediaBrowser.Model/Entities/CollectionType.cs b/MediaBrowser.Model/Entities/CollectionType.cs index 187334c71..b1cbb9ac3 100644 --- a/MediaBrowser.Model/Entities/CollectionType.cs +++ b/MediaBrowser.Model/Entities/CollectionType.cs @@ -48,18 +48,10 @@ public const string MovieGenres = "MovieGenres"; public const string MovieGenre = "MovieGenre"; - public const string LatestGames = "LatestGames"; - public const string RecentlyPlayedGames = "RecentlyPlayedGames"; - public const string GameSystems = "GameSystems"; - public const string GameGenres = "GameGenres"; - public const string GameFavorites = "GameFavorites"; - public const string GameGenre = "GameGenre"; - public const string MusicArtists = "MusicArtists"; public const string MusicAlbumArtists = "MusicAlbumArtists"; public const string MusicAlbums = "MusicAlbums"; public const string MusicGenres = "MusicGenres"; - public const string MusicGenre = "MusicGenre"; public const string MusicLatest = "MusicLatest"; public const string MusicPlaylists = "MusicPlaylists"; public const string MusicSongs = "MusicSongs";