New: Use RadarrApi For MovieInfo

pull/4454/head
Qstick 4 years ago
parent 9bdaea4a1b
commit c64c2d9f27

@ -1,8 +1,4 @@
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.MetadataSource.RadarrAPI;
using NzbDrone.Core.Movies;
using NzbDrone.Core.Movies.AlternativeTitles;
using NzbDrone.Core.Movies.Events;
using Radarr.Http;
namespace NzbDrone.Api.Movies
@ -10,30 +6,12 @@ namespace NzbDrone.Api.Movies
public class AlternativeTitleModule : RadarrRestModule<AlternativeTitleResource>
{
private readonly IAlternativeTitleService _altTitleService;
private readonly IMovieService _movieService;
private readonly IRadarrAPIClient _radarrApi;
private readonly IEventAggregator _eventAggregator;
public AlternativeTitleModule(IAlternativeTitleService altTitleService, IMovieService movieService, IRadarrAPIClient radarrApi, IEventAggregator eventAggregator)
public AlternativeTitleModule(IAlternativeTitleService altTitleService)
: base("/alttitle")
{
_altTitleService = altTitleService;
_movieService = movieService;
_radarrApi = radarrApi;
CreateResource = AddTitle;
GetResourceById = GetTitle;
_eventAggregator = eventAggregator;
}
private int AddTitle(AlternativeTitleResource altTitle)
{
var title = altTitle.ToModel();
var movie = _movieService.GetMovie(altTitle.MovieId);
var newTitle = _radarrApi.AddNewAlternativeTitle(title, movie.TmdbId);
var addedTitle = _altTitleService.AddAltTitle(newTitle, movie);
_eventAggregator.PublishEvent(new MovieUpdatedEvent(movie));
return addedTitle.Id;
}
private AlternativeTitleResource GetTitle(int id)

@ -1,42 +1,17 @@
using System;
using NzbDrone.Common.Cache;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.MetadataSource.RadarrAPI;
using NzbDrone.Core.Movies;
using NzbDrone.Core.Movies.Events;
using Radarr.Http;
namespace NzbDrone.Api.Movies
{
public class AlternativeYearModule : RadarrRestModule<AlternativeYearResource>
{
private readonly IMovieService _movieService;
private readonly IRadarrAPIClient _radarrApi;
private readonly ICached<int> _yearCache;
private readonly IEventAggregator _eventAggregator;
public AlternativeYearModule(IMovieService movieService, IRadarrAPIClient radarrApi, ICacheManager cacheManager, IEventAggregator eventAggregator)
public AlternativeYearModule(ICacheManager cacheManager)
: base("/altyear")
{
_movieService = movieService;
_radarrApi = radarrApi;
CreateResource = AddYear;
GetResourceById = GetYear;
_yearCache = cacheManager.GetCache<int>(GetType(), "altYears");
_eventAggregator = eventAggregator;
}
private int AddYear(AlternativeYearResource altYear)
{
var id = new Random().Next();
_yearCache.Set(id.ToString(), altYear.Year, TimeSpan.FromMinutes(1));
var movie = _movieService.GetMovie(altYear.MovieId);
var newYear = _radarrApi.AddNewAlternativeYear(altYear.Year, movie.TmdbId);
movie.SecondaryYear = newYear.Year;
movie.SecondaryYearSourceId = newYear.SourceId;
_movieService.UpdateMovie(movie);
_eventAggregator.PublishEvent(new MovieUpdatedEvent(movie));
return id;
}
private AlternativeYearResource GetYear(int id)

@ -2,7 +2,7 @@ using System.Collections.Generic;
using System.Linq;
using NzbDrone.Api.NetImport;
using NzbDrone.Core.MediaCover;
using NzbDrone.Core.MetadataSource;
using NzbDrone.Core.Movies;
using NzbDrone.Core.NetImport;
using Radarr.Http;
@ -10,13 +10,11 @@ namespace NzbDrone.Api.Movies
{
public class MovieDiscoverModule : RadarrRestModule<MovieResource>
{
private readonly IDiscoverNewMovies _searchProxy;
private readonly INetImportFactory _netImportFactory;
public MovieDiscoverModule(IDiscoverNewMovies searchProxy, INetImportFactory netImportFactory)
public MovieDiscoverModule(INetImportFactory netImportFactory)
: base("/movies/discover")
{
_searchProxy = searchProxy;
_netImportFactory = netImportFactory;
Get("/lists", x => GetLists());
Get("/{action?recommendations}", x => Search(x.action));
@ -24,7 +22,8 @@ namespace NzbDrone.Api.Movies
private object Search(string action)
{
var imdbResults = _searchProxy.DiscoverNewMovies(action);
//Return empty for now so as not to break 3rd Party
var imdbResults = new List<Movie>();
return MapToResource(imdbResults);
}
@ -43,12 +42,12 @@ namespace NzbDrone.Api.Movies
});
}
private static IEnumerable<MovieResource> MapToResource(IEnumerable<Core.Movies.Movie> movies)
private static IEnumerable<MovieResource> MapToResource(IEnumerable<Movie> movies)
{
foreach (var currentSeries in movies)
foreach (var currentMovie in movies)
{
var resource = currentSeries.ToResource();
var poster = currentSeries.Images.FirstOrDefault(c => c.CoverType == MediaCoverTypes.Poster);
var resource = currentMovie.ToResource();
var poster = currentMovie.Images.FirstOrDefault(c => c.CoverType == MediaCoverTypes.Poster);
if (poster != null)
{
resource.RemotePoster = poster.Url;

@ -28,7 +28,7 @@ namespace NzbDrone.Api.Movies
int tmdbId = -1;
if (int.TryParse(Request.Query.tmdbId, out tmdbId))
{
var result = _movieInfo.GetMovieInfo(tmdbId, true).Item1;
var result = _movieInfo.GetMovieInfo(tmdbId).Item1;
return result.ToResource();
}
@ -38,7 +38,7 @@ namespace NzbDrone.Api.Movies
private object SearchByImdbId()
{
string imdbId = Request.Query.imdbId;
var result = _movieInfo.GetMovieInfo(imdbId);
var result = _movieInfo.GetMovieByImdbId(imdbId);
return result.ToResource();
}

@ -7,7 +7,7 @@ namespace NzbDrone.Common.Cloud
IHttpRequestBuilderFactory Services { get; }
IHttpRequestBuilderFactory TMDB { get; }
IHttpRequestBuilderFactory TMDBSingle { get; }
IHttpRequestBuilderFactory RadarrAPI { get; }
IHttpRequestBuilderFactory RadarrMetadata { get; }
}
public class RadarrCloudRequestBuilder : IRadarrCloudRequestBuilder
@ -25,14 +25,14 @@ namespace NzbDrone.Common.Cloud
.SetHeader("Authorization", $"Bearer {AuthToken}")
.CreateFactory();
RadarrAPI = new HttpRequestBuilder("https://api.radarr.video/v2/{route}/{action}")
RadarrMetadata = new HttpRequestBuilder("https://radarrapi.servarr.com/v1/{route}")
.CreateFactory();
}
public IHttpRequestBuilderFactory Services { get; private set; }
public IHttpRequestBuilderFactory TMDB { get; private set; }
public IHttpRequestBuilderFactory TMDBSingle { get; private set; }
public IHttpRequestBuilderFactory RadarrAPI { get; private set; }
public IHttpRequestBuilderFactory RadarrMetadata { get; private set; }
public string AuthToken => "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIxYTczNzMzMDE5NjFkMDNmOTdmODUzYTg3NmRkMTIxMiIsInN1YiI6IjU4NjRmNTkyYzNhMzY4MGFiNjAxNzUzNCIsInNjb3BlcyI6WyJhcGlfcmVhZCJdLCJ2ZXJzaW9uIjoxfQ.gh1BwogCCKOda6xj9FRMgAAj_RYKMMPC3oNlcBtlmwk";
}

@ -1,7 +1,5 @@
using System.Data;
using System.Data.SQLite;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Core.Datastore.Converters;
using NzbDrone.Core.Messaging.Commands;

@ -1,6 +1,5 @@
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.MetadataSource;
using NzbDrone.Core.MetadataSource.SkyHook;
using NzbDrone.Core.Movies;
using NzbDrone.Core.Test.Framework;
@ -16,7 +15,6 @@ namespace NzbDrone.Core.Test.MetadataSource.SkyHook
public void Setup()
{
UseRealHttp();
Mocker.SetConstant<ITmdbConfigService>(Mocker.Resolve<TmdbConfigService>());
}
[TestCase(11, "Star Wars")]
@ -24,7 +22,7 @@ namespace NzbDrone.Core.Test.MetadataSource.SkyHook
[TestCase(70981, "Prometheus")]
public void should_be_able_to_get_movie_detail(int tmdbId, string title)
{
var details = Subject.GetMovieInfo(tmdbId, false).Item1;
var details = Subject.GetMovieInfo(tmdbId).Item1;
ValidateMovie(details);

@ -34,7 +34,7 @@ namespace NzbDrone.Core.Test.MovieTests
private void GivenValidMovie(int tmdbId)
{
Mocker.GetMock<IProvideMovieInfo>()
.Setup(s => s.GetMovieInfo(tmdbId, true))
.Setup(s => s.GetMovieInfo(tmdbId))
.Returns(new Tuple<Movie, List<Credit>>(_fakeMovie, new List<Credit>()));
}
@ -114,7 +114,7 @@ namespace NzbDrone.Core.Test.MovieTests
};
Mocker.GetMock<IProvideMovieInfo>()
.Setup(s => s.GetMovieInfo(newMovie.TmdbId, true))
.Setup(s => s.GetMovieInfo(newMovie.TmdbId))
.Throws(new MovieNotFoundException("Movie Not Found"));
Mocker.GetMock<IAddMovieValidator>()

@ -10,7 +10,6 @@ using NzbDrone.Core.MetadataSource;
using NzbDrone.Core.Movies;
using NzbDrone.Core.Movies.Commands;
using NzbDrone.Core.Movies.Credits;
using NzbDrone.Core.Profiles;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common;
@ -33,14 +32,14 @@ namespace NzbDrone.Core.Test.MovieTests
.Returns(_movie);
Mocker.GetMock<IProvideMovieInfo>()
.Setup(s => s.GetMovieInfo(It.IsAny<int>(), It.IsAny<bool>()))
.Callback<int, bool>((i, b) => { throw new MovieNotFoundException(i); });
.Setup(s => s.GetMovieInfo(It.IsAny<int>()))
.Callback<int>((i) => { throw new MovieNotFoundException(i); });
}
private void GivenNewMovieInfo(Movie movie)
{
Mocker.GetMock<IProvideMovieInfo>()
.Setup(s => s.GetMovieInfo(_movie.TmdbId, It.IsAny<bool>()))
.Setup(s => s.GetMovieInfo(_movie.TmdbId))
.Returns(new Tuple<Movie, List<Credit>>(movie, new List<Credit>()));
}

@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NLog;
using NzbDrone.Core.Configuration;

@ -1,4 +1,3 @@
using System;
using System.IO;
using System.Linq;
using System.Xml;

@ -13,7 +13,6 @@ using NzbDrone.Core.Lifecycle;
using NzbDrone.Core.MediaFiles.Commands;
using NzbDrone.Core.Messaging.Commands;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.MetadataSource.PreDB;
using NzbDrone.Core.Movies.Commands;
using NzbDrone.Core.NetImport;
using NzbDrone.Core.Update.Commands;
@ -71,7 +70,6 @@ namespace NzbDrone.Core.Jobs
var defaultTasks = new[]
{
new ScheduledTask { Interval = 1 * 60, TypeName = typeof(PreDBSyncCommand).FullName },
new ScheduledTask { Interval = 5, TypeName = typeof(MessagingCleanupCommand).FullName },
new ScheduledTask { Interval = updateInterval, TypeName = typeof(ApplicationCheckUpdateCommand).FullName },

@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NLog;
using NLog;
namespace NzbDrone.Core.Messaging.Commands
{

@ -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,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;
}
}
}

@ -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);
}
}
}
}

