aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Lavado <anthonylavado@users.noreply.github.com>2019-06-22 02:08:46 -0400
committerGitHub <noreply@github.com>2019-06-22 02:08:46 -0400
commit084854d71d15d35945de1ce59a397d3f4e750b61 (patch)
tree202b7eb703def2b35e5c3e04a9ca78784e30ebb5
parentd5fe82314e11d3b8b2ba58e4684a7968fbe6dbca (diff)
parentc2ab0ad641b60b453a0697918e9db7773e89a6f6 (diff)
Merge pull request #1478 from cvium/fix_tvdb_again
Wait for the async authentication to finish when the JTW token expires
-rw-r--r--MediaBrowser.Providers/TV/TheTVDB/TvDbClientManager.cs14
1 files changed, 9 insertions, 5 deletions
diff --git a/MediaBrowser.Providers/TV/TheTVDB/TvDbClientManager.cs b/MediaBrowser.Providers/TV/TheTVDB/TvDbClientManager.cs
index 1d1fbd00f..85833223e 100644
--- a/MediaBrowser.Providers/TV/TheTVDB/TvDbClientManager.cs
+++ b/MediaBrowser.Providers/TV/TheTVDB/TvDbClientManager.cs
@@ -24,24 +24,28 @@ namespace MediaBrowser.Providers.TV.TheTVDB
{
_cache = memoryCache;
_tvDbClient = new TvDbClient();
- _tvDbClient.Authentication.AuthenticateAsync(TvdbUtils.TvdbApiKey);
- _tokenCreatedAt = DateTime.Now;
}
- public TvDbClient TvDbClient
+ private TvDbClient TvDbClient
{
get
{
+ if (string.IsNullOrEmpty(_tvDbClient.Authentication.Token))
+ {
+ _tvDbClient.Authentication.AuthenticateAsync(TvdbUtils.TvdbApiKey).GetAwaiter().GetResult();
+ _tokenCreatedAt = DateTime.Now;
+ }
+
// Refresh if necessary
if (_tokenCreatedAt < DateTime.Now.Subtract(TimeSpan.FromHours(20)))
{
try
{
- _tvDbClient.Authentication.RefreshTokenAsync();
+ _tvDbClient.Authentication.RefreshTokenAsync().GetAwaiter().GetResult();
}
catch
{
- _tvDbClient.Authentication.AuthenticateAsync(TvdbUtils.TvdbApiKey);
+ _tvDbClient.Authentication.AuthenticateAsync(TvdbUtils.TvdbApiKey).GetAwaiter().GetResult();
}
_tokenCreatedAt = DateTime.Now;