mirror of
https://github.com/Radarr/Radarr.git
synced 2026-04-23 22:25:14 -04:00
New: Use RadarrApi For MovieInfo
This commit is contained in:
@@ -1,10 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using NzbDrone.Core.Movies;
|
||||
|
||||
namespace NzbDrone.Core.MetadataSource
|
||||
{
|
||||
public interface IDiscoverNewMovies
|
||||
{
|
||||
List<Movie> DiscoverNewMovies(string action);
|
||||
}
|
||||
}
|
||||
@@ -7,8 +7,8 @@ namespace NzbDrone.Core.MetadataSource
|
||||
{
|
||||
public interface IProvideMovieInfo
|
||||
{
|
||||
Movie GetMovieInfo(string imdbId);
|
||||
Tuple<Movie, List<Credit>> GetMovieInfo(int tmdbId, bool hasPreDBEntry);
|
||||
Movie GetMovieByImdbId(string imdbId);
|
||||
Tuple<Movie, List<Credit>> GetMovieInfo(int tmdbId);
|
||||
HashSet<int> GetChangedMovies(DateTime startTime);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using NzbDrone.Core.Movies;
|
||||
|
||||
namespace NzbDrone.Core.MetadataSource
|
||||
@@ -8,7 +8,5 @@ namespace NzbDrone.Core.MetadataSource
|
||||
List<Movie> SearchForNewMovie(string title);
|
||||
|
||||
Movie MapMovieToTmdbMovie(Movie movie);
|
||||
|
||||
Movie MapMovie(SkyHook.Resource.MovieResult result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
namespace NzbDrone.Core.MetadataSource.PreDB
|
||||
{
|
||||
internal class PreDBResult
|
||||
{
|
||||
public string Title { get; set; }
|
||||
public string Link { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,197 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Http;
|
||||
using NzbDrone.Common.Instrumentation.Extensions;
|
||||
using NzbDrone.Core.DecisionEngine;
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.Download.Pending;
|
||||
using NzbDrone.Core.Indexers;
|
||||
using NzbDrone.Core.IndexerSearch.Definitions;
|
||||
using NzbDrone.Core.Messaging.Commands;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.Core.Movies;
|
||||
using NzbDrone.Core.Parser;
|
||||
|
||||
namespace NzbDrone.Core.MetadataSource.PreDB
|
||||
{
|
||||
public interface IPreDBService
|
||||
{
|
||||
bool HasReleases(Movie movie);
|
||||
}
|
||||
|
||||
public class PreDBService : IPreDBService, IExecute<PreDBSyncCommand>
|
||||
{
|
||||
private readonly IFetchAndParseRss _rssFetcherAndParser;
|
||||
private readonly IMakeDownloadDecision _downloadDecisionMaker;
|
||||
private readonly IProcessDownloadDecisions _processDownloadDecisions;
|
||||
private readonly IPendingReleaseService _pendingReleaseService;
|
||||
private readonly IEventAggregator _eventAggregator;
|
||||
private readonly IMovieService _movieService;
|
||||
private readonly IHttpClient _httpClient;
|
||||
private readonly IParsingService _parsingService;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public PreDBService(
|
||||
IFetchAndParseRss rssFetcherAndParser,
|
||||
IMakeDownloadDecision downloadDecisionMaker,
|
||||
IProcessDownloadDecisions processDownloadDecisions,
|
||||
IPendingReleaseService pendingReleaseService,
|
||||
IEventAggregator eventAggregator,
|
||||
IMovieService movieService,
|
||||
IHttpClient httpClient,
|
||||
IParsingService parsingService,
|
||||
Logger logger)
|
||||
{
|
||||
_rssFetcherAndParser = rssFetcherAndParser;
|
||||
_downloadDecisionMaker = downloadDecisionMaker;
|
||||
_processDownloadDecisions = processDownloadDecisions;
|
||||
_pendingReleaseService = pendingReleaseService;
|
||||
_eventAggregator = eventAggregator;
|
||||
_movieService = movieService;
|
||||
_httpClient = httpClient;
|
||||
_parsingService = parsingService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
private List<PreDBResult> GetResults(string category = "", string search = "")
|
||||
{
|
||||
return new List<PreDBResult>();
|
||||
|
||||
/* PreDB is blocked
|
||||
var builder = new HttpRequestBuilder("http://predb.me").AddQueryParam("rss", "1");
|
||||
if (category.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
builder.AddQueryParam("cats", category);
|
||||
}
|
||||
|
||||
if (search.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
builder.AddQueryParam("search", search);
|
||||
}
|
||||
|
||||
var request = builder.Build();
|
||||
|
||||
request.AllowAutoRedirect = true;
|
||||
request.SuppressHttpError = true;
|
||||
|
||||
var response = _httpClient.Get(request);
|
||||
|
||||
if (response.StatusCode != System.Net.HttpStatusCode.OK)
|
||||
{
|
||||
_logger.Warn("Non 200 StatusCode {0} encountered while searching PreDB.", response.StatusCode);
|
||||
return new List<PreDBResult>();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var reader = XmlReader.Create(new StringReader(response.Content));
|
||||
|
||||
var items = SyndicationFeed.Load(reader);
|
||||
|
||||
var results = new List<PreDBResult>();
|
||||
|
||||
foreach (SyndicationItem item in items.Items)
|
||||
{
|
||||
var result = new PreDBResult();
|
||||
result.Title = item.Title.Text;
|
||||
result.Link = item.Links[0].Uri.ToString();
|
||||
results.Add(result);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Error(ex, "Error while searching PreDB.");
|
||||
}
|
||||
|
||||
return new List<PreDBResult>(); */
|
||||
}
|
||||
|
||||
private List<Movie> FindMatchesToResults(List<PreDBResult> results)
|
||||
{
|
||||
var matches = new List<Movie>();
|
||||
|
||||
foreach (PreDBResult result in results)
|
||||
{
|
||||
var parsedInfo = Parser.Parser.ParseMovieTitle(result.Title, true);
|
||||
|
||||
if (parsedInfo != null)
|
||||
{
|
||||
var movie = _movieService.FindByTitle(parsedInfo.MovieTitle, parsedInfo.Year);
|
||||
|
||||
if (movie != null)
|
||||
{
|
||||
matches.Add(movie);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return matches;
|
||||
}
|
||||
|
||||
private List<Movie> Sync()
|
||||
{
|
||||
_logger.ProgressInfo("Starting PreDB Sync");
|
||||
|
||||
var results = GetResults("movies");
|
||||
|
||||
var matches = FindMatchesToResults(results);
|
||||
|
||||
return matches;
|
||||
}
|
||||
|
||||
public void Execute(PreDBSyncCommand message)
|
||||
{
|
||||
var haveNewReleases = Sync();
|
||||
|
||||
foreach (Movie movie in haveNewReleases)
|
||||
{
|
||||
if (!movie.HasPreDBEntry)
|
||||
{
|
||||
movie.HasPreDBEntry = true;
|
||||
_movieService.UpdateMovie(movie);
|
||||
}
|
||||
|
||||
if (movie.Monitored)
|
||||
{
|
||||
//Maybe auto search each movie once?
|
||||
}
|
||||
}
|
||||
|
||||
_eventAggregator.PublishEvent(new PreDBSyncCompleteEvent(haveNewReleases));
|
||||
}
|
||||
|
||||
public bool HasReleases(Movie movie)
|
||||
{
|
||||
try
|
||||
{
|
||||
var results = GetResults("movies", movie.Title);
|
||||
|
||||
foreach (PreDBResult result in results)
|
||||
{
|
||||
var parsed = Parser.Parser.ParseMovieTitle(result.Title, true);
|
||||
if (parsed == null)
|
||||
{
|
||||
parsed = new Parser.Model.ParsedMovieInfo { MovieTitle = result.Title, Year = 0 };
|
||||
}
|
||||
|
||||
var match = _parsingService.Map(parsed, "", new MovieSearchCriteria { Movie = movie });
|
||||
|
||||
if (match != null && match.RemoteMovie.Movie != null && match.RemoteMovie.Movie.Id == movie.Id)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Warn(ex, "Error while looking on predb.me.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
using NzbDrone.Core.Messaging.Commands;
|
||||
|
||||
namespace NzbDrone.Core.MetadataSource.PreDB
|
||||
{
|
||||
public class PreDBSyncCommand : Command
|
||||
{
|
||||
public override bool SendUpdatesToClient => true;
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using NzbDrone.Common.Messaging;
|
||||
using NzbDrone.Core.Movies;
|
||||
|
||||
namespace NzbDrone.Core.MetadataSource.PreDB
|
||||
{
|
||||
public class PreDBSyncCompleteEvent : IEvent
|
||||
{
|
||||
public List<Movie> NewlyReleased { get; private set; }
|
||||
|
||||
public PreDBSyncCompleteEvent(List<Movie> newlyReleased)
|
||||
{
|
||||
NewlyReleased = newlyReleased;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,167 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using NzbDrone.Common.Cloud;
|
||||
using NzbDrone.Common.Http;
|
||||
using NzbDrone.Core.MetadataSource.SkyHook.Resource;
|
||||
using NzbDrone.Core.Movies.AlternativeTitles;
|
||||
using NzbDrone.Core.Parser;
|
||||
|
||||
namespace NzbDrone.Core.MetadataSource.RadarrAPI
|
||||
{
|
||||
public interface IRadarrAPIClient
|
||||
{
|
||||
List<MovieResult> DiscoverMovies(string action, Func<HttpRequest, HttpRequest> enhanceRequest);
|
||||
List<AlternativeTitle> AlternativeTitlesForMovie(int tmdbId);
|
||||
Tuple<List<AlternativeTitle>, AlternativeYear> AlternativeTitlesAndYearForMovie(int tmdbId);
|
||||
AlternativeTitle AddNewAlternativeTitle(AlternativeTitle title, int tmdbId);
|
||||
AlternativeYear AddNewAlternativeYear(int year, int tmdbId);
|
||||
}
|
||||
|
||||
public class RadarrAPIClient : IRadarrAPIClient
|
||||
{
|
||||
private readonly IHttpRequestBuilderFactory _apiBuilder;
|
||||
private readonly IHttpClient _httpClient;
|
||||
|
||||
public RadarrAPIClient(IHttpClient httpClient, IRadarrCloudRequestBuilder requestBuilder)
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
_apiBuilder = requestBuilder.RadarrAPI;
|
||||
}
|
||||
|
||||
public List<MovieResult> DiscoverMovies(string action, Func<HttpRequest, HttpRequest> enhanceRequest = null)
|
||||
{
|
||||
var request = _apiBuilder.Create().SetSegment("route", "discovery").SetSegment("action", action).Build();
|
||||
|
||||
if (enhanceRequest != null)
|
||||
{
|
||||
request = enhanceRequest(request);
|
||||
}
|
||||
|
||||
return Execute<List<MovieResult>>(request);
|
||||
}
|
||||
|
||||
public List<AlternativeTitle> AlternativeTitlesForMovie(int tmdbId)
|
||||
{
|
||||
var request = _apiBuilder.Create().SetSegment("route", "mappings").SetSegment("action", "find").AddQueryParam("tmdbid", tmdbId).Build();
|
||||
|
||||
var mappings = Execute<Mapping>(request);
|
||||
|
||||
var titles = new List<AlternativeTitle>();
|
||||
|
||||
foreach (var altTitle in mappings.Mappings.Titles)
|
||||
{
|
||||
titles.Add(new AlternativeTitle(altTitle.Info.AkaTitle, SourceType.Mappings, altTitle.Id));
|
||||
}
|
||||
|
||||
return titles;
|
||||
}
|
||||
|
||||
public Tuple<List<AlternativeTitle>, AlternativeYear> AlternativeTitlesAndYearForMovie(int tmdbId)
|
||||
{
|
||||
var request = _apiBuilder.Create().SetSegment("route", "mappings").SetSegment("action", "find").AddQueryParam("tmdbid", tmdbId).Build();
|
||||
|
||||
var mappings = Execute<Mapping>(request);
|
||||
|
||||
var titles = new List<AlternativeTitle>();
|
||||
|
||||
foreach (var altTitle in mappings.Mappings.Titles)
|
||||
{
|
||||
titles.Add(new AlternativeTitle(altTitle.Info.AkaTitle, SourceType.Mappings, altTitle.Id));
|
||||
}
|
||||
|
||||
var year = mappings.Mappings.Years.Where(y => y.Votes >= 3).OrderBy(y => y.Votes).FirstOrDefault();
|
||||
|
||||
AlternativeYear newYear = null;
|
||||
|
||||
if (year != null)
|
||||
{
|
||||
newYear = new AlternativeYear
|
||||
{
|
||||
Year = year.Info.AkaYear,
|
||||
SourceId = year.Id
|
||||
};
|
||||
}
|
||||
|
||||
return new Tuple<List<AlternativeTitle>, AlternativeYear>(titles, newYear);
|
||||
}
|
||||
|
||||
public AlternativeTitle AddNewAlternativeTitle(AlternativeTitle title, int tmdbId)
|
||||
{
|
||||
var request = _apiBuilder.Create().SetSegment("route", "mappings").SetSegment("action", "add")
|
||||
.AddQueryParam("tmdbid", tmdbId).AddQueryParam("type", "title")
|
||||
.AddQueryParam("language", IsoLanguages.Get(title.Language).TwoLetterCode)
|
||||
.AddQueryParam("aka_title", title.Title).Build();
|
||||
|
||||
var newMapping = Execute<AddTitleMapping>(request);
|
||||
|
||||
var newTitle = new AlternativeTitle(newMapping.Info.AkaTitle, SourceType.Mappings, newMapping.Id, title.Language);
|
||||
newTitle.VoteCount = newMapping.VoteCount;
|
||||
newTitle.Votes = newMapping.Votes;
|
||||
|
||||
return newTitle;
|
||||
}
|
||||
|
||||
public AlternativeYear AddNewAlternativeYear(int year, int tmdbId)
|
||||
{
|
||||
var request = _apiBuilder.Create().SetSegment("route", "mappings").SetSegment("action", "add")
|
||||
.AddQueryParam("tmdbid", tmdbId).AddQueryParam("type", "year")
|
||||
.AddQueryParam("aka_year", year).Build();
|
||||
|
||||
var newYear = Execute<AddYearMapping>(request);
|
||||
|
||||
return new AlternativeYear
|
||||
{
|
||||
Year = newYear.Info.AkaYear,
|
||||
SourceId = newYear.Id
|
||||
};
|
||||
}
|
||||
|
||||
private HttpResponse Execute(HttpRequest request)
|
||||
{
|
||||
if (request.Method == HttpMethod.GET)
|
||||
{
|
||||
return _httpClient.Get(request);
|
||||
}
|
||||
else if (request.Method == HttpMethod.POST)
|
||||
{
|
||||
return _httpClient.Post(request);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotImplementedException($"Method {request.Method} not implemented");
|
||||
}
|
||||
}
|
||||
|
||||
private T Execute<T>(HttpRequest request)
|
||||
{
|
||||
request.AllowAutoRedirect = true;
|
||||
request.Headers.Accept = HttpAccept.Json.Value;
|
||||
request.SuppressHttpError = true;
|
||||
|
||||
var response = Execute(request);
|
||||
|
||||
try
|
||||
{
|
||||
var error = JsonConvert.DeserializeObject<RadarrError>(response.Content);
|
||||
|
||||
if (error != null && error.Errors != null && error.Errors.Count != 0)
|
||||
{
|
||||
throw new RadarrAPIException(error);
|
||||
}
|
||||
}
|
||||
catch (JsonSerializationException)
|
||||
{
|
||||
//No error!
|
||||
}
|
||||
|
||||
if (response.StatusCode != System.Net.HttpStatusCode.OK)
|
||||
{
|
||||
throw new HttpException(request, response);
|
||||
}
|
||||
|
||||
return JsonConvert.DeserializeObject<T>(response.Content);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,201 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
namespace NzbDrone.Core.MetadataSource.RadarrAPI
|
||||
{
|
||||
public class Error
|
||||
{
|
||||
[JsonProperty("id")]
|
||||
public string RayId { get; set; }
|
||||
|
||||
[JsonProperty("status")]
|
||||
public int Status { get; set; }
|
||||
|
||||
[JsonProperty("title")]
|
||||
public string Title { get; set; }
|
||||
|
||||
[JsonProperty("detail")]
|
||||
public string Detail { get; set; }
|
||||
}
|
||||
|
||||
public class RadarrError
|
||||
{
|
||||
[JsonProperty("errors")]
|
||||
public IList<Error> Errors { get; set; }
|
||||
}
|
||||
|
||||
public class RadarrAPIException : Exception
|
||||
{
|
||||
public RadarrError APIErrors;
|
||||
|
||||
public RadarrAPIException(RadarrError apiError)
|
||||
: base(HumanReadable(apiError))
|
||||
{
|
||||
APIErrors = apiError;
|
||||
}
|
||||
|
||||
private static string HumanReadable(RadarrError apiErrors)
|
||||
{
|
||||
var firstError = apiErrors.Errors.First();
|
||||
var details = string.Join("\n", apiErrors.Errors.Select(error =>
|
||||
{
|
||||
return $"{error.Title} ({error.Status}, RayId: {error.RayId}), Details: {error.Detail}";
|
||||
}));
|
||||
return $"Error while calling api: {firstError.Title}\nFull error(s): {details}";
|
||||
}
|
||||
}
|
||||
|
||||
public class TitleInfo
|
||||
{
|
||||
[JsonProperty("id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
[JsonProperty("aka_title")]
|
||||
public string AkaTitle { get; set; }
|
||||
|
||||
[JsonProperty("aka_clean_title")]
|
||||
public string AkaCleanTitle { get; set; }
|
||||
}
|
||||
|
||||
public class YearInfo
|
||||
{
|
||||
[JsonProperty("id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
[JsonProperty("aka_year")]
|
||||
public int AkaYear { get; set; }
|
||||
}
|
||||
|
||||
public class Title
|
||||
{
|
||||
[JsonProperty("id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
[JsonProperty("tmdbid")]
|
||||
public int Tmdbid { get; set; }
|
||||
|
||||
[JsonProperty("votes")]
|
||||
public int Votes { get; set; }
|
||||
|
||||
[JsonProperty("vote_count")]
|
||||
public int VoteCount { get; set; }
|
||||
|
||||
[JsonProperty("locked")]
|
||||
public bool Locked { get; set; }
|
||||
|
||||
[JsonProperty("info_type")]
|
||||
public string InfoType { get; set; }
|
||||
|
||||
[JsonProperty("info_id")]
|
||||
public int InfoId { get; set; }
|
||||
|
||||
[JsonProperty("info")]
|
||||
public TitleInfo Info { get; set; }
|
||||
}
|
||||
|
||||
public class Year
|
||||
{
|
||||
[JsonProperty("id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
[JsonProperty("tmdbid")]
|
||||
public int Tmdbid { get; set; }
|
||||
|
||||
[JsonProperty("votes")]
|
||||
public int Votes { get; set; }
|
||||
|
||||
[JsonProperty("vote_count")]
|
||||
public int VoteCount { get; set; }
|
||||
|
||||
[JsonProperty("locked")]
|
||||
public bool Locked { get; set; }
|
||||
|
||||
[JsonProperty("info_type")]
|
||||
public string InfoType { get; set; }
|
||||
|
||||
[JsonProperty("info_id")]
|
||||
public int InfoId { get; set; }
|
||||
|
||||
[JsonProperty("info")]
|
||||
public YearInfo Info { get; set; }
|
||||
}
|
||||
|
||||
public class Mappings
|
||||
{
|
||||
[JsonProperty("titles")]
|
||||
public IList<Title> Titles { get; set; }
|
||||
|
||||
[JsonProperty("years")]
|
||||
public IList<Year> Years { get; set; }
|
||||
}
|
||||
|
||||
public class Mapping
|
||||
{
|
||||
[JsonProperty("id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
[JsonProperty("title")]
|
||||
public string Title { get; set; }
|
||||
|
||||
[JsonProperty("imdb_id")]
|
||||
public string ImdbId { get; set; }
|
||||
|
||||
[JsonProperty("mappings")]
|
||||
public Mappings Mappings { get; set; }
|
||||
}
|
||||
|
||||
public class AddTitleMapping
|
||||
{
|
||||
[JsonProperty("tmdbid")]
|
||||
public string Tmdbid { get; set; }
|
||||
|
||||
[JsonProperty("info_type")]
|
||||
public string InfoType { get; set; }
|
||||
|
||||
[JsonProperty("info_id")]
|
||||
public int InfoId { get; set; }
|
||||
|
||||
[JsonProperty("id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
[JsonProperty("info")]
|
||||
public TitleInfo Info { get; set; }
|
||||
|
||||
[JsonProperty("votes")]
|
||||
public int Votes { get; set; }
|
||||
|
||||
[JsonProperty("vote_count")]
|
||||
public int VoteCount { get; set; }
|
||||
|
||||
[JsonProperty("locked")]
|
||||
public bool Locked { get; set; }
|
||||
}
|
||||
|
||||
public class AddYearMapping
|
||||
{
|
||||
[JsonProperty("tmdbid")]
|
||||
public string Tmdbid { get; set; }
|
||||
|
||||
[JsonProperty("info_type")]
|
||||
public string InfoType { get; set; }
|
||||
|
||||
[JsonProperty("info_id")]
|
||||
public int InfoId { get; set; }
|
||||
|
||||
[JsonProperty("id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
[JsonProperty("info")]
|
||||
public YearInfo Info { get; set; }
|
||||
|
||||
[JsonProperty("votes")]
|
||||
public int Votes { get; set; }
|
||||
|
||||
[JsonProperty("vote_count")]
|
||||
public int VoteCount { get; set; }
|
||||
|
||||
[JsonProperty("locked")]
|
||||
public bool Locked { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace NzbDrone.Core.MetadataSource.SkyHook.Resource
|
||||
{
|
||||
public class AlternativeTitleResource
|
||||
{
|
||||
public string Title { get; set; }
|
||||
public string Type { get; set; }
|
||||
public string Language { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace NzbDrone.Core.MetadataSource.SkyHook.Resource
|
||||
{
|
||||
public class CertificationResource
|
||||
{
|
||||
public string Country { get; set; }
|
||||
public string Certification { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace NzbDrone.Core.MetadataSource.SkyHook.Resource
|
||||
{
|
||||
public class CollectionResource
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public int TmdbId { get; set; }
|
||||
public List<ImageResource> Images { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
namespace NzbDrone.Core.MetadataSource.SkyHook.Resource
|
||||
{
|
||||
public class ConfigResource
|
||||
{
|
||||
public Images images { get; set; }
|
||||
public string[] change_keys { get; set; }
|
||||
}
|
||||
|
||||
public class Images
|
||||
{
|
||||
public string base_url { get; set; }
|
||||
public string secure_base_url { get; set; }
|
||||
public string[] backdrop_sizes { get; set; }
|
||||
public string[] logo_sizes { get; set; }
|
||||
public string[] poster_sizes { get; set; }
|
||||
public string[] profile_sizes { get; set; }
|
||||
public string[] still_sizes { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace NzbDrone.Core.MetadataSource.SkyHook.Resource
|
||||
{
|
||||
public class Credits
|
||||
{
|
||||
public List<CastResource> Cast { get; set; }
|
||||
public List<CrewResource> Crew { get; set; }
|
||||
}
|
||||
|
||||
public class CastResource
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public int Order { get; set; }
|
||||
public string Character { get; set; }
|
||||
public int TmdbId { get; set; }
|
||||
public string CreditId { get; set; }
|
||||
public List<ImageResource> Images { get; set; }
|
||||
}
|
||||
|
||||
public class CrewResource
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Job { get; set; }
|
||||
public string Department { get; set; }
|
||||
public int TmdbId { get; set; }
|
||||
public string CreditId { get; set; }
|
||||
public List<ImageResource> Images { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,37 @@
|
||||
namespace NzbDrone.Core.MetadataSource.SkyHook.Resource
|
||||
{
|
||||
public class ImdbResource
|
||||
{
|
||||
public int v { get; set; }
|
||||
public string q { get; set; }
|
||||
public MovieResource[] d { get; set; }
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace NzbDrone.Core.MetadataSource.SkyHook.Resource
|
||||
{
|
||||
public class MovieResource
|
||||
{
|
||||
public string l { get; set; }
|
||||
public string id { get; set; }
|
||||
public string s { get; set; }
|
||||
public int y { get; set; }
|
||||
public string q { get; set; }
|
||||
public object[] i { get; set; }
|
||||
public int TmdbId { get; set; }
|
||||
public string ImdbId { get; set; }
|
||||
public string Overview { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string TitleSlug { get; set; }
|
||||
public List<RatingResource> Ratings { get; set; }
|
||||
public int? Runtime { get; set; }
|
||||
public List<ImageResource> Images { get; set; }
|
||||
public List<string> Genres { get; set; }
|
||||
|
||||
public int Year { get; set; }
|
||||
public DateTime? Premier { get; set; }
|
||||
public DateTime? InCinema { get; set; }
|
||||
public DateTime? PhysicalRelease { get; set; }
|
||||
public DateTime? DigitalRelease { get; set; }
|
||||
|
||||
public List<AlternativeTitleResource> AlternativeTitles { get; set; }
|
||||
public List<TranslationResource> Translations { get; set; }
|
||||
|
||||
public Credits Credits { get; set; }
|
||||
public string Studio { get; set; }
|
||||
public string YoutubeTrailerId { get; set; }
|
||||
|
||||
public List<CertificationResource> Certifications { get; set; }
|
||||
public string Status { get; set; }
|
||||
public CollectionResource Collection { get; set; }
|
||||
public string OriginalLanguage { get; set; }
|
||||
public string Homepage { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
namespace NzbDrone.Core.MetadataSource.SkyHook.Resource
|
||||
namespace NzbDrone.Core.MetadataSource.SkyHook.Resource
|
||||
{
|
||||
public class RatingResource
|
||||
{
|
||||
public int Count { get; set; }
|
||||
public decimal Value { get; set; }
|
||||
public string Origin { get; set; }
|
||||
public string Type { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,235 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace NzbDrone.Core.MetadataSource.SkyHook.Resource
|
||||
{
|
||||
public class FindRoot
|
||||
{
|
||||
public MovieResult[] movie_results { get; set; }
|
||||
}
|
||||
|
||||
public class MovieSearchRoot
|
||||
{
|
||||
public int page { get; set; }
|
||||
public MovieResult[] results { get; set; }
|
||||
public int total_results { get; set; }
|
||||
public int total_pages { get; set; }
|
||||
}
|
||||
|
||||
public class AuthRefreshTokenResponse
|
||||
{
|
||||
public string request_token { get; set; }
|
||||
}
|
||||
|
||||
public class AuthAccessTokenResponse
|
||||
{
|
||||
public string access_token { get; set; }
|
||||
public string account_id { get; set; }
|
||||
}
|
||||
|
||||
public class MovieResult
|
||||
{
|
||||
public string poster_path { get; set; }
|
||||
public bool adult { get; set; }
|
||||
public string overview { get; set; }
|
||||
public string release_date { get; set; }
|
||||
public int?[] genre_ids { get; set; }
|
||||
public int id { get; set; }
|
||||
public string original_title { get; set; }
|
||||
public string original_language { get; set; }
|
||||
public string title { get; set; }
|
||||
public string backdrop_path { get; set; }
|
||||
public float popularity { get; set; }
|
||||
public int vote_count { get; set; }
|
||||
public bool video { get; set; }
|
||||
public float vote_average { get; set; }
|
||||
public string trailer_key { get; set; }
|
||||
public string trailer_site { get; set; }
|
||||
public string physical_release { get; set; }
|
||||
public string physical_release_note { get; set; }
|
||||
}
|
||||
|
||||
public class CreditsResult : MovieResult
|
||||
{
|
||||
public string department { get; set; }
|
||||
public string job { get; set; }
|
||||
public string credit_id { get; set; }
|
||||
}
|
||||
|
||||
public class MovieResourceRoot
|
||||
{
|
||||
public bool adult { get; set; }
|
||||
public string backdrop_path { get; set; }
|
||||
public CollectionResource belongs_to_collection { get; set; }
|
||||
public int? status_code { get; set; }
|
||||
public string status_message { get; set; }
|
||||
public int budget { get; set; }
|
||||
public Genre[] genres { get; set; }
|
||||
public string homepage { get; set; }
|
||||
public int id { get; set; }
|
||||
public string imdb_id { get; set; }
|
||||
public string original_language { get; set; }
|
||||
public string original_title { get; set; }
|
||||
public string overview { get; set; }
|
||||
public float popularity { get; set; }
|
||||
public string poster_path { get; set; }
|
||||
public Production_Companies[] production_companies { get; set; }
|
||||
public Production_Countries[] production_countries { get; set; }
|
||||
public string release_date { get; set; }
|
||||
public long revenue { get; set; }
|
||||
public int runtime { get; set; }
|
||||
public Spoken_Languages[] spoken_languages { get; set; }
|
||||
public string status { get; set; }
|
||||
public string tagline { get; set; }
|
||||
public string title { get; set; }
|
||||
public bool video { get; set; }
|
||||
public float vote_average { get; set; }
|
||||
public int vote_count { get; set; }
|
||||
public AlternativeTitles alternative_titles { get; set; }
|
||||
public ReleaseDatesResource release_dates { get; set; }
|
||||
public VideosResource videos { get; set; }
|
||||
|
||||
public CreditsResource credits { get; set; }
|
||||
}
|
||||
|
||||
public class ReleaseDatesResource
|
||||
{
|
||||
public List<ReleaseDates> results { get; set; }
|
||||
}
|
||||
|
||||
public class CreditsResource
|
||||
{
|
||||
public List<CastResource> Cast { get; set; }
|
||||
public List<CrewResource> Crew { get; set; }
|
||||
}
|
||||
|
||||
public class ReleaseDate
|
||||
{
|
||||
public string certification { get; set; }
|
||||
public string iso_639_1 { get; set; }
|
||||
public string note { get; set; }
|
||||
public string release_date { get; set; }
|
||||
public int type { get; set; }
|
||||
}
|
||||
|
||||
public class ReleaseDates
|
||||
{
|
||||
public string iso_3166_1 { get; set; }
|
||||
public List<ReleaseDate> release_dates { get; set; }
|
||||
}
|
||||
|
||||
public class CollectionResource
|
||||
{
|
||||
public int id { get; set; }
|
||||
public string name { get; set; }
|
||||
public string poster_path { get; set; }
|
||||
public string backdrop_path { get; set; }
|
||||
}
|
||||
|
||||
public class Genre
|
||||
{
|
||||
public int id { get; set; }
|
||||
public string name { get; set; }
|
||||
}
|
||||
|
||||
public class Production_Companies
|
||||
{
|
||||
public string name { get; set; }
|
||||
public int id { get; set; }
|
||||
}
|
||||
|
||||
public class Production_Countries
|
||||
{
|
||||
public string iso_3166_1 { get; set; }
|
||||
public string name { get; set; }
|
||||
}
|
||||
|
||||
public class Spoken_Languages
|
||||
{
|
||||
public string iso_639_1 { get; set; }
|
||||
public string name { get; set; }
|
||||
}
|
||||
|
||||
public class AlternativeTitles
|
||||
{
|
||||
public List<Title> titles { get; set; }
|
||||
}
|
||||
|
||||
public class Title
|
||||
{
|
||||
public string iso_3166_1 { get; set; }
|
||||
public string title { get; set; }
|
||||
}
|
||||
|
||||
public class VideosResource
|
||||
{
|
||||
public List<Video> results { get; set; }
|
||||
}
|
||||
|
||||
public class CrewResource
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Department { get; set; }
|
||||
public string Job { get; set; }
|
||||
public string Credit_Id { get; set; }
|
||||
public int Id { get; set; }
|
||||
public string Profile_Path { get; set; }
|
||||
}
|
||||
|
||||
public class CastResource
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Character { get; set; }
|
||||
public string Credit_Id { get; set; }
|
||||
public int Id { get; set; }
|
||||
public int Order { get; set; }
|
||||
public string Profile_Path { get; set; }
|
||||
}
|
||||
|
||||
public class Video
|
||||
{
|
||||
public string id { get; set; }
|
||||
public string iso_639_1 { get; set; }
|
||||
public string iso_3166_1 { get; set; }
|
||||
public string key { get; set; }
|
||||
public string name { get; set; }
|
||||
public string site { get; set; }
|
||||
public string size { get; set; }
|
||||
public string type { get; set; }
|
||||
}
|
||||
|
||||
public class ListResponseRoot
|
||||
{
|
||||
public string id { get; set; }
|
||||
public List<ListItem> items { get; set; }
|
||||
public int item_count { get; set; }
|
||||
public string iso_639_1 { get; set; }
|
||||
public string name { get; set; }
|
||||
public object poster_path { get; set; }
|
||||
}
|
||||
|
||||
public class CollectionResponseRoot
|
||||
{
|
||||
public int id { get; set; }
|
||||
public string name { get; set; }
|
||||
public string overview { get; set; }
|
||||
public string poster_path { get; set; }
|
||||
public string backdrop_path { get; set; }
|
||||
public MovieResult[] parts { get; set; }
|
||||
}
|
||||
|
||||
public class PersonCreditsRoot
|
||||
{
|
||||
public CreditsResult[] cast { get; set; }
|
||||
public CreditsResult[] crew { get; set; }
|
||||
public int id { get; set; }
|
||||
}
|
||||
|
||||
public class ListItem : MovieResult
|
||||
{
|
||||
public string media_type { get; set; }
|
||||
public string first_air_date { get; set; }
|
||||
public string[] origin_country { get; set; }
|
||||
public string name { get; set; }
|
||||
public string original_name { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
namespace NzbDrone.Core.MetadataSource.SkyHook.Resource
|
||||
{
|
||||
public class TimeOfDayResource
|
||||
{
|
||||
public int Hours { get; set; }
|
||||
public int Minutes { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace NzbDrone.Core.MetadataSource.SkyHook.Resource
|
||||
{
|
||||
public class TranslationResource
|
||||
{
|
||||
public string Title { get; set; }
|
||||
public string Language { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -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,148 +62,110 @@ 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())
|
||||
httpRequest.AllowAutoRedirect = true;
|
||||
httpRequest.SuppressHttpError = true;
|
||||
|
||||
// .AddQueryParam("country", "US")
|
||||
.Build();
|
||||
var httpResponse = _httpClient.Get<MovieResource>(httpRequest);
|
||||
|
||||
request.AllowAutoRedirect = true;
|
||||
request.SuppressHttpError = true;
|
||||
|
||||
var response = _httpClient.Get<MovieResourceRoot>(request);
|
||||
|
||||
if (response.StatusCode == HttpStatusCode.NotFound)
|
||||
if (httpResponse.HasHttpError)
|
||||
{
|
||||
throw new MovieNotFoundException(tmdbId);
|
||||
}
|
||||
|
||||
if (response.StatusCode != HttpStatusCode.OK)
|
||||
{
|
||||
throw new HttpException(request, response);
|
||||
}
|
||||
|
||||
if (response.Headers.ContentType != HttpAccept.JsonCharset.Value)
|
||||
{
|
||||
throw new HttpException(request, response);
|
||||
}
|
||||
|
||||
// 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)
|
||||
if (httpResponse.StatusCode == HttpStatusCode.NotFound)
|
||||
{
|
||||
_logger.Trace("Waiting 5 seconds to get information for the next 35 movies");
|
||||
Thread.Sleep(5000);
|
||||
throw new MovieNotFoundException(tmdbId);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new HttpException(httpRequest, httpResponse);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
var credits = new List<Credit>();
|
||||
credits.AddRange(httpResponse.Resource.Credits.Cast.Select(MapCast));
|
||||
credits.AddRange(httpResponse.Resource.Credits.Crew.Select(MapCrew));
|
||||
|
||||
_logger.Warn(resource.status_message);
|
||||
return null;
|
||||
var movie = MapMovie(httpResponse.Resource);
|
||||
|
||||
return new Tuple<Movie, List<Credit>>(movie, credits.ToList());
|
||||
}
|
||||
|
||||
public Movie GetMovieByImdbId(string imdbId)
|
||||
{
|
||||
var httpRequest = _radarrMetadata.Create()
|
||||
.SetSegment("route", "movie/imdb")
|
||||
.Resource(imdbId.ToString())
|
||||
.Build();
|
||||
|
||||
httpRequest.AllowAutoRedirect = true;
|
||||
httpRequest.SuppressHttpError = true;
|
||||
|
||||
var httpResponse = _httpClient.Get<List<MovieResource>>(httpRequest);
|
||||
|
||||
if (httpResponse.HasHttpError)
|
||||
{
|
||||
if (httpResponse.StatusCode == HttpStatusCode.NotFound)
|
||||
{
|
||||
throw new MovieNotFoundException(imdbId);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new HttpException(httpRequest, httpResponse);
|
||||
}
|
||||
}
|
||||
|
||||
var movie = httpResponse.Resource.SelectList(MapMovie).FirstOrDefault();
|
||||
|
||||
return movie;
|
||||
}
|
||||
|
||||
public Movie MapMovie(MovieResource resource)
|
||||
{
|
||||
var movie = new Movie();
|
||||
var altTitles = new List<AlternativeTitle>();
|
||||
|
||||
foreach (var alternativeTitle in resource.alternative_titles.titles)
|
||||
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.AlternativeTitles.AddRange(resource.AlternativeTitles.Select(MapAlternativeTitle));
|
||||
|
||||
movie.Website = resource.Homepage;
|
||||
movie.InCinemas = resource.InCinema;
|
||||
movie.PhysicalRelease = resource.PhysicalRelease;
|
||||
|
||||
movie.Year = resource.Year;
|
||||
|
||||
//If the premier differs from the TMDB year, use it as a secondary year.
|
||||
if (resource.Premier.HasValue && resource.Premier?.Year != movie.Year)
|
||||
{
|
||||
if (alternativeTitle.iso_3166_1.ToLower() == langCode)
|
||||
{
|
||||
altTitles.Add(new AlternativeTitle(alternativeTitle.title, SourceType.TMDB, tmdbId, IsoLanguages.Find(alternativeTitle.iso_3166_1.ToLower())?.Language ?? Language.English));
|
||||
}
|
||||
else if (alternativeTitle.iso_3166_1.ToLower() == "us")
|
||||
{
|
||||
altTitles.Add(new AlternativeTitle(alternativeTitle.title, SourceType.TMDB, tmdbId, Language.English));
|
||||
}
|
||||
movie.SecondaryYear = resource.Premier?.Year;
|
||||
}
|
||||
|
||||
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;
|
||||
movie.Images = resource.Images.Select(MapImage).ToList();
|
||||
|
||||
if (resource.release_date.IsNotNullOrWhiteSpace())
|
||||
if (resource.Runtime != null)
|
||||
{
|
||||
movie.InCinemas = DateTime.Parse(resource.release_date);
|
||||
|
||||
movie.Year = movie.InCinemas.Value.Year;
|
||||
movie.Runtime = resource.Runtime.Value;
|
||||
}
|
||||
|
||||
movie.TitleSlug += "-" + movie.TmdbId.ToString();
|
||||
var certificationCountry = _configService.CertificationCountry.ToString();
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var countryReleases = resource.release_dates.results.FirstOrDefault(m => m.iso_3166_1 == _configService.CertificationCountry.ToString());
|
||||
|
||||
// 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())
|
||||
{
|
||||
var certRelease = countryReleases.release_dates.OrderByDescending(c => c.type).Where(d => d.type <= 3).FirstOrDefault(c => c.certification.IsNotNullOrWhiteSpace());
|
||||
|
||||
movie.Certification = certRelease?.certification;
|
||||
}
|
||||
|
||||
movie.Ratings = new Ratings();
|
||||
movie.Ratings.Votes = resource.vote_count;
|
||||
movie.Ratings.Value = (decimal)resource.vote_average;
|
||||
|
||||
foreach (var genre in resource.genres)
|
||||
{
|
||||
movie.Genres.Add(genre.name);
|
||||
}
|
||||
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;
|
||||
|
||||
@@ -262,146 +211,15 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
||||
movie.Status = MovieStatusType.Released;
|
||||
}
|
||||
|
||||
if (!hasPreDBEntry)
|
||||
movie.YouTubeTrailerId = resource.YoutubeTrailerId;
|
||||
movie.Studio = resource.Studio;
|
||||
|
||||
if (movie.Collection != null)
|
||||
{
|
||||
if (_predbService.HasReleases(movie))
|
||||
{
|
||||
movie.HasPreDBEntry = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
movie.HasPreDBEntry = false;
|
||||
}
|
||||
movie.Collection = new MovieCollection { Name = resource.Collection.Name, TmdbId = resource.Collection.TmdbId };
|
||||
}
|
||||
|
||||
if (resource.videos != null)
|
||||
{
|
||||
foreach (Video video in resource.videos.results)
|
||||
{
|
||||
if (video.type == "Trailer" && video.site == "YouTube")
|
||||
{
|
||||
if (video.key != null)
|
||||
{
|
||||
movie.YouTubeTrailerId = video.key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (resource.production_companies != null)
|
||||
{
|
||||
if (resource.production_companies.Any())
|
||||
{
|
||||
movie.Studio = resource.production_companies[0].name;
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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));
|
||||
}
|
||||
|
||||
return new Tuple<Movie, List<Credit>>(movie, people);
|
||||
}
|
||||
|
||||
public Movie GetMovieInfo(string imdbId)
|
||||
{
|
||||
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)
|
||||
{
|
||||
if (response.StatusCode == HttpStatusCode.NotFound)
|
||||
{
|
||||
throw new MovieNotFoundException(imdbId);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new HttpException(request, response);
|
||||
}
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
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 results = new List<MovieResult>();
|
||||
|
||||
try
|
||||
{
|
||||
results = _radarrAPI.DiscoverMovies(action, (request) =>
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
return results.SelectList(MapMovie);
|
||||
return movie;
|
||||
}
|
||||
|
||||
private string StripTrailingTheFromTitle(string title)
|
||||
@@ -418,306 +236,6 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
||||
return title;
|
||||
}
|
||||
|
||||
public List<Movie> SearchForNewMovie(string title)
|
||||
{
|
||||
try
|
||||
{
|
||||
var lowerTitle = title.ToLower();
|
||||
|
||||
lowerTitle = lowerTitle.Replace(".", "");
|
||||
|
||||
var parserResult = Parser.Parser.ParseMovieTitle(title, true, true);
|
||||
|
||||
var yearTerm = "";
|
||||
|
||||
if (parserResult != null && parserResult.MovieTitle != title)
|
||||
{
|
||||
//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)
|
||||
{
|
||||
yearTerm = parserResult.Year.ToString();
|
||||
}
|
||||
|
||||
if (parserResult.ImdbId.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
try
|
||||
{
|
||||
return new List<Movie> { GetMovieInfo(parserResult.ImdbId) };
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return new List<Movie>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lowerTitle = StripTrailingTheFromTitle(lowerTitle);
|
||||
|
||||
if (lowerTitle.StartsWith("imdb:") || lowerTitle.StartsWith("imdbid:"))
|
||||
{
|
||||
var slug = lowerTitle.Split(':')[1].Trim();
|
||||
|
||||
string imdbid = slug;
|
||||
|
||||
if (slug.IsNullOrWhiteSpace() || slug.Any(char.IsWhiteSpace))
|
||||
{
|
||||
return new List<Movie>();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return new List<Movie> { GetMovieInfo(imdbid) };
|
||||
}
|
||||
catch (MovieNotFoundException)
|
||||
{
|
||||
return new List<Movie>();
|
||||
}
|
||||
}
|
||||
|
||||
if (lowerTitle.StartsWith("tmdb:") || lowerTitle.StartsWith("tmdbid:"))
|
||||
{
|
||||
var slug = lowerTitle.Split(':')[1].Trim();
|
||||
|
||||
int tmdbid = -1;
|
||||
|
||||
if (slug.IsNullOrWhiteSpace() || slug.Any(char.IsWhiteSpace) || !int.TryParse(slug, out tmdbid))
|
||||
{
|
||||
return new List<Movie>();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return new List<Movie> { GetMovieInfo(tmdbid, false).Item1 };
|
||||
}
|
||||
catch (MovieNotFoundException)
|
||||
{
|
||||
return new List<Movie>();
|
||||
}
|
||||
}
|
||||
|
||||
var searchTerm = lowerTitle.Replace("_", "+").Replace(" ", "+").Replace(".", "+");
|
||||
|
||||
var firstChar = searchTerm.First();
|
||||
|
||||
var request = _movieBuilder.Create()
|
||||
.SetSegment("api", "3")
|
||||
.SetSegment("route", "search")
|
||||
.SetSegment("id", "movie")
|
||||
.SetSegment("secondaryRoute", "")
|
||||
.AddQueryParam("query", searchTerm)
|
||||
.AddQueryParam("year", yearTerm)
|
||||
.AddQueryParam("include_adult", false)
|
||||
.Build();
|
||||
|
||||
request.AllowAutoRedirect = true;
|
||||
request.SuppressHttpError = true;
|
||||
|
||||
var response = _httpClient.Get<MovieSearchRoot>(request);
|
||||
|
||||
var movieResults = response.Resource.results;
|
||||
|
||||
return movieResults.SelectList(MapSearchResult);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
private Movie MapSearchResult(MovieResult result)
|
||||
{
|
||||
var movie = _movieService.FindByTmdbId(result.id);
|
||||
|
||||
if (movie == null)
|
||||
{
|
||||
movie = MapMovie(result);
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
Name = arg.Name,
|
||||
Character = arg.Character,
|
||||
Order = arg.Order,
|
||||
CreditTmdbId = arg.Credit_Id,
|
||||
PersonTmdbId = arg.Id,
|
||||
Type = CreditType.Cast
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
private static Credit MapCrew(CrewResource arg)
|
||||
{
|
||||
var newActor = new Credit
|
||||
{
|
||||
Name = arg.Name,
|
||||
Department = arg.Department,
|
||||
Job = arg.Job,
|
||||
CreditTmdbId = arg.Credit_Id,
|
||||
PersonTmdbId = arg.Id,
|
||||
Type = CreditType.Crew
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
private static MovieCollection MapCollection(CollectionResource arg)
|
||||
{
|
||||
var newCollection = new MovieCollection
|
||||
{
|
||||
Name = arg.name,
|
||||
TmdbId = arg.id,
|
||||
};
|
||||
|
||||
return newCollection;
|
||||
}
|
||||
|
||||
private MediaCover.MediaCover MapImage(string path, MediaCoverTypes type)
|
||||
{
|
||||
if (path.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
return _tmdbConfigService.GetCoverForURL(path, type);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Movie MapMovieToTmdbMovie(Movie movie)
|
||||
{
|
||||
try
|
||||
@@ -725,11 +243,11 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
||||
Movie newMovie = movie;
|
||||
if (movie.TmdbId > 0)
|
||||
{
|
||||
newMovie = GetMovieInfo(movie.TmdbId, false).Item1;
|
||||
newMovie = GetMovieInfo(movie.TmdbId).Item1;
|
||||
}
|
||||
else if (movie.ImdbId.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
newMovie = GetMovieInfo(movie.ImdbId);
|
||||
newMovie = GetMovieByImdbId(movie.ImdbId);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -764,5 +282,218 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public List<Movie> SearchForNewMovie(string title)
|
||||
{
|
||||
try
|
||||
{
|
||||
var lowerTitle = title.ToLower();
|
||||
|
||||
lowerTitle = lowerTitle.Replace(".", "");
|
||||
|
||||
var parserResult = Parser.Parser.ParseMovieTitle(title, true, true);
|
||||
|
||||
var yearTerm = "";
|
||||
|
||||
if (parserResult != null && parserResult.MovieTitle != title)
|
||||
{
|
||||
//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)
|
||||
{
|
||||
yearTerm = parserResult.Year.ToString();
|
||||
}
|
||||
|
||||
if (parserResult.ImdbId.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
try
|
||||
{
|
||||
return new List<Movie> { GetMovieByImdbId(parserResult.ImdbId) };
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return new List<Movie>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lowerTitle = StripTrailingTheFromTitle(lowerTitle);
|
||||
|
||||
if (lowerTitle.StartsWith("imdb:") || lowerTitle.StartsWith("imdbid:"))
|
||||
{
|
||||
var slug = lowerTitle.Split(':')[1].Trim();
|
||||
|
||||
string imdbid = slug;
|
||||
|
||||
if (slug.IsNullOrWhiteSpace() || slug.Any(char.IsWhiteSpace))
|
||||
{
|
||||
return new List<Movie>();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return new List<Movie> { GetMovieByImdbId(imdbid) };
|
||||
}
|
||||
catch (MovieNotFoundException)
|
||||
{
|
||||
return new List<Movie>();
|
||||
}
|
||||
}
|
||||
|
||||
if (lowerTitle.StartsWith("tmdb:") || lowerTitle.StartsWith("tmdbid:"))
|
||||
{
|
||||
var slug = lowerTitle.Split(':')[1].Trim();
|
||||
|
||||
int tmdbid = -1;
|
||||
|
||||
if (slug.IsNullOrWhiteSpace() || slug.Any(char.IsWhiteSpace) || !int.TryParse(slug, out tmdbid))
|
||||
{
|
||||
return new List<Movie>();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return new List<Movie> { GetMovieInfo(tmdbid).Item1 };
|
||||
}
|
||||
catch (MovieNotFoundException)
|
||||
{
|
||||
return new List<Movie>();
|
||||
}
|
||||
}
|
||||
|
||||
var searchTerm = lowerTitle.Replace("_", "+").Replace(" ", "+").Replace(".", "+");
|
||||
|
||||
var firstChar = searchTerm.First();
|
||||
|
||||
var request = _radarrMetadata.Create()
|
||||
.SetSegment("route", "search")
|
||||
.AddQueryParam("q", searchTerm)
|
||||
.AddQueryParam("year", yearTerm)
|
||||
.Build();
|
||||
|
||||
request.AllowAutoRedirect = true;
|
||||
request.SuppressHttpError = true;
|
||||
|
||||
var httpResponse = _httpClient.Get<List<MovieResource>>(request);
|
||||
|
||||
return httpResponse.Resource.SelectList(MapSearchResult);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
private Movie MapSearchResult(MovieResource result)
|
||||
{
|
||||
var movie = _movieService.FindByTmdbId(result.TmdbId);
|
||||
|
||||
if (movie == null)
|
||||
{
|
||||
movie = MapMovie(result);
|
||||
}
|
||||
|
||||
return movie;
|
||||
}
|
||||
|
||||
private static Credit MapCast(CastResource arg)
|
||||
{
|
||||
var newActor = new Credit
|
||||
{
|
||||
Name = arg.Name,
|
||||
Character = arg.Character,
|
||||
Order = arg.Order,
|
||||
CreditTmdbId = arg.CreditId,
|
||||
PersonTmdbId = arg.TmdbId,
|
||||
Type = CreditType.Cast,
|
||||
Images = arg.Images.Select(MapImage).ToList()
|
||||
};
|
||||
|
||||
return newActor;
|
||||
}
|
||||
|
||||
private static Credit MapCrew(CrewResource arg)
|
||||
{
|
||||
var newActor = new Credit
|
||||
{
|
||||
Name = arg.Name,
|
||||
Department = arg.Department,
|
||||
Job = arg.Job,
|
||||
CreditTmdbId = arg.CreditId,
|
||||
PersonTmdbId = arg.TmdbId,
|
||||
Type = CreditType.Crew,
|
||||
Images = arg.Images.Select(MapImage).ToList()
|
||||
};
|
||||
|
||||
return newActor;
|
||||
}
|
||||
|
||||
private static AlternativeTitle MapAlternativeTitle(AlternativeTitleResource arg)
|
||||
{
|
||||
var newAlternativeTitle = new AlternativeTitle
|
||||
{
|
||||
Title = arg.Title,
|
||||
SourceType = SourceType.TMDB,
|
||||
CleanTitle = arg.Title.CleanSeriesTitle(),
|
||||
Language = IsoLanguages.Find(arg.Language.ToLower())?.Language ?? Language.English
|
||||
};
|
||||
|
||||
return newAlternativeTitle;
|
||||
}
|
||||
|
||||
private static MovieCollection MapCollection(CollectionResource arg)
|
||||
{
|
||||
var newCollection = new MovieCollection
|
||||
{
|
||||
Name = arg.Name,
|
||||
TmdbId = arg.TmdbId,
|
||||
Images = arg.Images.Select(MapImage).ToList()
|
||||
};
|
||||
|
||||
return newCollection;
|
||||
}
|
||||
|
||||
private static Ratings MapRatings(RatingResource rating)
|
||||
{
|
||||
if (rating == null)
|
||||
{
|
||||
return new Ratings();
|
||||
}
|
||||
|
||||
return new Ratings
|
||||
{
|
||||
Votes = rating.Count,
|
||||
Value = rating.Value
|
||||
};
|
||||
}
|
||||
|
||||
private static MediaCover.MediaCover MapImage(ImageResource arg)
|
||||
{
|
||||
return new MediaCover.MediaCover
|
||||
{
|
||||
Url = arg.Url,
|
||||
CoverType = MapCoverType(arg.CoverType)
|
||||
};
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
using System.Linq;
|
||||
using NzbDrone.Common.Cache;
|
||||
using NzbDrone.Common.Cloud;
|
||||
using NzbDrone.Common.Http;
|
||||
using NzbDrone.Core.MediaCover;
|
||||
using NzbDrone.Core.MetadataSource.SkyHook.Resource;
|
||||
|
||||
namespace NzbDrone.Core.MetadataSource
|
||||
{
|
||||
public interface ITmdbConfigService
|
||||
{
|
||||
MediaCover.MediaCover GetCoverForURL(string url, MediaCover.MediaCoverTypes type);
|
||||
}
|
||||
|
||||
internal class TmdbConfigService : ITmdbConfigService
|
||||
{
|
||||
private readonly ICached<ConfigResource> _configurationCache;
|
||||
private readonly IHttpClient _httpClient;
|
||||
private readonly IHttpRequestBuilderFactory _tmdbBuilder;
|
||||
|
||||
public TmdbConfigService(ICacheManager cacheManager, IHttpClient httpClient, IRadarrCloudRequestBuilder requestBuilder)
|
||||
{
|
||||
_configurationCache = cacheManager.GetCache<ConfigResource>(GetType(), "configuration_cache");
|
||||
_httpClient = httpClient;
|
||||
_tmdbBuilder = requestBuilder.TMDBSingle;
|
||||
}
|
||||
|
||||
public MediaCover.MediaCover GetCoverForURL(string url, MediaCover.MediaCoverTypes type)
|
||||
{
|
||||
if (_configurationCache.Count == 0)
|
||||
{
|
||||
RefreshCache();
|
||||
}
|
||||
|
||||
var images = _configurationCache.Find("configuration").images;
|
||||
|
||||
var cover = new MediaCover.MediaCover();
|
||||
cover.CoverType = type;
|
||||
|
||||
var realUrl = images.base_url;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case MediaCoverTypes.Fanart:
|
||||
realUrl += images.backdrop_sizes.Last();
|
||||
break;
|
||||
case MediaCoverTypes.Poster:
|
||||
realUrl += images.poster_sizes.Last();
|
||||
break;
|
||||
default:
|
||||
realUrl += "original";
|
||||
break;
|
||||
}
|
||||
|
||||
realUrl += url;
|
||||
|
||||
cover.Url = realUrl;
|
||||
|
||||
return cover;
|
||||
}
|
||||
|
||||
private void RefreshCache()
|
||||
{
|
||||
var request = _tmdbBuilder.Create().SetSegment("route", "configuration").Build();
|
||||
|
||||
var response = _httpClient.Get<ConfigResource>(request);
|
||||
|
||||
if (response.Resource.images != null)
|
||||
{
|
||||
_configurationCache.Set("configuration", response.Resource);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user