@ -75,7 +75,7 @@ namespace NzbDrone.Core.Movies
try
{
movie = _movieInfo.GetMovieInfo(newMovie.TmdbId, true).Item1;
movie = _movieInfo.GetMovieInfo(newMovie.TmdbId).Item1;
}
catch (MovieNotFoundException)
{

@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using NLog;
using NzbDrone.Common.EnsureThat;

@ -11,7 +11,6 @@ using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.Messaging.Commands;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.MetadataSource;
using NzbDrone.Core.MetadataSource.RadarrAPI;
using NzbDrone.Core.Movies.AlternativeTitles;
using NzbDrone.Core.Movies.Commands;
using NzbDrone.Core.Movies.Credits;
@ -29,7 +28,6 @@ namespace NzbDrone.Core.Movies
private readonly IDiskScanService _diskScanService;
private readonly ICheckIfMovieShouldBeRefreshed _checkIfMovieShouldBeRefreshed;
private readonly IConfigService _configService;
private readonly IRadarrAPIClient _apiClient;
private readonly Logger _logger;
@ -39,7 +37,6 @@ namespace NzbDrone.Core.Movies
ICreditService creditService,
IEventAggregator eventAggregator,
IDiskScanService diskScanService,
IRadarrAPIClient apiClient,
ICheckIfMovieShouldBeRefreshed checkIfMovieShouldBeRefreshed,
IConfigService configService,
Logger logger)
@ -49,7 +46,6 @@ namespace NzbDrone.Core.Movies
_titleService = titleService;
_creditService = creditService;
_eventAggregator = eventAggregator;
_apiClient = apiClient;
_diskScanService = diskScanService;
_checkIfMovieShouldBeRefreshed = checkIfMovieShouldBeRefreshed;
_configService = configService;
@ -65,7 +61,7 @@ namespace NzbDrone.Core.Movies
try
{
var tuple = _movieInfo.GetMovieInfo(movie.TmdbId, movie.HasPreDBEntry);
var tuple = _movieInfo.GetMovieInfo(movie.TmdbId);
movieInfo = tuple.Item1;
credits = tuple.Item2;
}
@ -105,8 +101,8 @@ namespace NzbDrone.Core.Movies
movie.InCinemas = movieInfo.InCinemas;
movie.Website = movieInfo.Website;
//movie.AlternativeTitles = movieInfo.AlternativeTitles;
movie.Year = movieInfo.Year;
movie.SecondaryYear = movieInfo.SecondaryYear;
movie.PhysicalRelease = movieInfo.PhysicalRelease;
movie.YouTubeTrailerId = movieInfo.YouTubeTrailerId;
movie.Studio = movieInfo.Studio;
@ -122,35 +118,6 @@ namespace NzbDrone.Core.Movies
_logger.Warn(e, "Couldn't update movie path for " + movie.Path);
}
try
{
var mappings = _apiClient.AlternativeTitlesAndYearForMovie(movieInfo.TmdbId);
var mappingsTitles = mappings.Item1;
mappingsTitles = mappingsTitles.Where(t => t.IsTrusted()).ToList();
movieInfo.AlternativeTitles.AddRange(mappingsTitles);
if (mappings.Item2 != null)
{
movie.SecondaryYear = mappings.Item2.Year;
movie.SecondaryYearSourceId = mappings.Item2.SourceId;
}
else
{
movie.SecondaryYear = null;
movie.SecondaryYearSourceId = 0;
}
}
catch (RadarrAPIException)
{
//Not that wild, could just be a 404.
}
catch (Exception ex)
{
_logger.Info(ex, "Unable to communicate with Mappings Server.");
}
movie.AlternativeTitles = _titleService.UpdateTitles(movieInfo.AlternativeTitles, movie);
_movieService.UpdateMovie(new List<Movie> { movie }, true);

