2013-05-26 01:19:03 +00:00
|
|
|
|
using System.Collections.Generic;
|
2013-05-25 02:08:26 +00:00
|
|
|
|
using Nancy;
|
2013-02-23 20:35:26 +00:00
|
|
|
|
using NzbDrone.Api.Extensions;
|
2013-05-26 01:19:03 +00:00
|
|
|
|
using NzbDrone.Core.MediaCover;
|
2013-03-04 05:53:02 +00:00
|
|
|
|
using NzbDrone.Core.MetadataSource;
|
2013-05-25 02:08:26 +00:00
|
|
|
|
using System.Linq;
|
2013-05-26 01:19:03 +00:00
|
|
|
|
using NzbDrone.Api.Mapping;
|
2013-01-28 18:06:54 +00:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Api.Series
|
|
|
|
|
{
|
2013-05-26 01:19:03 +00:00
|
|
|
|
public class SeriesLookupModule : NzbDroneRestModule<SeriesResource>
|
2013-01-28 18:06:54 +00:00
|
|
|
|
{
|
2013-03-31 20:25:39 +00:00
|
|
|
|
private readonly ISearchForNewSeries _searchProxy;
|
2013-01-28 18:06:54 +00:00
|
|
|
|
|
2013-03-31 20:25:39 +00:00
|
|
|
|
public SeriesLookupModule(ISearchForNewSeries searchProxy)
|
2013-01-28 18:06:54 +00:00
|
|
|
|
: base("/Series/lookup")
|
|
|
|
|
{
|
2013-03-31 20:25:39 +00:00
|
|
|
|
_searchProxy = searchProxy;
|
2013-05-26 01:19:03 +00:00
|
|
|
|
Get["/"] = x => Search();
|
2013-01-28 18:06:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-05-26 01:19:03 +00:00
|
|
|
|
private Response Search()
|
2013-01-28 18:06:54 +00:00
|
|
|
|
{
|
2013-03-31 20:25:39 +00:00
|
|
|
|
var tvDbResults = _searchProxy.SearchForNewSeries((string)Request.Query.term);
|
2013-05-26 05:54:02 +00:00
|
|
|
|
return MapToResource(tvDbResults).AsResponse();
|
2013-05-26 01:19:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
2013-01-28 18:06:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|