1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-11-01 00:12:30 +01:00
Sonarr/NzbDrone.Api/Series/SeriesLookupModule.cs

45 lines
1.3 KiB
C#

using System.Collections.Generic;
using Nancy;
using NzbDrone.Api.Extensions;
using NzbDrone.Core.MediaCover;
using NzbDrone.Core.MetadataSource;
using System.Linq;
using NzbDrone.Api.Mapping;
namespace NzbDrone.Api.Series
{
public class SeriesLookupModule : NzbDroneRestModule<SeriesResource>
{
private readonly ISearchForNewSeries _searchProxy;
public SeriesLookupModule(ISearchForNewSeries searchProxy)
: base("/Series/lookup")
{
_searchProxy = searchProxy;
Get["/"] = x => Search();
}
private Response Search()
{
var tvDbResults = _searchProxy.SearchForNewSeries((string)Request.Query.term);
return MapToResource(tvDbResults).AsResponse();
}
private static IEnumerable<SeriesResource> MapToResource(IEnumerable<Core.Tv.Series> series)
{
foreach (var currentSeries in series)
{
var resource = currentSeries.InjectTo<SeriesResource>();
var poster = currentSeries.Images.FirstOrDefault(c => c.CoverType == MediaCoverTypes.Poster);
if (poster != null)
{
resource.RemotePoster = poster.Url;
}
yield return resource;
}
}
}
}