Ejemplo n.º 1
0
        /// <summary>Adds a <see cref="ITraktEpisode" />, which will be added to the history post.</summary>
        /// <param name="episode">The Trakt episode, which will be added.</param>
        /// <param name="watchedAt">The datetime, when the given episode was watched. Will be converted to the Trakt UTC-datetime and -format.</param>
        /// <returns>The current <see cref="TraktSyncHistoryPostBuilder" /> instance.</returns>
        /// <exception cref="ArgumentNullException">
        /// Thrown, if the given episode is null.
        /// Thrown, if the given episode ids are null.
        /// </exception>
        /// <exception cref="ArgumentException">Thrown, if the given episode has no valid ids set.</exception>
        public TraktSyncHistoryPostBuilder AddEpisode(ITraktEpisode episode, DateTime watchedAt)
        {
            ValidateEpisode(episode);
            EnsureEpisodesListExists();

            return(AddEpisodeOrIgnore(episode, watchedAt));
        }
        /// <summary>Adds a <see cref="ITraktEpisode" />, which will be added to the history remove post.</summary>
        /// <param name="episode">The Trakt episode, which will be added.</param>
        /// <returns>The current <see cref="TraktSyncHistoryRemovePostBuilder" /> instance.</returns>
        /// <exception cref="ArgumentNullException">
        /// Thrown, if the given episode is null.
        /// Thrown, if the given episode ids are null.
        /// </exception>
        /// <exception cref="ArgumentException">Thrown, if the given episode has no valid ids set.</exception>
        public TraktSyncHistoryRemovePostBuilder AddEpisode(ITraktEpisode episode)
        {
            ValidateEpisode(episode);
            EnsureEpisodesListExists();

            return(AddEpisodeOrIgnore(episode));
        }
        public async Task Test_TraktShowsModule_GetShowNextEpisode_With_ExtendedInfo()
        {
            TraktClient client = TestUtility.GetMockClient(
                $"{GET_SHOW_NEXT_EPISODE_URI}?extended={EXTENDED_INFO}",
                SHOW_EPISODE_JSON);

            TraktResponse <ITraktEpisode> response = await client.Shows.GetShowNextEpisodeAsync(SHOW_ID, EXTENDED_INFO);

            response.Should().NotBeNull();
            response.IsSuccess.Should().BeTrue();
            response.HasValue.Should().BeTrue();
            response.Value.Should().NotBeNull();

            ITraktEpisode responseValue = response.Value;

            responseValue.Title.Should().Be("Winter Is Coming");
            responseValue.SeasonNumber.Should().Be(1);
            responseValue.Number.Should().Be(1);
            responseValue.Ids.Should().NotBeNull();
            responseValue.Ids.Trakt.Should().Be(73640U);
            responseValue.Ids.Tvdb.Should().Be(3254641U);
            responseValue.Ids.Imdb.Should().Be("tt1480055");
            responseValue.Ids.Tmdb.Should().Be(63056U);
            responseValue.Ids.TvRage.Should().Be(1065008299U);
            responseValue.NumberAbsolute.Should().Be(50);
            responseValue.Overview.Should().Be("Ned Stark, Lord of Winterfell learns that his mentor, Jon Arryn, has died and that King Robert is on his way north to offer Ned Arryn’s position as the King’s Hand. Across the Narrow Sea in Pentos, Viserys Targaryen plans to wed his sister Daenerys to the nomadic Dothraki warrior leader, Khal Drogo to forge an alliance to take the throne.");
            responseValue.FirstAired.Should().Be(DateTime.Parse("2011-04-18T01:00:00.000Z").ToUniversalTime());
            responseValue.UpdatedAt.Should().Be(DateTime.Parse("2014-08-29T23:16:39.000Z").ToUniversalTime());
            responseValue.Rating.Should().Be(9.0f);
            responseValue.Votes.Should().Be(111);
            responseValue.AvailableTranslationLanguageCodes.Should().NotBeNull().And.HaveCount(1);
        }
