Пример #1
0
        private TraktSyncRatingsPostBuilder AddMovieOrIgnore(ITraktMovie movie, int?rating = null, DateTime?ratedAt = null)
        {
            if (ContainsMovie(movie))
            {
                return(this);
            }

            var ratingsMovie = new TraktSyncRatingsPostMovie
            {
                Ids   = movie.Ids,
                Title = movie.Title,
                Year  = movie.Year
            };

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

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

            (_ratingsPost.Movies as List <ITraktSyncRatingsPostMovie>)?.Add(ratingsMovie);

            return(this);
        }
        /// <summary>Adds a <see cref="ITraktMovie" />, which will be added to the history remove post.</summary>
        /// <param name="movie">The Trakt movie, which will be added.</param>
        /// <returns>The current <see cref="TraktSyncHistoryRemovePostBuilder" /> instance.</returns>
        /// <exception cref="ArgumentNullException">
        /// Thrown, if the given movie is null.
        /// Thrown, if the given movie ids are null.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// Thrown, if the given movie has no valid ids set.
        /// Thrown, if the given movie has an year set, which has more or less than four digits.
        /// </exception>
        public TraktSyncHistoryRemovePostBuilder AddMovie(ITraktMovie movie)
        {
            ValidateMovie(movie);
            EnsureMoviesListExists();

            return(AddMovieOrIgnore(movie));
        }
Пример #3
0
        private ITraktMovieScrobblePost CreateMovieScrobblePost(ITraktMovie movie, float progress, string appVersion = null, DateTime?appDate = null)
        {
            Validate(movie);
            ValidateProgress(progress);

            var movieScrobblePost = new TraktMovieScrobblePost
            {
                Movie = new TraktMovie
                {
                    Title = movie.Title,
                    Year  = movie.Year,
                    Ids   = movie.Ids
                },
                Progress = progress
            };

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

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

            return(movieScrobblePost);
        }
Пример #4
0
        /// <summary>Adds a <see cref="ITraktMovie" />, which will be added to the history post.</summary>
        /// <param name="movie">The Trakt movie, which will be added.</param>
        /// <param name="watchedAt">The datetime, when the given movie 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 movie is null.
        /// Thrown, if the given movie ids are null.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// Thrown, if the given movie has no valid ids set.
        /// Thrown, if the given movie has an year set, which has more or less than four digits.
        /// </exception>
        public TraktSyncHistoryPostBuilder AddMovie(ITraktMovie movie, DateTime watchedAt)
        {
            ValidateMovie(movie);
            EnsureMoviesListExists();

            return(AddMovieOrIgnore(movie, watchedAt));
        }
Пример #5
0
        private void ValidateMovie(ITraktMovie movie)
        {
            if (movie == null)
            {
                throw new ArgumentNullException(nameof(movie), "movie must not be null");
            }

            if (string.IsNullOrEmpty(movie.Title))
            {
                throw new ArgumentException("movie title not valid", nameof(movie.Title));
            }

            if (movie.Year <= 0 || movie.Year.ToString().Length != 4)
            {
                throw new ArgumentOutOfRangeException(nameof(movie.Year), "movie year not valid");
            }

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

            if (!movie.Ids.HasAnyId)
            {
                throw new ArgumentException("movie ids have no valid id", nameof(movie.Ids));
            }
        }
        public ITraktSyncRecommendationsPostBuilder AddMovieWithNotes(ITraktMovie movie, string notes)
        {
            if (movie == null)
            {
                throw new ArgumentNullException(nameof(movie));
            }

            if (notes == null)
            {
                throw new ArgumentNullException(nameof(notes));
            }

            if (notes.Length > 255)
            {
                throw new ArgumentOutOfRangeException(nameof(notes), "notes cannot be longer than 255 characters");
            }

            _moviesWithNotes.Add(new PostBuilderObjectWithNotes <ITraktMovie>
            {
                Object = movie,
                Notes  = notes
            });

            return(this);
        }
Пример #7
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);
        }
