浏览代码

add ArtistItems to api output

Luke Pulverenti 10 年之前
父节点
当前提交
96ec4cef77

+ 1 - 1
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

+ 18 - 8
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;
             }
 

+ 4 - 6
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);
 

+ 1 - 1
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;

+ 32 - 13
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();
@@ -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
             if (!string.IsNullOrEmpty(request.Artists))
             {
@@ -1021,7 +1040,7 @@ namespace MediaBrowser.Api.UserLibrary
 
                 var audio = i as IHasArtist;
 
-                if (!(audio != null && artists.Any(audio.HasArtist)))
+                if (!(audio != null && artists.Any(audio.HasAnyArtist)))
                 {
                     return false;
                 }

+ 0 - 10
MediaBrowser.Controller/Entities/Audio/Audio.cs

@@ -171,16 +171,6 @@ namespace MediaBrowser.Controller.Entities.Audio
                     + (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>
         /// Gets the user data key.
         /// </summary>

+ 16 - 4
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);
+        }
     }
 }

+ 0 - 10
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>

+ 1 - 1
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);
             };
         }
     }

+ 0 - 10
MediaBrowser.Controller/Entities/MusicVideo.cs

@@ -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>
         /// Gets the user data key.
         /// </summary>

+ 1 - 1
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

+ 0 - 3
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>

+ 0 - 3
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>

+ 2 - 2
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.

+ 6 - 0
MediaBrowser.Model/Dto/BaseItemDto.cs

@@ -466,6 +466,12 @@ namespace MediaBrowser.Model.Dto
         /// <value>The artists.</value>
         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>

+ 0 - 1
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" />

+ 5 - 5
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[] { };

+ 0 - 29
MediaBrowser.Model/Querying/SimilarItemsByNameQuery.cs

@@ -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; }
-    }
-}

+ 1 - 1
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)
                 {

+ 28 - 11
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);

+ 1 - 1
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);