Ejemplo n.º 4
0
 private ITraktSyncWatchlistPostEpisode CreateSyncWatchlistPostEpisode(ITraktEpisode episode)
 {
     return(new TraktSyncWatchlistPostEpisode
     {
         Ids = episode.Ids
     });
 }
Ejemplo n.º 5
0
        private void HandleEpisodeScrobbleStart(IPlayerContext pc, IMediaPlaybackControl pmc)
        {
            ValidateAuthorization();

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

            _traktEpisode = ExtractTraktEpisode(episodeMediaItem);
            _traktShow    = ExtractTraktShow(episodeMediaItem);
            float progress = GetCurrentProgress(pmc);
            ITraktEpisodeScrobblePostResponse postEpisodeResponse = _traktClient.StartScrobbleEpisode(_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 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);
        }
Ejemplo n.º 6
0
        public TraktScrobbleModule_Tests()
        {
            Movie = new TraktMovie
            {
                Title = "Guardians of the Galaxy",
                Year  = 2014,
                Ids   = new TraktMovieIds
                {
                    Trakt = 28,
                    Slug  = "guardians-of-the-galaxy-2014",
                    Imdb  = "tt2015381",
                    Tmdb  = 118340
                }
            };

            Show = new TraktShow
            {
                Title = "Breaking Bad"
            };

            Episode = new TraktEpisode
            {
                SeasonNumber = 1,
                Number       = 1,
                Ids          = new TraktEpisodeIds
                {
                    Trakt  = 16,
                    Tvdb   = 349232,
                    Imdb   = "tt0959621",
                    Tmdb   = 62085,
                    TvRage = 637041
                }
            };
        }
Ejemplo n.º 7
0
        /// <summary>Adds a <see cref="ITraktEpisode" />, which will be added to the watchlist post.</summary>
        /// <param name="episode">The Trakt episode, which will be added.</param>
        /// <returns>The current <see cref="TraktSyncWatchlistPostBuilder" /> instance.</returns>
        /// <exception cref="ArgumentNullException">
        /// Thrown, if the given episode is null.
        /// Thrown, if the given episode ids are null.
        /// </exception>
        /// <exception cref="ArgumentException">Thrown, if the given episode has no valid ids set.</exception>
        public TraktSyncWatchlistPostBuilder AddEpisode(ITraktEpisode episode)
        {
            if (episode == null)
            {
                throw new ArgumentNullException(nameof(episode));
            }

            if (episode.Ids == null)
            {
                throw new ArgumentNullException(nameof(episode.Ids));
            }

            if (!episode.Ids.HasAnyId)
            {
                throw new ArgumentException("no episode ids set or valid", nameof(episode.Ids));
            }

            EnsureEpisodesListExists();

            var existingEpisode = _watchlistPost.Episodes.FirstOrDefault(e => e.Ids == episode.Ids);

            if (existingEpisode != null)
            {
                return(this);
            }

            (_watchlistPost.Episodes as List <ITraktSyncWatchlistPostEpisode>)?.Add(
                new TraktSyncWatchlistPostEpisode
            {
                Ids = episode.Ids
            });

            return(this);
        }
Ejemplo n.º 8
0
        private TraktSyncRatingsPostBuilder AddEpisodeOrIgnore(ITraktEpisode episode, int?rating = null, DateTime?ratedAt = null)
        {
            if (ContainsEpisode(episode))
            {
                return(this);
            }

            var ratingsEpisode = new TraktSyncRatingsPostEpisode
            {
                Ids = episode.Ids
            };

            if (rating.HasValue)
            {
                ratingsEpisode.Rating = rating;
            }

            if (ratedAt.HasValue)
            {
                ratingsEpisode.RatedAt = ratedAt.Value.ToUniversalTime();
            }

            (_ratingsPost.Episodes as List <ITraktSyncRatingsPostEpisode>)?.Add(ratingsEpisode);

            return(this);
        }