Пример #8
0
        public async Task Test_TraktMoviesModule_GetMovie_With_ExtendedInfo()
        {
            TraktClient client = TestUtility.GetMockClient($"{GET_MOVIE_URI}?extended={EXTENDED_INFO}", MOVIE_JSON);
            TraktResponse <ITraktMovie> response = await client.Movies.GetMovieAsync(MOVIE_ID, EXTENDED_INFO);

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

            ITraktMovie responseValue = response.Value;

            responseValue.Title.Should().Be("Star Wars: The Force Awakens");
            responseValue.Year.Should().Be(2015);
            responseValue.Ids.Should().NotBeNull();
            responseValue.Ids.Trakt.Should().Be(94024U);
            responseValue.Ids.Slug.Should().Be("star-wars-the-force-awakens-2015");
            responseValue.Ids.Imdb.Should().Be("tt2488496");
            responseValue.Ids.Tmdb.Should().Be(140607U);
            responseValue.Tagline.Should().Be("Every generation has a story.");
            responseValue.Overview.Should().Be("Thirty years after defeating the Galactic Empire, Han Solo and his allies face a new threat from the evil Kylo Ren and his army of Stormtroopers.");
            responseValue.Released.Should().Be(DateTime.Parse("2015-12-18"));
            responseValue.Runtime.Should().Be(136);
            responseValue.UpdatedAt.Should().Be(DateTime.Parse("2016-03-31T09:01:59Z").ToUniversalTime());
            responseValue.Trailer.Should().Be("http://youtube.com/watch?v=uwa7N0ShN2U");
            responseValue.Homepage.Should().Be("http://www.starwars.com/films/star-wars-episode-vii");
            responseValue.Rating.Should().Be(8.31988f);
            responseValue.Votes.Should().Be(9338);
            responseValue.LanguageCode.Should().Be("en");
            responseValue.AvailableTranslationLanguageCodes.Should().NotBeNull().And.HaveCount(4).And.Contain("en", "de", "en", "it");
            responseValue.Genres.Should().NotBeNull().And.HaveCount(4).And.Contain("action", "adventure", "fantasy", "science-fiction");
            responseValue.Certification.Should().Be("PG-13");
        }
Пример #9
0
        /// <summary>Adds a <see cref="ITraktMovie" />, which will be added to the ratings post.</summary>
        /// <param name="movie">The Trakt movie, which will be added.</param>
        /// <param name="rating">A rating from 1 to 10 for the given movie.</param>
        /// <returns>The current <see cref="TraktSyncRatingsPostBuilder" /> instance.</returns>
        /// <exception cref="ArgumentNullException">
        /// Thrown, if the given movie is null.
        /// Thrown, if the given movie ids are null.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// Thrown, if the given movie has no valid ids set.
        /// Thrown, if the given movie has an year set, which has more or less than four digits.
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">Thrown, if the given rating is not between 1 and 10.</exception>
        public TraktSyncRatingsPostBuilder AddMovie(ITraktMovie movie, int rating)
        {
            ValidateMovie(movie);
            ValidateRating(rating);
            EnsureMoviesListExists();

            return(AddMovieOrIgnore(movie, rating));
        }
Пример #10
0
 private ITraktSyncWatchlistPostMovie CreateSyncWatchlistPostMovie(ITraktMovie movie)
 {
     return(new TraktSyncWatchlistPostMovie
     {
         Ids = movie.Ids,
         Title = movie.Title,
         Year = movie.Year
     });
 }
Пример #11
0
 private ITraktUserHiddenItemsPostMovie CreateUserHiddenItemsPostMovie(ITraktMovie movie)
 {
     return(new TraktUserHiddenItemsPostMovie
     {
         Ids = movie.Ids,
         Title = movie.Title,
         Year = movie.Year
     });
 }
Пример #12
0
        public ITraktUserHiddenItemsPostBuilder WithMovie(ITraktMovie movie)
        {
            if (movie == null)
            {
                throw new ArgumentNullException(nameof(movie));
            }

            _movies.Add(movie);
            return(this);
        }
        public ITraktSyncHistoryPostBuilder WithMovie(ITraktMovie movie)
        {
            if (movie == null)
            {
                throw new ArgumentNullException(nameof(movie));
            }

            _movies.Add(movie);
            return(this);
        }
        private void ValidateMovie(ITraktMovie movie)
        {
            if (movie.Ids == null)
            {
                throw new ArgumentNullException(nameof(movie.Ids));
            }

            if (!movie.Ids.HasAnyId)
            {
                throw new ArgumentException("no movie ids set or valid", nameof(movie.Ids));
            }
        }
        private ITraktSyncHistoryPostMovie CreateSyncHistoryPostMovie(ITraktMovie movie, DateTime?watchedAt = null)
        {
            var syncHistoryPostMovie = new TraktSyncHistoryPostMovie
            {
                Ids   = movie.Ids,
                Title = movie.Title,
                Year  = movie.Year
            };

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

            return(syncHistoryPostMovie);
        }
