add ArtistItems to api output

pull/702/head
Luke Pulverenti 9 years ago
parent a92723fde3
commit 96ec4cef77

@ -53,7 +53,7 @@ namespace MediaBrowser.Api
var albums = _libraryManager.RootFolder var albums = _libraryManager.RootFolder
.GetRecursiveChildren() .GetRecursiveChildren()
.OfType<MusicAlbum>() .OfType<MusicAlbum>()
.Where(i => i.HasArtist(item.Name)) .Where(i => i.HasAnyArtist(item.Name))
.ToList(); .ToList();
var musicArtists = albums var musicArtists = albums

@ -389,23 +389,33 @@ namespace MediaBrowser.Api
game.PlayersSupported = request.Players; game.PlayersSupported = request.Players;
} }
var song = item as Audio; var hasAlbumArtists = item as IHasAlbumArtist;
if (hasAlbumArtists != null)
if (song != null)
{ {
song.Album = request.Album; hasAlbumArtists.AlbumArtists = request
song.AlbumArtists = request
.AlbumArtists .AlbumArtists
.Select(i => i.Name) .Select(i => i.Name)
.ToList(); .ToList();
song.Artists = request.Artists.ToList();
} }
var musicVideo = item as MusicVideo; var hasArtists = item as IHasArtist;
if (hasArtists != null)
{
hasArtists.Artists = request
.ArtistItems
.Select(i => i.Name)
.ToList();
}
var song = item as Audio;
if (song != null)
{
song.Album = request.Album;
}
var musicVideo = item as MusicVideo;
if (musicVideo != null) if (musicVideo != null)
{ {
musicVideo.Artists = request.Artists.ToList();
musicVideo.Album = request.Album; musicVideo.Album = request.Album;
} }

@ -77,15 +77,13 @@ namespace MediaBrowser.Api.Music
var album1 = (MusicAlbum)item1; var album1 = (MusicAlbum)item1;
var album2 = (MusicAlbum)item2; var album2 = (MusicAlbum)item2;
var artists1 = album1.GetRecursiveChildren(i => i is IHasArtist) var artists1 = album1
.Cast<IHasArtist>() .AllArtists
.SelectMany(i => i.AllArtists)
.Distinct(StringComparer.OrdinalIgnoreCase) .Distinct(StringComparer.OrdinalIgnoreCase)
.ToList(); .ToList();
var artists2 = album2.GetRecursiveChildren(i => i is IHasArtist) var artists2 = album2
.Cast<IHasArtist>() .AllArtists
.SelectMany(i => i.AllArtists)
.Distinct(StringComparer.OrdinalIgnoreCase) .Distinct(StringComparer.OrdinalIgnoreCase)
.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase); .ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);

@ -211,7 +211,7 @@ namespace MediaBrowser.Api
result.SongCount = album.Tracks.Count(); result.SongCount = album.Tracks.Count();
result.Artists = album.Artists.ToArray(); result.Artists = album.Artists.ToArray();
result.AlbumArtist = album.AlbumArtists.FirstOrDefault(); result.AlbumArtist = album.AlbumArtist;
} }
var song = item as Audio; var song = item as Audio;