Ejemplo n.º 9
0
        private void Validate(ITraktEpisode episode, ITraktShow show)
        {
            if (episode == null)
            {
                throw new ArgumentNullException(nameof(episode), "episode must not be null");
            }

            if (episode.Ids == null || !episode.Ids.HasAnyId)
            {
                if (show == null)
                {
                    throw new ArgumentNullException(nameof(show), "episode ids not set or have no valid id - show must not be null");
                }

                if (string.IsNullOrEmpty(show.Title))
                {
                    throw new ArgumentException("episode ids not set or have no valid id  - show title not valid", nameof(show));
                }

                if (episode.SeasonNumber < 0)
                {
                    throw new ArgumentOutOfRangeException(nameof(episode), "episode ids not set or have no valid id  - episode season number not valid");
                }

                if (episode.Number <= 0)
                {
                    throw new ArgumentOutOfRangeException(nameof(episode), "episode ids not set or have no valid id  - episode number not valid");
                }
            }
        }
Ejemplo n.º 10
0
        /// <summary>Adds a <see cref="ITraktEpisode" />, which will be added to the ratings post.</summary>
        /// <param name="episode">The Trakt episode, which will be added.</param>
        /// <param name="rating">A rating from 1 to 10 for the given episode.</param>
        /// <param name="ratedAt">The datetime, when the given episode was rated. Will be converted to the Trakt UTC-datetime and -format.</param>
        /// <returns>The current <see cref="TraktSyncRatingsPostBuilder" /> instance.</returns>
        /// <exception cref="ArgumentNullException">
        /// Thrown, if the given episode is null.
        /// Thrown, if the given episode ids are null.
        /// </exception>
        /// <exception cref="ArgumentException">Thrown, if the given episode has no valid ids set.</exception>
        /// <exception cref="ArgumentOutOfRangeException">Thrown, if the given rating is not between 1 and 10.</exception>
        public TraktSyncRatingsPostBuilder AddEpisode(ITraktEpisode episode, int rating, DateTime ratedAt)
        {
            ValidateEpisode(episode);
            ValidateRating(rating);
            EnsureEpisodesListExists();

            return(AddEpisodeOrIgnore(episode, rating, ratedAt));
        }
        public ITraktSyncHistoryPostBuilder WithEpisode(ITraktEpisode episode)
        {
            if (episode == null)
            {
                throw new ArgumentNullException(nameof(episode));
            }

            _episodes.Add(episode);
            return(this);
        }
        private ITraktSyncHistoryPostEpisode CreateSyncHistoryPostEpisode(ITraktEpisode episode, DateTime?watchedAt = null)
        {
            var syncHistoryPostEpisode = new TraktSyncHistoryPostEpisode
            {
                Ids = episode.Ids
            };

            if (watchedAt.HasValue)
            {
                syncHistoryPostEpisode.WatchedAt = watchedAt.Value.ToUniversalTime();
            }

            return(syncHistoryPostEpisode);
        }
        protected TraktSyncHistoryRemovePostBuilder AddEpisodeOrIgnore(ITraktEpisode episode)
        {
            if (ContainsEpisode(episode))
            {
                return(this);
            }

            var historyEpisode = new TraktSyncHistoryPostEpisode
            {
                Ids = episode.Ids
            };

            (_historyPost.Episodes as List <ITraktSyncHistoryPostEpisode>)?.Add(historyEpisode);
            return(this);
        }
Ejemplo n.º 14
0
        public ITraktEpisodeScrobblePostResponse StopScrobbleEpisode(ITraktEpisode episode, ITraktShow traktShow, float progress, string appVersion = null,
                                                                     DateTime?appBuildDate = null)
        {
            ITraktResponse <ITraktEpisodeScrobblePostResponse> response = new TraktResponse <ITraktEpisodeScrobblePostResponse>();

            try
            {
                response = Task.Run(() => base.Scrobble.StopEpisodeWithShowAsync(episode, traktShow, progress, appVersion, appBuildDate)).Result;
            }
            catch (AggregateException aggregateException)
            {
                UnwrapAggregateException(aggregateException);
            }

            return(response.Value);
        }
