From 7ee60375a88277ec3f09f349baead317db101d1f Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 24 Apr 2013 10:05:47 -0400 Subject: [PATCH 1/2] added Artists filter --- MediaBrowser.Api/UserLibrary/ItemsService.cs | 39 +++++++++++++++++-- .../Entities/Audio/Artist.cs | 6 +++ .../Entities/Audio/MusicAlbum.cs | 10 +++++ .../Providers/Music/LastfmHelper.cs | 8 ++++ 4 files changed, 60 insertions(+), 3 deletions(-) diff --git a/MediaBrowser.Api/UserLibrary/ItemsService.cs b/MediaBrowser.Api/UserLibrary/ItemsService.cs index 7d3581846..d3b905746 100644 --- a/MediaBrowser.Api/UserLibrary/ItemsService.cs +++ b/MediaBrowser.Api/UserLibrary/ItemsService.cs @@ -1,5 +1,6 @@ using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Localization; @@ -76,6 +77,13 @@ namespace MediaBrowser.Api.UserLibrary [ApiMember(Name = "Studios", Description = "Optional. If specified, results will be filtered based on studio. This allows multiple, comma delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)] public string Studios { get; set; } + /// + /// Gets or sets the studios. + /// + /// The studios. + [ApiMember(Name = "Artists", Description = "Optional. If specified, results will be filtered based on studio. This allows multiple, pipe delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)] + public string Artists { get; set; } + /// /// Limit results to items containing specific years /// @@ -87,21 +95,21 @@ namespace MediaBrowser.Api.UserLibrary /// Gets or sets the image types. /// /// The image types. - [ApiMember(Name = "ImageTypes", Description = "Optional. If specified, results will be filtered based on those containing image types. This allows multiple, comma delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)] + [ApiMember(Name = "ImageTypes", Description = "Optional. If specified, results will be filtered based on those containing image types. This allows multiple, comma delimited.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)] public string ImageTypes { get; set; } /// /// Gets or sets the item ids. /// /// The item ids. - [ApiMember(Name = "Ids", Description = "Optional. If specific items are needed, specify a list of item id's to retrieve. This allows multiple, comma delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)] + [ApiMember(Name = "Ids", Description = "Optional. If specific items are needed, specify a list of item id's to retrieve. This allows multiple, comma delimited.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)] public string Ids { get; set; } /// /// Gets or sets the media types. /// /// The media types. - [ApiMember(Name = "MediaTypes", Description = "Optional filter by MediaType. Allows multiple, comma delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)] + [ApiMember(Name = "MediaTypes", Description = "Optional filter by MediaType. Allows multiple, comma delimited.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)] public string MediaTypes { get; set; } /// @@ -379,6 +387,31 @@ namespace MediaBrowser.Api.UserLibrary /// IEnumerable{BaseItem}. internal static IEnumerable ApplyAdditionalFilters(GetItems request, IEnumerable items) { + // Artists + if (!string.IsNullOrEmpty(request.Artists)) + { + var artists = request.Artists.Split('|'); + + items = items.Where(i => + { + var audio = i as Audio; + + if (audio != null) + { + return artists.Any(audio.HasArtist); + } + + var album = i as MusicAlbum; + + if (album != null) + { + return artists.Any(album.HasArtist); + } + + return false; + }); + } + // Min official rating if (!string.IsNullOrEmpty(request.MinOfficalRating)) { diff --git a/MediaBrowser.Controller/Entities/Audio/Artist.cs b/MediaBrowser.Controller/Entities/Audio/Artist.cs index 567b67868..6052a277e 100644 --- a/MediaBrowser.Controller/Entities/Audio/Artist.cs +++ b/MediaBrowser.Controller/Entities/Audio/Artist.cs @@ -14,5 +14,11 @@ namespace MediaBrowser.Controller.Entities.Audio { return "Artist-" + Name; } + + /// + /// Gets or sets a value indicating whether this instance is on tour. + /// + /// true if this instance is on tour; otherwise, false. + public bool IsOnTour { get; set; } } } diff --git a/MediaBrowser.Controller/Entities/Audio/MusicAlbum.cs b/MediaBrowser.Controller/Entities/Audio/MusicAlbum.cs index d93aec94c..859910ae6 100644 --- a/MediaBrowser.Controller/Entities/Audio/MusicAlbum.cs +++ b/MediaBrowser.Controller/Entities/Audio/MusicAlbum.cs @@ -139,5 +139,15 @@ namespace MediaBrowser.Controller.Entities.Audio base.Images = value; } } + + /// + /// Determines whether the specified artist has artist. + /// + /// The artist. + /// true if the specified artist has artist; otherwise, false. + public bool HasArtist(string artist) + { + return Children.OfType