internal static bool RateMovie(TraktMovie movie)
        {
            TraktRateMovie rateObject = new TraktRateMovie
            {
                IMDBID = movie.IMDBID,
                TMDBID = movie.TMDBID,
                Title = movie.Title,
                Year = movie.Year,
                Rating = movie.RatingAdvanced.ToString(),
                UserName = TraktSettings.Username,
                Password = TraktSettings.Password
            };

            int prevRating = movie.RatingAdvanced;
            int newRating = int.Parse(GUIUtils.ShowRateDialog<TraktRateMovie>(rateObject));
            if (newRating == -1) return false;

            // If previous rating not equal to current rating then
            // update skin properties to reflect changes
            // This is not really needed but saves waiting for response
            // from server to calculate fields...we can do it ourselves

            if (prevRating != newRating)
            {
                movie.RatingAdvanced = newRating;

                // if not rated previously bump up the votes
                if (prevRating == 0)
                {
                    movie.Ratings.Votes++;
                    if (movie.RatingAdvanced > 5)
                    {
                        movie.Rating = "love";
                        movie.Ratings.LovedCount++;
                    }
                    else
                    {
                        movie.Rating = "hate";
                        movie.Ratings.HatedCount++;
                    }
                }

                if (prevRating != 0 && prevRating > 5 && newRating <= 5)
                {
                    movie.Rating = "hate";
                    movie.Ratings.LovedCount--;
                    movie.Ratings.HatedCount++;
                }

                if (prevRating != 0 && prevRating <= 5 && newRating > 5)
                {
                    movie.Rating = "love";
                    movie.Ratings.LovedCount++;
                    movie.Ratings.HatedCount--;
                }

                if (newRating == 0)
                {
                    if (prevRating <= 5) movie.Ratings.HatedCount++;
                    movie.Ratings.Votes--;
                    movie.Rating = "false";
                }

                // Could be in-accurate, best guess
                if (prevRating == 0)
                {
                    movie.Ratings.Percentage = (int)Math.Round(((movie.Ratings.Percentage * (movie.Ratings.Votes - 1)) + (10 * newRating)) / (float)movie.Ratings.Votes);
                }
                else
                {
                    movie.Ratings.Percentage = (int)Math.Round(((movie.Ratings.Percentage * (movie.Ratings.Votes)) + (10 * newRating) - (10 * prevRating)) / (float)movie.Ratings.Votes);
                }

                return true;
            }

            return false;
        }
        /// <summary>
        /// Shows the Rate Dialog after playback has ended
        /// </summary>
        /// <param name="episode">The item being rated</param>
        private void ShowRateDialog(ITrackingInfo videoInfo)
        {
            if (!TraktSettings.ShowRateDialogOnWatched) return;     // not enabled

            TraktLogger.Debug("Showing rate dialog for '{0}'", videoInfo.Title);

            new Thread((o) =>
            {
                ITrackingInfo itemToRate = o as ITrackingInfo;
                if (itemToRate == null) return;

                int rating = 0;

                if (itemToRate.VideoKind == VideoKind.TvSeries)
                {
                    TraktRateEpisode rateObject = new TraktRateEpisode
                    {
                        SeriesID = itemToRate.ID_TVDB,
                        Title = itemToRate.Title,
                        Year = itemToRate.Year > 1900 ? itemToRate.Year.ToString() : null,
                        Episode = itemToRate.Episode.ToString(),
                        Season = itemToRate.Season.ToString(),
                        UserName = TraktSettings.Username,
                        Password = TraktSettings.Password
                    };
                    // get the rating submitted to trakt
                    rating = int.Parse(GUIUtils.ShowRateDialog<TraktRateEpisode>(rateObject));
                }
                else if (itemToRate.VideoKind == VideoKind.Movie)
                {
                    TraktRateMovie rateObject = new TraktRateMovie
                    {
                        IMDBID = itemToRate.ID_IMDB,
                        TMDBID = itemToRate.ID_TMDB,
                        Title = itemToRate.Title,
                        Year = itemToRate.Year > 1900 ? itemToRate.Year.ToString() : null,
                        UserName = TraktSettings.Username,
                        Password = TraktSettings.Password
                    };
                    // get the rating submitted to trakt
                    rating = int.Parse(GUIUtils.ShowRateDialog<TraktRateMovie>(rateObject));
                }

                if (rating > 0)
                {
                    TraktLogger.Debug("Rating {0} as {1}/10", itemToRate.Title, rating.ToString());
                    // note: no user rating field to set
                }
            })
            {
                Name = "Rate",
                IsBackground = true
            }.Start(videoInfo);
        }
        /// <summary>
        /// Creates Movie Rate Data object
        /// </summary>
        /// <param name="title">Title of Movie</param>
        /// <param name="year">Year of Movie</param>
        /// <param name="imdb">IMDB ID of movie</param>
        /// <returns>Rate Data Object</returns>
        public static TraktRateMovie CreateMovieRateData(string title, string year, string imdb)
        {
            TraktRateMovie rateObject = new TraktRateMovie
            {
                IMDBID = imdb,
                Title = title,
                Year = year,
                Rating = TraktSettings.ShowAdvancedRatingsDialog ? "7" : "10",
                UserName = TraktSettings.Username,
                Password = TraktSettings.Password
            };

            return rateObject;
        }
        /// <summary>
        /// Shows the Rate Movie Dialog after playback has ended
        /// </summary>
        /// <param name="movie">The movie being rated</param>
        private void ShowRateDialog(MFMovie movie)
        {
            if (!TraktSettings.ShowRateDialogOnWatched) return;     // not enabled
            if (movie.Rating > 0) return;                           // already rated

            TraktLogger.Debug("Showing rate dialog for '{0}'", movie.Title);

            new Thread((o) =>
            {
                MFMovie movieToRate = o as MFMovie;
                if (movieToRate == null) return;

                TraktRateMovie rateObject = new TraktRateMovie
                {
                    IMDBID = movieToRate.IMDBNumber,
                    TMDBID = movieToRate.TMDBNumber,
                    Title = movieToRate.Title,
                    Year = movieToRate.Year.ToString(),
                    UserName = TraktSettings.Username,
                    Password = TraktSettings.Password
                };

                // get the rating submitted to trakt
                int rating = int.Parse(GUIUtils.ShowRateDialog<TraktRateMovie>(rateObject));

                if (rating > 0)
                {
                    TraktLogger.Debug("Rating {0} as {1}/10", movieToRate.Title, rating.ToString());
                    movieToRate.Rating = (float)rating;
                    movieToRate.Username = TraktSettings.Username;
                    movieToRate.Commit();
                }
            })
            {
                Name = "Rate",
                IsBackground = true
            }.Start(movie);
        }
        public static TraktRateMovie CreateRateData(MFMovie movie, String rating)
        {
            string username = TraktSettings.Username;
            string password = TraktSettings.Password;

            if (String.IsNullOrEmpty(username) || String.IsNullOrEmpty(password))
                return null;

            TraktRateMovie rateData = new TraktRateMovie
            {
                Title = movie.Title,
                Year = movie.Year.ToString(),
                IMDBID = movie.IMDBNumber,
                TMDBID = null,
                UserName = username,
                Password = password,
                Rating = rating
            };
            return rateData;
        }
 private void RateMovie(TraktRateMovie rateData)
 {
     BackgroundWorker rateMovie = new BackgroundWorker();
     rateMovie.DoWork += new DoWorkEventHandler(rateMovie_DoWork);
     rateMovie.RunWorkerCompleted += new RunWorkerCompletedEventHandler(rateMovie_RunWorkerCompleted);
     rateMovie.RunWorkerAsync(rateData);
 }
        /// <summary>
        /// Shows the Rate Movie Dialog after playback has ended
        /// </summary>
        /// <param name="movie">The movie being rated</param>
        private void ShowRateDialog(DBMovieInfo movie)
        {
            if (MovingPicturesCore.Settings.AutoPromptForRating) return;    // movpics dialog is enabled
            if (!TraktSettings.ShowRateDialogOnWatched) return;             // not enabled
            if (movie.ActiveUserSettings.UserRating > 0) return;            // already rated

            TraktLogger.Debug("Showing rate dialog for '{0}'", movie.Title);

            new System.Threading.Thread((o) =>
            {
                var movieToRate = o as DBMovieInfo;
                if (movieToRate == null) return;

                TraktRateMovie rateObject = new TraktRateMovie
                {
                    TMDBID = GetTmdbID(movieToRate),
                    IMDBID = movieToRate.ImdbID,
                    Title = movieToRate.Title,
                    Year = movieToRate.Year.ToString(),
                    UserName = TraktSettings.Username,
                    Password = TraktSettings.Password
                };

                // get the rating submitted to trakt
                int rating = int.Parse(GUIUtils.ShowRateDialog<TraktRateMovie>(rateObject));

                if (rating > 0)
                {
                    // flag to ignore event handler
                    TraktRateSent = true;

                    TraktLogger.Debug("Rating {0} as {1}/10", movieToRate.Title, rating.ToString());
                    movieToRate.ActiveUserSettings.UserRating = (int)(Math.Round(rating / 2.0, MidpointRounding.AwayFromZero));
                    movieToRate.Commit();

                    TraktRateSent = false;
                }
            })
            {
                Name = "Rate",
                IsBackground = true
            }.Start(movie);
        }