Ejemplo n.º 15
0
        private void ValidateEpisode(ITraktEpisode episode)
        {
            if (episode == null)
            {
                throw new ArgumentNullException(nameof(episode), "episode must not be null");
            }

            if (episode.Ids == null)
            {
                throw new ArgumentNullException(nameof(episode.Ids), "episode ids must not be null");
            }

            if (!episode.Ids.HasAnyId)
            {
                throw new ArgumentException("episode ids have no valid id", nameof(episode.Ids));
            }
        }
Ejemplo n.º 16
0
        protected void ValidateEpisode(ITraktEpisode episode)
        {
            if (episode == null)
            {
                throw new ArgumentNullException(nameof(episode));
            }

            if (episode.Ids == null)
            {
                throw new ArgumentNullException(nameof(episode.Ids));
            }

            if (!episode.Ids.HasAnyId)
            {
                throw new ArgumentException("no episode ids set or valid", nameof(episode.Ids));
            }
        }
Ejemplo n.º 17
0
        private void StartScrobble(SystemMessage message)
        {
            try
            {
                IPlayerSlotController psc = (IPlayerSlotController)message.MessageData[PlayerManagerMessaging.PLAYER_SLOT_CONTROLLER];
                IPlayerContext        pc  = _mediaPortalServices.GetPlayerContext(psc);
                if (pc?.CurrentMediaItem == null)
                {
                    throw new ArgumentNullException(nameof(pc.CurrentMediaItem));
                }

                IMediaPlaybackControl pmc = pc.CurrentPlayer as IMediaPlaybackControl;
                if (pmc == null)
                {
                    throw new ArgumentNullException(nameof(pmc));
                }

                if (IsSeries(pc.CurrentMediaItem))
                {
                    HandleEpisodeScrobbleStart(pc, pmc);
                }
                else if (IsMovie(pc.CurrentMediaItem))
                {
                    HandleMovieScrobbleStart(pc, pmc);
                }
            }
            catch (ArgumentNullException ex)
            {
                _mediaPortalServices.GetLogger().Error("Trakt: exception occurred while starting scrobble: " + ex);
            }
            catch (Exception ex)
            {
                bool startNotificationsEnabled          = _mediaPortalServices.GetTraktSettingsWatcher().TraktSettings.ShowScrobbleStartedNotifications;
                bool startNotificationsOnFailureEnabled = _mediaPortalServices.GetTraktSettingsWatcher().TraktSettings.ShowScrobbleStartedNotificationsOnFailure;
                if (startNotificationsEnabled || startNotificationsOnFailureEnabled)
                {
                    ShowNotification(new TraktScrobbleStartedNotification(ex.Message, false, 0, "Unspecified"), TimeSpan.FromSeconds(5));
                }
                _mediaPortalServices.GetLogger().Error("Trakt: exception occurred while starting scrobble: " + ex);
                _traktEpisode = null;
                _traktMovie   = null;
                _duration     = TimeSpan.Zero;
            }
        }
Ejemplo n.º 18
0
        private ITraktSyncRatingsPostEpisode CreateSyncRatingsPostEpisode(ITraktEpisode episode, int?rating = null, DateTime?ratedAt = null)
        {
            var syncRatingsPostEpisode = new TraktSyncRatingsPostEpisode
            {
                Ids = episode.Ids
            };

            if (rating.HasValue)
            {
                syncRatingsPostEpisode.Rating = rating.Value;
            }

            if (ratedAt.HasValue)
            {
                syncRatingsPostEpisode.RatedAt = ratedAt.Value.ToUniversalTime();
            }

            return(syncRatingsPostEpisode);
        }
        private ITraktSyncCollectionPostEpisode CreateSyncCollectionPostEpisode(ITraktEpisode episode, ITraktMetadata metadata = null, DateTime?collectedAt = null)
        {
            var syncCollectionPostEpisode = new TraktSyncCollectionPostEpisode
            {
                Ids              = episode.Ids,
                MediaType        = metadata?.MediaType,
                MediaResolution  = metadata?.MediaResolution,
                Audio            = metadata?.Audio,
                AudioChannels    = metadata?.AudioChannels,
                ThreeDimensional = metadata?.ThreeDimensional,
                HDR              = metadata?.HDR
            };

            if (collectedAt.HasValue)
            {
                syncCollectionPostEpisode.CollectedAt = collectedAt.Value.ToUniversalTime();
            }

            return(syncCollectionPostEpisode);
        }
