From 31e657d05294e4cd3cb36701ddeba697a832955c Mon Sep 17 00:00:00 2001 From: Devin Buhl Date: Fri, 10 Feb 2017 23:03:24 -0500 Subject: [PATCH 1/2] Limit TMDb requests when importing via IMDBid (#703) --- .../MetadataSource/SkyHook/SkyHookProxy.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs b/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs index aaa9e9f78..47b648fba 100644 --- a/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs +++ b/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs @@ -232,7 +232,19 @@ namespace NzbDrone.Core.MetadataSource.SkyHook request.AllowAutoRedirect = true; request.SuppressHttpError = true; - var resources = _httpClient.Get(request).Resource; + var response = _httpClient.Get(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(); } From ea33b75764d96f9988b9f70c8206b32f348d539b Mon Sep 17 00:00:00 2001 From: zductiv Date: Sat, 11 Feb 2017 21:48:02 +0800 Subject: [PATCH 2/2] search all missing movie works - missing tab only (#710) --- .../IndexerSearch/MoviesSearchService.cs | 49 ++++++++++++++++++- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/src/NzbDrone.Core/IndexerSearch/MoviesSearchService.cs b/src/NzbDrone.Core/IndexerSearch/MoviesSearchService.cs index 5b8e4dd37..affb1437b 100644 --- a/src/NzbDrone.Core/IndexerSearch/MoviesSearchService.cs +++ b/src/NzbDrone.Core/IndexerSearch/MoviesSearchService.cs @@ -1,10 +1,14 @@ -using System.Linq; +using System; +using System.Linq; +using System.Collections.Generic; using NLog; using NzbDrone.Common.Instrumentation.Extensions; using NzbDrone.Core.Download; using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Tv; using NzbDrone.Core.Datastore; +using NzbDrone.Core.Queue; +using NzbDrone.Core.DecisionEngine; namespace NzbDrone.Core.IndexerSearch { @@ -13,17 +17,48 @@ namespace NzbDrone.Core.IndexerSearch private readonly IMovieService _movieService; private readonly ISearchForNzb _nzbSearchService; private readonly IProcessDownloadDecisions _processDownloadDecisions; + private readonly IQueueService _queueService; private readonly Logger _logger; public MovieSearchService(IMovieService movieService, ISearchForNzb nzbSearchService, IProcessDownloadDecisions processDownloadDecisions, + IQueueService queueService, Logger logger) { _movieService = movieService; _nzbSearchService = nzbSearchService; _processDownloadDecisions = processDownloadDecisions; + _queueService = queueService; _logger = logger; + } + + private void SearchForMissingMovies(List 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 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) @@ -47,7 +82,9 @@ namespace NzbDrone.Core.IndexerSearch public void Execute(MissingMoviesSearchCommand message) { - var movies = _movieService.MoviesWithoutFiles(new PagingSpec + List movies; + + movies = _movieService.MoviesWithoutFiles(new PagingSpec { Page = 1, PageSize = 100000, @@ -57,6 +94,14 @@ namespace NzbDrone.Core.IndexerSearch v => v.Monitored == true }).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); + } + } }