@ -60,6 +60,9 @@ namespace MediaBrowser.Api.UserLibrary
[ApiMember(Name = "Artists", Description = "Optional. If specified, results will be filtered based on artist. This allows multiple, pipe delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)] [ApiMember(Name = "Artists", Description = "Optional. If specified, results will be filtered based on artist. This allows multiple, pipe delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
public string Artists { get; set; } public string Artists { get; set; }
[ApiMember(Name = "ArtistIds", Description = "Optional. If specified, results will be filtered based on artist. This allows multiple, pipe delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
public string ArtistIds { get; set; }
[ApiMember(Name = "Albums", Description = "Optional. If specified, results will be filtered based on album. This allows multiple, pipe delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)] [ApiMember(Name = "Albums", Description = "Optional. If specified, results will be filtered based on album. This allows multiple, pipe delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
public string Albums { get; set; } public string Albums { get; set; }
@ -600,6 +603,8 @@ namespace MediaBrowser.Api.UserLibrary
private bool ApplyAdditionalFilters(GetItems request, BaseItem i, User user, bool isPreFiltered, ILibraryManager libraryManager) private bool ApplyAdditionalFilters(GetItems request, BaseItem i, User user, bool isPreFiltered, ILibraryManager libraryManager)
{ {
var video = i as Video;
if (!isPreFiltered) if (!isPreFiltered)
{ {
var mediaTypes = request.GetMediaTypes(); var mediaTypes = request.GetMediaTypes();
@ -647,7 +652,6 @@ namespace MediaBrowser.Api.UserLibrary
if (request.Is3D.HasValue) if (request.Is3D.HasValue)
{ {
var val = request.Is3D.Value; var val = request.Is3D.Value;
var video = i as Video;
if (video == null || val != video.Video3DFormat.HasValue) if (video == null || val != video.Video3DFormat.HasValue)
{ {
@ -658,7 +662,6 @@ namespace MediaBrowser.Api.UserLibrary
if (request.IsHD.HasValue) if (request.IsHD.HasValue)
{ {
var val = request.IsHD.Value; var val = request.IsHD.Value;
var video = i as Video;
if (video == null || val != video.IsHD) if (video == null || val != video.IsHD)
{ {
@ -800,8 +803,6 @@ namespace MediaBrowser.Api.UserLibrary
{ {
var val = request.HasSubtitles.Value; var val = request.HasSubtitles.Value;
var video = i as Video;
if (video == null || val != video.HasSubtitles) if (video == null || val != video.HasSubtitles)
{ {
return false; return false;
@ -922,15 +923,10 @@ namespace MediaBrowser.Api.UserLibrary
} }
// Filter by VideoType // Filter by VideoType
if (!string.IsNullOrEmpty(request.VideoTypes)) var videoTypes = request.GetVideoTypes();
if (video == null || !videoTypes.Contains(video.VideoType))
{ {
var types = request.VideoTypes.Split(','); return false;
var video = i as Video;
if (video == null || !types.Contains(video.VideoType.ToString(), StringComparer.OrdinalIgnoreCase))
{
return false;
}
} }
var imageTypes = request.GetImageTypes().ToList(); var imageTypes = request.GetImageTypes().ToList();
@ -1014,6 +1010,29 @@ namespace MediaBrowser.Api.UserLibrary
} }
} }
// Artists
if (!string.IsNullOrEmpty(request.ArtistIds))
{
var artistIds = request.ArtistIds.Split('|');
var audio = i as IHasArtist;
if (!(audio != null && artistIds.Any(id =>
{
try
{
return audio.HasAnyArtist(libraryManager.GetItemById(id).Name);
}
catch (Exception ex)
{
return false;
}
})))
{
return false;
}
}
// Artists // Artists
if (!string.IsNullOrEmpty(request.Artists)) if (!string.IsNullOrEmpty(request.Artists))
{ {
@ -1021,7 +1040,7 @@ namespace MediaBrowser.Api.UserLibrary
var audio = i as IHasArtist; var audio = i as IHasArtist;
if (!(audio != null && artists.Any(audio.HasArtist))) if (!(audio != null && artists.Any(audio.HasAnyArtist)))
{ {
return false; return false;
} }

@ -171,16 +171,6 @@ namespace MediaBrowser.Controller.Entities.Audio
+ (IndexNumber != null ? IndexNumber.Value.ToString("0000 - ") : "") + Name; + (IndexNumber != null ? IndexNumber.Value.ToString("0000 - ") : "") + Name;
} }
/// <summary>
/// Determines whether the specified name has artist.
/// </summary>
/// <param name="name">The name.</param>
/// <returns><c>true</c> if the specified name has artist; otherwise, <c>false</c>.</returns>
public bool HasArtist(string name)
{
return AllArtists.Contains(name, StringComparer.OrdinalIgnoreCase);
}
/// <summary> /// <summary>
/// Gets the user data key. /// Gets the user data key.
/// </summary> /// </summary>

@ -1,4 +1,6 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.Linq;
namespace MediaBrowser.Controller.Entities.Audio namespace MediaBrowser.Controller.Entities.Audio
{ {
@ -9,10 +11,20 @@ namespace MediaBrowser.Controller.Entities.Audio
public interface IHasArtist public interface IHasArtist
{ {
bool HasArtist(string name);
List<string> AllArtists { get; } List<string> AllArtists { get; }
List<string> Artists { get; } List<string> Artists { get; set; }
}
public static class HasArtistExtensions
{
public static bool HasArtist(this IHasArtist hasArtist, string artist)
{
return hasArtist.Artists.Contains(artist, StringComparer.OrdinalIgnoreCase);
}
public static bool HasAnyArtist(this IHasArtist hasArtist, string artist)
{
return hasArtist.AllArtists.Contains(artist, StringComparer.OrdinalIgnoreCase);
}
} }
} }

@ -120,16 +120,6 @@ namespace MediaBrowser.Controller.Entities.Audio
get { return Parent as MusicArtist ?? UnknwonArtist; } get { return Parent as MusicArtist ?? UnknwonArtist; }
} }
/// <summary>
/// Determines whether the specified artist has artist.
/// </summary>
/// <param name="artist">The artist.</param>
/// <returns><c>true</c> if the specified artist has artist; otherwise, <c>false</c>.</returns>
public bool HasArtist(string artist)
{
return AllArtists.Contains(artist, StringComparer.OrdinalIgnoreCase);
}
public List<string> Artists { get; set; } public List<string> Artists { get; set; }
/// <summary> /// <summary>

@ -213,7 +213,7 @@ namespace MediaBrowser.Controller.Entities.Audio
return i => return i =>
{ {
var hasArtist = i as IHasArtist; var hasArtist = i as IHasArtist;
return hasArtist != null && hasArtist.HasArtist(Name); return hasArtist != null && hasArtist.HasAnyArtist(Name);
}; };
} }
} }

@ -47,16 +47,6 @@ namespace MediaBrowser.Controller.Entities
} }
} }
/// <summary>
/// Determines whether the specified name has artist.
/// </summary>
/// <param name="name">The name.</param>
/// <returns><c>true</c> if the specified name has artist; otherwise, <c>false</c>.</returns>
public bool HasArtist(string name)
{
return AllArtists.Contains(name, StringComparer.OrdinalIgnoreCase);
}
/// <summary> /// <summary>
/// Gets the user data key. /// Gets the user data key.
/// </summary> /// </summary>

@ -106,7 +106,7 @@ namespace MediaBrowser.Controller.Playlists
Func<BaseItem, bool> filter = i => Func<BaseItem, bool> filter = i =>
{ {
var audio = i as Audio; var audio = i as Audio;
return audio != null && audio.HasArtist(musicArtist.Name); return audio != null && audio.HasAnyArtist(musicArtist.Name);
}; };
var items = user == null var items = user == null

@ -980,9 +980,6 @@
<Compile Include="..\MediaBrowser.Model\Querying\SessionQuery.cs"> <Compile Include="..\MediaBrowser.Model\Querying\SessionQuery.cs">
<Link>Querying\SessionQuery.cs</Link> <Link>Querying\SessionQuery.cs</Link>
</Compile> </Compile>
<Compile Include="..\MediaBrowser.Model\Querying\SimilarItemsByNameQuery.cs">
<Link>Querying\SimilarItemsByNameQuery.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\Querying\SimilarItemsQuery.cs"> <Compile Include="..\MediaBrowser.Model\Querying\SimilarItemsQuery.cs">
<Link>Querying\SimilarItemsQuery.cs</Link> <Link>Querying\SimilarItemsQuery.cs</Link>
</Compile> </Compile>

@ -942,9 +942,6 @@
<Compile Include="..\MediaBrowser.Model\Querying\SessionQuery.cs"> <Compile Include="..\MediaBrowser.Model\Querying\SessionQuery.cs">
<Link>Querying\SessionQuery.cs</Link> <Link>Querying\SessionQuery.cs</Link>
</Compile> </Compile>
<Compile Include="..\MediaBrowser.Model\Querying\SimilarItemsByNameQuery.cs">
<Link>Querying\SimilarItemsByNameQuery.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\Querying\SimilarItemsQuery.cs"> <Compile Include="..\MediaBrowser.Model\Querying\SimilarItemsQuery.cs">
<Link>Querying\SimilarItemsQuery.cs</Link> <Link>Querying\SimilarItemsQuery.cs</Link>
</Compile> </Compile>

@ -344,14 +344,14 @@ namespace MediaBrowser.Model.ApiClient
/// </summary> /// </summary>
/// <param name="query">The query.</param> /// <param name="query">The query.</param>
/// <returns>Task{ItemsResult}.</returns> /// <returns>Task{ItemsResult}.</returns>
Task<ItemsResult> GetInstantMixFromArtistAsync(SimilarItemsByNameQuery query); Task<ItemsResult> GetInstantMixFromArtistAsync(SimilarItemsQuery query);
/// <summary> /// <summary>
/// Gets the instant mix from music genre async. /// Gets the instant mix from music genre async.
/// </summary> /// </summary>
/// <param name="query">The query.</param> /// <param name="query">The query.</param>
/// <returns>Task{ItemsResult}.</returns> /// <returns>Task{ItemsResult}.</returns>
Task<ItemsResult> GetInstantMixFromMusicGenreAsync(SimilarItemsByNameQuery query); Task<ItemsResult> GetInstantMixFromMusicGenreAsync(SimilarItemsQuery query);
/// <summary> /// <summary>
/// Gets the similar movies async. /// Gets the similar movies async.

@ -466,6 +466,12 @@ namespace MediaBrowser.Model.Dto
/// <value>The artists.</value> /// <value>The artists.</value>
public List<string> Artists { get; set; } public List<string> Artists { get; set; }
/// <summary>
/// Gets or sets the artist items.
/// </summary>
/// <value>The artist items.</value>
public List<NameIdPair> ArtistItems { get; set; }
/// <summary> /// <summary>
/// Gets or sets the album. /// Gets or sets the album.
/// </summary> /// </summary>

@ -322,7 +322,6 @@
<Compile Include="Querying\QueryResult.cs" /> <Compile Include="Querying\QueryResult.cs" />
<Compile Include="Querying\SeasonQuery.cs" /> <Compile Include="Querying\SeasonQuery.cs" />
<Compile Include="Querying\SessionQuery.cs" /> <Compile Include="Querying\SessionQuery.cs" />
<Compile Include="Querying\SimilarItemsByNameQuery.cs" />
<Compile Include="Querying\SimilarItemsQuery.cs" /> <Compile Include="Querying\SimilarItemsQuery.cs" />
<Compile Include="Querying\UpcomingEpisodesQuery.cs" /> <Compile Include="Querying\UpcomingEpisodesQuery.cs" />
<Compile Include="Querying\UserQuery.cs" /> <Compile Include="Querying\UserQuery.cs" />

@ -39,11 +39,11 @@ namespace MediaBrowser.Model.Querying
public string[] SortBy { get; set; } public string[] SortBy { get; set; }
/// <summary> /// <summary>
/// Filter by artists /// Gets or sets the artist ids.
/// </summary> /// </summary>
/// <value>The artists.</value> /// <value>The artist ids.</value>
public string[] Artists { get; set; } public string[] ArtistIds { get; set; }
/// <summary> /// <summary>
/// The sort order to return results with /// The sort order to return results with
/// </summary> /// </summary>
@ -306,7 +306,7 @@ namespace MediaBrowser.Model.Querying
Years = new int[] { }; Years = new int[] { };
PersonTypes = new string[] { }; PersonTypes = new string[] { };
Ids = new string[] { }; Ids = new string[] { };
Artists = new string[] { }; ArtistIds = new string[] { };
ImageTypes = new ImageType[] { }; ImageTypes = new ImageType[] { };
AirDays = new DayOfWeek[] { }; AirDays = new DayOfWeek[] { };

@ -1,29 +0,0 @@
namespace MediaBrowser.Model.Querying
{
public class SimilarItemsByNameQuery
{
/// <summary>
/// The user to localize search results for
/// </summary>
/// <value>The user id.</value>
public string UserId { get; set; }
/// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>The name.</value>
public string Name { get; set; }
/// <summary>
/// The maximum number of items to return
/// </summary>
/// <value>The limit.</value>
public int? Limit { get; set; }
/// <summary>
/// Fields to return within the items, in addition to basic information
/// </summary>
/// <value>The fields.</value>
public ItemFields[] Fields { get; set; }
}
}

@ -387,7 +387,7 @@ namespace MediaBrowser.Providers.MediaInfo
if (!string.IsNullOrEmpty(val)) if (!string.IsNullOrEmpty(val))
{ {
// Sometimes the artist name is listed here, account for that // Sometimes the artist name is listed here, account for that
var studios = Split(val, true).Where(i => !audio.HasArtist(i)); var studios = Split(val, true).Where(i => !audio.HasAnyArtist(i));
foreach (var studio in studios) foreach (var studio in studios)
{ {

@ -504,7 +504,6 @@ namespace MediaBrowser.Server.Implementations.Dto
} }
dto.Album = item.Album; dto.Album = item.Album;
dto.Artists = item.Artists;
} }
private void SetGameProperties(BaseItemDto dto, Game item) private void SetGameProperties(BaseItemDto dto, Game item)
@ -1142,7 +1141,6 @@ namespace MediaBrowser.Server.Implementations.Dto
if (audio != null) if (audio != null)
{ {
dto.Album = audio.Album; dto.Album = audio.Album;
dto.Artists = audio.Artists;
var albumParent = audio.FindParent<MusicAlbum>(); var albumParent = audio.FindParent<MusicAlbum>();
@ -1163,15 +1161,40 @@ namespace MediaBrowser.Server.Implementations.Dto
if (album != null) if (album != null)
{ {
dto.Artists = album.Artists;
dto.SoundtrackIds = album.SoundtrackIds dto.SoundtrackIds = album.SoundtrackIds
.Select(i => i.ToString("N")) .Select(i => i.ToString("N"))
.ToArray(); .ToArray();
} }
var hasAlbumArtist = item as IHasAlbumArtist; var hasArtist = item as IHasArtist;
if (hasArtist != null)
{
dto.Artists = hasArtist.Artists;
dto.ArtistItems = hasArtist
.Artists
.Select(i =>
{
try
{
var artist = _libraryManager.GetArtist(i);
return new NameIdPair
{
Name = artist.Name,
Id = artist.Id.ToString("N")
};
}
catch (Exception ex)
{
_logger.ErrorException("Error getting artist", ex);
return null;
}
})
.Where(i => i != null)
.ToList();
}
var hasAlbumArtist = item as IHasAlbumArtist;
if (hasAlbumArtist != null) if (hasAlbumArtist != null)
{ {
dto.AlbumArtist = hasAlbumArtist.AlbumArtists.FirstOrDefault(); dto.AlbumArtist = hasAlbumArtist.AlbumArtists.FirstOrDefault();
@ -1253,7 +1276,6 @@ namespace MediaBrowser.Server.Implementations.Dto
// Add MovieInfo // Add MovieInfo
var movie = item as Movie; var movie = item as Movie;
if (movie != null) if (movie != null)
{ {
if (fields.Contains(ItemFields.TmdbCollectionName)) if (fields.Contains(ItemFields.TmdbCollectionName))
@ -1263,7 +1285,6 @@ namespace MediaBrowser.Server.Implementations.Dto
} }
var hasSpecialFeatures = item as IHasSpecialFeatures; var hasSpecialFeatures = item as IHasSpecialFeatures;
if (hasSpecialFeatures != null) if (hasSpecialFeatures != null)
{ {
var specialFeatureCount = hasSpecialFeatures.SpecialFeatureIds.Count; var specialFeatureCount = hasSpecialFeatures.SpecialFeatureIds.Count;
@ -1276,7 +1297,6 @@ namespace MediaBrowser.Server.Implementations.Dto
// Add EpisodeInfo // Add EpisodeInfo
var episode = item as Episode; var episode = item as Episode;
if (episode != null) if (episode != null)
{ {
dto.IndexNumberEnd = episode.IndexNumberEnd; dto.IndexNumberEnd = episode.IndexNumberEnd;
@ -1318,7 +1338,6 @@ namespace MediaBrowser.Server.Implementations.Dto
// Add SeriesInfo // Add SeriesInfo
var series = item as Series; var series = item as Series;
if (series != null) if (series != null)
{ {
dto.AirDays = series.AirDays; dto.AirDays = series.AirDays;
@ -1368,7 +1387,6 @@ namespace MediaBrowser.Server.Implementations.Dto
// Add SeasonInfo // Add SeasonInfo
var season = item as Season; var season = item as Season;
if (season != null) if (season != null)
{ {
series = season.Series; series = season.Series;
@ -1402,7 +1420,6 @@ namespace MediaBrowser.Server.Implementations.Dto
} }
var musicVideo = item as MusicVideo; var musicVideo = item as MusicVideo;
if (musicVideo != null) if (musicVideo != null)
{ {
SetMusicVideoProperties(dto, musicVideo); SetMusicVideoProperties(dto, musicVideo);

@ -34,7 +34,7 @@ namespace MediaBrowser.Server.Implementations.Library
var genres = user.RootFolder var genres = user.RootFolder
.GetRecursiveChildren(user, i => i is Audio) .GetRecursiveChildren(user, i => i is Audio)
.Cast<Audio>() .Cast<Audio>()
.Where(i => i.HasArtist(name)) .Where(i => i.HasAnyArtist(name))
.SelectMany(i => i.Genres) .SelectMany(i => i.Genres)
.Concat(artist.Genres) .Concat(artist.Genres)
.Distinct(StringComparer.OrdinalIgnoreCase); .Distinct(StringComparer.OrdinalIgnoreCase);

Loading…
Cancel
Save