Пример #16
0
        public ITraktMovieScrobblePostResponse StopScrobbleMovie(ITraktMovie movie, float progress, string appVersion = null,
                                                                 DateTime?appBuildDate = null)
        {
            ITraktResponse <ITraktMovieScrobblePostResponse> response = new TraktResponse <ITraktMovieScrobblePostResponse>();

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

            return(response.Value);
        }
Пример #17
0
        private void Validate(ITraktMovie movie)
        {
            if (movie == null)
            {
                throw new ArgumentNullException(nameof(movie), "movie must not be null");
            }

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

            if (!movie.Ids.HasAnyId)
            {
                throw new ArgumentException("movie.Ids have no valid id", nameof(movie));
            }
        }
        protected TraktSyncHistoryRemovePostBuilder AddMovieOrIgnore(ITraktMovie movie)
        {
            if (ContainsMovie(movie))
            {
                return(this);
            }

            var historyMovie = new TraktSyncHistoryPostMovie
            {
                Ids   = movie.Ids,
                Title = movie.Title,
                Year  = movie.Year
            };

            (_historyPost.Movies as List <ITraktSyncHistoryPostMovie>)?.Add(historyMovie);

            return(this);
        }
Пример #19
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;
            }
        }
Пример #20
0
        public async Task Test_TraktMoviesModule_GetMovie()
        {
            TraktClient client = TestUtility.GetMockClient(GET_MOVIE_URI, MOVIE_JSON);
            TraktResponse <ITraktMovie> response = await client.Movies.GetMovieAsync(MOVIE_ID);

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

            ITraktMovie responseValue = response.Value;

            responseValue.Title.Should().Be("Star Wars: The Force Awakens");
            responseValue.Year.Should().Be(2015);
            responseValue.Ids.Should().NotBeNull();
            responseValue.Ids.Trakt.Should().Be(94024U);
            responseValue.Ids.Slug.Should().Be("star-wars-the-force-awakens-2015");
            responseValue.Ids.Imdb.Should().Be("tt2488496");
            responseValue.Ids.Tmdb.Should().Be(140607U);
        }
Пример #21
0
        /// <summary>Adds a <see cref="ITraktMovie" />, which will be added to the watchlist post.</summary>
        /// <param name="movie">The Trakt movie, which will be added.</param>
        /// <returns>The current <see cref="TraktSyncWatchlistPostBuilder" /> instance.</returns>
        /// <exception cref="ArgumentNullException">
        /// Thrown, if the given movie is null.
        /// Thrown, if the given movie ids are null.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// Thrown, if the given movie has no valid ids set.
        /// Thrown, if the given movie has an year set, which has more or less than four digits.
        /// </exception>
        public TraktSyncWatchlistPostBuilder AddMovie(ITraktMovie movie)
        {
            if (movie == null)
            {
                throw new ArgumentNullException(nameof(movie));
            }

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

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

            if (movie.Year.HasValue && movie.Year.Value.ToString().Length != 4)
            {
                throw new ArgumentException("movie year not valid", nameof(movie.Year));
            }

            EnsureMoviesListExists();

            var existingMovie = _watchlistPost.Movies.FirstOrDefault(m => m.Ids == movie.Ids);

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

            (_watchlistPost.Movies as List <ITraktSyncWatchlistPostMovie>)?.Add(
                new TraktSyncWatchlistPostMovie
            {
                Ids   = movie.Ids,
                Title = movie.Title,
                Year  = movie.Year
            });

            return(this);
        }
Пример #22
0
        private ITraktSyncRatingsPostMovie CreateSyncRatingsPostMovie(ITraktMovie movie, int?rating = null, DateTime?ratedAt = null)
        {
            var syncRatingsPostMovie = new TraktSyncRatingsPostMovie
            {
                Ids   = movie.Ids,
                Title = movie.Title,
                Year  = movie.Year
            };

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

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

            return(syncRatingsPostMovie);
        }
