private ITraktClient GetMockedTraktClientWithValidAuthorization()
        {
            ITraktClient traktClient = Substitute.For <ITraktClient>();

            traktClient.TraktAuthorization.Returns(new TraktAuthorization
            {
                RefreshToken = "ValidToken",
                AccessToken  = "ValidToken"
            });

            traktClient.RefreshAuthorization(Arg.Any <string>()).Returns(new TraktAuthorization
            {
                RefreshToken = "ValidToken"
            });
            traktClient.StartScrobbleMovie(Arg.Any <ITraktMovie>(), Arg.Any <float>()).Returns(
                new TraktMovieScrobblePostResponse
            {
                Movie = new TraktMovie
                {
                    Ids = new TraktMovieIds {
                        Imdb = "tt1431045", Tmdb = 67890
                    },
                    Title = "Movie1",
                    Year  = 2016,
                },
                Progress = 10,
                Action   = TraktScrobbleActionType.Start
            });

            traktClient.StopScrobbleMovie(Arg.Any <ITraktMovie>(), Arg.Any <float>()).Returns(
                new TraktMovieScrobblePostResponse
            {
                Movie = new TraktMovie
                {
                    Ids = new TraktMovieIds {
                        Imdb = "tt1431045", Tmdb = 67890
                    },
                    Title = "Movie1",
                    Year  = 2016,
                },
                Progress = 100,
                Action   = TraktScrobbleActionType.Stop
            });

            return(traktClient);
        }
예제 #2
0
        private void StopScrobble()
        {
            try
            {
                if (_traktEpisode != null && _traktShow != null)
                {
                    ValidateAuthorization();

                    float progress = GetSavedProgress();
                    ITraktEpisodeScrobblePostResponse postEpisodeResponse = _traktClient.StopScrobbleEpisode(_traktEpisode, _traktShow, progress);
                    string title         = postEpisodeResponse.Show.Title + " " + postEpisodeResponse.Episode.SeasonNumber + "x" + postEpisodeResponse.Episode.Number;
                    int?   traktProgress = null;
                    if (postEpisodeResponse.Progress != null)
                    {
                        traktProgress = (int)postEpisodeResponse.Progress;
                    }
                    string actionType = postEpisodeResponse.Action.DisplayName;

                    bool stopNotificationsEnabled = _mediaPortalServices.GetTraktSettingsWatcher().TraktSettings.ShowScrobbleStoppedNotifications;
                    if (stopNotificationsEnabled)
                    {
                        ShowNotification(new TraktScrobbleStoppedNotification(title, true, traktProgress, actionType), TimeSpan.FromSeconds(5));
                    }

                    _traktEpisode = null;
                    _traktShow    = null;
                    _mediaPortalServices.GetLogger().Info("Trakt: stopped to scrobble: {0}", title);
                }
                else if (_traktMovie != null)
                {
                    ValidateAuthorization();

                    float progress = GetSavedProgress();
                    ITraktMovieScrobblePostResponse postMovieResponse = _traktClient.StopScrobbleMovie(_traktMovie, progress);
                    string title         = postMovieResponse.Movie.Title + " " + "(" + postMovieResponse.Movie.Year + ")";
                    int?   traktProgress = null;
                    if (postMovieResponse.Progress != null)
                    {
                        traktProgress = (int)postMovieResponse.Progress;
                    }
                    string actionType = postMovieResponse.Action.DisplayName;

                    bool stopNotificationsEnabled = _mediaPortalServices.GetTraktSettingsWatcher().TraktSettings.ShowScrobbleStoppedNotifications;
                    if (stopNotificationsEnabled)
                    {
                        ShowNotification(new TraktScrobbleStoppedNotification(title, true, traktProgress, actionType), TimeSpan.FromSeconds(5));
                    }

                    _traktMovie = null;
                    _mediaPortalServices.GetLogger().Info("Trakt: stopped scrobble: {0}", title);
                }
            }
            catch (Exception ex)
            {
                bool stopNotificationsEnabled          = _mediaPortalServices.GetTraktSettingsWatcher().TraktSettings.ShowScrobbleStoppedNotifications;
                bool stopNotificationsOnFailureEnabled = _mediaPortalServices.GetTraktSettingsWatcher().TraktSettings.ShowScrobbleStoppedNotificationsOnFailure;
                if (stopNotificationsEnabled || stopNotificationsOnFailureEnabled)
                {
                    ShowNotification(new TraktScrobbleStoppedNotification(ex.Message, false, null, "Unspecified"), TimeSpan.FromSeconds(4));
                }
                _mediaPortalServices.GetLogger().Error("Trakt: exception while stopping scrobble: " + ex);
            }
        }