internal TraktClient() { Configuration = new TraktConfiguration(); Authentication = new TraktAuthentication(this); OAuth = new TraktOAuth(this); DeviceAuth = new TraktDeviceAuth(this); Shows = new TraktShowsModule(this); Seasons = new TraktSeasonsModule(this); Episodes = new TraktEpisodesModule(this); Movies = new TraktMoviesModule(this); Calendar = new TraktCalendarModule(this); Comments = new TraktCommentsModule(this); People = new TraktPeopleModule(this); Genres = new TraktGenresModule(this); Search = new TraktSearchModule(this); Recommendations = new TraktRecommendationsModule(this); Sync = new TraktSyncModule(this); Users = new TraktUsersModule(this); Checkins = new TraktCheckinsModule(this); Scrobble = new TraktScrobbleModule(this); }
/// <summary> /// Login to trak.tv, this is called from other modules in Ember to connect to trakt.tv, Entry point /// </summary> /// <param name="account">Account data</param> /// <returns>Retrieved Token from trakt.tv API</returns> public static TraktToken LoginToAccount(TraktAuthentication account) { TraktToken response = null; response = Trakttv.TrakttvAPI.Login(account.ToJSON()); if (response == null || string.IsNullOrEmpty(response.Token)) { // not good, process failed logger.Warn("[LoginToAccount] Invalid Response!"); } else { // Save User Token TraktSettings.Token = response.Token; // Save New Account Settings TraktSettings.Username = account.Username; TraktSettings.Password = account.Password; } return(response); }
private void TestAccount(TraktAuthentication account) { TraktUserToken response = null; if (NewAccount) { // No longer supported with v2 API. //if (lblTestConnect != null) // GUIControl.SetControlLabel(GetID, lblTestConnect.GetID, Translation.CreatingAccount); //GUIWindowManager.Process(); //response = TraktAPI.v1.TraktAPI.CreateAccount(account); } else { if (lblTestConnect != null) { GUIControl.SetControlLabel(GetID, lblTestConnect.GetID, Translation.SigningIntoAccount); } GUIWindowManager.Process(); response = TraktAPI.TraktAPI.Login(account.ToJSON()); } if (response == null || string.IsNullOrEmpty(response.Token)) { GUIUtils.ShowNotifyDialog(Translation.Error, Translation.FailedLogin); if (lblTestConnect != null) { GUIControl.SetControlLabel(GetID, lblTestConnect.GetID, string.Empty); } } else { // Save User Token TraktAPI.TraktAPI.UserToken = response.Token; // Save New Account Settings TraktSettings.Username = account.Username; TraktSettings.Password = account.Password; if (!TraktSettings.UserLogins.Exists(u => u.Username == TraktSettings.Username)) { TraktSettings.UserLogins.Add(new TraktAuthentication { Username = TraktSettings.Username, Password = TraktSettings.Password }); } TraktSettings.AccountStatus = ConnectionState.Connected; HideAccountControls(); InitProperties(); // clear caches // watchlists are stored by user so dont need clearing. GUINetwork.ClearCache(); GUICalendar.ClearCache(); GUIRecommendationsMovies.ClearCache(); GUIRecommendationsShows.ClearCache(); // clear any stored user data TraktCache.ClearSyncCache(); } }
protected override void OnClicked(int controlId, GUIControl control, Action.ActionType actionType) { // wait for any background action to finish if (GUIBackgroundTask.Instance.IsBusy) { return; } switch (controlId) { // Disconnect case ((int)SkinControls.Disconnect): DisconnectAccount(); break; case ((int)SkinControls.Create): ShowAccountControls(true); break; case ((int)SkinControls.Login): bool autoLogin = ShowLoginMenu(); ShowAccountControls(false); if (autoLogin) { GUIControl.SetControlLabel(GetID, btnUsername.GetID, this.Username); GUIControl.SetControlLabel(GetID, btnPassword.GetID, GetMaskedPassword(this.Password)); var account = new TraktAuthentication { Username = this.Username, Password = this.Password }; TestAccount(account); } break; case ((int)SkinControls.Username): string username = Username; if (GUIUtils.GetStringFromKeyboard(ref username)) { GUIUtils.SetProperty("#Trakt.Settings.Account.Dialog.HasUsername", "true"); if (!username.Equals(Username)) { Username = username; GUIControl.SetControlLabel(GetID, btnUsername.GetID, username); } } break; case ((int)SkinControls.Password): string password = Password; if (GUIUtils.GetStringFromKeyboard(ref password, true)) { GUIUtils.SetProperty("#Trakt.Settings.Account.Dialog.HasPassword", "true"); if (!password.Equals(Password)) { Password = password; GUIControl.SetControlLabel(GetID, btnPassword.GetID, GetMaskedPassword(password)); } } break; case ((int)SkinControls.EmailButton): string email = Email; if (GUIUtils.GetStringFromKeyboard(ref email)) { if (!email.Equals(Email)) { Email = email; GUIControl.SetControlLabel(GetID, btnEmail.GetID, email); } } break; case ((int)SkinControls.Ok): if (ValidateFields()) { var account = new TraktAuthentication { Username = this.Username, Password = this.Password, //Email = this.Email }; TestAccount(account); } break; case ((int)SkinControls.Cancel): HideAccountControls(); break; default: break; } base.OnClicked(controlId, control, actionType); }
private void StartImport() { if (ImportRunning) { return; } if (string.IsNullOrEmpty(AppSettings.TraktUsername) || string.IsNullOrEmpty(AppSettings.TraktPassword)) { UIUtils.UpdateStatus("You must enter in your trakt username and password!", true); return; } sites.Clear(); // add import sites for processing sites.Add(new TMDb(AppSettings.TMDbRequestToken, AppSettings.TMDbSessionId)); sites.Add(new TVDb(AppSettings.TVDbAccountIdentifier)); sites.Add(new IMDb(AppSettings.IMDbFilename)); if (sites.Where(s => s.Enabled).Count() == 0) { UIUtils.UpdateStatus("Incorrect site information supplied!", true); return; } #region Import Thread importThread = new Thread((o) => { ImportRunning = true; // only one import at a time SetControlState(false); // Clear Progress ClearProgress(); #region Login to trakt UIUtils.UpdateStatus("Logging in to trakt.tv..."); var accountDetails = new TraktAuthentication { Username = AppSettings.TraktUsername, Password = AppSettings.TraktPassword }; var response = TraktAPI.TraktAPI.TestAccount(accountDetails); if (response == null || response.Status != "success") { UIUtils.UpdateStatus("Unable to login to trakt, check username and password!", true); SetControlState(true); ImportRunning = false; ImportCancelled = false; return; } #endregion // import ratings foreach (var site in sites.Where(s => s.Enabled)) { try { if (!ImportCancelled) { site.ImportRatings(); } } catch (Exception e) { UIUtils.UpdateStatus(string.Format("{0}:{1}", site.Name, e.Message), true); Thread.Sleep(5000); } } // finished SetControlState(true); UIUtils.UpdateStatus("Import Complete!"); ImportRunning = false; ImportCancelled = false; }); importThread.Start(); #endregion }
/// <summary> /// Tests account details can login to trakt.tv /// </summary> /// <param name="data">Object containing username/password</param> /// <returns>The response from trakt</returns> public static TraktResponse TestAccount(TraktAuthentication data) { string response = TraktWeb.Transmit(TraktURIs.TestAccount, data.ToJSON()); return(response.FromJSON <TraktResponse>()); }