Пример #23
0
        protected void ValidateMovie(ITraktMovie movie)
        {
            if (movie == null)
            {
                throw new ArgumentNullException(nameof(movie));
            }

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

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

            if (movie.Year.HasValue && movie.Year.Value.ToString().Length != 4)
            {
                throw new ArgumentException("movie year not valid", nameof(movie.Year));
            }
        }
        private ITraktSyncCollectionPostMovie CreateSyncCollectionPostMovie(ITraktMovie movie, ITraktMetadata metadata = null, DateTime?collectedAt = null)
        {
            var syncCollectionPostMovie = new TraktSyncCollectionPostMovie
            {
                Ids              = movie.Ids,
                Title            = movie.Title,
                Year             = movie.Year,
                MediaType        = metadata?.MediaType,
                MediaResolution  = metadata?.MediaResolution,
                Audio            = metadata?.Audio,
                AudioChannels    = metadata?.AudioChannels,
                ThreeDimensional = metadata?.ThreeDimensional,
                HDR              = metadata?.HDR
            };

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

            return(syncCollectionPostMovie);
        }
        public TraktUserHiddenItemsPostBuilder AddMovie(ITraktMovie movie)
        {
            ValidateMovie(movie);
            EnsureMoviesListExists();

            var existingMovie = _hiddenItemsPost.Movies.FirstOrDefault(m => m.Ids == movie.Ids);

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

            (_hiddenItemsPost.Movies as List <TraktUserHiddenItemsPostMovie>)?.Add(
                new TraktUserHiddenItemsPostMovie
            {
                Title = movie.Title,
                Year  = movie.Year,
                Ids   = movie.Ids
            });

            return(this);
        }
Пример #26
0
        protected TraktSyncHistoryPostBuilder AddMovieOrIgnore(ITraktMovie movie, DateTime?watchedAt = null)
        {
            if (ContainsMovie(movie))
            {
                return(this);
            }

            var historyMovie = new TraktSyncHistoryPostMovie
            {
                Ids   = movie.Ids,
                Title = movie.Title,
                Year  = movie.Year
            };

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

            (_historyPost.Movies as List <ITraktSyncHistoryPostMovie>)?.Add(historyMovie);

            return(this);
        }
        public ITraktPostBuilderMovieAddedWatchedAt <ITraktSyncHistoryPostBuilder, ITraktSyncHistoryPost> AddWatchedMovie(ITraktMovie movie)
        {
            if (movie == null)
            {
                throw new ArgumentNullException(nameof(movie));
            }

            _watchedMovies.SetCurrentMovie(movie);
            return(_watchedMovies);
        }
        private ITraktSyncRecommendationsPostMovie CreateSyncRecommendationsPostMovie(ITraktMovie movie, string notes = null)
        {
            var syncRecommendationsPostMovie = new TraktSyncRecommendationsPostMovie
            {
                Ids   = movie.Ids,
                Title = movie.Title,
                Year  = movie.Year
            };

            if (!string.IsNullOrWhiteSpace(notes))
            {
                syncRecommendationsPostMovie.Notes = notes;
            }

            return(syncRecommendationsPostMovie);
        }
Пример #29
0
        /// <summary>
        /// Posts a comment for the given <see cref="ITraktMovie" />.
        /// <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="movie">The <see cref="ITraktMovie" />, for which the comment should be posted.</param>
        /// <param name="comment">The comment's content for the given movie. 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 movie's title is null, empty or contains spaces.
        /// Thrown, if the given movie has no valid ids. See also <seealso cref="ITraktMovieIds" />.
        /// Thrown, if the given comment is null or empty.
        /// </exception>
        /// <exception cref="ArgumentNullException">Thrown, if the given movie is null or its ids are null.</exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// Thrown, if the given movie's year is not valid.
        /// Thrown, if the given comment's word count is below five.
        /// </exception>
        public Task <TraktResponse <ITraktCommentPostResponse> > PostMovieCommentAsync(ITraktMovie movie, string comment,
                                                                                       bool?containsSpoiler = null, ITraktSharing sharing = null,
                                                                                       CancellationToken cancellationToken = default)
        {
            ValidateMovie(movie);
            ValidateComment(comment);

            var requestHandler = new RequestHandler(Client);

            return(requestHandler.ExecuteSingleItemRequestAsync(new CommentPostRequest <ITraktMovieCommentPost>
            {
                RequestBody = new TraktMovieCommentPost
                {
                    Movie = new TraktMovie
                    {
                        Title = movie.Title,
                        Year = movie.Year,
                        Ids = movie.Ids
                    },
                    Comment = comment,
                    Spoiler = containsSpoiler,
                    Sharing = sharing
                }
            },
                                                                cancellationToken));
        }
Пример #30
0
        public ITraktPostBuilderMovieAddedRating <ITraktSyncRatingsPostBuilder, ITraktSyncRatingsPost> AddRatedMovie(ITraktMovie movie)
        {
            if (movie == null)
            {
                throw new ArgumentNullException(nameof(movie));
            }

            _ratedMovies.SetCurrentMovie(movie);
            return(_ratedMovies);
        }