mirror of https://github.com/Radarr/Radarr
Merged branch develop into develop
This commit is contained in:
commit
a1961603d7
|
@ -1,10 +1,14 @@
|
||||||
using System.Linq;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Collections.Generic;
|
||||||
using NLog;
|
using NLog;
|
||||||
using NzbDrone.Common.Instrumentation.Extensions;
|
using NzbDrone.Common.Instrumentation.Extensions;
|
||||||
using NzbDrone.Core.Download;
|
using NzbDrone.Core.Download;
|
||||||
using NzbDrone.Core.Messaging.Commands;
|
using NzbDrone.Core.Messaging.Commands;
|
||||||
using NzbDrone.Core.Tv;
|
using NzbDrone.Core.Tv;
|
||||||
using NzbDrone.Core.Datastore;
|
using NzbDrone.Core.Datastore;
|
||||||
|
using NzbDrone.Core.Queue;
|
||||||
|
using NzbDrone.Core.DecisionEngine;
|
||||||
|
|
||||||
namespace NzbDrone.Core.IndexerSearch
|
namespace NzbDrone.Core.IndexerSearch
|
||||||
{
|
{
|
||||||
|
@ -13,19 +17,50 @@ namespace NzbDrone.Core.IndexerSearch
|
||||||
private readonly IMovieService _movieService;
|
private readonly IMovieService _movieService;
|
||||||
private readonly ISearchForNzb _nzbSearchService;
|
private readonly ISearchForNzb _nzbSearchService;
|
||||||
private readonly IProcessDownloadDecisions _processDownloadDecisions;
|
private readonly IProcessDownloadDecisions _processDownloadDecisions;
|
||||||
|
private readonly IQueueService _queueService;
|
||||||
private readonly Logger _logger;
|
private readonly Logger _logger;
|
||||||
|
|
||||||
public MovieSearchService(IMovieService movieService,
|
public MovieSearchService(IMovieService movieService,
|
||||||
ISearchForNzb nzbSearchService,
|
ISearchForNzb nzbSearchService,
|
||||||
IProcessDownloadDecisions processDownloadDecisions,
|
IProcessDownloadDecisions processDownloadDecisions,
|
||||||
|
IQueueService queueService,
|
||||||
Logger logger)
|
Logger logger)
|
||||||
{
|
{
|
||||||
_movieService = movieService;
|
_movieService = movieService;
|
||||||
_nzbSearchService = nzbSearchService;
|
_nzbSearchService = nzbSearchService;
|
||||||
_processDownloadDecisions = processDownloadDecisions;
|
_processDownloadDecisions = processDownloadDecisions;
|
||||||
|
_queueService = queueService;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void SearchForMissingMovies(List<Movie> movies, bool userInvokedSearch)
|
||||||
|
{
|
||||||
|
_logger.ProgressInfo("Performing missing search for {0} movies", movies.Count);
|
||||||
|
var downloadedCount = 0;
|
||||||
|
|
||||||
|
foreach (var movieId in movies.GroupBy(e => e.Id))
|
||||||
|
{
|
||||||
|
List<DownloadDecision> decisions;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
decisions = _nzbSearchService.MovieSearch(movieId.Key, userInvokedSearch);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
var message = String.Format("Unable to search for missing movie {0}", movieId.Key);
|
||||||
|
_logger.Error(ex, message);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var processed = _processDownloadDecisions.ProcessDecisions(decisions);
|
||||||
|
|
||||||
|
downloadedCount += processed.Grabbed.Count;
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.ProgressInfo("Completed missing search for {0} movies. {1} reports downloaded.", movies.Count, downloadedCount);
|
||||||
|
}
|
||||||
|
|
||||||
public void Execute(MoviesSearchCommand message)
|
public void Execute(MoviesSearchCommand message)
|
||||||
{
|
{
|
||||||
var downloadedCount = 0;
|
var downloadedCount = 0;
|
||||||
|
@ -47,7 +82,9 @@ namespace NzbDrone.Core.IndexerSearch
|
||||||
|
|
||||||
public void Execute(MissingMoviesSearchCommand message)
|
public void Execute(MissingMoviesSearchCommand message)
|
||||||
{
|
{
|
||||||
var movies = _movieService.MoviesWithoutFiles(new PagingSpec<Movie>
|
List<Movie> movies;
|
||||||
|
|
||||||
|
movies = _movieService.MoviesWithoutFiles(new PagingSpec<Movie>
|
||||||
{
|
{
|
||||||
Page = 1,
|
Page = 1,
|
||||||
PageSize = 100000,
|
PageSize = 100000,
|
||||||
|
@ -57,6 +94,14 @@ namespace NzbDrone.Core.IndexerSearch
|
||||||
v =>
|
v =>
|
||||||
v.Monitored == true
|
v.Monitored == true
|
||||||
}).Records.ToList();
|
}).Records.ToList();
|
||||||
|
|
||||||
|
|
||||||
|
var queue = _queueService.GetQueue().Select(q => q.Movie.Id);
|
||||||
|
var missing = movies.Where(e => !queue.Contains(e.Id)).ToList();
|
||||||
|
|
||||||
|
SearchForMissingMovies(missing, message.Trigger == CommandTrigger.Manual);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -232,7 +232,19 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
||||||
request.AllowAutoRedirect = true;
|
request.AllowAutoRedirect = true;
|
||||||
request.SuppressHttpError = true;
|
request.SuppressHttpError = true;
|
||||||
|
|
||||||
var resources = _httpClient.Get<FindRoot>(request).Resource;
|
var response = _httpClient.Get<FindRoot>(request);
|
||||||
|
|
||||||
|
// 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
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
var resources = response.Resource;
|
||||||
|
|
||||||
return resources.movie_results.SelectList(MapMovie).FirstOrDefault();
|
return resources.movie_results.SelectList(MapMovie).FirstOrDefault();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue