예제 #1
0
        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  = 2012
                },
                Action   = TraktScrobbleActionType.Start,
                Progress = 10
            });

            return(traktClient);
        }
예제 #2
0
        private void HandleMovieScrobbleStart(IPlayerContext pc, IMediaPlaybackControl pmc)
        {
            ValidateAuthorization();

            MediaItem movieMediaItem = GetMediaItem(pc.CurrentMediaItem.MediaItemId, new Guid[] { MediaAspect.ASPECT_ID, ExternalIdentifierAspect.ASPECT_ID, MovieAspect.ASPECT_ID });

            _traktMovie = ConvertMediaItemToTraktMovie(movieMediaItem);
            float progress = GetCurrentProgress(pmc);
            ITraktMovieScrobblePostResponse postMovieResponse = _traktClient.StartScrobbleMovie(_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 startNotificationsEnabled = _mediaPortalServices.GetTraktSettingsWatcher().TraktSettings.ShowScrobbleStartedNotifications;

            if (startNotificationsEnabled)
            {
                ShowNotification(new TraktScrobbleStartedNotification(title, true, traktProgress, actionType), TimeSpan.FromSeconds(5));
            }

            _duration = pmc.Duration;
            _mediaPortalServices.GetLogger().Info("Trakt: started to scrobble: {0}", title);
        }