|
|
|
@ -10,6 +10,7 @@ using MediaBrowser.Model.Providers;
|
|
|
|
|
using MediaBrowser.Model.Serialization;
|
|
|
|
|
using MediaBrowser.Providers.Movies;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Concurrent;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.IO;
|
|
|
|
@ -18,6 +19,7 @@ using System.Net;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using CommonIO;
|
|
|
|
|
using MediaBrowser.Model.Logging;
|
|
|
|
|
using MediaBrowser.Model.Net;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Providers.People
|
|
|
|
@ -32,14 +34,30 @@ namespace MediaBrowser.Providers.People
|
|
|
|
|
private readonly IFileSystem _fileSystem;
|
|
|
|
|
private readonly IServerConfigurationManager _configurationManager;
|
|
|
|
|
private readonly IHttpClient _httpClient;
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
|
|
|
|
|
public MovieDbPersonProvider(IFileSystem fileSystem, IServerConfigurationManager configurationManager, IJsonSerializer jsonSerializer, IHttpClient httpClient)
|
|
|
|
|
private int _requestCount;
|
|
|
|
|
private readonly object _requestCountLock = new object();
|
|
|
|
|
private Timer _requestCountReset;
|
|
|
|
|
|
|
|
|
|
public MovieDbPersonProvider(IFileSystem fileSystem, IServerConfigurationManager configurationManager, IJsonSerializer jsonSerializer, IHttpClient httpClient, ILogger logger)
|
|
|
|
|
{
|
|
|
|
|
_fileSystem = fileSystem;
|
|
|
|
|
_configurationManager = configurationManager;
|
|
|
|
|
_jsonSerializer = jsonSerializer;
|
|
|
|
|
_httpClient = httpClient;
|
|
|
|
|
_logger = logger;
|
|
|
|
|
Current = this;
|
|
|
|
|
|
|
|
|
|
_requestCountReset = new Timer(OnRequestThrottleTimerFired, null, TimeSpan.FromHours(1), TimeSpan.FromHours(1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnRequestThrottleTimerFired(object state)
|
|
|
|
|
{
|
|
|
|
|
lock (_requestCountLock)
|
|
|
|
|
{
|
|
|
|
|
_requestCount = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Name
|
|
|
|
@ -79,6 +97,24 @@ namespace MediaBrowser.Providers.People
|
|
|
|
|
return new[] { result };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (searchInfo.IsAutomated)
|
|
|
|
|
{
|
|
|
|
|
lock (_requestCountLock)
|
|
|
|
|
{
|
|
|
|
|
var requestCount = _requestCount;
|
|
|
|
|
|
|
|
|
|
if (requestCount >= 5)
|
|
|
|
|
{
|
|
|
|
|
_logger.Debug("Throttling Tmdb people");
|
|
|
|
|
|
|
|
|
|
// This needs to be throttled
|
|
|
|
|
return new List<RemoteSearchResult>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_requestCount = requestCount + 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var url = string.Format(@"http://api.themoviedb.org/3/search/person?api_key={1}&query={0}", WebUtility.UrlEncode(searchInfo.Name), MovieDbProvider.ApiKey);
|
|
|
|
|
|
|
|
|
|
using (var json = await MovieDbProvider.Current.GetMovieDbResponse(new HttpRequestOptions
|
|
|
|
|