Ejemplo n.º 20
0
        protected TraktSyncHistoryPostBuilder AddEpisodeOrIgnore(ITraktEpisode episode, DateTime?watchedAt = null)
        {
            if (ContainsEpisode(episode))
            {
                return(this);
            }

            var historyEpisode = new TraktSyncHistoryPostEpisode
            {
                Ids = episode.Ids
            };

            if (watchedAt.HasValue)
            {
                historyEpisode.WatchedAt = watchedAt.Value.ToUniversalTime();
            }

            (_historyPost.Episodes as List <ITraktSyncHistoryPostEpisode>)?.Add(historyEpisode);

            return(this);
        }
        public async Task Test_TraktShowsModule_GetShowNextEpisode()
        {
            TraktClient client = TestUtility.GetMockClient(GET_SHOW_NEXT_EPISODE_URI, SHOW_EPISODE_JSON);
            TraktResponse <ITraktEpisode> response = await client.Shows.GetShowNextEpisodeAsync(SHOW_ID);

            response.Should().NotBeNull();
            response.IsSuccess.Should().BeTrue();
            response.HasValue.Should().BeTrue();
            response.Value.Should().NotBeNull();

            ITraktEpisode responseValue = response.Value;

            responseValue.Title.Should().Be("Winter Is Coming");
            responseValue.SeasonNumber.Should().Be(1);
            responseValue.Number.Should().Be(1);
            responseValue.Ids.Should().NotBeNull();
            responseValue.Ids.Trakt.Should().Be(73640U);
            responseValue.Ids.Tvdb.Should().Be(3254641U);
            responseValue.Ids.Imdb.Should().Be("tt1480055");
            responseValue.Ids.Tmdb.Should().Be(63056U);
            responseValue.Ids.TvRage.Should().Be(1065008299U);
        }
Ejemplo n.º 22
0
        private ITraktEpisodeScrobblePost CreateEpisodeScrobblePost(ITraktEpisode episode, float progress, ITraktShow show = null,
                                                                    string appVersion = null, DateTime?appDate = null)
        {
            Validate(episode, show);
            ValidateProgress(progress);

            var episodeScrobblePost = new TraktEpisodeScrobblePost
            {
                Episode = new TraktEpisode
                {
                    Ids          = episode.Ids,
                    SeasonNumber = episode.SeasonNumber,
                    Number       = episode.Number
                },
                Show = show != null
                    ? new TraktShow
                {
                    Title = show.Title,
                    Ids   = show.Ids
                }
                    : null,
                Progress = progress
            };

            if (!string.IsNullOrEmpty(appVersion))
            {
                episodeScrobblePost.AppVersion = appVersion;
            }

            if (appDate.HasValue)
            {
                episodeScrobblePost.AppDate = appDate.Value.ToTraktDateString();
            }

            return(episodeScrobblePost);
        }
Ejemplo n.º 23
0
 internal PostBuilderEpisodeAddedWatchedAt(TPostBuilderAddEpisode postBuilder)
 {
     _postBuilder    = postBuilder;
     _currentEpisode = null;
     WatchedEpisodes = new List <PostBuilderWatchedObject <ITraktEpisode> >();
 }
