diff options
| author | Anthony Lavado <anthonylavado@users.noreply.github.com> | 2019-06-22 02:08:46 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-06-22 02:08:46 -0400 |
| commit | 084854d71d15d35945de1ce59a397d3f4e750b61 (patch) | |
| tree | 202b7eb703def2b35e5c3e04a9ca78784e30ebb5 | |
| parent | d5fe82314e11d3b8b2ba58e4684a7968fbe6dbca (diff) | |
| parent | c2ab0ad641b60b453a0697918e9db7773e89a6f6 (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.cs | 14 |
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; |
