public async Task TestAuthenticationRequestNewToken() { Token token = await TMDbClient.AuthenticationRequestAutenticationTokenAsync(); Assert.NotNull(token); Assert.True(token.Success); Assert.NotNull(token.AuthenticationCallback); Assert.NotNull(token.RequestToken); }
public async Task TestCustomDatetimeFormatConverter() { Token token = await TMDbClient.AuthenticationRequestAutenticationTokenAsync(); DateTime low = DateTime.UtcNow.AddHours(-2); DateTime high = DateTime.UtcNow.AddHours(2); Assert.InRange(token.ExpiresAt, low, high); }
public TMDbClient GetTMDbClient() { String apiKey = configuration.GetValue <String>("api:api_key"); String username = configuration.GetValue <String>("api:username"); String password = configuration.GetValue <String>("api:password"); TMDbClient client = new TMDbClient(apiKey); Token token = client.AuthenticationRequestAutenticationTokenAsync().Result; Task task = client.AuthenticationValidateUserTokenAsync(token.RequestToken, username, password); task.GetAwaiter().GetResult(); UserSession session = client.AuthenticationGetUserSessionAsync(token.RequestToken).Result; client.SetSessionInformation(session.SessionId, SessionType.UserSession); return(client); }
public async Task TestAuthenticationGetUserSessionApiUserValidationInvalidLoginAsync() { Token token = await TMDbClient.AuthenticationRequestAutenticationTokenAsync(); await Assert.ThrowsAsync <UnauthorizedAccessException>(() => TMDbClient.AuthenticationValidateUserTokenAsync(token.RequestToken, "bla", "bla")); }
public async Task TestAuthenticationGetUserSessionApiUserValidationSuccessAsync() { Token token = await TMDbClient.AuthenticationRequestAutenticationTokenAsync(); await TMDbClient.AuthenticationValidateUserTokenAsync(token.RequestToken, TestConfig.Username, TestConfig.Password); }
private async void ProcessTmDbInfo() { try { IsBusy = true; BusyMessage = "Saving Config..."; SaveConfig(); if (string.IsNullOrWhiteSpace(Settings.Default.TMDbApiKey)) { // Prompt user for API key // Prompt from : https://github.com/ramer/IPrompt var prompt = IInputBox.Show("Enter your Movie Database API Key", "API Key Required"); if (string.IsNullOrWhiteSpace(prompt)) { IMessageBox.Show("The Movie Database Key is required for this service. Signup for the API key (free) at www.themoviedb.org"); return; } Settings.Default.TMDbApiKey = prompt; Settings.Default.Save(); } // API using nuget package -- code here; https://github.com/LordMike/TMDbLib var client = new TMDbClient(Settings.Default.TMDbApiKey); await client.AuthenticationRequestAutenticationTokenAsync(); // API permits only 40 calls per 10 seconds. using this nuget package to limit it to 35. var timeconstraint = TimeLimiter.GetFromMaxCountByInterval(35, TimeSpan.FromSeconds(10)); // loop over the folders and find the folders that dont have a metadata data file in them var foldersToProcess = _files.Where(x => !x.IsSelected && x.TheMovieDatabaseData == null).ToList(); for (var index = 0; index < foldersToProcess.Count; index++) { var f = foldersToProcess[index]; var folderName = f.LocalFolderPath.Substring(1, f.LocalFolderPath.Length - 1); if (folderName.Contains(DirectorySeperator)) { continue; } var name = f.SingleDirectoryName.GetNameBeforeYear(); if (name.EndsWith("-")) { name = name.Substring(0, name.Length - 1).Trim(); } if (Config.MovieOption) { // Currently dont support season info lookup. Just primary anme. if (f.SingleDirectoryName.ToLower().StartsWith("season")) { continue; } var year = f.SingleDirectoryName.GetYear(); if (year.HasValue) { BusyMessage = $"Searching For Movie [{index + 1} / {foldersToProcess.Count}] '{name}' ({year.Value})"; await timeconstraint.Perform(async() => { var result = await client.SearchMovieAsync(name, year: year.Value); if (result.TotalResults >= 1) { f.TheMovieDatabaseData = result.Results.OrderByDescending(x => x.VoteCount) .FirstOrDefault(); var json = JsonConvert.SerializeObject(f.TheMovieDatabaseData, Formatting.Indented); File.WriteAllText(f.TheMovieDatabaseFileName, json); } }); } } else if (Config.TvOption) { BusyMessage = $"Searching For Tv [{index + 1} / {foldersToProcess.Count}] '{name}')"; await timeconstraint.Perform(async() => { var result = await client.SearchTvShowAsync(name); if (result.TotalResults >= 1) { f.TheMovieDatabaseData = result.Results.OrderByDescending(x => x.VoteCount).FirstOrDefault(); var json = JsonConvert.SerializeObject(f.TheMovieDatabaseData, Formatting.Indented); File.WriteAllText(f.TheMovieDatabaseFileName, json); } }); } } } catch (TaskCanceledException t) { // Ignore, Task was canceled. } catch (Exception ex) { IMessageBox.Show(ex.Message); if (ex.Message.Contains("unauthorized")) { Settings.Default.TMDbApiKey = string.Empty; Settings.Default.Save(); } } finally { IsBusy = false; } }