Radarr/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs

487 lines
16 KiB
C#
Raw Normal View History

using System;
2015-01-09 01:43:51 +00:00
using System.Collections.Generic;
using System.Linq;
2015-05-07 15:43:52 +00:00
using System.Net;
using NLog;
using NzbDrone.Common.Cloud;
2015-01-09 01:43:51 +00:00
using NzbDrone.Common.Extensions;
using NzbDrone.Common.Http;
2020-04-03 00:57:36 +00:00
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Exceptions;
2019-12-22 22:08:53 +00:00
using NzbDrone.Core.Languages;
2015-01-09 01:43:51 +00:00
using NzbDrone.Core.MediaCover;
2019-12-22 22:08:53 +00:00
using NzbDrone.Core.MetadataSource.SkyHook.Resource;
using NzbDrone.Core.Movies;
2019-12-22 22:08:53 +00:00
using NzbDrone.Core.Movies.AlternativeTitles;
using NzbDrone.Core.Movies.Credits;
2020-05-10 01:49:09 +00:00
using NzbDrone.Core.NetImport.TMDb;
using NzbDrone.Core.Parser;
2015-01-09 01:43:51 +00:00
namespace NzbDrone.Core.MetadataSource.SkyHook
{
2020-05-10 01:49:09 +00:00
public class SkyHookProxy : IProvideMovieInfo, ISearchForNewMovie
2015-01-09 01:43:51 +00:00
{
private readonly IHttpClient _httpClient;
2015-05-07 15:43:52 +00:00
private readonly Logger _logger;
2019-12-22 21:24:11 +00:00
private readonly IHttpRequestBuilderFactory _movieBuilder;
2020-05-10 01:49:09 +00:00
private readonly IHttpRequestBuilderFactory _radarrMetadata;
2020-04-03 00:57:36 +00:00
private readonly IConfigService _configService;
private readonly IMovieService _movieService;
2019-12-22 22:08:53 +00:00
public SkyHookProxy(IHttpClient httpClient,
IRadarrCloudRequestBuilder requestBuilder,
2020-04-03 00:57:36 +00:00
IConfigService configService,
2019-12-22 22:08:53 +00:00
IMovieService movieService,
Logger logger)
2015-01-09 01:43:51 +00:00
{
_httpClient = httpClient;
_movieBuilder = requestBuilder.TMDB;
2020-05-10 01:49:09 +00:00
_radarrMetadata = requestBuilder.RadarrMetadata;
_configService = configService;
_movieService = movieService;
2015-05-07 15:43:52 +00:00
_logger = logger;
2015-01-09 01:43:51 +00:00
}
2019-12-22 22:08:53 +00:00
public HashSet<int> GetChangedMovies(DateTime startTime)
2019-12-15 03:30:44 +00:00
{
2019-12-15 05:35:42 +00:00
var startDate = startTime.ToString("o");
2019-12-15 03:30:44 +00:00
var request = _movieBuilder.Create()
2019-12-15 07:34:27 +00:00
.SetSegment("api", "3")
2019-12-15 03:30:44 +00:00
.SetSegment("route", "movie")
.SetSegment("id", "")
.SetSegment("secondaryRoute", "changes")
2019-12-15 05:35:42 +00:00
.AddQueryParam("start_date", startDate)
2019-12-15 03:30:44 +00:00
.Build();
request.AllowAutoRedirect = true;
request.SuppressHttpError = true;
2020-05-20 01:17:39 +00:00
var response = _httpClient.Get<MovieSearchResource>(request);
2019-12-15 03:30:44 +00:00
2020-05-20 01:17:39 +00:00
return new HashSet<int>(response.Resource.Results.Select(c => c.Id));
2019-12-15 03:30:44 +00:00
}
public Tuple<Movie, List<Credit>> GetMovieInfo(int tmdbId)
{
2020-05-10 01:49:09 +00:00
var httpRequest = _radarrMetadata.Create()
.SetSegment("route", "movie")
.Resource(tmdbId.ToString())
.Build();
2020-05-10 01:49:09 +00:00
httpRequest.AllowAutoRedirect = true;
httpRequest.SuppressHttpError = true;
var httpResponse = _httpClient.Get<MovieResource>(httpRequest);
2019-12-17 02:44:59 +00:00
2020-05-10 01:49:09 +00:00
if (httpResponse.HasHttpError)
{
2020-05-10 01:49:09 +00:00
if (httpResponse.StatusCode == HttpStatusCode.NotFound)
{
throw new MovieNotFoundException(tmdbId);
}
else
{
throw new HttpException(httpRequest, httpResponse);
}
}
2019-12-22 22:08:53 +00:00
2020-05-10 01:49:09 +00:00
var credits = new List<Credit>();
credits.AddRange(httpResponse.Resource.Credits.Cast.Select(MapCast));
credits.AddRange(httpResponse.Resource.Credits.Crew.Select(MapCrew));
2020-05-10 01:49:09 +00:00
var movie = MapMovie(httpResponse.Resource);
2020-05-10 01:49:09 +00:00
return new Tuple<Movie, List<Credit>>(movie, credits.ToList());
}
2020-05-10 01:49:09 +00:00
public Movie GetMovieByImdbId(string imdbId)
{
var httpRequest = _radarrMetadata.Create()
.SetSegment("route", "movie/imdb")
.Resource(imdbId.ToString())
.Build();
2020-05-10 01:49:09 +00:00
httpRequest.AllowAutoRedirect = true;
httpRequest.SuppressHttpError = true;
2020-05-10 01:49:09 +00:00
var httpResponse = _httpClient.Get<List<MovieResource>>(httpRequest);
2020-05-10 01:49:09 +00:00
if (httpResponse.HasHttpError)
{
2020-05-10 01:49:09 +00:00
if (httpResponse.StatusCode == HttpStatusCode.NotFound)
{
2020-05-10 01:49:09 +00:00
throw new MovieNotFoundException(imdbId);
}
2020-05-10 01:49:09 +00:00
else
{
2020-05-10 01:49:09 +00:00
throw new HttpException(httpRequest, httpResponse);
}
}
2020-05-10 01:49:09 +00:00
var movie = httpResponse.Resource.SelectList(MapMovie).FirstOrDefault();
2020-05-10 01:49:09 +00:00
return movie;
}
2020-05-10 01:49:09 +00:00
public Movie MapMovie(MovieResource resource)
{
var movie = new Movie();
var altTitles = new List<AlternativeTitle>();
2020-05-10 01:49:09 +00:00
movie.TmdbId = resource.TmdbId;
movie.ImdbId = resource.ImdbId;
movie.Title = resource.Title;
movie.TitleSlug = resource.TitleSlug;
movie.CleanTitle = resource.Title.CleanSeriesTitle();
movie.SortTitle = Parser.Parser.NormalizeTitle(resource.Title);
movie.Overview = resource.Overview;
2020-05-10 01:49:09 +00:00
movie.AlternativeTitles.AddRange(resource.AlternativeTitles.Select(MapAlternativeTitle));
2020-05-10 01:49:09 +00:00
movie.Website = resource.Homepage;
movie.InCinemas = resource.InCinema;
movie.PhysicalRelease = resource.PhysicalRelease;
2020-05-10 01:49:09 +00:00
movie.Year = resource.Year;
2020-04-05 07:30:03 +00:00
2020-05-10 01:49:09 +00:00
//If the premier differs from the TMDB year, use it as a secondary year.
if (resource.Premier.HasValue && resource.Premier?.Year != movie.Year)
2020-04-05 07:30:03 +00:00
{
2020-05-10 01:49:09 +00:00
movie.SecondaryYear = resource.Premier?.Year;
2020-04-05 07:30:03 +00:00
}
2020-05-10 01:49:09 +00:00
movie.Images = resource.Images.Select(MapImage).ToList();
2020-05-10 01:49:09 +00:00
if (resource.Runtime != null)
{
2020-05-10 01:49:09 +00:00
movie.Runtime = resource.Runtime.Value;
}
2020-05-10 01:49:09 +00:00
var certificationCountry = _configService.CertificationCountry.ToString();
movie.Certification = resource.Certifications.FirstOrDefault(m => m.Country == certificationCountry)?.Certification;
movie.Ratings = resource.Ratings.Select(MapRatings).FirstOrDefault() ?? new Ratings();
movie.Genres = resource.Genres;
Min availability (#816) * availability specification to prevent downloading titles before their release * pull inCinamas status out of js handlebars and set it in SkyHook * minor code improvement * add incinemas to footer * typo * another typo * release date handling * still print cinema date out for announced titles * revert a minor change from before since its unnecessary * early implementation of minimumAvailability --> when does radarr consider a movie "available" should be specified by user default to "Physical release?" this isn't functional yet, but it has a skeleton + comments. I dont know how to have the minimumavailability attribute default to something or to have it actually populate the Movieinfo object could use some help with that * adding another comment for another location that might need to be updated to handle minimumAvailability * the implementation is now function; however, i still need to specify default values for minimumAvailability * missed these changes in the previous commit * fix rounded corners on new field in editmovie dialog * add minimum availability specification to the addMovie page * minor adjustment from last commit * handle the case where minimumavailability has never yet been set nullstring.. if its never been set, default to Released (Physical/Web) represented by integer value 3 * minAvailability specification on NetImport lists * add support for min availability to the movie editor * use enum MovieStatusType values directly makes for cleaner code * need to fix up the migration forgot in last commit * cleaning up code, proper case * erroneous code added in this feature needed to be removed * update "Wanted" page to take into account minimumAvailability * implement preDB minimumAvailability as default.. behaves same as Physical/Web a few comments with TODO for when preDB is implemented * minor adjustment * remove some unused code (leave commented for now) * improve code for minimumavailability and add option for availabilitydelay (but doesnt do anything yet) * improve isAvailable method * clean up and fix helper info on indexer configuration page * add buttons in Wanted/Missing view
2017-02-23 05:03:48 +00:00
var now = DateTime.Now;
2019-12-22 22:08:53 +00:00
Min availability (#816) * availability specification to prevent downloading titles before their release * pull inCinamas status out of js handlebars and set it in SkyHook * minor code improvement * add incinemas to footer * typo * another typo * release date handling * still print cinema date out for announced titles * revert a minor change from before since its unnecessary * early implementation of minimumAvailability --> when does radarr consider a movie "available" should be specified by user default to "Physical release?" this isn't functional yet, but it has a skeleton + comments. I dont know how to have the minimumavailability attribute default to something or to have it actually populate the Movieinfo object could use some help with that * adding another comment for another location that might need to be updated to handle minimumAvailability * the implementation is now function; however, i still need to specify default values for minimumAvailability * missed these changes in the previous commit * fix rounded corners on new field in editmovie dialog * add minimum availability specification to the addMovie page * minor adjustment from last commit * handle the case where minimumavailability has never yet been set nullstring.. if its never been set, default to Released (Physical/Web) represented by integer value 3 * minAvailability specification on NetImport lists * add support for min availability to the movie editor * use enum MovieStatusType values directly makes for cleaner code * need to fix up the migration forgot in last commit * cleaning up code, proper case * erroneous code added in this feature needed to be removed * update "Wanted" page to take into account minimumAvailability * implement preDB minimumAvailability as default.. behaves same as Physical/Web a few comments with TODO for when preDB is implemented * minor adjustment * remove some unused code (leave commented for now) * improve code for minimumavailability and add option for availabilitydelay (but doesnt do anything yet) * improve isAvailable method * clean up and fix helper info on indexer configuration page * add buttons in Wanted/Missing view
2017-02-23 05:03:48 +00:00
//handle the case when we have both theatrical and physical release dates
if (resource.InCinema.HasValue && resource.PhysicalRelease.HasValue)
Min availability (#816) * availability specification to prevent downloading titles before their release * pull inCinamas status out of js handlebars and set it in SkyHook * minor code improvement * add incinemas to footer * typo * another typo * release date handling * still print cinema date out for announced titles * revert a minor change from before since its unnecessary * early implementation of minimumAvailability --> when does radarr consider a movie "available" should be specified by user default to "Physical release?" this isn't functional yet, but it has a skeleton + comments. I dont know how to have the minimumavailability attribute default to something or to have it actually populate the Movieinfo object could use some help with that * adding another comment for another location that might need to be updated to handle minimumAvailability * the implementation is now function; however, i still need to specify default values for minimumAvailability * missed these changes in the previous commit * fix rounded corners on new field in editmovie dialog * add minimum availability specification to the addMovie page * minor adjustment from last commit * handle the case where minimumavailability has never yet been set nullstring.. if its never been set, default to Released (Physical/Web) represented by integer value 3 * minAvailability specification on NetImport lists * add support for min availability to the movie editor * use enum MovieStatusType values directly makes for cleaner code * need to fix up the migration forgot in last commit * cleaning up code, proper case * erroneous code added in this feature needed to be removed * update "Wanted" page to take into account minimumAvailability * implement preDB minimumAvailability as default.. behaves same as Physical/Web a few comments with TODO for when preDB is implemented * minor adjustment * remove some unused code (leave commented for now) * improve code for minimumavailability and add option for availabilitydelay (but doesnt do anything yet) * improve isAvailable method * clean up and fix helper info on indexer configuration page * add buttons in Wanted/Missing view
2017-02-23 05:03:48 +00:00
{
if (now < resource.InCinema)
2019-12-22 22:08:53 +00:00
{
Min availability (#816) * availability specification to prevent downloading titles before their release * pull inCinamas status out of js handlebars and set it in SkyHook * minor code improvement * add incinemas to footer * typo * another typo * release date handling * still print cinema date out for announced titles * revert a minor change from before since its unnecessary * early implementation of minimumAvailability --> when does radarr consider a movie "available" should be specified by user default to "Physical release?" this isn't functional yet, but it has a skeleton + comments. I dont know how to have the minimumavailability attribute default to something or to have it actually populate the Movieinfo object could use some help with that * adding another comment for another location that might need to be updated to handle minimumAvailability * the implementation is now function; however, i still need to specify default values for minimumAvailability * missed these changes in the previous commit * fix rounded corners on new field in editmovie dialog * add minimum availability specification to the addMovie page * minor adjustment from last commit * handle the case where minimumavailability has never yet been set nullstring.. if its never been set, default to Released (Physical/Web) represented by integer value 3 * minAvailability specification on NetImport lists * add support for min availability to the movie editor * use enum MovieStatusType values directly makes for cleaner code * need to fix up the migration forgot in last commit * cleaning up code, proper case * erroneous code added in this feature needed to be removed * update "Wanted" page to take into account minimumAvailability * implement preDB minimumAvailability as default.. behaves same as Physical/Web a few comments with TODO for when preDB is implemented * minor adjustment * remove some unused code (leave commented for now) * improve code for minimumavailability and add option for availabilitydelay (but doesnt do anything yet) * improve isAvailable method * clean up and fix helper info on indexer configuration page * add buttons in Wanted/Missing view
2017-02-23 05:03:48 +00:00
movie.Status = MovieStatusType.Announced;
2019-12-22 22:08:53 +00:00
}
else if (now >= resource.InCinema)
2019-12-22 22:08:53 +00:00
{
Min availability (#816) * availability specification to prevent downloading titles before their release * pull inCinamas status out of js handlebars and set it in SkyHook * minor code improvement * add incinemas to footer * typo * another typo * release date handling * still print cinema date out for announced titles * revert a minor change from before since its unnecessary * early implementation of minimumAvailability --> when does radarr consider a movie "available" should be specified by user default to "Physical release?" this isn't functional yet, but it has a skeleton + comments. I dont know how to have the minimumavailability attribute default to something or to have it actually populate the Movieinfo object could use some help with that * adding another comment for another location that might need to be updated to handle minimumAvailability * the implementation is now function; however, i still need to specify default values for minimumAvailability * missed these changes in the previous commit * fix rounded corners on new field in editmovie dialog * add minimum availability specification to the addMovie page * minor adjustment from last commit * handle the case where minimumavailability has never yet been set nullstring.. if its never been set, default to Released (Physical/Web) represented by integer value 3 * minAvailability specification on NetImport lists * add support for min availability to the movie editor * use enum MovieStatusType values directly makes for cleaner code * need to fix up the migration forgot in last commit * cleaning up code, proper case * erroneous code added in this feature needed to be removed * update "Wanted" page to take into account minimumAvailability * implement preDB minimumAvailability as default.. behaves same as Physical/Web a few comments with TODO for when preDB is implemented * minor adjustment * remove some unused code (leave commented for now) * improve code for minimumavailability and add option for availabilitydelay (but doesnt do anything yet) * improve isAvailable method * clean up and fix helper info on indexer configuration page * add buttons in Wanted/Missing view
2017-02-23 05:03:48 +00:00
movie.Status = MovieStatusType.InCinemas;
2019-12-22 22:08:53 +00:00
}
if (now >= resource.PhysicalRelease)
2019-12-22 22:08:53 +00:00
{
Min availability (#816) * availability specification to prevent downloading titles before their release * pull inCinamas status out of js handlebars and set it in SkyHook * minor code improvement * add incinemas to footer * typo * another typo * release date handling * still print cinema date out for announced titles * revert a minor change from before since its unnecessary * early implementation of minimumAvailability --> when does radarr consider a movie "available" should be specified by user default to "Physical release?" this isn't functional yet, but it has a skeleton + comments. I dont know how to have the minimumavailability attribute default to something or to have it actually populate the Movieinfo object could use some help with that * adding another comment for another location that might need to be updated to handle minimumAvailability * the implementation is now function; however, i still need to specify default values for minimumAvailability * missed these changes in the previous commit * fix rounded corners on new field in editmovie dialog * add minimum availability specification to the addMovie page * minor adjustment from last commit * handle the case where minimumavailability has never yet been set nullstring.. if its never been set, default to Released (Physical/Web) represented by integer value 3 * minAvailability specification on NetImport lists * add support for min availability to the movie editor * use enum MovieStatusType values directly makes for cleaner code * need to fix up the migration forgot in last commit * cleaning up code, proper case * erroneous code added in this feature needed to be removed * update "Wanted" page to take into account minimumAvailability * implement preDB minimumAvailability as default.. behaves same as Physical/Web a few comments with TODO for when preDB is implemented * minor adjustment * remove some unused code (leave commented for now) * improve code for minimumavailability and add option for availabilitydelay (but doesnt do anything yet) * improve isAvailable method * clean up and fix helper info on indexer configuration page * add buttons in Wanted/Missing view
2017-02-23 05:03:48 +00:00
movie.Status = MovieStatusType.Released;
2019-12-22 22:08:53 +00:00
}
Min availability (#816) * availability specification to prevent downloading titles before their release * pull inCinamas status out of js handlebars and set it in SkyHook * minor code improvement * add incinemas to footer * typo * another typo * release date handling * still print cinema date out for announced titles * revert a minor change from before since its unnecessary * early implementation of minimumAvailability --> when does radarr consider a movie "available" should be specified by user default to "Physical release?" this isn't functional yet, but it has a skeleton + comments. I dont know how to have the minimumavailability attribute default to something or to have it actually populate the Movieinfo object could use some help with that * adding another comment for another location that might need to be updated to handle minimumAvailability * the implementation is now function; however, i still need to specify default values for minimumAvailability * missed these changes in the previous commit * fix rounded corners on new field in editmovie dialog * add minimum availability specification to the addMovie page * minor adjustment from last commit * handle the case where minimumavailability has never yet been set nullstring.. if its never been set, default to Released (Physical/Web) represented by integer value 3 * minAvailability specification on NetImport lists * add support for min availability to the movie editor * use enum MovieStatusType values directly makes for cleaner code * need to fix up the migration forgot in last commit * cleaning up code, proper case * erroneous code added in this feature needed to be removed * update "Wanted" page to take into account minimumAvailability * implement preDB minimumAvailability as default.. behaves same as Physical/Web a few comments with TODO for when preDB is implemented * minor adjustment * remove some unused code (leave commented for now) * improve code for minimumavailability and add option for availabilitydelay (but doesnt do anything yet) * improve isAvailable method * clean up and fix helper info on indexer configuration page * add buttons in Wanted/Missing view
2017-02-23 05:03:48 +00:00
}
2019-12-22 22:08:53 +00:00
Min availability (#816) * availability specification to prevent downloading titles before their release * pull inCinamas status out of js handlebars and set it in SkyHook * minor code improvement * add incinemas to footer * typo * another typo * release date handling * still print cinema date out for announced titles * revert a minor change from before since its unnecessary * early implementation of minimumAvailability --> when does radarr consider a movie "available" should be specified by user default to "Physical release?" this isn't functional yet, but it has a skeleton + comments. I dont know how to have the minimumavailability attribute default to something or to have it actually populate the Movieinfo object could use some help with that * adding another comment for another location that might need to be updated to handle minimumAvailability * the implementation is now function; however, i still need to specify default values for minimumAvailability * missed these changes in the previous commit * fix rounded corners on new field in editmovie dialog * add minimum availability specification to the addMovie page * minor adjustment from last commit * handle the case where minimumavailability has never yet been set nullstring.. if its never been set, default to Released (Physical/Web) represented by integer value 3 * minAvailability specification on NetImport lists * add support for min availability to the movie editor * use enum MovieStatusType values directly makes for cleaner code * need to fix up the migration forgot in last commit * cleaning up code, proper case * erroneous code added in this feature needed to be removed * update "Wanted" page to take into account minimumAvailability * implement preDB minimumAvailability as default.. behaves same as Physical/Web a few comments with TODO for when preDB is implemented * minor adjustment * remove some unused code (leave commented for now) * improve code for minimumavailability and add option for availabilitydelay (but doesnt do anything yet) * improve isAvailable method * clean up and fix helper info on indexer configuration page * add buttons in Wanted/Missing view
2017-02-23 05:03:48 +00:00
//handle the case when we have theatrical release dates but we dont know the physical release date
else if (resource.InCinema.HasValue && (now >= resource.InCinema))
Min availability (#816) * availability specification to prevent downloading titles before their release * pull inCinamas status out of js handlebars and set it in SkyHook * minor code improvement * add incinemas to footer * typo * another typo * release date handling * still print cinema date out for announced titles * revert a minor change from before since its unnecessary * early implementation of minimumAvailability --> when does radarr consider a movie "available" should be specified by user default to "Physical release?" this isn't functional yet, but it has a skeleton + comments. I dont know how to have the minimumavailability attribute default to something or to have it actually populate the Movieinfo object could use some help with that * adding another comment for another location that might need to be updated to handle minimumAvailability * the implementation is now function; however, i still need to specify default values for minimumAvailability * missed these changes in the previous commit * fix rounded corners on new field in editmovie dialog * add minimum availability specification to the addMovie page * minor adjustment from last commit * handle the case where minimumavailability has never yet been set nullstring.. if its never been set, default to Released (Physical/Web) represented by integer value 3 * minAvailability specification on NetImport lists * add support for min availability to the movie editor * use enum MovieStatusType values directly makes for cleaner code * need to fix up the migration forgot in last commit * cleaning up code, proper case * erroneous code added in this feature needed to be removed * update "Wanted" page to take into account minimumAvailability * implement preDB minimumAvailability as default.. behaves same as Physical/Web a few comments with TODO for when preDB is implemented * minor adjustment * remove some unused code (leave commented for now) * improve code for minimumavailability and add option for availabilitydelay (but doesnt do anything yet) * improve isAvailable method * clean up and fix helper info on indexer configuration page * add buttons in Wanted/Missing view
2017-02-23 05:03:48 +00:00
{
movie.Status = MovieStatusType.InCinemas;
}
2019-12-22 22:08:53 +00:00
Min availability (#816) * availability specification to prevent downloading titles before their release * pull inCinamas status out of js handlebars and set it in SkyHook * minor code improvement * add incinemas to footer * typo * another typo * release date handling * still print cinema date out for announced titles * revert a minor change from before since its unnecessary * early implementation of minimumAvailability --> when does radarr consider a movie "available" should be specified by user default to "Physical release?" this isn't functional yet, but it has a skeleton + comments. I dont know how to have the minimumavailability attribute default to something or to have it actually populate the Movieinfo object could use some help with that * adding another comment for another location that might need to be updated to handle minimumAvailability * the implementation is now function; however, i still need to specify default values for minimumAvailability * missed these changes in the previous commit * fix rounded corners on new field in editmovie dialog * add minimum availability specification to the addMovie page * minor adjustment from last commit * handle the case where minimumavailability has never yet been set nullstring.. if its never been set, default to Released (Physical/Web) represented by integer value 3 * minAvailability specification on NetImport lists * add support for min availability to the movie editor * use enum MovieStatusType values directly makes for cleaner code * need to fix up the migration forgot in last commit * cleaning up code, proper case * erroneous code added in this feature needed to be removed * update "Wanted" page to take into account minimumAvailability * implement preDB minimumAvailability as default.. behaves same as Physical/Web a few comments with TODO for when preDB is implemented * minor adjustment * remove some unused code (leave commented for now) * improve code for minimumavailability and add option for availabilitydelay (but doesnt do anything yet) * improve isAvailable method * clean up and fix helper info on indexer configuration page * add buttons in Wanted/Missing view
2017-02-23 05:03:48 +00:00
//handle the case where we only have a physical release date
else if ((resource.PhysicalRelease.HasValue && (now >= resource.PhysicalRelease)) || (resource.DigitalRelease.HasValue && (now >= resource.DigitalRelease)))
{
movie.Status = MovieStatusType.Released;
}
2019-12-22 22:08:53 +00:00
Min availability (#816) * availability specification to prevent downloading titles before their release * pull inCinamas status out of js handlebars and set it in SkyHook * minor code improvement * add incinemas to footer * typo * another typo * release date handling * still print cinema date out for announced titles * revert a minor change from before since its unnecessary * early implementation of minimumAvailability --> when does radarr consider a movie "available" should be specified by user default to "Physical release?" this isn't functional yet, but it has a skeleton + comments. I dont know how to have the minimumavailability attribute default to something or to have it actually populate the Movieinfo object could use some help with that * adding another comment for another location that might need to be updated to handle minimumAvailability * the implementation is now function; however, i still need to specify default values for minimumAvailability * missed these changes in the previous commit * fix rounded corners on new field in editmovie dialog * add minimum availability specification to the addMovie page * minor adjustment from last commit * handle the case where minimumavailability has never yet been set nullstring.. if its never been set, default to Released (Physical/Web) represented by integer value 3 * minAvailability specification on NetImport lists * add support for min availability to the movie editor * use enum MovieStatusType values directly makes for cleaner code * need to fix up the migration forgot in last commit * cleaning up code, proper case * erroneous code added in this feature needed to be removed * update "Wanted" page to take into account minimumAvailability * implement preDB minimumAvailability as default.. behaves same as Physical/Web a few comments with TODO for when preDB is implemented * minor adjustment * remove some unused code (leave commented for now) * improve code for minimumavailability and add option for availabilitydelay (but doesnt do anything yet) * improve isAvailable method * clean up and fix helper info on indexer configuration page * add buttons in Wanted/Missing view
2017-02-23 05:03:48 +00:00
//otherwise the title has only been announced
else
{
2019-12-22 21:24:10 +00:00
movie.Status = MovieStatusType.Announced;
}
Min availability (#816) * availability specification to prevent downloading titles before their release * pull inCinamas status out of js handlebars and set it in SkyHook * minor code improvement * add incinemas to footer * typo * another typo * release date handling * still print cinema date out for announced titles * revert a minor change from before since its unnecessary * early implementation of minimumAvailability --> when does radarr consider a movie "available" should be specified by user default to "Physical release?" this isn't functional yet, but it has a skeleton + comments. I dont know how to have the minimumavailability attribute default to something or to have it actually populate the Movieinfo object could use some help with that * adding another comment for another location that might need to be updated to handle minimumAvailability * the implementation is now function; however, i still need to specify default values for minimumAvailability * missed these changes in the previous commit * fix rounded corners on new field in editmovie dialog * add minimum availability specification to the addMovie page * minor adjustment from last commit * handle the case where minimumavailability has never yet been set nullstring.. if its never been set, default to Released (Physical/Web) represented by integer value 3 * minAvailability specification on NetImport lists * add support for min availability to the movie editor * use enum MovieStatusType values directly makes for cleaner code * need to fix up the migration forgot in last commit * cleaning up code, proper case * erroneous code added in this feature needed to be removed * update "Wanted" page to take into account minimumAvailability * implement preDB minimumAvailability as default.. behaves same as Physical/Web a few comments with TODO for when preDB is implemented * minor adjustment * remove some unused code (leave commented for now) * improve code for minimumavailability and add option for availabilitydelay (but doesnt do anything yet) * improve isAvailable method * clean up and fix helper info on indexer configuration page * add buttons in Wanted/Missing view
2017-02-23 05:03:48 +00:00
//since TMDB lacks alot of information lets assume that stuff is released if its been in cinemas for longer than 3 months.
2019-12-22 22:08:53 +00:00
if (!movie.PhysicalRelease.HasValue && (movie.Status == MovieStatusType.InCinemas) && (DateTime.Now.Subtract(movie.InCinemas.Value).TotalSeconds > 60 * 60 * 24 * 30 * 3))
Min availability (#816) * availability specification to prevent downloading titles before their release * pull inCinamas status out of js handlebars and set it in SkyHook * minor code improvement * add incinemas to footer * typo * another typo * release date handling * still print cinema date out for announced titles * revert a minor change from before since its unnecessary * early implementation of minimumAvailability --> when does radarr consider a movie "available" should be specified by user default to "Physical release?" this isn't functional yet, but it has a skeleton + comments. I dont know how to have the minimumavailability attribute default to something or to have it actually populate the Movieinfo object could use some help with that * adding another comment for another location that might need to be updated to handle minimumAvailability * the implementation is now function; however, i still need to specify default values for minimumAvailability * missed these changes in the previous commit * fix rounded corners on new field in editmovie dialog * add minimum availability specification to the addMovie page * minor adjustment from last commit * handle the case where minimumavailability has never yet been set nullstring.. if its never been set, default to Released (Physical/Web) represented by integer value 3 * minAvailability specification on NetImport lists * add support for min availability to the movie editor * use enum MovieStatusType values directly makes for cleaner code * need to fix up the migration forgot in last commit * cleaning up code, proper case * erroneous code added in this feature needed to be removed * update "Wanted" page to take into account minimumAvailability * implement preDB minimumAvailability as default.. behaves same as Physical/Web a few comments with TODO for when preDB is implemented * minor adjustment * remove some unused code (leave commented for now) * improve code for minimumavailability and add option for availabilitydelay (but doesnt do anything yet) * improve isAvailable method * clean up and fix helper info on indexer configuration page * add buttons in Wanted/Missing view
2017-02-23 05:03:48 +00:00
{
movie.Status = MovieStatusType.Released;
}
2020-05-10 01:49:09 +00:00
movie.YouTubeTrailerId = resource.YoutubeTrailerId;
movie.Studio = resource.Studio;
2020-05-10 01:49:09 +00:00
if (movie.Collection != null)
{
2020-05-10 01:49:09 +00:00
movie.Collection = new MovieCollection { Name = resource.Collection.Name, TmdbId = resource.Collection.TmdbId };
}
2020-05-10 01:49:09 +00:00
return movie;
}
private string StripTrailingTheFromTitle(string title)
{
if (title.EndsWith(",the"))
{
2020-05-10 01:49:09 +00:00
title = title.Substring(0, title.Length - 4);
}
2020-05-10 01:49:09 +00:00
else if (title.EndsWith(", the"))
{
2020-05-10 01:49:09 +00:00
title = title.Substring(0, title.Length - 5);
}
2020-05-10 01:49:09 +00:00
return title;
}
public Movie MapMovieToTmdbMovie(Movie movie)
{
2020-05-10 01:49:09 +00:00
try
{
2020-05-10 01:49:09 +00:00
Movie newMovie = movie;
if (movie.TmdbId > 0)
2019-12-17 02:44:59 +00:00
{
newMovie = GetMovieInfo(movie.TmdbId).Item1;
2019-12-17 02:44:59 +00:00
}
2020-05-10 01:49:09 +00:00
else if (movie.ImdbId.IsNotNullOrWhiteSpace())
2019-12-17 02:44:59 +00:00
{
2020-05-10 01:49:09 +00:00
newMovie = GetMovieByImdbId(movie.ImdbId);
2019-12-17 02:44:59 +00:00
}
2020-05-10 01:49:09 +00:00
else
2019-07-10 03:14:53 +00:00
{
2020-05-10 01:49:09 +00:00
var yearStr = "";
if (movie.Year > 1900)
{
yearStr = $" {movie.Year}";
}
2020-05-10 01:49:09 +00:00
newMovie = SearchForNewMovie(movie.Title + yearStr).FirstOrDefault();
}
2020-05-10 01:49:09 +00:00
if (newMovie == null)
{
2020-05-10 01:49:09 +00:00
_logger.Warn("Couldn't map movie {0} to a movie on The Movie DB. It will not be added :(", movie.Title);
return null;
}
2020-05-10 01:49:09 +00:00
newMovie.Path = movie.Path;
newMovie.RootFolderPath = movie.RootFolderPath;
newMovie.ProfileId = movie.ProfileId;
newMovie.Monitored = movie.Monitored;
newMovie.MovieFile = movie.MovieFile;
newMovie.MinimumAvailability = movie.MinimumAvailability;
newMovie.Tags = movie.Tags;
2020-05-10 01:49:09 +00:00
return newMovie;
2019-12-22 22:08:53 +00:00
}
2020-05-10 01:49:09 +00:00
catch (Exception ex)
{
2020-05-10 01:49:09 +00:00
_logger.Warn(ex, "Couldn't map movie {0} to a movie on The Movie DB. It will not be added :(", movie.Title);
return null;
}
}
public List<Movie> SearchForNewMovie(string title)
{
2019-12-17 02:44:59 +00:00
try
{
var lowerTitle = title.ToLower();
2019-12-17 02:44:59 +00:00
lowerTitle = lowerTitle.Replace(".", "");
2019-12-17 02:44:59 +00:00
var parserResult = Parser.Parser.ParseMovieTitle(title, true, true);
2019-12-17 02:44:59 +00:00
var yearTerm = "";
2019-12-17 02:44:59 +00:00
if (parserResult != null && parserResult.MovieTitle != title)
{
2019-12-17 02:44:59 +00:00
//Parser found something interesting!
lowerTitle = parserResult.MovieTitle.ToLower().Replace(".", " "); //TODO Update so not every period gets replaced (e.g. R.I.P.D.)
if (parserResult.Year > 1800)
{
2019-12-17 02:44:59 +00:00
yearTerm = parserResult.Year.ToString();
}
2019-12-17 02:44:59 +00:00
if (parserResult.ImdbId.IsNotNullOrWhiteSpace())
{
2019-12-17 02:44:59 +00:00
try
{
2020-05-10 01:49:09 +00:00
return new List<Movie> { GetMovieByImdbId(parserResult.ImdbId) };
2019-12-17 02:44:59 +00:00
}
catch (Exception)
{
return new List<Movie>();
}
}
}
2019-12-17 02:44:59 +00:00
lowerTitle = StripTrailingTheFromTitle(lowerTitle);
2019-12-17 02:44:59 +00:00
if (lowerTitle.StartsWith("imdb:") || lowerTitle.StartsWith("imdbid:"))
{
var slug = lowerTitle.Split(':')[1].Trim();
2019-12-17 02:44:59 +00:00
string imdbid = slug;
2019-12-17 02:44:59 +00:00
if (slug.IsNullOrWhiteSpace() || slug.Any(char.IsWhiteSpace))
{
return new List<Movie>();
}
2015-01-09 01:43:51 +00:00
2019-12-17 02:44:59 +00:00
try
{
2020-05-10 01:49:09 +00:00
return new List<Movie> { GetMovieByImdbId(imdbid) };
2019-12-17 02:44:59 +00:00
}
catch (MovieNotFoundException)
{
return new List<Movie>();
}
}
2019-12-17 02:44:59 +00:00
if (lowerTitle.StartsWith("tmdb:") || lowerTitle.StartsWith("tmdbid:"))
{
var slug = lowerTitle.Split(':')[1].Trim();
2019-12-17 02:44:59 +00:00
int tmdbid = -1;
2019-12-22 22:08:53 +00:00
if (slug.IsNullOrWhiteSpace() || slug.Any(char.IsWhiteSpace) || !int.TryParse(slug, out tmdbid))
2019-12-17 02:44:59 +00:00
{
return new List<Movie>();
}
2019-12-17 02:44:59 +00:00
try
{
2020-05-10 01:49:09 +00:00
return new List<Movie> { GetMovieInfo(tmdbid).Item1 };
2019-12-17 02:44:59 +00:00
}
catch (MovieNotFoundException)
{
return new List<Movie>();
}
}
2019-12-17 02:44:59 +00:00
var searchTerm = lowerTitle.Replace("_", "+").Replace(" ", "+").Replace(".", "+");
2019-12-17 02:44:59 +00:00
var firstChar = searchTerm.First();
2020-05-10 01:49:09 +00:00
var request = _radarrMetadata.Create()
2019-12-17 02:44:59 +00:00
.SetSegment("route", "search")
2020-05-10 01:49:09 +00:00
.AddQueryParam("q", searchTerm)
2019-12-17 02:44:59 +00:00
.AddQueryParam("year", yearTerm)
.Build();
2019-12-17 02:44:59 +00:00
request.AllowAutoRedirect = true;
request.SuppressHttpError = true;
2020-05-10 01:49:09 +00:00
var httpResponse = _httpClient.Get<List<MovieResource>>(request);
2020-05-10 01:49:09 +00:00
return httpResponse.Resource.SelectList(MapSearchResult);
2019-12-17 02:44:59 +00:00
}
catch (HttpException)
{
throw new SkyHookException("Search for '{0}' failed. Unable to communicate with TMDb.", title);
}
catch (Exception ex)
{
_logger.Warn(ex, ex.Message);
throw new SkyHookException("Search for '{0}' failed. Invalid response received from TMDb.", title);
}
2015-01-09 01:43:51 +00:00
}
2020-05-10 01:49:09 +00:00
private Movie MapSearchResult(MovieResource result)
{
2020-05-10 01:49:09 +00:00
var movie = _movieService.FindByTmdbId(result.TmdbId);
if (movie == null)
{
movie = MapMovie(result);
}
return movie;
}
private static Credit MapCast(CastResource arg)
2015-01-09 01:43:51 +00:00
{
var newActor = new Credit
2015-01-09 01:43:51 +00:00
{
Name = arg.Name,
Character = arg.Character,
Order = arg.Order,
2020-05-10 01:49:09 +00:00
CreditTmdbId = arg.CreditId,
PersonTmdbId = arg.TmdbId,
Type = CreditType.Cast,
Images = arg.Images.Select(MapImage).ToList()
2015-01-09 01:43:51 +00:00
};
return newActor;
}
private static Credit MapCrew(CrewResource arg)
2015-01-09 01:43:51 +00:00
{
var newActor = new Credit
2015-01-09 01:43:51 +00:00
{
Name = arg.Name,
Department = arg.Department,
Job = arg.Job,
2020-05-10 01:49:09 +00:00
CreditTmdbId = arg.CreditId,
PersonTmdbId = arg.TmdbId,
Type = CreditType.Crew,
Images = arg.Images.Select(MapImage).ToList()
};
2015-01-09 01:43:51 +00:00
2020-05-10 01:49:09 +00:00
return newActor;
}
private static AlternativeTitle MapAlternativeTitle(AlternativeTitleResource arg)
{
var newAlternativeTitle = new AlternativeTitle
2015-01-09 01:43:51 +00:00
{
2020-05-10 01:49:09 +00:00
Title = arg.Title,
SourceType = SourceType.TMDB,
CleanTitle = arg.Title.CleanSeriesTitle(),
Language = IsoLanguages.Find(arg.Language.ToLower())?.Language ?? Language.English
};
2020-05-10 01:49:09 +00:00
return newAlternativeTitle;
2015-01-09 01:43:51 +00:00
}
2020-05-10 01:49:09 +00:00
private static Ratings MapRatings(RatingResource rating)
{
2020-05-10 01:49:09 +00:00
if (rating == null)
{
2020-05-10 01:49:09 +00:00
return new Ratings();
}
2020-05-10 01:49:09 +00:00
return new Ratings
{
Votes = rating.Count,
Value = rating.Value
};
}
2020-05-10 01:49:09 +00:00
private static MediaCover.MediaCover MapImage(ImageResource arg)
{
2020-05-10 01:49:09 +00:00
return new MediaCover.MediaCover
2019-12-22 21:24:10 +00:00
{
2020-05-10 01:49:09 +00:00
Url = arg.Url,
CoverType = MapCoverType(arg.CoverType)
};
}
2019-12-22 21:24:10 +00:00
2020-05-10 01:49:09 +00:00
private static MediaCoverTypes MapCoverType(string coverType)
{
switch (coverType.ToLower())
{
case "poster":
return MediaCoverTypes.Poster;
case "headshot":
return MediaCoverTypes.Headshot;
case "fanart":
return MediaCoverTypes.Fanart;
default:
return MediaCoverTypes.Unknown;
2019-12-22 21:24:10 +00:00
}
}
2015-01-09 01:43:51 +00:00
}
}