@ -26,6 +26,7 @@ using System.Xml;
using MediaBrowser.Controller.Dto ;
using MediaBrowser.Controller.Entities.Audio ;
using MediaBrowser.Controller.MediaEncoding ;
using MediaBrowser.Controller.Playlists ;
using MediaBrowser.Model.Globalization ;
using MediaBrowser.Model.Xml ;
@ -482,6 +483,12 @@ namespace Emby.Dlna.ContentDirectory
return GetMusicArtistItems ( item , null , user , sort , startIndex , limit ) ;
}
var collectionFolder = item as ICollectionFolder ;
if ( collectionFolder ! = null & & string . Equals ( CollectionType . Music , collectionFolder . CollectionType , StringComparison . OrdinalIgnoreCase ) )
{
return GetMusicFolders ( item , user , stubType , sort , startIndex , limit ) ;
}
if ( stubType . HasValue )
{
if ( stubType . Value = = StubType . People )
@ -518,7 +525,7 @@ namespace Emby.Dlna.ContentDirectory
StartIndex = startIndex ,
User = user ,
IsMissing = false ,
PresetViews = new [ ] { CollectionType . Movies , CollectionType . TvShows , CollectionType . Music } ,
PresetViews = new [ ] { CollectionType . Movies , CollectionType . TvShows } ,
ExcludeItemTypes = new [ ] { typeof ( Game ) . Name , typeof ( Book ) . Name } ,
IsPlaceHolder = false ,
DtoOptions = GetDtoOptions ( )
@ -531,6 +538,278 @@ namespace Emby.Dlna.ContentDirectory
return ToResult ( queryResult ) ;
}
private QueryResult < ServerItem > GetMusicFolders ( BaseItem item , User user , StubType ? stubType , SortCriteria sort , int? startIndex , int? limit )
{
var query = new InternalItemsQuery ( user )
{
StartIndex = startIndex ,
Limit = limit
} ;
SetSorting ( query , sort , false ) ;
if ( stubType . HasValue & & stubType . Value = = StubType . Latest )
{
return GetMusicLatest ( item , user , query ) ;
}
if ( stubType . HasValue & & stubType . Value = = StubType . Playlists )
{
return GetMusicPlaylists ( item , user , query ) ;
}
if ( stubType . HasValue & & stubType . Value = = StubType . Albums )
{
return GetMusicAlbums ( item , user , query ) ;
}
if ( stubType . HasValue & & stubType . Value = = StubType . Artists )
{
return GetMusicArtists ( item , user , query ) ;
}
if ( stubType . HasValue & & stubType . Value = = StubType . AlbumArtists )
{
return GetMusicAlbumArtists ( item , user , query ) ;
}
if ( stubType . HasValue & & stubType . Value = = StubType . FavoriteAlbums )
{
return GetFavoriteAlbums ( item , user , query ) ;
}
if ( stubType . HasValue & & stubType . Value = = StubType . FavoriteArtists )
{
return GetFavoriteArtists ( item , user , query ) ;
}
if ( stubType . HasValue & & stubType . Value = = StubType . FavoriteSongs )
{
return GetFavoriteSongs ( item , user , query ) ;
}
if ( stubType . HasValue & & stubType . Value = = StubType . Songs )
{
return GetMusicSongs ( item , user , query ) ;
}
if ( stubType . HasValue & & stubType . Value = = StubType . Genres )
{
return GetMusicGenres ( item , user , query ) ;
}
var list = new List < ServerItem > ( ) ;
list . Add ( new ServerItem ( item )
{
StubType = StubType . Latest
} ) ;
list . Add ( new ServerItem ( item )
{
StubType = StubType . Playlists
} ) ;
list . Add ( new ServerItem ( item )
{
StubType = StubType . Albums
} ) ;
list . Add ( new ServerItem ( item )
{
StubType = StubType . AlbumArtists
} ) ;
list . Add ( new ServerItem ( item )
{
StubType = StubType . Artists
} ) ;
list . Add ( new ServerItem ( item )
{
StubType = StubType . Songs
} ) ;
list . Add ( new ServerItem ( item )
{
StubType = StubType . Genres
} ) ;
list . Add ( new ServerItem ( item )
{
StubType = StubType . FavoriteArtists
} ) ;
list . Add ( new ServerItem ( item )
{
StubType = StubType . FavoriteAlbums
} ) ;
list . Add ( new ServerItem ( item )
{
StubType = StubType . FavoriteSongs
} ) ;
return new QueryResult < ServerItem >
{
Items = list . ToArray ( ) ,
TotalRecordCount = list . Count
} ;
}
private QueryResult < ServerItem > GetMusicAlbums ( BaseItem parent , User user , InternalItemsQuery query )
{
query . Recursive = true ;
query . Parent = parent ;
query . SetUser ( user ) ;
query . IncludeItemTypes = new [ ] { typeof ( MusicAlbum ) . Name } ;
var result = _libraryManager . GetItemsResult ( query ) ;
return ToResult ( result ) ;
}
private QueryResult < ServerItem > GetMusicSongs ( BaseItem parent , User user , InternalItemsQuery query )
{
query . Recursive = true ;
query . Parent = parent ;
query . SetUser ( user ) ;
query . IncludeItemTypes = new [ ] { typeof ( Audio ) . Name } ;
var result = _libraryManager . GetItemsResult ( query ) ;
return ToResult ( result ) ;
}
private QueryResult < ServerItem > GetFavoriteSongs ( BaseItem parent , User user , InternalItemsQuery query )
{
query . Recursive = true ;
query . Parent = parent ;
query . SetUser ( user ) ;
query . IsFavorite = true ;
query . IncludeItemTypes = new [ ] { typeof ( Audio ) . Name } ;
var result = _libraryManager . GetItemsResult ( query ) ;
return ToResult ( result ) ;
}
private QueryResult < ServerItem > GetFavoriteAlbums ( BaseItem parent , User user , InternalItemsQuery query )
{
query . Recursive = true ;
query . Parent = parent ;
query . SetUser ( user ) ;
query . IsFavorite = true ;
query . IncludeItemTypes = new [ ] { typeof ( MusicAlbum ) . Name } ;
var result = _libraryManager . GetItemsResult ( query ) ;
return ToResult ( result ) ;
}
private QueryResult < ServerItem > GetMusicGenres ( BaseItem parent , User user , InternalItemsQuery query )
{
var genresResult = _libraryManager . GetMusicGenres ( new InternalItemsQuery ( user )
{
AncestorIds = new [ ] { parent . Id . ToString ( "N" ) } ,
StartIndex = query . StartIndex ,
Limit = query . Limit
} ) ;
var result = new QueryResult < BaseItem >
{
TotalRecordCount = genresResult . TotalRecordCount ,
Items = genresResult . Items . Select ( i = > i . Item1 ) . ToArray ( )
} ;
return ToResult ( result ) ;
}
private QueryResult < ServerItem > GetMusicAlbumArtists ( BaseItem parent , User user , InternalItemsQuery query )
{
var artists = _libraryManager . GetAlbumArtists ( new InternalItemsQuery ( user )
{
AncestorIds = new [ ] { parent . Id . ToString ( "N" ) } ,
StartIndex = query . StartIndex ,
Limit = query . Limit
} ) ;
var result = new QueryResult < BaseItem >
{
TotalRecordCount = artists . TotalRecordCount ,
Items = artists . Items . Select ( i = > i . Item1 ) . ToArray ( )
} ;
return ToResult ( result ) ;
}
private QueryResult < ServerItem > GetMusicArtists ( BaseItem parent , User user , InternalItemsQuery query )
{
var artists = _libraryManager . GetArtists ( new InternalItemsQuery ( user )
{
AncestorIds = new [ ] { parent . Id . ToString ( "N" ) } ,
StartIndex = query . StartIndex ,
Limit = query . Limit
} ) ;
var result = new QueryResult < BaseItem >
{
TotalRecordCount = artists . TotalRecordCount ,
Items = artists . Items . Select ( i = > i . Item1 ) . ToArray ( )
} ;
return ToResult ( result ) ;
}
private QueryResult < ServerItem > GetFavoriteArtists ( BaseItem parent , User user , InternalItemsQuery query )
{
var artists = _libraryManager . GetArtists ( new InternalItemsQuery ( user )
{
AncestorIds = new [ ] { parent . Id . ToString ( "N" ) } ,
StartIndex = query . StartIndex ,
Limit = query . Limit ,
IsFavorite = true
} ) ;
var result = new QueryResult < BaseItem >
{
TotalRecordCount = artists . TotalRecordCount ,
Items = artists . Items . Select ( i = > i . Item1 ) . ToArray ( )
} ;
return ToResult ( result ) ;
}
private QueryResult < ServerItem > GetMusicPlaylists ( BaseItem parent , User user , InternalItemsQuery query )
{
query . Parent = null ;
query . IncludeItemTypes = new [ ] { typeof ( Playlist ) . Name } ;
query . SetUser ( user ) ;
query . Recursive = true ;
var result = _libraryManager . GetItemsResult ( query ) ;
return ToResult ( result ) ;
}
private QueryResult < ServerItem > GetMusicLatest ( BaseItem parent , User user , InternalItemsQuery query )
{
query . SortBy = new string [ ] { } ;
var items = _userViewManager . GetLatestItems ( new LatestItemsQuery
{
UserId = user . Id . ToString ( "N" ) ,
Limit = 50 ,
IncludeItemTypes = new [ ] { typeof ( Audio ) . Name } ,
ParentId = parent = = null ? null : parent . Id . ToString ( "N" ) ,
GroupItems = true
} , query . DtoOptions ) . Select ( i = > i . Item1 ? ? i . Item2 . FirstOrDefault ( ) ) . Where ( i = > i ! = null ) . ToList ( ) ;
return ToResult ( items ) ;
}
private QueryResult < ServerItem > GetMusicArtistItems ( BaseItem item , Guid ? parentId , User user , SortCriteria sort , int? startIndex , int? limit )
{
var query = new InternalItemsQuery ( user )
@ -571,6 +850,19 @@ namespace Emby.Dlna.ContentDirectory
return ToResult ( result ) ;
}
private QueryResult < ServerItem > ToResult ( List < BaseItem > result )
{
var serverItems = result
. Select ( i = > new ServerItem ( i ) )
. ToArray ( ) ;
return new QueryResult < ServerItem >
{
TotalRecordCount = result . Count ,
Items = serverItems
} ;
}
private QueryResult < ServerItem > ToResult ( QueryResult < BaseItem > result )
{
var serverItems = result
@ -660,6 +952,56 @@ namespace Emby.Dlna.ContentDirectory
stubType = StubType . People ;
id = id . Split ( new [ ] { '_' } , 2 ) [ 1 ] ;
}
else if ( id . StartsWith ( "latest_" , StringComparison . OrdinalIgnoreCase ) )
{
stubType = StubType . Latest ;
id = id . Split ( new [ ] { '_' } , 2 ) [ 1 ] ;
}
else if ( id . StartsWith ( "playlists_" , StringComparison . OrdinalIgnoreCase ) )
{
stubType = StubType . Playlists ;
id = id . Split ( new [ ] { '_' } , 2 ) [ 1 ] ;
}
else if ( id . StartsWith ( "Albums_" , StringComparison . OrdinalIgnoreCase ) )
{
stubType = StubType . Albums ;
id = id . Split ( new [ ] { '_' } , 2 ) [ 1 ] ;
}
else if ( id . StartsWith ( "AlbumArtists_" , StringComparison . OrdinalIgnoreCase ) )
{
stubType = StubType . AlbumArtists ;
id = id . Split ( new [ ] { '_' } , 2 ) [ 1 ] ;
}
else if ( id . StartsWith ( "Artists_" , StringComparison . OrdinalIgnoreCase ) )
{
stubType = StubType . Artists ;
id = id . Split ( new [ ] { '_' } , 2 ) [ 1 ] ;
}
else if ( id . StartsWith ( "Genres_" , StringComparison . OrdinalIgnoreCase ) )
{
stubType = StubType . Genres ;
id = id . Split ( new [ ] { '_' } , 2 ) [ 1 ] ;
}
else if ( id . StartsWith ( "Songs_" , StringComparison . OrdinalIgnoreCase ) )
{
stubType = StubType . Songs ;
id = id . Split ( new [ ] { '_' } , 2 ) [ 1 ] ;
}
else if ( id . StartsWith ( "FavoriteAlbums_" , StringComparison . OrdinalIgnoreCase ) )
{
stubType = StubType . FavoriteAlbums ;
id = id . Split ( new [ ] { '_' } , 2 ) [ 1 ] ;
}
else if ( id . StartsWith ( "FavoriteArtists_" , StringComparison . OrdinalIgnoreCase ) )
{
stubType = StubType . FavoriteArtists ;
id = id . Split ( new [ ] { '_' } , 2 ) [ 1 ] ;
}
else if ( id . StartsWith ( "FavoriteSongs_" , StringComparison . OrdinalIgnoreCase ) )
{
stubType = StubType . FavoriteSongs ;
id = id . Split ( new [ ] { '_' } , 2 ) [ 1 ] ;
}
if ( Guid . TryParse ( id , out itemId ) )
{
@ -696,6 +1038,16 @@ namespace Emby.Dlna.ContentDirectory
public enum StubType
{
Folder = 0 ,
People = 1
People = 1 ,
Latest = 2 ,
Playlists = 3 ,
Albums = 4 ,
AlbumArtists = 5 ,
Artists = 6 ,
Songs = 7 ,
Genres = 8 ,
FavoriteSongs = 9 ,
FavoriteArtists = 10 ,
FavoriteAlbums = 11
}
}