@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
namespace NzbDrone.Core.NetImport.RadarrList
{
public class RadarrListException : Exception
{
public RadarrErrors APIErrors;
public RadarrListException(RadarrErrors apiError)
: base(HumanReadable(apiError))
{
APIErrors = apiError;
}
private static string HumanReadable(RadarrErrors 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 RadarrError
{
[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 RadarrErrors
{
[JsonProperty("errors")]
public IList<RadarrError> Errors { get; set; }
}
}

@ -2,7 +2,6 @@ using System.Collections.Generic;
using NLog;
using NzbDrone.Common.Http;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.MetadataSource;
using NzbDrone.Core.Parser;
using NzbDrone.Core.ThingiProvider;
@ -10,8 +9,6 @@ namespace NzbDrone.Core.NetImport.RadarrList
{
public class RadarrListImport : HttpNetImportBase<RadarrListSettings>
{
private readonly ISearchForNewMovie _skyhookProxy;
public override string Name => "Radarr Lists";
public override NetImportType ListType => NetImportType.Other;
@ -21,11 +18,9 @@ namespace NzbDrone.Core.NetImport.RadarrList
public RadarrListImport(IHttpClient httpClient,
IConfigService configService,
IParsingService parsingService,
ISearchForNewMovie skyhookProxy,
Logger logger)
: base(httpClient, configService, parsingService, logger)
{
_skyhookProxy = skyhookProxy;
}
public override IEnumerable<ProviderDefinition> DefaultDefinitions
@ -79,7 +74,7 @@ namespace NzbDrone.Core.NetImport.RadarrList
public override IParseNetImportResponse GetParser()
{
return new RadarrListParser(_skyhookProxy);
return new RadarrListParser();
}
}
}

@ -2,20 +2,15 @@ using System.Collections.Generic;
using Newtonsoft.Json;
using NzbDrone.Common.Extensions;
using NzbDrone.Common.Http;
using NzbDrone.Core.MetadataSource;
using NzbDrone.Core.MetadataSource.RadarrAPI;
using NzbDrone.Core.MetadataSource.SkyHook.Resource;
using NzbDrone.Core.Movies;
using NzbDrone.Core.NetImport.TMDb;
namespace NzbDrone.Core.NetImport.RadarrList
{
public class RadarrListParser : IParseNetImportResponse
{
private readonly ISearchForNewMovie _skyhookProxy;
public RadarrListParser(ISearchForNewMovie skyhookProxy)
public RadarrListParser()
{
_skyhookProxy = skyhookProxy;
}
public IList<Movie> ParseResponse(NetImportResponse netMovieImporterResponse)
@ -37,18 +32,18 @@ namespace NzbDrone.Core.NetImport.RadarrList
return movies;
}
return jsonResponse.SelectList(_skyhookProxy.MapMovie);
return jsonResponse.SelectList(m => new Movie { TmdbId = m.id });
}
protected virtual bool PreProcess(NetImportResponse netImportResponse)
{
try
{
var error = JsonConvert.DeserializeObject<RadarrError>(netImportResponse.HttpResponse.Content);
var error = JsonConvert.DeserializeObject<RadarrErrors>(netImportResponse.HttpResponse.Content);
if (error != null && error.Errors != null && error.Errors.Count != 0)
{
throw new RadarrAPIException(error);
throw new RadarrListException(error);
}
}
catch (JsonSerializationException)

@ -1,8 +1,7 @@
using System.Collections.Generic;
using System.Collections.Generic;
using Newtonsoft.Json;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.MetadataSource;
using NzbDrone.Core.MetadataSource.SkyHook.Resource;
using NzbDrone.Core.Movies;
namespace NzbDrone.Core.NetImport.TMDb.Collection
@ -42,7 +41,7 @@ namespace NzbDrone.Core.NetImport.TMDb.Collection
continue;
}
movies.AddIfNotNull(_skyhookProxy.MapMovie(movie));
movies.AddIfNotNull(new Movie { TmdbId = movie.id });
}
return movies;

@ -2,7 +2,6 @@ using System.Collections.Generic;
using Newtonsoft.Json;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.MetadataSource;
using NzbDrone.Core.MetadataSource.SkyHook.Resource;
using NzbDrone.Core.Movies;
namespace NzbDrone.Core.NetImport.TMDb.List
@ -42,7 +41,7 @@ namespace NzbDrone.Core.NetImport.TMDb.List
continue;
}
movies.AddIfNotNull(_skyhookProxy.MapMovie(movie));
movies.AddIfNotNull(new Movie { TmdbId = movie.id });
}
return movies;

@ -1,8 +1,7 @@
using System.Collections.Generic;
using System.Collections.Generic;
using Newtonsoft.Json;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.MetadataSource;
using NzbDrone.Core.MetadataSource.SkyHook.Resource;
using NzbDrone.Core.Movies;
namespace NzbDrone.Core.NetImport.TMDb.Person
@ -48,7 +47,7 @@ namespace NzbDrone.Core.NetImport.TMDb.Person
continue;
}
movies.AddIfNotNull(_skyhookProxy.MapMovie(movie));
movies.AddIfNotNull(new Movie { TmdbId = movie.id });
}
}
@ -64,7 +63,7 @@ namespace NzbDrone.Core.NetImport.TMDb.Person
if (crewTypes.Contains(movie.department))
{
movies.AddIfNotNull(_skyhookProxy.MapMovie(movie));
movies.AddIfNotNull(new Movie { TmdbId = movie.id });
}
}
}

