diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2015-03-13 13:25:28 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2015-03-13 13:25:28 -0400 |
| commit | 96ec4cef77d98b0cad42a7b105e025df3543784d (patch) | |
| tree | 9048aadbed8dcfebb3affefffdf9bf29a0ae10c5 | |
| parent | a92723fde3fc44410c782ee93d36c749ae8d6f82 (diff) | |
add ArtistItems to api output
21 files changed, 117 insertions, 121 deletions
diff --git a/MediaBrowser.Api/ItemRefreshService.cs b/MediaBrowser.Api/ItemRefreshService.cs index 78bc14ab0..6a7b4826c 100644 --- a/MediaBrowser.Api/ItemRefreshService.cs +++ b/MediaBrowser.Api/ItemRefreshService.cs @@ -53,7 +53,7 @@ namespace MediaBrowser.Api var albums = _libraryManager.RootFolder .GetRecursiveChildren() .OfType<MusicAlbum>() - .Where(i => i.HasArtist(item.Name)) + .Where(i => i.HasAnyArtist(item.Name)) .ToList(); var musicArtists = albums diff --git a/MediaBrowser.Api/ItemUpdateService.cs b/MediaBrowser.Api/ItemUpdateService.cs index bdcad73b0..86689f5cf 100644 --- a/MediaBrowser.Api/ItemUpdateService.cs +++ b/MediaBrowser.Api/ItemUpdateService.cs @@ -389,23 +389,33 @@ namespace MediaBrowser.Api game.PlayersSupported = request.Players; } - var song = item as Audio; - - if (song != null) + var hasAlbumArtists = item as IHasAlbumArtist; + if (hasAlbumArtists != null) { - song.Album = request.Album; - song.AlbumArtists = request + hasAlbumArtists.AlbumArtists = request .AlbumArtists .Select(i => i.Name) .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) { - musicVideo.Artists = request.Artists.ToList(); musicVideo.Album = request.Album; } diff --git a/MediaBrowser.Api/Music/AlbumsService.cs b/MediaBrowser.Api/Music/AlbumsService.cs index 76c6c5776..a1c98addb 100644 --- a/MediaBrowser.Api/Music/AlbumsService.cs +++ b/MediaBrowser.Api/Music/AlbumsService.cs @@ -77,15 +77,13 @@ namespace MediaBrowser.Api.Music var album1 = (MusicAlbum)item1; var album2 = (MusicAlbum)item2; - var artists1 = album1.GetRecursiveChildren(i => i is IHasArtist) - .Cast<IHasArtist>() - .SelectMany(i => i.AllArtists) + var artists1 = album1 + .AllArtists .Distinct(StringComparer.OrdinalIgnoreCase) .ToList(); - var artists2 = album2.GetRecursiveChildren(i => i is IHasArtist) - .Cast<IHasArtist>() - .SelectMany(i => i.AllArtists) + var artists2 = album2 + .AllArtists .Distinct(StringComparer.OrdinalIgnoreCase) .ToDictionary(i => i, StringComparer.OrdinalIgnoreCase); diff --git a/MediaBrowser.Api/SearchService.cs b/MediaBrowser.Api/SearchService.cs index ee48946d5..2cca72593 100644 --- a/MediaBrowser.Api/SearchService.cs +++ b/MediaBrowser.Api/SearchService.cs @@ -211,7 +211,7 @@ namespace MediaBrowser.Api result.SongCount = album.Tracks.Count(); result.Artists = album.Artists.ToArray(); - result.AlbumArtist = album.AlbumArtists.FirstOrDefault(); + result.AlbumArtist = album.AlbumArtist; } var song = item as Audio; diff --git a/MediaBrowser.Api/UserLibrary/ItemsService.cs b/MediaBrowser.Api/UserLibrary/ItemsService.cs index 0b636e93b..256ae3625 100644 --- a/MediaBrowser.Api/UserLibrary/ItemsService.cs +++ b/MediaBrowser.Api/UserLibrary/ItemsService.cs @@ -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)] 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)] 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) { + var video = i as Video; + if (!isPreFiltered) { var mediaTypes = request.GetMediaTypes(); @@ -647,7 +652,6 @@ namespace MediaBrowser.Api.UserLibrary if (request.Is3D.HasValue) { var val = request.Is3D.Value; - var video = i as Video; if (video == null || val != video.Video3DFormat.HasValue) { @@ -658,7 +662,6 @@ namespace MediaBrowser.Api.UserLibrary if (request.IsHD.HasValue) { var val = request.IsHD.Value; - var video = i as Video; if (video == null || val != video.IsHD) { @@ -800,8 +803,6 @@ namespace MediaBrowser.Api.UserLibrary { var val = request.HasSubtitles.Value; - var video = i as Video; - if (video == null || val != video.HasSubtitles) { return false; @@ -922,15 +923,10 @@ namespace MediaBrowser.Api.UserLibrary } // Filter by VideoType - if (!string.IsNullOrEmpty(request.VideoTypes)) + var videoTypes = request.GetVideoTypes(); + if (video == null || !videoTypes.Contains(video.VideoType)) { - var types = request.VideoTypes.Split(','); - - var video = i as Video; - if (video == null || !types.Contains(video.VideoType.ToString(), StringComparer.OrdinalIgnoreCase)) - { - return false; - } + return false; } var imageTypes = request.GetImageTypes().ToList(); @@ -1015,13 +1011,36 @@ 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 if (!string.IsNullOrEmpty(request.Artists)) { var artists = request.Artists.Split('|'); var audio = i as IHasArtist; - if (!(audio != null && artists.Any(audio.HasArtist))) + if (!(audio != null && artists.Any(audio.HasAnyArtist))) { return false; } diff --git a/MediaBrowser.Controller/Entities/Audio/Audio.cs b/MediaBrowser.Controller/Entities/Audio/Audio.cs index d868227d9..c033b144a 100644 --- a/MediaBrowser.Controller/Entities/Audio/Audio.cs +++ b/MediaBrowser.Controller/Entities/Audio/Audio.cs @@ -172,16 +172,6 @@ namespace MediaBrowser.Controller.Entities.Audio } /// <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> /// Gets the user data key. /// </summary> /// <returns>System.String.</returns> diff --git a/MediaBrowser.Controller/Entities/Audio/IHasAlbumArtist.cs b/MediaBrowser.Controller/Entities/Audio/IHasAlbumArtist.cs index a20f05323..56921409a 100644 --- a/MediaBrowser.Controller/Entities/Audio/IHasAlbumArtist.cs +++ b/MediaBrowser.Controller/Entities/Audio/IHasAlbumArtist.cs @@ -1,4 +1,6 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using System.Linq; namespace MediaBrowser.Controller.Entities.Audio { @@ -9,10 +11,20 @@ namespace MediaBrowser.Controller.Entities.Audio public interface IHasArtist { - bool HasArtist(string name); - 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); + } } } diff --git a/MediaBrowser.Controller/Entities/Audio/MusicAlbum.cs b/MediaBrowser.Controller/Entities/Audio/MusicAlbum.cs index e3f523b5a..dc3f13b01 100644 --- a/MediaBrowser.Controller/Entities/Audio/MusicAlbum.cs +++ b/MediaBrowser.Controller/Entities/Audio/MusicAlbum.cs @@ -120,16 +120,6 @@ namespace MediaBrowser.Controller.Entities.Audio 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; } /// <summary> diff --git a/MediaBrowser.Controller/Entities/Audio/MusicArtist.cs b/MediaBrowser.Controller/Entities/Audio/MusicArtist.cs index fed9689b3..4185590ab 100644 --- a/MediaBrowser.Controller/Entities/Audio/MusicArtist.cs +++ b/MediaBrowser.Controller/Entities/Audio/MusicArtist.cs @@ -213,7 +213,7 @@ namespace MediaBrowser.Controller.Entities.Audio return i => { var hasArtist = i as IHasArtist; - return hasArtist != null && hasArtist.HasArtist(Name); + return hasArtist != null && hasArtist.HasAnyArtist(Name); }; } } diff --git a/MediaBrowser.Controller/Entities/MusicVideo.cs b/MediaBrowser.Controller/Entities/MusicVideo.cs index 771c62fd6..b2cad02de 100644 --- a/MediaBrowser.Controller/Entities/MusicVideo.cs +++ b/MediaBrowser.Controller/Entities/MusicVideo.cs @@ -48,16 +48,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> /// Gets the user data key. /// </summary> /// <returns>System.String.</returns> diff --git a/MediaBrowser.Controller/Playlists/Playlist.cs b/MediaBrowser.Controller/Playlists/Playlist.cs index 3479902cb..fdc36db35 100644 --- a/MediaBrowser.Controller/Playlists/Playlist.cs +++ b/MediaBrowser.Controller/Playlists/Playlist.cs @@ -106,7 +106,7 @@ namespace MediaBrowser.Controller.Playlists Func<BaseItem, bool> filter = i => { var audio = i as Audio; - return audio != null && audio.HasArtist(musicArtist.Name); + return audio != null && audio.HasAnyArtist(musicArtist.Name); }; var items = user == null diff --git a/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj b/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj index b72a895ca..74f927c7e 100644 --- a/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj +++ b/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj @@ -980,9 +980,6 @@ <Compile Include="..\MediaBrowser.Model\Querying\SessionQuery.cs"> <Link>Querying\SessionQuery.cs</Link> </Compile> - <Compile Include="..\MediaBrowser.Model\Querying\SimilarItemsByNameQuery.cs"> - <Link>Querying\SimilarItemsByNameQuery.cs</Link> - </Compile> <Compile Include="..\MediaBrowser.Model\Querying\SimilarItemsQuery.cs"> <Link>Querying\SimilarItemsQuery.cs</Link> </Compile> diff --git a/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj b/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj index 7a28f6de8..7f6f7bc13 100644 --- a/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj +++ b/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj @@ -942,9 +942,6 @@ <Compile Include="..\MediaBrowser.Model\Querying\SessionQuery.cs"> <Link>Querying\SessionQuery.cs</Link> </Compile> - <Compile Include="..\MediaBrowser.Model\Querying\SimilarItemsByNameQuery.cs"> - <Link>Querying\SimilarItemsByNameQuery.cs</Link> - </Compile> <Compile Include="..\MediaBrowser.Model\Querying\SimilarItemsQuery.cs"> <Link>Querying\SimilarItemsQuery.cs</Link> </Compile> diff --git a/MediaBrowser.Model/ApiClient/IApiClient.cs b/MediaBrowser.Model/ApiClient/IApiClient.cs index 190f2100e..0b55d0b45 100644 --- a/MediaBrowser.Model/ApiClient/IApiClient.cs +++ b/MediaBrowser.Model/ApiClient/IApiClient.cs @@ -344,14 +344,14 @@ namespace MediaBrowser.Model.ApiClient /// </summary> /// <param name="query">The query.</param> /// <returns>Task{ItemsResult}.</returns> - Task<ItemsResult> GetInstantMixFromArtistAsync(SimilarItemsByNameQuery query); + Task<ItemsResult> GetInstantMixFromArtistAsync(SimilarItemsQuery query); /// <summary> /// Gets the instant mix from music genre async. /// </summary> /// <param name="query">The query.</param> /// <returns>Task{ItemsResult}.</returns> - Task<ItemsResult> GetInstantMixFromMusicGenreAsync(SimilarItemsByNameQuery query); + Task<ItemsResult> GetInstantMixFromMusicGenreAsync(SimilarItemsQuery query); /// <summary> /// Gets the similar movies async. diff --git a/MediaBrowser.Model/Dto/BaseItemDto.cs b/MediaBrowser.Model/Dto/BaseItemDto.cs index 66066e392..7a1c78112 100644 --- a/MediaBrowser.Model/Dto/BaseItemDto.cs +++ b/MediaBrowser.Model/Dto/BaseItemDto.cs @@ -467,6 +467,12 @@ namespace MediaBrowser.Model.Dto 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> /// Gets or sets the album. /// </summary> /// <value>The album.</value> diff --git a/MediaBrowser.Model/MediaBrowser.Model.csproj b/MediaBrowser.Model/MediaBrowser.Model.csproj index fd50e598a..601ba6dc1 100644 --- a/MediaBrowser.Model/MediaBrowser.Model.csproj +++ b/MediaBrowser.Model/MediaBrowser.Model.csproj @@ -322,7 +322,6 @@ <Compile Include="Querying\QueryResult.cs" /> <Compile Include="Querying\SeasonQuery.cs" /> <Compile Include="Querying\SessionQuery.cs" /> - <Compile Include="Querying\SimilarItemsByNameQuery.cs" /> <Compile Include="Querying\SimilarItemsQuery.cs" /> <Compile Include="Querying\UpcomingEpisodesQuery.cs" /> <Compile Include="Querying\UserQuery.cs" /> diff --git a/MediaBrowser.Model/Querying/ItemQuery.cs b/MediaBrowser.Model/Querying/ItemQuery.cs index a40eca5b5..1fde6d62d 100644 --- a/MediaBrowser.Model/Querying/ItemQuery.cs +++ b/MediaBrowser.Model/Querying/ItemQuery.cs @@ -39,11 +39,11 @@ namespace MediaBrowser.Model.Querying public string[] SortBy { get; set; } /// <summary> - /// Filter by artists + /// Gets or sets the artist ids. /// </summary> - /// <value>The artists.</value> - public string[] Artists { get; set; } - + /// <value>The artist ids.</value> + public string[] ArtistIds { get; set; } + /// <summary> /// The sort order to return results with /// </summary> @@ -306,7 +306,7 @@ namespace MediaBrowser.Model.Querying Years = new int[] { }; PersonTypes = new string[] { }; Ids = new string[] { }; - Artists = new string[] { }; + ArtistIds = new string[] { }; ImageTypes = new ImageType[] { }; AirDays = new DayOfWeek[] { }; diff --git a/MediaBrowser.Model/Querying/SimilarItemsByNameQuery.cs b/MediaBrowser.Model/Querying/SimilarItemsByNameQuery.cs deleted file mode 100644 index 7d0d4da31..000000000 --- a/MediaBrowser.Model/Querying/SimilarItemsByNameQuery.cs +++ /dev/null @@ -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; } - } -}
\ No newline at end of file diff --git a/MediaBrowser.Providers/MediaInfo/FFProbeAudioInfo.cs b/MediaBrowser.Providers/MediaInfo/FFProbeAudioInfo.cs index 26d00d544..ea191dd08 100644 --- a/MediaBrowser.Providers/MediaInfo/FFProbeAudioInfo.cs +++ b/MediaBrowser.Providers/MediaInfo/FFProbeAudioInfo.cs @@ -387,7 +387,7 @@ namespace MediaBrowser.Providers.MediaInfo if (!string.IsNullOrEmpty(val)) { // 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) { diff --git a/MediaBrowser.Server.Implementations/Dto/DtoService.cs b/MediaBrowser.Server.Implementations/Dto/DtoService.cs index 8086033eb..3280cf264 100644 --- a/MediaBrowser.Server.Implementations/Dto/DtoService.cs +++ b/MediaBrowser.Server.Implementations/Dto/DtoService.cs @@ -504,7 +504,6 @@ namespace MediaBrowser.Server.Implementations.Dto } dto.Album = item.Album; - dto.Artists = item.Artists; } private void SetGameProperties(BaseItemDto dto, Game item) @@ -1142,7 +1141,6 @@ namespace MediaBrowser.Server.Implementations.Dto if (audio != null) { dto.Album = audio.Album; - dto.Artists = audio.Artists; var albumParent = audio.FindParent<MusicAlbum>(); @@ -1163,15 +1161,40 @@ namespace MediaBrowser.Server.Implementations.Dto if (album != null) { - dto.Artists = album.Artists; - dto.SoundtrackIds = album.SoundtrackIds .Select(i => i.ToString("N")) .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) { dto.AlbumArtist = hasAlbumArtist.AlbumArtists.FirstOrDefault(); @@ -1253,7 +1276,6 @@ namespace MediaBrowser.Server.Implementations.Dto // Add MovieInfo var movie = item as Movie; - if (movie != null) { if (fields.Contains(ItemFields.TmdbCollectionName)) @@ -1263,7 +1285,6 @@ namespace MediaBrowser.Server.Implementations.Dto } var hasSpecialFeatures = item as IHasSpecialFeatures; - if (hasSpecialFeatures != null) { var specialFeatureCount = hasSpecialFeatures.SpecialFeatureIds.Count; @@ -1276,7 +1297,6 @@ namespace MediaBrowser.Server.Implementations.Dto // Add EpisodeInfo var episode = item as Episode; - if (episode != null) { dto.IndexNumberEnd = episode.IndexNumberEnd; @@ -1318,7 +1338,6 @@ namespace MediaBrowser.Server.Implementations.Dto // Add SeriesInfo var series = item as Series; - if (series != null) { dto.AirDays = series.AirDays; @@ -1368,7 +1387,6 @@ namespace MediaBrowser.Server.Implementations.Dto // Add SeasonInfo var season = item as Season; - if (season != null) { series = season.Series; @@ -1402,7 +1420,6 @@ namespace MediaBrowser.Server.Implementations.Dto } var musicVideo = item as MusicVideo; - if (musicVideo != null) { SetMusicVideoProperties(dto, musicVideo); diff --git a/MediaBrowser.Server.Implementations/Library/MusicManager.cs b/MediaBrowser.Server.Implementations/Library/MusicManager.cs index 7733e7d37..3a854f2fe 100644 --- a/MediaBrowser.Server.Implementations/Library/MusicManager.cs +++ b/MediaBrowser.Server.Implementations/Library/MusicManager.cs @@ -34,7 +34,7 @@ namespace MediaBrowser.Server.Implementations.Library var genres = user.RootFolder .GetRecursiveChildren(user, i => i is Audio) .Cast<Audio>() - .Where(i => i.HasArtist(name)) + .Where(i => i.HasAnyArtist(name)) .SelectMany(i => i.Genres) .Concat(artist.Genres) .Distinct(StringComparer.OrdinalIgnoreCase); |
