2018-11-23 07:03:32 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2021-10-21 20:04:19 +00:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2020-05-26 01:55:10 +00:00
|
|
|
using NzbDrone.Core.Configuration;
|
2020-03-01 22:13:45 +00:00
|
|
|
using NzbDrone.Core.DecisionEngine.Specifications;
|
2020-05-26 01:55:10 +00:00
|
|
|
using NzbDrone.Core.Languages;
|
2018-11-23 07:03:32 +00:00
|
|
|
using NzbDrone.Core.Movies;
|
2020-05-26 01:55:10 +00:00
|
|
|
using NzbDrone.Core.Movies.Translations;
|
2018-11-23 07:03:32 +00:00
|
|
|
using NzbDrone.SignalR;
|
2019-12-22 22:08:53 +00:00
|
|
|
using Radarr.Api.V3.Movies;
|
2018-11-23 07:03:32 +00:00
|
|
|
using Radarr.Http;
|
2021-10-21 20:04:19 +00:00
|
|
|
using Radarr.Http.REST;
|
2018-11-23 07:03:32 +00:00
|
|
|
|
2019-12-03 01:36:18 +00:00
|
|
|
namespace Radarr.Api.V3.Calendar
|
2018-11-23 07:03:32 +00:00
|
|
|
{
|
2021-10-21 20:04:19 +00:00
|
|
|
[V3ApiController]
|
|
|
|
public class CalendarController : RestControllerWithSignalR<MovieResource, Movie>
|
2018-11-23 07:03:32 +00:00
|
|
|
{
|
2020-03-01 22:13:45 +00:00
|
|
|
private readonly IMovieService _moviesService;
|
2020-05-26 01:55:10 +00:00
|
|
|
private readonly IMovieTranslationService _movieTranslationService;
|
2020-03-01 22:13:45 +00:00
|
|
|
private readonly IUpgradableSpecification _qualityUpgradableSpecification;
|
2020-05-26 01:55:10 +00:00
|
|
|
private readonly IConfigService _configService;
|
2018-11-23 07:03:32 +00:00
|
|
|
|
2021-10-21 20:04:19 +00:00
|
|
|
public CalendarController(IBroadcastSignalRMessage signalR,
|
2020-03-01 22:13:45 +00:00
|
|
|
IMovieService moviesService,
|
2020-05-26 01:55:10 +00:00
|
|
|
IMovieTranslationService movieTranslationService,
|
|
|
|
IUpgradableSpecification qualityUpgradableSpecification,
|
|
|
|
IConfigService configService)
|
2021-10-21 20:04:19 +00:00
|
|
|
: base(signalR)
|
2018-11-23 07:03:32 +00:00
|
|
|
{
|
|
|
|
_moviesService = moviesService;
|
2020-05-26 01:55:10 +00:00
|
|
|
_movieTranslationService = movieTranslationService;
|
2020-03-01 22:13:45 +00:00
|
|
|
_qualityUpgradableSpecification = qualityUpgradableSpecification;
|
2020-05-26 01:55:10 +00:00
|
|
|
_configService = configService;
|
2018-11-23 07:03:32 +00:00
|
|
|
}
|
|
|
|
|
2021-10-24 20:35:22 +00:00
|
|
|
protected override MovieResource GetResourceById(int id)
|
2018-11-23 07:03:32 +00:00
|
|
|
{
|
2021-10-21 20:04:19 +00:00
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
2019-12-22 22:08:53 +00:00
|
|
|
|
2021-10-21 20:04:19 +00:00
|
|
|
[HttpGet]
|
|
|
|
public List<MovieResource> GetCalendar(DateTime? start, DateTime? end, bool unmonitored = false, bool includeArtist = false)
|
|
|
|
{
|
|
|
|
var startUse = start ?? DateTime.Today;
|
|
|
|
var endUse = end ?? DateTime.Today.AddDays(2);
|
2018-11-23 07:03:32 +00:00
|
|
|
|
2021-10-21 20:04:19 +00:00
|
|
|
var resources = _moviesService.GetMoviesBetweenDates(startUse, endUse, unmonitored).Select(MapToResource);
|
2018-11-23 07:03:32 +00:00
|
|
|
|
|
|
|
return resources.OrderBy(e => e.InCinemas).ToList();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected MovieResource MapToResource(Movie movie)
|
|
|
|
{
|
2019-12-22 22:08:53 +00:00
|
|
|
if (movie == null)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
2018-11-23 07:03:32 +00:00
|
|
|
|
2020-11-25 20:55:28 +00:00
|
|
|
var availDelay = _configService.AvailabilityDelay;
|
2020-09-09 03:13:42 +00:00
|
|
|
var translations = _movieTranslationService.GetAllTranslationsForMovie(movie.Id);
|
|
|
|
var translation = GetMovieTranslation(translations, movie);
|
2020-11-25 20:55:28 +00:00
|
|
|
var resource = movie.ToResource(availDelay, translation, _qualityUpgradableSpecification);
|
2018-11-23 07:03:32 +00:00
|
|
|
|
|
|
|
return resource;
|
|
|
|
}
|
2020-09-09 03:13:42 +00:00
|
|
|
|
|
|
|
private MovieTranslation GetMovieTranslation(List<MovieTranslation> translations, Movie movie)
|
|
|
|
{
|
|
|
|
if ((Language)_configService.MovieInfoLanguage == Language.Original)
|
|
|
|
{
|
|
|
|
return new MovieTranslation
|
|
|
|
{
|
|
|
|
Title = movie.OriginalTitle,
|
|
|
|
Overview = movie.Overview
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return translations.FirstOrDefault(t => t.Language == (Language)_configService.MovieInfoLanguage && t.MovieId == movie.Id);
|
|
|
|
}
|
2018-11-23 07:03:32 +00:00
|
|
|
}
|
|
|
|
}
|