@ -0,0 +1,86 @@
namespace NzbDrone.Core.NetImport.TMDb
{
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 ListResponseRoot
{
public string id { get; set; }
public Item[] 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 Item : 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,9 +1,8 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Net;
using Newtonsoft.Json;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.MetadataSource;
using NzbDrone.Core.MetadataSource.SkyHook.Resource;
using NzbDrone.Core.Movies;
using NzbDrone.Core.NetImport.Exceptions;
@ -35,7 +34,7 @@ namespace NzbDrone.Core.NetImport.TMDb
return movies;
}
return jsonResponse.results.SelectList(_skyhookProxy.MapMovie);
return jsonResponse.Results.SelectList(m => new Movie { TmdbId = m.id });
}
protected virtual bool PreProcess(NetImportResponse listResponse)

@ -5,7 +5,6 @@ using NzbDrone.Common.Http;
using NzbDrone.Common.Serializer;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.MetadataSource;
using NzbDrone.Core.MetadataSource.SkyHook.Resource;
using NzbDrone.Core.Parser;
namespace NzbDrone.Core.NetImport.TMDb.User

@ -1,10 +1,8 @@
using System;
using System.Collections.Generic;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.MetadataSource.RadarrAPI;
using NzbDrone.Core.Movies;
using NzbDrone.Core.Movies.AlternativeTitles;
using NzbDrone.Core.Movies.Events;
using Radarr.Http;
namespace Radarr.Api.V3.Movies
@ -13,33 +11,19 @@ namespace Radarr.Api.V3.Movies
{
private readonly IAlternativeTitleService _altTitleService;
private readonly IMovieService _movieService;
private readonly IRadarrAPIClient _radarrApi;
private readonly IEventAggregator _eventAggregator;
public AlternativeTitleModule(IAlternativeTitleService altTitleService, IMovieService movieService, IRadarrAPIClient radarrApi, IEventAggregator eventAggregator)
public AlternativeTitleModule(IAlternativeTitleService altTitleService, IMovieService movieService, IEventAggregator eventAggregator)
: base("/alttitle")
{
_altTitleService = altTitleService;
_movieService = movieService;
_radarrApi = radarrApi;
_eventAggregator = eventAggregator;
CreateResource = AddTitle;
GetResourceById = GetAltTitle;
GetResourceAll = GetAltTitles;
}
private int AddTitle(AlternativeTitleResource altTitle)
{
var title = altTitle.ToModel();
var movie = _movieService.GetMovie(altTitle.MovieId);
var newTitle = _radarrApi.AddNewAlternativeTitle(title, movie.TmdbId);
var addedTitle = _altTitleService.AddAltTitle(newTitle, movie);
_eventAggregator.PublishEvent(new MovieUpdatedEvent(movie));
return addedTitle.Id;
}
private AlternativeTitleResource GetAltTitle(int id)
{
return _altTitleService.GetById(id).ToResource();

@ -1,9 +1,6 @@
using System;
using NzbDrone.Common.Cache;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.MetadataSource.RadarrAPI;
using NzbDrone.Core.Movies;
using NzbDrone.Core.Movies.Events;
using Radarr.Http;
namespace Radarr.Api.V3.Movies
@ -11,34 +8,18 @@ namespace Radarr.Api.V3.Movies
public class AlternativeYearModule : RadarrRestModule<AlternativeYearResource>
{
private readonly IMovieService _movieService;
private readonly IRadarrAPIClient _radarrApi;
private readonly ICached<int> _yearCache;
private readonly IEventAggregator _eventAggregator;
public AlternativeYearModule(IMovieService movieService, IRadarrAPIClient radarrApi, ICacheManager cacheManager, IEventAggregator eventAggregator)
public AlternativeYearModule(IMovieService movieService, ICacheManager cacheManager, IEventAggregator eventAggregator)
: base("/altyear")
{
_movieService = movieService;
_radarrApi = radarrApi;
CreateResource = AddYear;
GetResourceById = GetYear;
_yearCache = cacheManager.GetCache<int>(GetType(), "altYears");
_eventAggregator = eventAggregator;
}
private int AddYear(AlternativeYearResource altYear)
{
var id = new Random().Next();
_yearCache.Set(id.ToString(), altYear.Year, TimeSpan.FromMinutes(1));
var movie = _movieService.GetMovie(altYear.MovieId);
var newYear = _radarrApi.AddNewAlternativeYear(altYear.Year, movie.TmdbId);
movie.SecondaryYear = newYear.Year;
movie.SecondaryYearSourceId = newYear.SourceId;
_movieService.UpdateMovie(movie);
_eventAggregator.PublishEvent(new MovieUpdatedEvent(movie));
return id;
}
private AlternativeYearResource GetYear(int id)
{
return new AlternativeYearResource

@ -1,67 +0,0 @@
using System.Collections.Generic;
using System.Linq;
using NzbDrone.Core.MediaCover;
using NzbDrone.Core.MetadataSource;
using NzbDrone.Core.Movies;
using NzbDrone.Core.NetImport;
using NzbDrone.Core.Organizer;
using Radarr.Api.V3.NetImport;
using Radarr.Http;
namespace Radarr.Api.V3.Movies
{
public class MovieDiscoverModule : RadarrRestModule<MovieResource>
{
private readonly IDiscoverNewMovies _searchProxy;
private readonly INetImportFactory _netImportFactory;
private readonly IBuildFileNames _fileNameBuilder;
public MovieDiscoverModule(IDiscoverNewMovies searchProxy, INetImportFactory netImportFactory, IBuildFileNames fileNameBuilder)
: base("/movies/discover")
{
_searchProxy = searchProxy;
_netImportFactory = netImportFactory;
_fileNameBuilder = fileNameBuilder;
Get("/lists", x => GetLists());
Get("/{action?recommendations}", x => Search(x.action));
}
private object Search(string action)
{
var imdbResults = _searchProxy.DiscoverNewMovies(action);
return MapToResource(imdbResults);
}
private object GetLists()
{
var lists = _netImportFactory.Discoverable();
return lists.Select(definition =>
{
var resource = new NetImportResource();
resource.Id = definition.Definition.Id;
resource.Name = definition.Definition.Name;
return resource;
});
}
private IEnumerable<MovieResource> MapToResource(IEnumerable<Movie> movies)
{
foreach (var currentMovie in movies)
{
var resource = currentMovie.ToResource();
var poster = currentMovie.Images.FirstOrDefault(c => c.CoverType == MediaCoverTypes.Poster);
if (poster != null)
{
resource.RemotePoster = poster.Url;
}
resource.Folder = _fileNameBuilder.GetMovieFolder(currentMovie);
yield return resource;
}
}
}
}

@ -32,7 +32,7 @@ namespace Radarr.Api.V3.Movies
int tmdbId = -1;
if (int.TryParse(Request.Query.tmdbId, out tmdbId))
{
var result = _movieInfo.GetMovieInfo(tmdbId, true).Item1;
var result = _movieInfo.GetMovieInfo(tmdbId).Item1;
return result.ToResource();
}
@ -42,7 +42,7 @@ namespace Radarr.Api.V3.Movies
private object SearchByImdbId()
{
string imdbId = Request.Query.imdbId;
var result = _movieInfo.GetMovieInfo(imdbId);
var result = _movieInfo.GetMovieByImdbId(imdbId);
return result.ToResource();
}

@ -1,6 +1,5 @@
using System;
using System.Linq;
using System.Net;
using System.Security.Claims;
using System.Security.Principal;
using Nancy;

Loading…
Cancel
Save