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;
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerable<Audio> GetInstantMixFromSong(Audio item, User user)
|
|
|
|
|
{
|
2014-07-04 12:17:22 -07:00
|
|
|
|
var list = new List<Audio>
|
|
|
|
|
{
|
|
|
|
|
item
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return list.Concat(GetInstantMixFromGenres(item.Genres, user));
|
2014-03-30 09:49:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-19 16:57:27 -07:00
|
|
|
|
public IEnumerable<Audio> GetInstantMixFromArtist(MusicArtist artist, User user)
|
2014-03-30 09:49:40 -07:00
|
|
|
|
{
|
2014-08-18 18:42:53 -07:00
|
|
|
|
var genres = user.RootFolder
|
2016-05-17 22:34:10 -07:00
|
|
|
|
.GetRecursiveChildren(user, new InternalItemsQuery(user)
|
|
|
|
|
{
|
|
|
|
|
IncludeItemTypes = new[] { typeof(Audio).Name }
|
|
|
|
|
})
|
2015-01-24 23:34:50 -07:00
|
|
|
|
.Cast<Audio>()
|
2015-04-25 20:25:07 -07:00
|
|
|
|
.Where(i => i.HasAnyArtist(artist.Name))
|
2014-03-30 09:49:40 -07:00
|
|
|
|
.SelectMany(i => i.Genres)
|
|
|
|
|
.Concat(artist.Genres)
|
|
|
|
|
.Distinct(StringComparer.OrdinalIgnoreCase);
|
|
|
|
|
|
|
|
|
|
return GetInstantMixFromGenres(genres, user);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerable<Audio> GetInstantMixFromAlbum(MusicAlbum item, User user)
|
|
|
|
|
{
|
|
|
|
|
var genres = item
|
2016-05-17 22:34:10 -07:00
|
|
|
|
.GetRecursiveChildren(user, new InternalItemsQuery(user)
|
|
|
|
|
{
|
|
|
|
|
IncludeItemTypes = new[] { typeof(Audio).Name }
|
|
|
|
|
})
|
2015-01-24 23:34:50 -07:00
|
|
|
|
.Cast<Audio>()
|
2014-12-12 20:56:30 -07:00
|
|
|
|
.SelectMany(i => i.Genres)
|
|
|
|
|
.Concat(item.Genres)
|
2015-04-25 20:25:07 -07:00
|
|
|
|
.DistinctNames();
|
2014-12-12 20:56:30 -07:00
|
|
|
|
|
|
|
|
|
return GetInstantMixFromGenres(genres, user);
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-27 21:19:08 -07:00
|
|
|
|
public IEnumerable<Audio> GetInstantMixFromFolder(Folder item, User user)
|
|
|
|
|
{
|
|
|
|
|
var genres = item
|
2016-05-17 22:34:10 -07:00
|
|
|
|
.GetRecursiveChildren(user, new InternalItemsQuery(user)
|
|
|
|
|
{
|
|
|
|
|
IncludeItemTypes = new[] {typeof(Audio).Name}
|
|
|
|
|
})
|
2015-08-27 21:19:08 -07:00
|
|
|
|
.Cast<Audio>()
|
|
|
|
|
.SelectMany(i => i.Genres)
|
|
|
|
|
.Concat(item.Genres)
|
|
|
|
|
.DistinctNames();
|
|
|
|
|
|
|
|
|
|
return GetInstantMixFromGenres(genres, user);
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-12 20:56:30 -07:00
|
|
|
|
public IEnumerable<Audio> GetInstantMixFromPlaylist(Playlist item, User user)
|
|
|
|
|
{
|
|
|
|
|
var genres = item
|
2016-05-17 22:34:10 -07:00
|
|
|
|
.GetRecursiveChildren(user, new InternalItemsQuery(user)
|
|
|
|
|
{
|
|
|
|
|
IncludeItemTypes = new[] { typeof(Audio).Name }
|
|
|
|
|
})
|
2015-01-24 23:34:50 -07:00
|
|
|
|
.Cast<Audio>()
|
2014-03-30 09:49:40 -07:00
|
|
|
|
.SelectMany(i => i.Genres)
|
|
|
|
|
.Concat(item.Genres)
|
2015-04-25 20:25:07 -07:00
|
|
|
|
.DistinctNames();
|
2014-03-30 09:49:40 -07:00
|
|
|
|
|
|
|
|
|
return GetInstantMixFromGenres(genres, user);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerable<Audio> GetInstantMixFromGenres(IEnumerable<string> genres, User user)
|
|
|
|
|
{
|
2015-10-19 08:33:49 -07:00
|
|
|
|
var genreList = genres.ToList();
|
2014-03-30 09:49:40 -07:00
|
|
|
|
|
2016-03-19 23:46:51 -07:00
|
|
|
|
var inputItems = _libraryManager.GetItemList(new InternalItemsQuery(user)
|
2015-10-19 08:33:49 -07:00
|
|
|
|
{
|
|
|
|
|
IncludeItemTypes = new[] { typeof(Audio).Name },
|
|
|
|
|
|
2015-10-29 06:28:05 -07:00
|
|
|
|
Genres = genreList.ToArray()
|
2015-10-19 08:33:49 -07:00
|
|
|
|
|
2016-06-30 12:01:48 -07:00
|
|
|
|
});
|
2015-10-19 08:33:49 -07:00
|
|
|
|
|
|
|
|
|
var genresDictionary = genreList.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);
|
2014-03-30 09:49:40 -07:00
|
|
|
|
|
|
|
|
|
return inputItems
|
2015-01-24 23:34:50 -07:00
|
|
|
|
.Cast<Audio>()
|
2014-03-30 09:49:40 -07:00
|
|
|
|
.Select(i => new Tuple<Audio, int>(i, i.Genres.Count(genresDictionary.ContainsKey)))
|
2014-07-04 12:17:22 -07:00
|
|
|
|
.Where(i => i.Item2 > 0)
|
2014-03-30 09:49:40 -07:00
|
|
|
|
.OrderByDescending(i => i.Item2)
|
|
|
|
|
.ThenBy(i => Guid.NewGuid())
|
|
|
|
|
.Select(i => i.Item1)
|
|
|
|
|
.Take(100)
|
|
|
|
|
.OrderBy(i => Guid.NewGuid());
|
|
|
|
|
}
|
2015-01-26 09:47:15 -07:00
|
|
|
|
|
|
|
|
|
public IEnumerable<Audio> GetInstantMixFromItem(BaseItem item, User user)
|
|
|
|
|
{
|
|
|
|
|
var genre = item as MusicGenre;
|
|
|
|
|
if (genre != null)
|
|
|
|
|
{
|
|
|
|
|
return GetInstantMixFromGenres(new[] { item.Name }, user);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var playlist = item as Playlist;
|
|
|
|
|
if (playlist != null)
|
|
|
|
|
{
|
|
|
|
|
return GetInstantMixFromPlaylist(playlist, user);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var album = item as MusicAlbum;
|
|
|
|
|
if (album != null)
|
|
|
|
|
{
|
|
|
|
|
return GetInstantMixFromAlbum(album, user);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var artist = item as MusicArtist;
|
|
|
|
|
if (artist != null)
|
|
|
|
|
{
|
2015-08-19 16:57:27 -07:00
|
|
|
|
return GetInstantMixFromArtist(artist, user);
|
2015-01-26 09:47:15 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var song = item as Audio;
|
|
|
|
|
if (song != null)
|
|
|
|
|
{
|
|
|
|
|
return GetInstantMixFromSong(song, user);
|
|
|
|
|
}
|
2015-08-27 21:19:08 -07:00
|
|
|
|
|
|
|
|
|
var folder = item as Folder;
|
|
|
|
|
if (folder != null)
|
|
|
|
|
{
|
|
|
|
|
return GetInstantMixFromFolder(folder, user);
|
|
|
|
|
}
|
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
|
|
|
|
}
|
|
|
|
|
}
|