Radarr/src/NzbDrone.Api/Movies/MovieLookupModule.cs

68 lines
2.0 KiB
C#
Raw Normal View History

2019-12-22 22:08:53 +00:00
using System;
2018-02-13 18:10:49 +00:00
using System.Collections.Generic;
2019-12-22 22:08:53 +00:00
using System.Linq;
using Nancy;
using NzbDrone.Core.MediaCover;
using NzbDrone.Core.MetadataSource;
2018-11-23 07:03:32 +00:00
using Radarr.Http;
using Radarr.Http.REST;
2018-02-19 07:18:14 +00:00
namespace NzbDrone.Api.Movies
{
2018-11-23 07:03:32 +00:00
public class MovieLookupModule : RadarrRestModule<MovieResource>
{
private readonly ISearchForNewMovie _searchProxy;
private readonly IProvideMovieInfo _movieInfo;
public MovieLookupModule(ISearchForNewMovie searchProxy, IProvideMovieInfo movieInfo)
2018-02-13 18:10:49 +00:00
: base("/movie/lookup")
{
_movieInfo = movieInfo;
_searchProxy = searchProxy;
2019-12-22 22:08:53 +00:00
Get("/", x => Search());
Get("/tmdb", x => SearchByTmdbId());
Get("/imdb", x => SearchByImdbId());
}
2019-08-28 21:43:55 +00:00
private object SearchByTmdbId()
{
int tmdbId = -1;
2019-12-22 22:08:53 +00:00
if (int.TryParse(Request.Query.tmdbId, out tmdbId))
{
var result = _movieInfo.GetMovieInfo(tmdbId, null, true);
2019-08-28 21:43:55 +00:00
return result.ToResource();
}
throw new BadRequestException("Tmdb Id was not valid");
}
2019-08-28 21:43:55 +00:00
private object SearchByImdbId()
2017-02-25 21:38:52 +00:00
{
string imdbId = Request.Query.imdbId;
var result = _movieInfo.GetMovieInfo(imdbId);
2019-08-28 21:43:55 +00:00
return result.ToResource();
2017-02-25 21:38:52 +00:00
}
2019-08-28 21:43:55 +00:00
private object Search()
{
var imdbResults = _searchProxy.SearchForNewMovie((string)Request.Query.term);
2019-08-28 21:43:55 +00:00
return MapToResource(imdbResults);
}
private static IEnumerable<MovieResource> MapToResource(IEnumerable<Core.Movies.Movie> movies)
{
foreach (var currentSeries in movies)
{
var resource = currentSeries.ToResource();
var poster = currentSeries.Images.FirstOrDefault(c => c.CoverType == MediaCoverTypes.Poster);
if (poster != null)
{
resource.RemotePoster = poster.Url;
}
yield return resource;
}
}
}
2018-02-13 18:10:49 +00:00
}