|
|
|
@ -1,9 +1,7 @@
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using NLog;
|
|
|
|
|
using NzbDrone.Common.Cloud;
|
|
|
|
|
using NzbDrone.Common.Extensions;
|
|
|
|
@ -12,48 +10,37 @@ using NzbDrone.Core.Configuration;
|
|
|
|
|
using NzbDrone.Core.Exceptions;
|
|
|
|
|
using NzbDrone.Core.Languages;
|
|
|
|
|
using NzbDrone.Core.MediaCover;
|
|
|
|
|
using NzbDrone.Core.MetadataSource.PreDB;
|
|
|
|
|
using NzbDrone.Core.MetadataSource.RadarrAPI;
|
|
|
|
|
using NzbDrone.Core.MetadataSource.SkyHook.Resource;
|
|
|
|
|
using NzbDrone.Core.Movies;
|
|
|
|
|
using NzbDrone.Core.Movies.AlternativeTitles;
|
|
|
|
|
using NzbDrone.Core.Movies.Credits;
|
|
|
|
|
using NzbDrone.Core.NetImport.ImportExclusions;
|
|
|
|
|
using NzbDrone.Core.NetImport.TMDb;
|
|
|
|
|
using NzbDrone.Core.Parser;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.MetadataSource.SkyHook
|
|
|
|
|
{
|
|
|
|
|
public class SkyHookProxy : IProvideMovieInfo, ISearchForNewMovie, IDiscoverNewMovies
|
|
|
|
|
public class SkyHookProxy : IProvideMovieInfo, ISearchForNewMovie
|
|
|
|
|
{
|
|
|
|
|
private readonly IHttpClient _httpClient;
|
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
|
|
|
|
|
private readonly IHttpRequestBuilderFactory _movieBuilder;
|
|
|
|
|
private readonly ITmdbConfigService _tmdbConfigService;
|
|
|
|
|
private readonly IHttpRequestBuilderFactory _radarrMetadata;
|
|
|
|
|
private readonly IConfigService _configService;
|
|
|
|
|
private readonly IMovieService _movieService;
|
|
|
|
|
private readonly IPreDBService _predbService;
|
|
|
|
|
private readonly IImportExclusionsService _exclusionService;
|
|
|
|
|
private readonly IRadarrAPIClient _radarrAPI;
|
|
|
|
|
|
|
|
|
|
public SkyHookProxy(IHttpClient httpClient,
|
|
|
|
|
IRadarrCloudRequestBuilder requestBuilder,
|
|
|
|
|
ITmdbConfigService tmdbConfigService,
|
|
|
|
|
IConfigService configService,
|
|
|
|
|
IMovieService movieService,
|
|
|
|
|
IPreDBService predbService,
|
|
|
|
|
IImportExclusionsService exclusionService,
|
|
|
|
|
IRadarrAPIClient radarrAPI,
|
|
|
|
|
Logger logger)
|
|
|
|
|
{
|
|
|
|
|
_httpClient = httpClient;
|
|
|
|
|
_movieBuilder = requestBuilder.TMDB;
|
|
|
|
|
_tmdbConfigService = tmdbConfigService;
|
|
|
|
|
_radarrMetadata = requestBuilder.RadarrMetadata;
|
|
|
|
|
_configService = configService;
|
|
|
|
|
_movieService = movieService;
|
|
|
|
|
_predbService = predbService;
|
|
|
|
|
_exclusionService = exclusionService;
|
|
|
|
|
_radarrAPI = radarrAPI;
|
|
|
|
|
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
@ -75,149 +62,111 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
|
|
|
|
|
|
|
|
|
var response = _httpClient.Get<MovieSearchRoot>(request);
|
|
|
|
|
|
|
|
|
|
return new HashSet<int>(response.Resource.results.Select(c => c.id));
|
|
|
|
|
return new HashSet<int>(response.Resource.Results.Select(c => c.id));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Tuple<Movie, List<Credit>> GetMovieInfo(int tmdbId, bool hasPreDBEntry)
|
|
|
|
|
public Tuple<Movie, List<Credit>> GetMovieInfo(int tmdbId)
|
|
|
|
|
{
|
|
|
|
|
var langCode = "en";
|
|
|
|
|
var httpRequest = _radarrMetadata.Create()
|
|
|
|
|
.SetSegment("route", "movie")
|
|
|
|
|
.Resource(tmdbId.ToString())
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var request = _movieBuilder.Create()
|
|
|
|
|
.SetSegment("api", "3")
|
|
|
|
|
.SetSegment("route", "movie")
|
|
|
|
|
.SetSegment("id", tmdbId.ToString())
|
|
|
|
|
.SetSegment("secondaryRoute", "")
|
|
|
|
|
.AddQueryParam("append_to_response", "alternative_titles,release_dates,videos,credits")
|
|
|
|
|
.AddQueryParam("language", langCode.ToUpper())
|
|
|
|
|
|
|
|
|
|
// .AddQueryParam("country", "US")
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
request.AllowAutoRedirect = true;
|
|
|
|
|
request.SuppressHttpError = true;
|
|
|
|
|
httpRequest.AllowAutoRedirect = true;
|
|
|
|
|
httpRequest.SuppressHttpError = true;
|
|
|
|
|
|
|
|
|
|
var response = _httpClient.Get<MovieResourceRoot>(request);
|
|
|
|
|
var httpResponse = _httpClient.Get<MovieResource>(httpRequest);
|
|
|
|
|
|
|
|
|
|
if (response.StatusCode == HttpStatusCode.NotFound)
|
|
|
|
|
if (httpResponse.HasHttpError)
|
|
|
|
|
{
|
|
|
|
|
throw new MovieNotFoundException(tmdbId);
|
|
|
|
|
if (httpResponse.StatusCode == HttpStatusCode.NotFound)
|
|
|
|
|
{
|
|
|
|
|
throw new MovieNotFoundException(tmdbId);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw new HttpException(httpRequest, httpResponse);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (response.StatusCode != HttpStatusCode.OK)
|
|
|
|
|
{
|
|
|
|
|
throw new HttpException(request, response);
|
|
|
|
|
}
|
|
|
|
|
var credits = new List<Credit>();
|
|
|
|
|
credits.AddRange(httpResponse.Resource.Credits.Cast.Select(MapCast));
|
|
|
|
|
credits.AddRange(httpResponse.Resource.Credits.Crew.Select(MapCrew));
|
|
|
|
|
|
|
|
|
|
if (response.Headers.ContentType != HttpAccept.JsonCharset.Value)
|
|
|
|
|
{
|
|
|
|
|
throw new HttpException(request, response);
|
|
|
|
|
}
|
|
|
|
|
var movie = MapMovie(httpResponse.Resource);
|
|
|
|
|
|
|
|
|
|
// The dude abides, so should us, Lets be nice to TMDb
|
|
|
|
|
// var allowed = int.Parse(response.Headers.GetValues("X-RateLimit-Limit").First()); // get allowed
|
|
|
|
|
// var reset = long.Parse(response.Headers.GetValues("X-RateLimit-Reset").First()); // get time when it resets
|
|
|
|
|
if (response.Headers.ContainsKey("X-RateLimit-Remaining"))
|
|
|
|
|
{
|
|
|
|
|
var remaining = int.Parse(response.Headers.GetValues("X-RateLimit-Remaining").First());
|
|
|
|
|
if (remaining <= 5)
|
|
|
|
|
{
|
|
|
|
|
_logger.Trace("Waiting 5 seconds to get information for the next 35 movies");
|
|
|
|
|
Thread.Sleep(5000);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return new Tuple<Movie, List<Credit>>(movie, credits.ToList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var resource = response.Resource;
|
|
|
|
|
if (resource.status_message != null)
|
|
|
|
|
{
|
|
|
|
|
if (resource.status_code == 34)
|
|
|
|
|
{
|
|
|
|
|
_logger.Warn("Movie with TmdbId {0} could not be found. This is probably the case when the movie was deleted from TMDB.", tmdbId);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
public Movie GetMovieByImdbId(string imdbId)
|
|
|
|
|
{
|
|
|
|
|
var httpRequest = _radarrMetadata.Create()
|
|
|
|
|
.SetSegment("route", "movie/imdb")
|
|
|
|
|
.Resource(imdbId.ToString())
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
_logger.Warn(resource.status_message);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
httpRequest.AllowAutoRedirect = true;
|
|
|
|
|
httpRequest.SuppressHttpError = true;
|
|
|
|
|
|
|
|
|
|
var movie = new Movie();
|
|
|
|
|
var altTitles = new List<AlternativeTitle>();
|
|
|
|
|
var httpResponse = _httpClient.Get<List<MovieResource>>(httpRequest);
|
|
|
|
|
|
|
|
|
|
foreach (var alternativeTitle in resource.alternative_titles.titles)
|
|
|
|
|
if (httpResponse.HasHttpError)
|
|
|
|
|
{
|
|
|
|
|
if (alternativeTitle.iso_3166_1.ToLower() == langCode)
|
|
|
|
|
if (httpResponse.StatusCode == HttpStatusCode.NotFound)
|
|
|
|
|
{
|
|
|
|
|
altTitles.Add(new AlternativeTitle(alternativeTitle.title, SourceType.TMDB, tmdbId, IsoLanguages.Find(alternativeTitle.iso_3166_1.ToLower())?.Language ?? Language.English));
|
|
|
|
|
throw new MovieNotFoundException(imdbId);
|
|
|
|
|
}
|
|
|
|
|
else if (alternativeTitle.iso_3166_1.ToLower() == "us")
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
altTitles.Add(new AlternativeTitle(alternativeTitle.title, SourceType.TMDB, tmdbId, Language.English));
|
|
|
|
|
throw new HttpException(httpRequest, httpResponse);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
movie.TmdbId = tmdbId;
|
|
|
|
|
movie.ImdbId = resource.imdb_id;
|
|
|
|
|
movie.Title = resource.title;
|
|
|
|
|
movie.TitleSlug = Parser.Parser.ToUrlSlug(resource.title);
|
|
|
|
|
movie.CleanTitle = resource.title.CleanSeriesTitle();
|
|
|
|
|
movie.SortTitle = Parser.Parser.NormalizeTitle(resource.title);
|
|
|
|
|
movie.Overview = resource.overview;
|
|
|
|
|
movie.Website = resource.homepage;
|
|
|
|
|
var movie = httpResponse.Resource.SelectList(MapMovie).FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
if (resource.release_date.IsNotNullOrWhiteSpace())
|
|
|
|
|
{
|
|
|
|
|
movie.InCinemas = DateTime.Parse(resource.release_date);
|
|
|
|
|
return movie;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
movie.Year = movie.InCinemas.Value.Year;
|
|
|
|
|
}
|
|
|
|
|
public Movie MapMovie(MovieResource resource)
|
|
|
|
|
{
|
|
|
|
|
var movie = new Movie();
|
|
|
|
|
var altTitles = new List<AlternativeTitle>();
|
|
|
|
|
|
|
|
|
|
movie.TitleSlug += "-" + movie.TmdbId.ToString();
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
movie.Images.AddIfNotNull(MapImage(resource.poster_path, MediaCoverTypes.Poster)); //TODO: Update to load image specs from tmdb page!
|
|
|
|
|
movie.Images.AddIfNotNull(MapImage(resource.backdrop_path, MediaCoverTypes.Fanart));
|
|
|
|
|
movie.Runtime = resource.runtime;
|
|
|
|
|
movie.AlternativeTitles.AddRange(resource.AlternativeTitles.Select(MapAlternativeTitle));
|
|
|
|
|
|
|
|
|
|
foreach (var releaseDates in resource.release_dates.results)
|
|
|
|
|
{
|
|
|
|
|
foreach (var releaseDate in releaseDates.release_dates)
|
|
|
|
|
{
|
|
|
|
|
if (releaseDate.type == 5 || releaseDate.type == 4)
|
|
|
|
|
{
|
|
|
|
|
if (movie.PhysicalRelease.HasValue)
|
|
|
|
|
{
|
|
|
|
|
if (movie.PhysicalRelease.Value.After(DateTime.Parse(releaseDate.release_date)))
|
|
|
|
|
{
|
|
|
|
|
movie.PhysicalRelease = DateTime.Parse(releaseDate.release_date); //Use oldest release date available.
|
|
|
|
|
movie.PhysicalReleaseNote = releaseDate.note;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
movie.PhysicalRelease = DateTime.Parse(releaseDate.release_date);
|
|
|
|
|
movie.PhysicalReleaseNote = releaseDate.note;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
movie.Website = resource.Homepage;
|
|
|
|
|
movie.InCinemas = resource.InCinema;
|
|
|
|
|
movie.PhysicalRelease = resource.PhysicalRelease;
|
|
|
|
|
|
|
|
|
|
var countryReleases = resource.release_dates.results.FirstOrDefault(m => m.iso_3166_1 == _configService.CertificationCountry.ToString());
|
|
|
|
|
movie.Year = resource.Year;
|
|
|
|
|
|
|
|
|
|
// Set Certification from Theatrical Release(Type 3), if not fall back to Limited Threatrical(Type 2) and then Premiere(Type 1)
|
|
|
|
|
if (countryReleases != null && countryReleases.release_dates.Any())
|
|
|
|
|
//If the premier differs from the TMDB year, use it as a secondary year.
|
|
|
|
|
if (resource.Premier.HasValue && resource.Premier?.Year != movie.Year)
|
|
|
|
|
{
|
|
|
|
|
var certRelease = countryReleases.release_dates.OrderByDescending(c => c.type).Where(d => d.type <= 3).FirstOrDefault(c => c.certification.IsNotNullOrWhiteSpace());
|
|
|
|
|
|
|
|
|
|
movie.Certification = certRelease?.certification;
|
|
|
|
|
movie.SecondaryYear = resource.Premier?.Year;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
movie.Ratings = new Ratings();
|
|
|
|
|
movie.Ratings.Votes = resource.vote_count;
|
|
|
|
|
movie.Ratings.Value = (decimal)resource.vote_average;
|
|
|
|
|
movie.Images = resource.Images.Select(MapImage).ToList();
|
|
|
|
|
|
|
|
|
|
foreach (var genre in resource.genres)
|
|
|
|
|
if (resource.Runtime != null)
|
|
|
|
|
{
|
|
|
|
|
movie.Genres.Add(genre.name);
|
|
|
|
|
movie.Runtime = resource.Runtime.Value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
var now = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
//handle the case when we have both theatrical and physical release dates
|
|
|
|
@ -262,160 +211,76 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
|
|
|
|
movie.Status = MovieStatusType.Released;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!hasPreDBEntry)
|
|
|
|
|
{
|
|
|
|
|
if (_predbService.HasReleases(movie))
|
|
|
|
|
{
|
|
|
|
|
movie.HasPreDBEntry = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
movie.HasPreDBEntry = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
movie.YouTubeTrailerId = resource.YoutubeTrailerId;
|
|
|
|
|
movie.Studio = resource.Studio;
|
|
|
|
|
|
|
|
|
|
if (resource.videos != null)
|
|
|
|
|
if (movie.Collection != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (Video video in resource.videos.results)
|
|
|
|
|
{
|
|
|
|
|
if (video.type == "Trailer" && video.site == "YouTube")
|
|
|
|
|
{
|
|
|
|
|
if (video.key != null)
|
|
|
|
|
{
|
|
|
|
|
movie.YouTubeTrailerId = video.key;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
movie.Collection = new MovieCollection { Name = resource.Collection.Name, TmdbId = resource.Collection.TmdbId };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (resource.production_companies != null)
|
|
|
|
|
return movie;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string StripTrailingTheFromTitle(string title)
|
|
|
|
|
{
|
|
|
|
|
if (title.EndsWith(",the"))
|
|
|
|
|
{
|
|
|
|
|
if (resource.production_companies.Any())
|
|
|
|
|
{
|
|
|
|
|
movie.Studio = resource.production_companies[0].name;
|
|
|
|
|
}
|
|
|
|
|
title = title.Substring(0, title.Length - 4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
movie.AlternativeTitles.AddRange(altTitles);
|
|
|
|
|
|
|
|
|
|
var people = new List<Credit>();
|
|
|
|
|
|
|
|
|
|
people.AddRange(resource.credits.Cast.Select(MapCast).ToList());
|
|
|
|
|
people.AddRange(resource.credits.Crew.Select(MapCrew).ToList());
|
|
|
|
|
|
|
|
|
|
if (resource.belongs_to_collection != null)
|
|
|
|
|
else if (title.EndsWith(", the"))
|
|
|
|
|
{
|
|
|
|
|
movie.Collection = MapCollection(resource.belongs_to_collection);
|
|
|
|
|
|
|
|
|
|
movie.Collection.Images.AddIfNotNull(MapImage(resource.belongs_to_collection.poster_path, MediaCoverTypes.Poster));
|
|
|
|
|
movie.Collection.Images.AddIfNotNull(MapImage(resource.belongs_to_collection.backdrop_path, MediaCoverTypes.Fanart));
|
|
|
|
|
title = title.Substring(0, title.Length - 5);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new Tuple<Movie, List<Credit>>(movie, people);
|
|
|
|
|
return title;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Movie GetMovieInfo(string imdbId)
|
|
|
|
|
public Movie MapMovieToTmdbMovie(Movie movie)
|
|
|
|
|
{
|
|
|
|
|
var request = _movieBuilder.Create()
|
|
|
|
|
.SetSegment("api", "3")
|
|
|
|
|
.SetSegment("route", "find")
|
|
|
|
|
.SetSegment("id", imdbId)
|
|
|
|
|
.SetSegment("secondaryRoute", "")
|
|
|
|
|
.AddQueryParam("external_source", "imdb_id")
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
request.AllowAutoRedirect = true;
|
|
|
|
|
|
|
|
|
|
// request.SuppressHttpError = true;
|
|
|
|
|
var response = _httpClient.Get<FindRoot>(request);
|
|
|
|
|
|
|
|
|
|
if (response.HasHttpError)
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (response.StatusCode == HttpStatusCode.NotFound)
|
|
|
|
|
Movie newMovie = movie;
|
|
|
|
|
if (movie.TmdbId > 0)
|
|
|
|
|
{
|
|
|
|
|
throw new MovieNotFoundException(imdbId);
|
|
|
|
|
newMovie = GetMovieInfo(movie.TmdbId).Item1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
else if (movie.ImdbId.IsNotNullOrWhiteSpace())
|
|
|
|
|
{
|
|
|
|
|
throw new HttpException(request, response);
|
|
|
|
|
newMovie = GetMovieByImdbId(movie.ImdbId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The dude abides, so should us, Lets be nice to TMDb
|
|
|
|
|
// var allowed = int.Parse(response.Headers.GetValues("X-RateLimit-Limit").First()); // get allowed
|
|
|
|
|
// var reset = long.Parse(response.Headers.GetValues("X-RateLimit-Reset").First()); // get time when it resets
|
|
|
|
|
if (response.Headers.ContainsKey("X-RateLimit-Remaining"))
|
|
|
|
|
{
|
|
|
|
|
var remaining = int.Parse(response.Headers.GetValues("X-RateLimit-Remaining").First());
|
|
|
|
|
if (remaining <= 5)
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_logger.Trace("Waiting 5 seconds to get information for the next 35 movies");
|
|
|
|
|
Thread.Sleep(5000);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!response.Resource.movie_results.Any())
|
|
|
|
|
{
|
|
|
|
|
throw new MovieNotFoundException(imdbId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return MapMovie(response.Resource.movie_results.First());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Movie> DiscoverNewMovies(string action)
|
|
|
|
|
{
|
|
|
|
|
var allMovies = _movieService.GetAllMovies();
|
|
|
|
|
|
|
|
|
|
if (!allMovies.Any())
|
|
|
|
|
{
|
|
|
|
|
_logger.Debug("Skipping discover, no movies in library");
|
|
|
|
|
return new List<Movie>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var allExclusions = _exclusionService.GetAllExclusions();
|
|
|
|
|
var allIds = string.Join(",", allMovies.Select(m => m.TmdbId));
|
|
|
|
|
var ignoredIds = string.Join(",", allExclusions.Select(ex => ex.TmdbId));
|
|
|
|
|
var yearStr = "";
|
|
|
|
|
if (movie.Year > 1900)
|
|
|
|
|
{
|
|
|
|
|
yearStr = $" {movie.Year}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var results = new List<MovieResult>();
|
|
|
|
|
newMovie = SearchForNewMovie(movie.Title + yearStr).FirstOrDefault();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
results = _radarrAPI.DiscoverMovies(action, (request) =>
|
|
|
|
|
if (newMovie == null)
|
|
|
|
|
{
|
|
|
|
|
request.AllowAutoRedirect = true;
|
|
|
|
|
request.Method = HttpMethod.POST;
|
|
|
|
|
request.Headers.ContentType = "application/x-www-form-urlencoded";
|
|
|
|
|
request.SetContent($"tmdbIds={allIds}&ignoredIds={ignoredIds}");
|
|
|
|
|
return request;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
results = results.Where(m => allMovies.None(mo => mo.TmdbId == m.id) && allExclusions.None(ex => ex.TmdbId == m.id)).ToList();
|
|
|
|
|
}
|
|
|
|
|
catch (RadarrAPIException exception)
|
|
|
|
|
{
|
|
|
|
|
_logger.Error(exception, "Failed to discover movies for action {0}!", action);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception exception)
|
|
|
|
|
{
|
|
|
|
|
_logger.Error(exception, "Failed to discover movies for action {0}!", action);
|
|
|
|
|
}
|
|
|
|
|
_logger.Warn("Couldn't map movie {0} to a movie on The Movie DB. It will not be added :(", movie.Title);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return results.SelectList(MapMovie);
|
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
private string StripTrailingTheFromTitle(string title)
|
|
|
|
|
{
|
|
|
|
|
if (title.EndsWith(",the"))
|
|
|
|
|
{
|
|
|
|
|
title = title.Substring(0, title.Length - 4);
|
|
|
|
|
return newMovie;
|
|
|
|
|
}
|
|
|
|
|
else if (title.EndsWith(", the"))
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
title = title.Substring(0, title.Length - 5);
|
|
|
|
|
_logger.Warn(ex, "Couldn't map movie {0} to a movie on The Movie DB. It will not be added :(", movie.Title);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return title;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Movie> SearchForNewMovie(string title)
|
|
|
|
@ -443,7 +308,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return new List<Movie> { GetMovieInfo(parserResult.ImdbId) };
|
|
|
|
|
return new List<Movie> { GetMovieByImdbId(parserResult.ImdbId) };
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
@ -467,7 +332,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return new List<Movie> { GetMovieInfo(imdbid) };
|
|
|
|
|
return new List<Movie> { GetMovieByImdbId(imdbid) };
|
|
|
|
|
}
|
|
|
|
|
catch (MovieNotFoundException)
|
|
|
|
|
{
|
|
|
|
@ -488,7 +353,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return new List<Movie> { GetMovieInfo(tmdbid, false).Item1 };
|
|
|
|
|
return new List<Movie> { GetMovieInfo(tmdbid).Item1 };
|
|
|
|
|
}
|
|
|
|
|
catch (MovieNotFoundException)
|
|
|
|
|
{
|
|
|
|
@ -500,24 +365,18 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
|
|
|
|
|
|
|
|
|
var firstChar = searchTerm.First();
|
|
|
|
|
|
|
|
|
|
var request = _movieBuilder.Create()
|
|
|
|
|
.SetSegment("api", "3")
|
|
|
|
|
var request = _radarrMetadata.Create()
|
|
|
|
|
.SetSegment("route", "search")
|
|
|
|
|
.SetSegment("id", "movie")
|
|
|
|
|
.SetSegment("secondaryRoute", "")
|
|
|
|
|
.AddQueryParam("query", searchTerm)
|
|
|
|
|
.AddQueryParam("q", searchTerm)
|
|
|
|
|
.AddQueryParam("year", yearTerm)
|
|
|
|
|
.AddQueryParam("include_adult", false)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
request.AllowAutoRedirect = true;
|
|
|
|
|
request.SuppressHttpError = true;
|
|
|
|
|
|
|
|
|
|
var response = _httpClient.Get<MovieSearchRoot>(request);
|
|
|
|
|
var httpResponse = _httpClient.Get<List<MovieResource>>(request);
|
|
|
|
|
|
|
|
|
|
var movieResults = response.Resource.results;
|
|
|
|
|
|
|
|
|
|
return movieResults.SelectList(MapSearchResult);
|
|
|
|
|
return httpResponse.Resource.SelectList(MapSearchResult);
|
|
|
|
|
}
|
|
|
|
|
catch (HttpException)
|
|
|
|
|
{
|
|
|
|
@ -530,9 +389,9 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Movie MapSearchResult(MovieResult result)
|
|
|
|
|
private Movie MapSearchResult(MovieResource result)
|
|
|
|
|
{
|
|
|
|
|
var movie = _movieService.FindByTmdbId(result.id);
|
|
|
|
|
var movie = _movieService.FindByTmdbId(result.TmdbId);
|
|
|
|
|
|
|
|
|
|
if (movie == null)
|
|
|
|
|
{
|
|
|
|
@ -542,115 +401,6 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
|
|
|
|
return movie;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Movie MapMovie(MovieResult result)
|
|
|
|
|
{
|
|
|
|
|
var imdbMovie = new Movie();
|
|
|
|
|
imdbMovie.TmdbId = result.id;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
imdbMovie.SortTitle = Parser.Parser.NormalizeTitle(result.title);
|
|
|
|
|
imdbMovie.Title = result.title;
|
|
|
|
|
imdbMovie.TitleSlug = Parser.Parser.ToUrlSlug(result.title);
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (result.release_date.IsNotNullOrWhiteSpace())
|
|
|
|
|
{
|
|
|
|
|
imdbMovie.InCinemas = DateTime.ParseExact(result.release_date, "yyyy-MM-dd", DateTimeFormatInfo.InvariantInfo);
|
|
|
|
|
imdbMovie.Year = imdbMovie.InCinemas.Value.Year;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result.physical_release.IsNotNullOrWhiteSpace())
|
|
|
|
|
{
|
|
|
|
|
imdbMovie.PhysicalRelease = DateTime.ParseExact(result.physical_release, "yyyy-MM-dd", DateTimeFormatInfo.InvariantInfo);
|
|
|
|
|
if (result.physical_release_note.IsNotNullOrWhiteSpace())
|
|
|
|
|
{
|
|
|
|
|
imdbMovie.PhysicalReleaseNote = result.physical_release_note;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
_logger.Debug("Not a valid date time.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var now = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
//handle the case when we have both theatrical and physical release dates
|
|
|
|
|
if (imdbMovie.InCinemas.HasValue && imdbMovie.PhysicalRelease.HasValue)
|
|
|
|
|
{
|
|
|
|
|
if (now < imdbMovie.InCinemas)
|
|
|
|
|
{
|
|
|
|
|
imdbMovie.Status = MovieStatusType.Announced;
|
|
|
|
|
}
|
|
|
|
|
else if (now >= imdbMovie.InCinemas)
|
|
|
|
|
{
|
|
|
|
|
imdbMovie.Status = MovieStatusType.InCinemas;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (now >= imdbMovie.PhysicalRelease)
|
|
|
|
|
{
|
|
|
|
|
imdbMovie.Status = MovieStatusType.Released;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//handle the case when we have theatrical release dates but we dont know the physical release date
|
|
|
|
|
else if (imdbMovie.InCinemas.HasValue && (now >= imdbMovie.InCinemas))
|
|
|
|
|
{
|
|
|
|
|
imdbMovie.Status = MovieStatusType.InCinemas;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//handle the case where we only have a physical release date
|
|
|
|
|
else if (imdbMovie.PhysicalRelease.HasValue && (now >= imdbMovie.PhysicalRelease))
|
|
|
|
|
{
|
|
|
|
|
imdbMovie.Status = MovieStatusType.Released;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//otherwise the title has only been announced
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
imdbMovie.Status = MovieStatusType.Announced;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//since TMDB lacks alot of information lets assume that stuff is released if its been in cinemas for longer than 3 months.
|
|
|
|
|
if (!imdbMovie.PhysicalRelease.HasValue && (imdbMovie.Status == MovieStatusType.InCinemas) && (DateTime.Now.Subtract(imdbMovie.InCinemas.Value).TotalSeconds > 60 * 60 * 24 * 30 * 3))
|
|
|
|
|
{
|
|
|
|
|
imdbMovie.Status = MovieStatusType.Released;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
imdbMovie.TitleSlug += "-" + imdbMovie.TmdbId;
|
|
|
|
|
|
|
|
|
|
imdbMovie.Images = new List<MediaCover.MediaCover>();
|
|
|
|
|
imdbMovie.Overview = result.overview;
|
|
|
|
|
imdbMovie.Ratings = new Ratings { Value = (decimal)result.vote_average, Votes = result.vote_count };
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
imdbMovie.Images.AddIfNotNull(MapImage(result.poster_path, MediaCoverTypes.Poster));
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
_logger.Debug(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result.trailer_key.IsNotNullOrWhiteSpace() && result.trailer_site.IsNotNullOrWhiteSpace())
|
|
|
|
|
{
|
|
|
|
|
if (result.trailer_site == "youtube")
|
|
|
|
|
{
|
|
|
|
|
imdbMovie.YouTubeTrailerId = result.trailer_key;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return imdbMovie;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
_logger.Error(e, "Error occured while searching for new movies.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static Credit MapCast(CastResource arg)
|
|
|
|
|
{
|
|
|
|
|
var newActor = new Credit
|
|
|
|
@ -658,19 +408,12 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
|
|
|
|
Name = arg.Name,
|
|
|
|
|
Character = arg.Character,
|
|
|
|
|
Order = arg.Order,
|
|
|
|
|
CreditTmdbId = arg.Credit_Id,
|
|
|
|
|
PersonTmdbId = arg.Id,
|
|
|
|
|
Type = CreditType.Cast
|
|
|
|
|
CreditTmdbId = arg.CreditId,
|
|
|
|
|
PersonTmdbId = arg.TmdbId,
|
|
|
|
|
Type = CreditType.Cast,
|
|
|
|
|
Images = arg.Images.Select(MapImage).ToList()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (arg.Profile_Path != null)
|
|
|
|
|
{
|
|
|
|
|
newActor.Images = new List<MediaCover.MediaCover>
|
|
|
|
|
{
|
|
|
|
|
new MediaCover.MediaCover(MediaCoverTypes.Headshot, "https://image.tmdb.org/t/p/original" + arg.Profile_Path)
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return newActor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -681,87 +424,75 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
|
|
|
|
Name = arg.Name,
|
|
|
|
|
Department = arg.Department,
|
|
|
|
|
Job = arg.Job,
|
|
|
|
|
CreditTmdbId = arg.Credit_Id,
|
|
|
|
|
PersonTmdbId = arg.Id,
|
|
|
|
|
Type = CreditType.Crew
|
|
|
|
|
CreditTmdbId = arg.CreditId,
|
|
|
|
|
PersonTmdbId = arg.TmdbId,
|
|
|
|
|
Type = CreditType.Crew,
|
|
|
|
|
Images = arg.Images.Select(MapImage).ToList()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (arg.Profile_Path != null)
|
|
|
|
|
return newActor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static AlternativeTitle MapAlternativeTitle(AlternativeTitleResource arg)
|
|
|
|
|
{
|
|
|
|
|
var newAlternativeTitle = new AlternativeTitle
|
|
|
|
|
{
|
|
|
|
|
newActor.Images = new List<MediaCover.MediaCover>
|
|
|
|
|
{
|
|
|
|
|
new MediaCover.MediaCover(MediaCoverTypes.Headshot, "https://image.tmdb.org/t/p/original" + arg.Profile_Path)
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
Title = arg.Title,
|
|
|
|
|
SourceType = SourceType.TMDB,
|
|
|
|
|
CleanTitle = arg.Title.CleanSeriesTitle(),
|
|
|
|
|
Language = IsoLanguages.Find(arg.Language.ToLower())?.Language ?? Language.English
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return newActor;
|
|
|
|
|
return newAlternativeTitle;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static MovieCollection MapCollection(CollectionResource arg)
|
|
|
|
|
{
|
|
|
|
|
var newCollection = new MovieCollection
|
|
|
|
|
{
|
|
|
|
|
Name = arg.name,
|
|
|
|
|
TmdbId = arg.id,
|
|
|
|
|
Name = arg.Name,
|
|
|
|
|
TmdbId = arg.TmdbId,
|
|
|
|
|
Images = arg.Images.Select(MapImage).ToList()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return newCollection;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private MediaCover.MediaCover MapImage(string path, MediaCoverTypes type)
|
|
|
|
|
private static Ratings MapRatings(RatingResource rating)
|
|
|
|
|
{
|
|
|
|
|
if (path.IsNotNullOrWhiteSpace())
|
|
|
|
|
if (rating == null)
|
|
|
|
|
{
|
|
|
|
|
return _tmdbConfigService.GetCoverForURL(path, type);
|
|
|
|
|
return new Ratings();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
return new Ratings
|
|
|
|
|
{
|
|
|
|
|
Votes = rating.Count,
|
|
|
|
|
Value = rating.Value
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Movie MapMovieToTmdbMovie(Movie movie)
|
|
|
|
|
private static MediaCover.MediaCover MapImage(ImageResource arg)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
return new MediaCover.MediaCover
|
|
|
|
|
{
|
|
|
|
|
Movie newMovie = movie;
|
|
|
|
|
if (movie.TmdbId > 0)
|
|
|
|
|
{
|
|
|
|
|
newMovie = GetMovieInfo(movie.TmdbId, false).Item1;
|
|
|
|
|
}
|
|
|
|
|
else if (movie.ImdbId.IsNotNullOrWhiteSpace())
|
|
|
|
|
{
|
|
|
|
|
newMovie = GetMovieInfo(movie.ImdbId);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var yearStr = "";
|
|
|
|
|
if (movie.Year > 1900)
|
|
|
|
|
{
|
|
|
|
|
yearStr = $" {movie.Year}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
newMovie = SearchForNewMovie(movie.Title + yearStr).FirstOrDefault();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (newMovie == null)
|
|
|
|
|
{
|
|
|
|
|
_logger.Warn("Couldn't map movie {0} to a movie on The Movie DB. It will not be added :(", movie.Title);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
Url = arg.Url,
|
|
|
|
|
CoverType = MapCoverType(arg.CoverType)
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return newMovie;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.Warn(ex, "Couldn't map movie {0} to a movie on The Movie DB. It will not be added :(", movie.Title);
|
|
|
|
|
return null;
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|