2014-03-30 09:49:40 -07:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
|
using MediaBrowser.Controller.Entities.Audio;
|
|
|
|
|
using MediaBrowser.Controller.Library;
|
2014-12-12 20:56:30 -07:00
|
|
|
|
using MediaBrowser.Controller.Playlists;
|
2014-03-30 09:49:40 -07:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2017-05-21 00:25:49 -07:00
|
|
|
|
using MediaBrowser.Controller.Dto;
|
2017-04-27 11:12:44 -07:00
|
|
|
|
using MediaBrowser.Model.Querying;
|
2014-03-30 09:49:40 -07:00
|
|
|
|
|
2016-11-02 23:37:52 -07:00
|
|
|
|
namespace Emby.Server.Implementations.Library
|
2014-03-30 09:49:40 -07:00
|
|
|
|
{
|
|
|
|
|
public class MusicManager : IMusicManager
|
|
|
|
|
{
|
|
|
|
|
private readonly ILibraryManager _libraryManager;
|
|
|
|
|
|
|
|
|
|
public MusicManager(ILibraryManager libraryManager)
|
|
|
|
|
{
|
|
|
|
|
_libraryManager = libraryManager;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-21 00:25:49 -07:00
|
|
|
|
public IEnumerable<Audio> GetInstantMixFromSong(Audio item, User user, DtoOptions dtoOptions)
|
2014-03-30 09:49:40 -07:00
|
|
|
|
{
|
2014-07-04 12:17:22 -07:00
|
|
|
|
var list = new List<Audio>
|
|
|
|
|
{
|
|
|
|
|
item
|
|
|
|
|
};
|
|
|
|
|
|
2017-05-21 00:25:49 -07:00
|
|
|
|
return list.Concat(GetInstantMixFromGenres(item.Genres, user, dtoOptions));
|
2014-03-30 09:49:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-21 00:25:49 -07:00
|
|
|
|
public IEnumerable<Audio> GetInstantMixFromArtist(MusicArtist item, User user, DtoOptions dtoOptions)
|
2014-03-30 09:49:40 -07:00
|
|
|
|
{
|
2017-05-21 00:25:49 -07:00
|
|
|
|
return GetInstantMixFromGenres(item.Genres, user, dtoOptions);
|
2014-03-30 09:49:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-21 00:25:49 -07:00
|
|
|
|
public IEnumerable<Audio> GetInstantMixFromAlbum(MusicAlbum item, User user, DtoOptions dtoOptions)
|
2014-03-30 09:49:40 -07:00
|
|
|
|
{
|
2017-05-21 00:25:49 -07:00
|
|
|
|
return GetInstantMixFromGenres(item.Genres, user, dtoOptions);
|
2014-12-12 20:56:30 -07:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-21 00:25:49 -07:00
|
|
|
|
public IEnumerable<Audio> GetInstantMixFromFolder(Folder item, User user, DtoOptions dtoOptions)
|
2015-08-27 21:19:08 -07:00
|
|
|
|
{
|
|
|
|
|
var genres = item
|
2016-05-17 22:34:10 -07:00
|
|
|
|
.GetRecursiveChildren(user, new InternalItemsQuery(user)
|
|
|
|
|
{
|
2017-05-21 00:25:49 -07:00
|
|
|
|
IncludeItemTypes = new[] { typeof(Audio).Name },
|
|
|
|
|
DtoOptions = dtoOptions
|
2016-05-17 22:34:10 -07:00
|
|
|
|
})
|
2015-08-27 21:19:08 -07:00
|
|
|
|
.Cast<Audio>()
|
|
|
|
|
.SelectMany(i => i.Genres)
|
|
|
|
|
.Concat(item.Genres)
|
|
|
|
|
.DistinctNames();
|
|
|
|
|
|
2017-05-21 00:25:49 -07:00
|
|
|
|
return GetInstantMixFromGenres(genres, user, dtoOptions);
|
2015-08-27 21:19:08 -07:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-21 00:25:49 -07:00
|
|
|
|
public IEnumerable<Audio> GetInstantMixFromPlaylist(Playlist item, User user, DtoOptions dtoOptions)
|
2014-12-12 20:56:30 -07:00
|
|
|
|
{
|
2017-05-21 00:25:49 -07:00
|
|
|
|
return GetInstantMixFromGenres(item.Genres, user, dtoOptions);
|
2014-03-30 09:49:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-21 00:25:49 -07:00
|
|
|
|
public IEnumerable<Audio> GetInstantMixFromGenres(IEnumerable<string> genres, User user, DtoOptions dtoOptions)
|
2014-03-30 09:49:40 -07:00
|
|
|
|
{
|
2017-04-27 11:12:44 -07:00
|
|
|
|
var genreIds = genres.DistinctNames().Select(i =>
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _libraryManager.GetMusicGenre(i).Id.ToString("N");
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}).Where(i => i != null);
|
2014-03-30 09:49:40 -07:00
|
|
|
|
|
2017-05-21 00:25:49 -07:00
|
|
|
|
return GetInstantMixFromGenreIds(genreIds, user, dtoOptions);
|
2017-04-27 11:12:44 -07:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-21 00:25:49 -07:00
|
|
|
|
public IEnumerable<Audio> GetInstantMixFromGenreIds(IEnumerable<string> genreIds, User user, DtoOptions dtoOptions)
|
2017-04-27 11:12:44 -07:00
|
|
|
|
{
|
|
|
|
|
return _libraryManager.GetItemList(new InternalItemsQuery(user)
|
2015-10-19 08:33:49 -07:00
|
|
|
|
{
|
|
|
|
|
IncludeItemTypes = new[] { typeof(Audio).Name },
|
|
|
|
|
|
2017-04-27 11:12:44 -07:00
|
|
|
|
GenreIds = genreIds.ToArray(),
|
2015-10-19 08:33:49 -07:00
|
|
|
|
|
2017-04-27 11:12:44 -07:00
|
|
|
|
Limit = 200,
|
2015-10-19 08:33:49 -07:00
|
|
|
|
|
2017-05-21 00:25:49 -07:00
|
|
|
|
SortBy = new[] { ItemSortBy.Random },
|
|
|
|
|
|
|
|
|
|
DtoOptions = dtoOptions
|
2014-03-30 09:49:40 -07:00
|
|
|
|
|
2017-04-27 11:12:44 -07:00
|
|
|
|
}).Cast<Audio>();
|
2014-03-30 09:49:40 -07:00
|
|
|
|
}
|
2015-01-26 09:47:15 -07:00
|
|
|
|
|
2017-05-21 00:25:49 -07:00
|
|
|
|
public IEnumerable<Audio> GetInstantMixFromItem(BaseItem item, User user, DtoOptions dtoOptions)
|
2015-01-26 09:47:15 -07:00
|
|
|
|
{
|
|
|
|
|
var genre = item as MusicGenre;
|
|
|
|
|
if (genre != null)
|
|
|
|
|
{
|
2017-05-21 00:25:49 -07:00
|
|
|
|
return GetInstantMixFromGenreIds(new[] { item.Id.ToString("N") }, user, dtoOptions);
|
2015-01-26 09:47:15 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var playlist = item as Playlist;
|
|
|
|
|
if (playlist != null)
|
|
|
|
|
{
|
2017-05-21 00:25:49 -07:00
|
|
|
|
return GetInstantMixFromPlaylist(playlist, user, dtoOptions);
|
2015-01-26 09:47:15 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var album = item as MusicAlbum;
|
|
|
|
|
if (album != null)
|
|
|
|
|
{
|
2017-05-21 00:25:49 -07:00
|
|
|
|
return GetInstantMixFromAlbum(album, user, dtoOptions);
|
2015-01-26 09:47:15 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var artist = item as MusicArtist;
|
|
|
|
|
if (artist != null)
|
|
|
|
|
{
|
2017-05-21 00:25:49 -07:00
|
|
|
|
return GetInstantMixFromArtist(artist, user, dtoOptions);
|
2015-01-26 09:47:15 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var song = item as Audio;
|
|
|
|
|
if (song != null)
|
|
|
|
|
{
|
2017-05-21 00:25:49 -07:00
|
|
|
|
return GetInstantMixFromSong(song, user, dtoOptions);
|
2015-01-26 09:47:15 -07:00
|
|
|
|
}
|
2015-08-27 21:19:08 -07:00
|
|
|
|
|
|
|
|
|
var folder = item as Folder;
|
|
|
|
|
if (folder != null)
|
|
|
|
|
{
|
2017-05-21 00:25:49 -07:00
|
|
|
|
return GetInstantMixFromFolder(folder, user, dtoOptions);
|
2015-08-27 21:19:08 -07:00
|
|
|
|
}
|
2015-10-19 08:33:49 -07:00
|
|
|
|
|
2015-01-26 09:47:15 -07:00
|
|
|
|
return new Audio[] { };
|
|
|
|
|
}
|
2014-03-30 09:49:40 -07:00
|
|
|
|
}
|
|
|
|
|
}
|