|
|
|
@ -21,7 +21,7 @@ using Radarr.Http;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Api.Movies
|
|
|
|
|
{
|
|
|
|
|
public class MovieModule : RadarrRestModuleWithSignalR<MovieResource, Core.Movies.Movie>,
|
|
|
|
|
public class MovieModule : RadarrRestModuleWithSignalR<MovieResource, Movie>,
|
|
|
|
|
IHandle<MovieImportedEvent>,
|
|
|
|
|
IHandle<MovieFileDeletedEvent>,
|
|
|
|
|
IHandle<MovieUpdatedEvent>,
|
|
|
|
@ -53,14 +53,8 @@ namespace NzbDrone.Api.Movies
|
|
|
|
|
_coverMapper = coverMapper;
|
|
|
|
|
|
|
|
|
|
GetResourceAll = AllMovie;
|
|
|
|
|
GetResourcePaged = GetMoviePaged;
|
|
|
|
|
GetResourceById = GetMovie;
|
|
|
|
|
Get[TITLE_SLUG_ROUTE] = GetByTitleSlug; /*(options) => {
|
|
|
|
|
return ReqResExtensions.AsResponse(GetByTitleSlug(options.slug), Nancy.HttpStatusCode.OK);
|
|
|
|
|
};*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Get[TITLE_SLUG_ROUTE] = GetByTitleSlug;
|
|
|
|
|
CreateResource = AddMovie;
|
|
|
|
|
UpdateResource = UpdateMovie;
|
|
|
|
|
DeleteResource = DeleteMovie;
|
|
|
|
@ -86,65 +80,34 @@ namespace NzbDrone.Api.Movies
|
|
|
|
|
PutValidator.RuleFor(s => s.Path).IsValidPath();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public MovieModule(IBroadcastSignalRMessage signalRBroadcaster,
|
|
|
|
|
IMovieService moviesService,
|
|
|
|
|
IMapCoversToLocal coverMapper,
|
|
|
|
|
string resource)
|
|
|
|
|
: base(signalRBroadcaster, resource)
|
|
|
|
|
{
|
|
|
|
|
_moviesService = moviesService;
|
|
|
|
|
|
|
|
|
|
_coverMapper = coverMapper;
|
|
|
|
|
|
|
|
|
|
GetResourceAll = AllMovie;
|
|
|
|
|
GetResourceById = GetMovie;
|
|
|
|
|
CreateResource = AddMovie;
|
|
|
|
|
UpdateResource = UpdateMovie;
|
|
|
|
|
DeleteResource = DeleteMovie;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private MovieResource GetMovie(int id)
|
|
|
|
|
{
|
|
|
|
|
var movies = _moviesService.GetMovie(id);
|
|
|
|
|
return MapToResource(movies);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private PagingResource<MovieResource> GetMoviePaged(PagingResource<MovieResource> pagingResource)
|
|
|
|
|
{
|
|
|
|
|
var pagingSpec = pagingResource.MapToPagingSpec<MovieResource, Movie>();
|
|
|
|
|
|
|
|
|
|
pagingSpec.FilterExpressions.Add(_moviesService.ConstructFilterExpression(pagingResource.Filters.FirstOrDefault().Key, pagingResource.Filters.FirstOrDefault().Value));
|
|
|
|
|
|
|
|
|
|
return ApplyToPage(_moviesService.Paged, pagingSpec, MapToResource);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected MovieResource MapToResource(Movie movies)
|
|
|
|
|
{
|
|
|
|
|
if (movies == null) return null;
|
|
|
|
|
|
|
|
|
|
var resource = movies.ToResource();
|
|
|
|
|
MapCoversToLocal(resource);
|
|
|
|
|
//FetchAndLinkMovieStatistics(resource);
|
|
|
|
|
//PopulateAlternateTitles(resource);
|
|
|
|
|
|
|
|
|
|
return resource;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<MovieResource> AllMovie()
|
|
|
|
|
{
|
|
|
|
|
//var moviesStats = _moviesStatisticsService.MovieStatistics();
|
|
|
|
|
var moviesResources = _moviesService.GetAllMovies().ToResource();
|
|
|
|
|
|
|
|
|
|
MapCoversToLocal(moviesResources.ToArray());
|
|
|
|
|
//LinkMovieStatistics(moviesResources, moviesStats);
|
|
|
|
|
PopulateAlternateTitles(moviesResources);
|
|
|
|
|
|
|
|
|
|
return moviesResources;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Response GetByTitleSlug(dynamic options)
|
|
|
|
|
{
|
|
|
|
|
var slug = "";
|
|
|
|
|
string slug;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
slug = options.slug;
|
|
|
|
@ -157,7 +120,7 @@ namespace NzbDrone.Api.Movies
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return MapToResource(_moviesService.FindByTitleSlug(slug)).AsResponse(Nancy.HttpStatusCode.OK);
|
|
|
|
|
return MapToResource(_moviesService.FindByTitleSlug(slug)).AsResponse(HttpStatusCode.OK);
|
|
|
|
|
}
|
|
|
|
|
catch (ModelNotFoundException)
|
|
|
|
|
{
|
|
|
|
@ -208,48 +171,6 @@ namespace NzbDrone.Api.Movies
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//private void FetchAndLinkMovieStatistics(MovieResource resource)
|
|
|
|
|
//{
|
|
|
|
|
// LinkMovieStatistics(resource, _moviesStatisticsService.MovieStatistics(resource.Id));
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
//private void LinkMovieStatistics(List<MovieResource> resources, List<MovieStatistics> moviesStatistics)
|
|
|
|
|
//{
|
|
|
|
|
// var dictMovieStats = moviesStatistics.ToDictionary(v => v.MovieId);
|
|
|
|
|
|
|
|
|
|
// foreach (var movies in resources)
|
|
|
|
|
// {
|
|
|
|
|
// var stats = dictMovieStats.GetValueOrDefault(movies.Id);
|
|
|
|
|
// if (stats == null) continue;
|
|
|
|
|
|
|
|
|
|
// LinkMovieStatistics(movies, stats);
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
//private void LinkMovieStatistics(MovieResource resource, MovieStatistics moviesStatistics)
|
|
|
|
|
//{
|
|
|
|
|
// //resource.SizeOnDisk = 0;//TODO: incorporate movie statistics moviesStatistics.SizeOnDisk;
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
private void PopulateAlternateTitles(List<MovieResource> resources)
|
|
|
|
|
{
|
|
|
|
|
foreach (var resource in resources)
|
|
|
|
|
{
|
|
|
|
|
PopulateAlternateTitles(resource);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void PopulateAlternateTitles(MovieResource resource)
|
|
|
|
|
{
|
|
|
|
|
//var mappings = null;//_sceneMappingService.FindByTvdbId(resource.TvdbId);
|
|
|
|
|
|
|
|
|
|
//if (mappings == null) return;
|
|
|
|
|
|
|
|
|
|
//Not necessary anymore
|
|
|
|
|
|
|
|
|
|
//resource.AlternateTitles = mappings.Select(v => new AlternateTitleResource { Title = v.Title, SeasonNumber = v.SeasonNumber, SceneSeasonNumber = v.SceneSeasonNumber }).ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Handle(MovieImportedEvent message)
|
|
|
|
|
{
|
|
|
|
|
BroadcastResourceChange(ModelAction.Updated, message.ImportedMovie.MovieId);
|
|
|
|
|