private bool TestAccount(TraktAuthenticationToken token) { // test account by requesting the user settings var response = TraktAPI.TraktAPI.GetUserSettings(); if (response == null || response.User == null) { GUIUtils.ShowNotifyDialog(Translation.Error, Translation.FailedOnlineSettings); return(false); } else { // Save New Account Settings TraktSettings.Username = response.User.Username; TraktSettings.OnlineSettings = response; TraktSettings.AccountStatus = ConnectionState.Connected; InitProperties(); // clear caches // watchlists are stored by user so dont need clearing. GUINetwork.ClearCache(); GUICalendarTV.ClearCache(); GUIRecommendationsMovies.ClearCache(); GUIRecommendationsShows.ClearCache(); // clear any stored user data TraktCache.ClearSyncCache(); // persist settings TraktSettings.SaveSettings(false); return(true); } }
protected override void OnPageDestroy(int new_windowId) { // save settings if (btnDownloadFanart != null) { TraktSettings.DownloadFanart = btnDownloadFanart.Selected; } if (btnDownloadFullSizeFanart != null) { TraktSettings.DownloadFullSizeFanart = btnDownloadFullSizeFanart.Selected; } if (btnGetFollowerRequests != null) { TraktSettings.GetFollowerRequestsOnStartup = btnGetFollowerRequests.Selected; } if (btnShowRateDialogOnWatched != null) { TraktSettings.ShowRateDialogOnWatched = btnShowRateDialogOnWatched.Selected; } if (btnSyncRatings != null) { TraktSettings.SyncRatings = btnSyncRatings.Selected; } if (btnCreateMyFilmsCategories != null) { TraktSettings.MyFilmsCategories = btnCreateMyFilmsCategories.Selected; } // update any internal plugin settings required TraktSettings.UpdateInternalPluginSettings(); TraktSettings.SaveSettings(); base.OnPageDestroy(new_windowId); }
public void AuthorizeUser() { if (string.IsNullOrEmpty(PinCode) || PinCode.Length != 8) { TestStatus = "[Trakt.WrongToken]"; TraktLogger.Error("Wrong pin entered"); return; } if (!Login()) { return; } if (string.IsNullOrEmpty(Username)) { TestStatus = "[Trakt.EmptyUsername]"; TraktLogger.Error("Username is missing"); return; } ISettingsManager settingsManager = ServiceRegistration.Get <ISettingsManager>(); TraktSettings settings = settingsManager.Load <TraktSettings>(); // temp. fix to disable the authorize button, when the user already is authorized IsAuthorized = true; settings.IsAuthorized = IsAuthorized; settings.EnableTrakt = IsEnabled; settings.Username = Username; settingsManager.Save(settings); }
public void Setup() { _validator = new TestValidator <TraktSettings> { v => v.RuleFor(s => s).SetValidator(Subject) }; _traktSettings = Builder <TraktSettings> .CreateNew() .With(s => s.AccessToken = "sometoken") .With(s => s.RefreshToken = "sometoken") .With(s => s.Expires = DateTime.Now.AddDays(2)) .Build(); }
private void btnChkCred_Click(object sender, RoutedEventArgs e) { Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(AppSettings.Culture); TraktSettings OP = new TraktSettings(); var host = new Window(); host.Content = OP; host.Title = Shoko.Commons.Properties.Resources.Trakt_CheckCred; host.Width = 630; host.Height = 240; host.WindowStartupLocation = WindowStartupLocation.CenterScreen; OP.Margin = new Thickness(5); host.ResizeMode = ResizeMode.NoResize; host.ShowDialog(); }
public void EnterModelContext(NavigationContext oldContext, NavigationContext newContext) { ISettingsManager settingsManager = ServiceRegistration.Get <ISettingsManager>(); TraktSettings settings = settingsManager.Load <TraktSettings>(); IsEnabled = settings.EnableTrakt; IsAuthorized = settings.IsAuthorized; //Clear the PIN Code textbox PinCode = string.Empty; // initialise the last sync activities if (settings.LastSyncActivities == null) { settings.LastSyncActivities = new TraktLastSyncActivities(); } }
public void Setup() { _downloadMessage = new DownloadMessage { Movie = new Movie(), MovieFile = new MovieFile { MediaInfo = null, Quality = new QualityModel { Quality = Quality.Unknown } } }; _traktSettings = new TraktSettings { AccessToken = "", RefreshToken = "" }; }
private void DisconnectAccount() { TraktLogger.Info("Revoking application access to trakt.tv account"); GUIBackgroundTask.Instance.ExecuteInBackgroundAndCallback(() => { TraktAPI.TraktAPI.RevokeToken(); return(true); }, delegate(bool success, object result) { if (success) { // clear account settings TraktSettings.Username = string.Empty; TraktSettings.UserAccessToken = string.Empty; TraktSettings.UserAccessTokenExpiry = string.Empty; TraktSettings.UserRefreshToken = string.Empty; TraktSettings.AccountStatus = ConnectionState.Disconnected; InitProperties(); // clear caches // watchlists are stored by user so dont need clearing. GUINetwork.ClearCache(); GUICalendarTV.ClearCache(); GUIRecommendationsMovies.ClearCache(); GUIRecommendationsShows.ClearCache(); // clear any stored user data TraktCache.ClearSyncCache(); // persist settings TraktSettings.SaveSettings(false); } }, Translation.AuthorizingApplication, false); }
private bool Login() { ISettingsManager settingsManager = ServiceRegistration.Get <ISettingsManager>(); TraktSettings settings = settingsManager.Load <TraktSettings>(); TraktLogger.Info("Exchanging {0} for access-token...", PinCode.Length == 8 ? "pin-code" : "refresh-token"); var response = TraktAuth.GetOAuthToken(PinCode.Length == 8 ? PinCode : settings.TraktOAuthToken); if (response == null || string.IsNullOrEmpty(response.AccessToken)) { TestStatus = "[Trakt.CheckPin]"; TraktLogger.Error("Unable to login to trakt, wrong pin?"); PinCode = string.Empty; return(false); } TestStatus = "[Trakt.LoggedIn]"; settings.TraktOAuthToken = response.RefreshToken; settingsManager.Save(settings); TraktLogger.Info("Successfully logged in!"); return(true); }
public void SyncMediaToTrakt() { if (!IsSynchronizing) { ISettingsManager settingsManager = ServiceRegistration.Get <ISettingsManager>(); TraktSettings settings = settingsManager.Load <TraktSettings>(); if (!settings.IsAuthorized) { TestStatus = "[Trakt.NotAuthorized]"; TraktLogger.Error("Trakt.tv not authorized"); return; } if (!TraktCache.RefreshData()) { return; } IsSynchronizing = true; IThreadPool threadPool = ServiceRegistration.Get <IThreadPool>(); threadPool.Add(SyncMediaToTrakt_Async, ThreadPriority.BelowNormal); } }
protected override void OnPageDestroy(int new_windowId) { // disable plugins if (!btnTVSeries.Selected) { TVSeries = -1; } if (!btnMovingPictures.Selected) { MovingPictures = -1; } if (!btnMyVideos.Selected) { MyVideos = -1; } if (!btnMyFilms.Selected) { MyFilms = -1; } if (!btnOnlineVideos.Selected) { OnlineVideos = -1; } if (!btnMyRecordedTV.IsSelected(TraktSettings.MyTVRecordings >= 0)) { MyRecordedTV = -1; } if (!btnArgusRecordings.IsSelected(TraktSettings.ArgusRecordings >= 0)) { ArgusRecordings = -1; } if (!btnMyLiveTV.IsSelected(TraktSettings.MyTVLive >= 0)) { MyLiveTV = -1; } if (!btnArgusLiveTV.IsSelected(TraktSettings.ArgusTVLive >= 0)) { ArgusLiveTV = -1; } // enable plugins int i = 1; int[] intArray = new int[9] { TVSeries, MovingPictures, MyVideos, MyFilms, OnlineVideos, MyRecordedTV, MyLiveTV, ArgusLiveTV, ArgusRecordings }; Array.Sort(intArray); // keep existing sort order if (btnTVSeries.Selected && TVSeries < 0) { TVSeries = intArray.Max() + i; i++; } if (btnMovingPictures.Selected && MovingPictures < 0) { MovingPictures = intArray.Max() + i; i++; } if (btnMyVideos.Selected && MyVideos < 0) { MyVideos = intArray.Max() + i; i++; } if (btnMyFilms.Selected && MyFilms < 0) { MyFilms = intArray.Max() + i; i++; } if (btnOnlineVideos.Selected && OnlineVideos < 0) { OnlineVideos = intArray.Max() + i; i++; } if (btnMyRecordedTV.IsSelected(TraktSettings.MyTVRecordings >= 0) && MyRecordedTV < 0) { MyRecordedTV = intArray.Max() + i; i++; } if (btnArgusRecordings.IsSelected(TraktSettings.ArgusRecordings >= 0) && ArgusRecordings < 0) { ArgusRecordings = intArray.Max() + i; i++; } if (btnMyLiveTV.IsSelected(TraktSettings.MyTVLive >= 0) && MyLiveTV < 0) { MyLiveTV = intArray.Max() + i; i++; } if (btnArgusLiveTV.IsSelected(TraktSettings.ArgusTVLive >= 0) && ArgusLiveTV < 0) { ArgusLiveTV = intArray.Max() + i; i++; } // save settings TraktSettings.TVSeries = TVSeries; TraktSettings.MovingPictures = MovingPictures; TraktSettings.MyVideos = MyVideos; TraktSettings.MyFilms = MyFilms; TraktSettings.OnlineVideos = OnlineVideos; if (btnMyRecordedTV != null) { TraktSettings.MyTVRecordings = MyRecordedTV; } if (btnArgusRecordings != null) { TraktSettings.ArgusRecordings = ArgusRecordings; } if (btnMyLiveTV != null) { TraktSettings.MyTVLive = MyLiveTV; } if (btnArgusLiveTV != null) { TraktSettings.ArgusTVLive = ArgusLiveTV; } TraktSettings.SaveSettings(false); base.OnPageDestroy(new_windowId); }
public bool SyncMovies() { ISettingsManager settingsManager = ServiceRegistration.Get <ISettingsManager>(); TraktSettings settings = settingsManager.Load <TraktSettings>(); #region Get online data from cache #region Get unwatched / watched movies from trakt.tv IEnumerable <TraktMovieWatched> traktWatchedMovies = null; var traktUnWatchedMovies = TraktCache.GetUnWatchedMoviesFromTrakt(); if (traktUnWatchedMovies == null) { TraktLogger.Error("Error getting unwatched movies from trakt server, unwatched and watched sync will be skipped"); } else { TraktLogger.Info("There are {0} unwatched movies since the last sync with trakt.tv", traktUnWatchedMovies.Count()); traktWatchedMovies = TraktCache.GetWatchedMoviesFromTrakt(); if (traktWatchedMovies == null) { TraktLogger.Error("Error getting watched movies from trakt server, watched sync will be skipped"); } else { TraktLogger.Info("There are {0} watched movies in trakt.tv library", traktWatchedMovies.Count().ToString()); } } #endregion #region Get collected movies from trakt.tv var traktCollectedMovies = TraktCache.GetCollectedMoviesFromTrakt(); if (traktCollectedMovies == null) { TraktLogger.Error("Error getting collected movies from trakt server"); } else { TraktLogger.Info("There are {0} collected movies in trakt.tv library", traktCollectedMovies.Count()); } #endregion #region Get rated movies from trakt.tv //var traktRatedMovies = TraktCache.GetRatedMoviesFromTrakt(); //if (traktRatedMovies == null) //{ // TraktLogger.Error("Error getting rated movies from trakt server"); //} //else //{ // TraktLogger.Info("There are {0} rated movies in trakt.tv library", traktRatedMovies.Count()); //} #endregion #region Get watchlisted movies from trakt.tv //var traktWatchlistedMovies = TraktCache.GetWatchlistedMoviesFromTrakt(); //if (traktWatchlistedMovies == null) //{ // TraktLogger.Error("Error getting watchlisted movies from trakt server"); //} //else //{ // TraktLogger.Info("There are {0} watchlisted movies in trakt.tv library", traktWatchlistedMovies.Count()); //} #endregion #region Get custom lists from trakt.tv //var traktCustomLists = TraktCache.GetCustomLists(); //if (traktCustomLists == null) //{ // TraktLogger.Error("Error getting custom lists from trakt server"); //} //else //{ // TraktLogger.Info("There are {0} custom lists in trakt.tv library", traktCustomLists.Count()); //} #endregion #endregion try { TestStatus = "[Trakt.SyncMovies]"; Guid[] types = { MediaAspect.ASPECT_ID, MovieAspect.ASPECT_ID, VideoAspect.ASPECT_ID, ImporterAspect.ASPECT_ID }; var contentDirectory = ServiceRegistration.Get <IServerConnectionManager>().ContentDirectory; if (contentDirectory == null) { TestStatus = "[Trakt.MediaLibraryNotConnected]"; return(false); } #region Get local database info var collectedMovies = contentDirectory.Search(new MediaItemQuery(types, null, null), true); TraktLogger.Info("Found {0} movies available to sync in local database", collectedMovies.Count); // get the movies that we have watched var watchedMovies = collectedMovies.Where(IsWatched).ToList(); TraktLogger.Info("Found {0} watched movies available to sync in local database", watchedMovies.Count); #endregion #region Add movies to watched history at trakt.tv if (traktWatchedMovies != null) { var syncWatchedMovies = new List <TraktSyncMovieWatched>(); TraktLogger.Info("Finding movies to add to trakt.tv watched history"); syncWatchedMovies = (from movie in watchedMovies where !traktWatchedMovies.ToList().Exists(c => MovieMatch(movie, c.Movie)) select new TraktSyncMovieWatched { Ids = new TraktMovieId { Imdb = GetMovieImdbId(movie), Tmdb = GetMovieTmdbId(movie) }, Title = GetMovieTitle(movie), Year = GetMovieYear(movie), WatchedAt = GetLastPlayedDate(movie), }).ToList(); TraktLogger.Info("Adding {0} movies to trakt.tv watched history", syncWatchedMovies.Count); if (syncWatchedMovies.Count > 0) { // update internal cache TraktCache.AddMoviesToWatchHistory(syncWatchedMovies); int pageSize = settings.SyncBatchSize; int pages = (int)Math.Ceiling((double)syncWatchedMovies.Count / pageSize); for (int i = 0; i < pages; i++) { TraktLogger.Info("Adding movies [{0}/{1}] to trakt.tv watched history", i + 1, pages); var pagedMovies = syncWatchedMovies.Skip(i * pageSize).Take(pageSize).ToList(); pagedMovies.ForEach(s => TraktLogger.Info("Adding movie to trakt.tv watched history. Title = '{0}', Year = '{1}', IMDb ID = '{2}', TMDb ID = '{3}', Date Watched = '{4}'", s.Title, s.Year.HasValue ? s.Year.ToString() : "<empty>", s.Ids.Imdb ?? "<empty>", s.Ids.Tmdb.HasValue ? s.Ids.Tmdb.ToString() : "<empty>", s.WatchedAt)); // remove title/year such that match against online ID only if (settings.SkipMoviesWithNoIdsOnSync) { pagedMovies.ForEach(m => { m.Title = null; m.Year = null; }); } var response = TraktAPI.AddMoviesToWatchedHistory(new TraktSyncMoviesWatched { Movies = pagedMovies }); TraktLogger.LogTraktResponse <TraktSyncResponse>(response); // remove movies from cache which didn't succeed if (response != null && response.NotFound != null && response.NotFound.Movies.Count > 0) { TraktCache.RemoveMoviesFromWatchHistory(response.NotFound.Movies); } } } } #endregion #region Add movies to collection at trakt.tv if (traktCollectedMovies != null) { var syncCollectedMovies = new List <TraktSyncMovieCollected>(); TraktLogger.Info("Finding movies to add to trakt.tv collection"); syncCollectedMovies = (from movie in collectedMovies where !traktCollectedMovies.ToList().Exists(c => MovieMatch(movie, c.Movie)) select new TraktSyncMovieCollected { Ids = new TraktMovieId { Imdb = GetMovieImdbId(movie), Tmdb = GetMovieTmdbId(movie) }, Title = GetMovieTitle(movie), Year = GetMovieYear(movie), CollectedAt = GetDateAddedToDb(movie), MediaType = GetVideoMediaType(movie), Resolution = GetVideoResolution(movie), AudioCodec = GetVideoAudioCodec(movie), AudioChannels = "", Is3D = false }).ToList(); TraktLogger.Info("Adding {0} movies to trakt.tv watched history", syncCollectedMovies.Count); if (syncCollectedMovies.Count > 0) { //update internal cache TraktCache.AddMoviesToCollection(syncCollectedMovies); int pageSize = settings.SyncBatchSize; int pages = (int)Math.Ceiling((double)syncCollectedMovies.Count / pageSize); for (int i = 0; i < pages; i++) { TraktLogger.Info("Adding movies [{0}/{1}] to trakt.tv collection", i + 1, pages); var pagedMovies = syncCollectedMovies.Skip(i * pageSize).Take(pageSize).ToList(); pagedMovies.ForEach(s => TraktLogger.Info("Adding movie to trakt.tv collection. Title = '{0}', Year = '{1}', IMDb ID = '{2}', TMDb ID = '{3}', Date Added = '{4}', MediaType = '{5}', Resolution = '{6}', Audio Codec = '{7}', Audio Channels = '{8}'", s.Title, s.Year.HasValue ? s.Year.ToString() : "<empty>", s.Ids.Imdb ?? "<empty>", s.Ids.Tmdb.HasValue ? s.Ids.Tmdb.ToString() : "<empty>", s.CollectedAt, s.MediaType ?? "<empty>", s.Resolution ?? "<empty>", s.AudioCodec ?? "<empty>", s.AudioChannels ?? "<empty>")); //// remove title/year such that match against online ID only if (settings.SkipMoviesWithNoIdsOnSync) { pagedMovies.ForEach(m => { m.Title = null; m.Year = null; }); } var response = TraktAPI.AddMoviesToCollecton(new TraktSyncMoviesCollected { Movies = pagedMovies }); TraktLogger.LogTraktResponse(response); // remove movies from cache which didn't succeed if (response != null && response.NotFound != null && response.NotFound.Movies.Count > 0) { TraktCache.RemoveMoviesFromCollection(response.NotFound.Movies); } } } } #endregion return(true); } catch (Exception ex) { ServiceRegistration.Get <ILogger>().Error("Trakt.tv: Exception while synchronizing media library.", ex); } return(false); }