Ejemplo n.º 24
0
 internal PostBuilderEpisodeAddedRating(TPostBuilderAddEpisode postBuilder)
 {
     _postBuilder      = postBuilder;
     _currentEpisode   = null;
     EpisodesAndRating = new List <PostBuilderRatedObject <ITraktEpisode> >();
 }
        public ITraktPostBuilderEpisodeAddedWatchedAt <ITraktSyncHistoryPostBuilder, ITraktSyncHistoryPost> AddWatchedEpisode(ITraktEpisode episode)
        {
            if (episode == null)
            {
                throw new ArgumentNullException(nameof(episode));
            }

            _watchedEpisodes.SetCurrentEpisode(episode);
            return(_watchedEpisodes);
        }
Ejemplo n.º 26
0
 protected bool ContainsEpisode(ITraktEpisode episode)
 => _historyPost.Episodes.FirstOrDefault(e => e.Ids == episode.Ids) != null;
Ejemplo n.º 27
0
        public ITraktPostBuilderEpisodeAddedRating <ITraktSyncRatingsPostBuilder, ITraktSyncRatingsPost> AddRatedEpisode(ITraktEpisode episode)
        {
            if (episode == null)
            {
                throw new ArgumentNullException(nameof(episode));
            }

            _ratedEpisodes.SetCurrentEpisode(episode);
            return(_ratedEpisodes);
        }
 internal PostBuilderEpisodeAddedMetadata(TPostBuilderAddEpisode postBuilder)
 {
     _postBuilder        = postBuilder;
     _currentEpisode     = null;
     EpisodesAndMetadata = new List <PostBuilderObjectWithMetadata <ITraktEpisode> >();
 }
 public void SetCurrentEpisode(ITraktEpisode episode)
 {
     _currentEpisode = episode;
 }
Ejemplo n.º 30
0
        /// <summary>
        /// Posts a comment for the given <see cref="ITraktEpisode" />.
        /// <para>OAuth authorization required.</para>
        /// <para>
        /// See <a href="http://docs.trakt.apiary.io/#reference/comments/comments/post-a-comment">"Trakt API Doc - Comments: Comments"</a> for more information.
        /// </para>
        /// </summary>
        /// <param name="episode">The <see cref="ITraktEpisode" />, for which the comment should be posted.</param>
        /// <param name="comment">The comment's content for the given episode. Should be at least five words long.</param>
        /// <param name="containsSpoiler">Determines, if the <paramref name="comment" /> contains any spoilers.</param>
        /// <param name="sharing"><see cref="ITraktSharing" /> instance, containing sharing information for the comment.</param>
        /// <param name="cancellationToken"></param>
        /// <returns>An <see cref="ITraktCommentPostResponse" /> instance, containing the successfully posted comment's data.</returns>
        /// <exception cref="TraktException">Thrown, if the request fails.</exception>
        /// <exception cref="ArgumentException">
        /// Thrown, if the given episode has no valid ids. See also <seealso cref="ITraktEpisodeIds" />.
        /// Thrown, if the given comment is null or empty.
        /// </exception>
        /// <exception cref="ArgumentNullException">Thrown, if the given episode is null or its ids are null.</exception>
        /// <exception cref="ArgumentOutOfRangeException">Thrown, if the given comment's word count is below five.</exception>
        public Task <TraktResponse <ITraktCommentPostResponse> > PostEpisodeCommentAsync(ITraktEpisode episode, string comment,
                                                                                         bool?containsSpoiler = null, ITraktSharing sharing = null,
                                                                                         CancellationToken cancellationToken = default)
        {
            ValidateEpisode(episode);
            ValidateComment(comment);

            var requestHandler = new RequestHandler(Client);

            return(requestHandler.ExecuteSingleItemRequestAsync(new CommentPostRequest <ITraktEpisodeCommentPost>
            {
                RequestBody = new TraktEpisodeCommentPost
                {
                    Episode = new TraktEpisode
                    {
                        Ids = episode.Ids
                    },
                    Comment = comment,
                    Spoiler = containsSpoiler,
                    Sharing = sharing
                }
            },
                                                                cancellationToken));
        }