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