From 0d1150d4d26d8ccf3e754d5113a867470b5f2d1d Mon Sep 17 00:00:00 2001 From: Devin Buhl Date: Tue, 7 Feb 2017 16:55:57 -0500 Subject: [PATCH] Wait 5 seconds before getting the next 35 movies from TMDb using X-RateLimit-Remaining (#647) * Wait 5 seconds before getting the next 35 movies from TMDb using X-RateLimit-Remaining * Update SkyHookProxy.cs --- .../MetadataSource/SkyHook/SkyHookProxy.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs b/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs index 084957bfa..124957358 100644 --- a/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs +++ b/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs @@ -14,6 +14,7 @@ using NzbDrone.Core.Tv; using Newtonsoft.Json; using System.Text.RegularExpressions; using System.Text; +using System.Threading; using NzbDrone.Core.Parser; using NzbDrone.Core.Profiles; @@ -86,8 +87,18 @@ namespace NzbDrone.Core.MetadataSource.SkyHook request.SuppressHttpError = true; var response = _httpClient.Get(request); - var resource = response.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 + 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 resource = response.Resource; if (resource.status_message != null) { if (resource.status_code == 34)