Exemple #8
0
        private void ShowTraktRate()
        {
            TraktRateMovie rateMovie = new TraktRateMovie
            {
                IMDBID = GUIPropertyManager.GetProperty("#MovingPictures.SelectedMovie.imdb_id").Trim(),
                Title = GUIPropertyManager.GetProperty("#MovingPictures.SelectedMovie.title").Trim(),
                Year = GUIPropertyManager.GetProperty("#MovingPictures.SelectedMovie.year").Trim(),
                Rating = "love",
                UserName = TraktSettings.Username,
                Password = TraktSettings.Password

            };

            TraktPlugin.GUI.GUIUtils.ShowRateDialog<TraktRateMovie>(rateMovie);
        }
        private void RateMovie(TraktTrendingMovie movie)
        {
            // default rating to love if not already set
            TraktRateMovie rateObject = new TraktRateMovie
            {
                IMDBID = movie.Imdb,
                Title = movie.Title,
                Year = movie.Year,
                Rating = movie.Rating,
                UserName = TraktSettings.Username,
                Password = TraktSettings.Password
            };

            string prevRating = movie.Rating;
            movie.Rating = GUIUtils.ShowRateDialog<TraktRateMovie>(rateObject);

            // if previous rating not equal to current rating then
            // update skin properties to reflect changes so we dont
            // need to re-request from server
            if (prevRating != movie.Rating)
            {
                if (prevRating == "false")
                {
                    movie.Ratings.Votes++;
                    if (movie.Rating == "love")
                        movie.Ratings.LovedCount++;
                    else
                        movie.Ratings.HatedCount++;
                }

                if (prevRating == "love")
                {
                    movie.Ratings.LovedCount--;
                    movie.Ratings.HatedCount++;
                }

                if (prevRating == "hate")
                {
                    movie.Ratings.LovedCount++;
                    movie.Ratings.HatedCount--;
                }

                movie.Ratings.Percentage = (int)Math.Round(100 * (movie.Ratings.LovedCount / (float)movie.Ratings.Votes));
            }
        }
        /// <summary>
        /// Shows the Rate Movie Dialog after playback has ended
        /// </summary>
        /// <param name="movie">The movie being rated</param>
        private void ShowRateDialog(DBMovieInfo movie)
        {
            if (MovingPicturesCore.Settings.AutoPromptForRating) return;    // movpics dialog is enabled
            if (!TraktSettings.ShowRateDialogOnWatched) return;             // not enabled
            if (movie.ActiveUserSettings.UserRating > 0) return;            // already rated

            TraktLogger.Debug("Showing rate dialog for '{0}'", movie.Title);

            new System.Threading.Thread((o) =>
            {
                var movieToRate = o as DBMovieInfo;
                if (movieToRate == null) return;

                TraktRateMovie rateObject = new TraktRateMovie
                {
                    TMDBID = GetTmdbID(movieToRate),
                    IMDBID = movieToRate.ImdbID,
                    Title = movieToRate.Title,
                    Year = movieToRate.Year.ToString(),
                    UserName = TraktSettings.Username,
                    Password = TraktSettings.Password
                };

                // added a delay due to bug in MovingPictures blocking OnPageLoad()
                // a call to GUIWindowManager.Process() causes MediaPortal to wait until any modal dialog is closed.
                // the value may need to be tweaked on some systems
                // visible symtoms of issue is wrong backdrop / progress in background whilst dialog is modal
                System.Threading.Thread.Sleep(TraktSettings.MovPicsRatingDlgDelay);

                // get the rating submitted to trakt
                int rating = int.Parse(GUIUtils.ShowRateDialog<TraktRateMovie>(rateObject));

                if (rating > 0)
                {
                    // flag to ignore event handler
                    TraktRateSent = true;

                    TraktLogger.Debug("Rating {0} as {1}/10", movieToRate.Title, rating.ToString());
                    movieToRate.ActiveUserSettings.UserRating = (int)(Math.Round(rating / 2.0, MidpointRounding.AwayFromZero));

                    // Publish to skin - same as how MovingPictures does it i.e. lose precision due to rounding
                    if (GUIUtils.GetProperty("#MovingPictures.SelectedMovie.title").Equals(movieToRate.Title))
                    {
                        GUICommon.SetProperty("#MovingPictures.UserMovieSettings.user_rating", movieToRate.ActiveUserSettings.UserRating.ToString());
                        GUICommon.SetProperty("#MovingPictures.UserMovieSettings.10point_user_rating", (movieToRate.ActiveUserSettings.UserRating * 2).ToString());
                    }

                    if (movieToRate.Popularity == 0 && movieToRate.Score == 0)
                    {
                        movieToRate.Score = rating;
                        movieToRate.Popularity = 1;
                    }

                    movieToRate.Commit();

                    TraktRateSent = false;
                }
            })
            {
                Name = "Rate",
                IsBackground = true
            }.Start(movie);
        }
        private bool RateMovie(TraktMovie movie)
        {
            // init since its not part of the API
            movie.Rating = "false";
            bool ratingChanged = false;

            // default rating to love if not already set
            TraktRateMovie rateObject = new TraktRateMovie
            {
                IMDBID = movie.Imdb,
                Title = movie.Title,
                Year = movie.Year,
                Rating = movie.Rating,
                UserName = TraktSettings.Username,
                Password = TraktSettings.Password
            };

            string prevRating = movie.Rating;
            movie.Rating = GUIUtils.ShowRateDialog<TraktRateMovie>(rateObject);

            if (prevRating != movie.Rating)
            {
                ratingChanged = true;
            }

            return ratingChanged;
        }
        /// <summary>
        /// Shows the Rate Movie Dialog after playback has ended
        /// </summary>
        /// <param name="movie">The movie being rated</param>
        private void ShowRateDialog(IMDBMovie movie)
        {
            if (!TraktSettings.ShowRateDialogOnWatched) return;
            if (!TraktSettings.ShowRateDlgForPlaylists && PlayListPlayer.SingletonPlayer.CurrentPlaylistType == PlayListType.PLAYLIST_VIDEO) return;

            TraktLogger.Debug("Showing rate dialog for '{0}'", movie.Title);

            new Thread((o) =>
            {
                IMDBMovie movieToRate = o as IMDBMovie;
                if (movieToRate == null) return;

                TraktRateMovie rateObject = new TraktRateMovie
                {
                    IMDBID = movieToRate.IMDBNumber,
                    Title = movieToRate.Title,
                    Year = movieToRate.Year.ToString(),
                    UserName = TraktSettings.Username,
                    Password = TraktSettings.Password
                };

                // get the rating submitted to trakt
                int rating = int.Parse(GUIUtils.ShowRateDialog<TraktRateMovie>(rateObject));

                if (rating > 0)
                {
                    TraktLogger.Debug("Rating {0} as {1}/10", movieToRate.Title, rating.ToString());
                    // note: no user rating field to update locally
                }
            })
            {
                Name = "Rate",
                IsBackground = true
            }.Start(movie);
        }