Lidarr/src/Lidarr.Api.V1/Artist/ArtistLookupModule.cs

43 lines
1.3 KiB
C#
Raw Normal View History

2017-09-04 02:20:56 +00:00
using System.Collections.Generic;
using System.Linq;
using Lidarr.Http;
2017-09-04 02:20:56 +00:00
using Nancy;
using NzbDrone.Core.MediaCover;
using NzbDrone.Core.MetadataSource;
2017-10-31 01:28:29 +00:00
namespace Lidarr.Api.V1.Artist
2017-09-04 02:20:56 +00:00
{
public class ArtistLookupModule : LidarrRestModule<ArtistResource>
{
private readonly ISearchForNewArtist _searchProxy;
public ArtistLookupModule(ISearchForNewArtist searchProxy)
: base("/artist/lookup")
{
_searchProxy = searchProxy;
Get("/", x => Search());
2017-09-04 02:20:56 +00:00
}
2019-09-12 20:32:51 +00:00
private object Search()
2017-09-04 02:20:56 +00:00
{
2017-11-26 04:55:07 +00:00
var searchResults = _searchProxy.SearchForNewArtist((string)Request.Query.term);
2019-09-12 20:32:51 +00:00
return MapToResource(searchResults).ToList();
2017-09-04 02:20:56 +00:00
}
private static IEnumerable<ArtistResource> MapToResource(IEnumerable<NzbDrone.Core.Music.Artist> artist)
{
foreach (var currentArtist in artist)
{
var resource = currentArtist.ToResource();
var poster = currentArtist.Metadata.Value.Images.FirstOrDefault(c => c.CoverType == MediaCoverTypes.Poster);
2017-09-04 02:20:56 +00:00
if (poster != null)
{
resource.RemotePoster = poster.Url;
}
yield return resource;
}
}
}
}