public static TraktRateEpisode CreateEpisodeRateData(string title, string tvdb, string seasonidx, string episodeidx)
        {
            TraktRateEpisode rateObject = new TraktRateEpisode
            {
                Title = title,
                SeriesID = tvdb,
                Episode = episodeidx,
                Season = seasonidx,
                Rating = TraktSettings.ShowAdvancedRatingsDialog ? "7" : "10",
                UserName = TraktSettings.Username,
                Password = TraktSettings.Password
            };

            return rateObject;
        }
Exemplo n.º 2
0
        internal static bool RateEpisode(TraktShow show, TraktEpisode episode)
        {
            TraktRateEpisode rateObject = new TraktRateEpisode
            {
                SeriesID = show.Tvdb,
                Title = show.Title,
                Year = show.Year.ToString(),
                Episode = episode.Number.ToString(),
                Season = episode.Season.ToString(),
                Rating = episode.RatingAdvanced.ToString(),
                UserName = TraktSettings.Username,
                Password = TraktSettings.Password
            };

            int prevRating = episode.RatingAdvanced;
            int newRating = int.Parse(GUIUtils.ShowRateDialog<TraktRateEpisode>(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)
            {
                episode.RatingAdvanced = newRating;

                if (episode.Ratings == null)
                    episode.Ratings = new TraktRatings();

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

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

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

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

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

                return true;
            }

            return false;
        }
Exemplo n.º 3
0
        private TraktRateEpisode CreateEpisodeRateData(DBEpisode episode)
        {
            DBSeries series = Helper.getCorrespondingSeries(episode[DBOnlineEpisode.cSeriesID]);

            if (series == null || series[DBOnlineSeries.cTraktIgnore]) return null;

            string rating = episode[DBOnlineEpisode.cMyRating];

            TraktRateEpisode episodeData = new TraktRateEpisode()
            {
                Episode = episode[DBOnlineEpisode.cEpisodeIndex],
                Rating = rating,
                Season = episode[DBOnlineEpisode.cSeasonIndex],
                SeriesID = episode[DBOnlineEpisode.cSeriesID],
                Year = series.Year,
                Title = series[DBOnlineSeries.cOriginalName],
                UserName = TraktSettings.Username,
                Password = TraktSettings.Password
            };

            TraktLogger.Info("Rating '{0}' as '{1}/10'", episode.ToString(), rating.ToString());
            return episodeData;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Shows the Rate Episode Dialog after playback has ended
        /// </summary>
        /// <param name="episode">The episode being rated</param>
        private void ShowRateDialog(DBEpisode episode)
        {
            if (DBOption.GetOptions(DBOption.cAskToRate)) return;   // tvseries dialog is enabled
            if (!TraktSettings.ShowRateDialogOnWatched) return;     // not enabled
            if (episode[DBOnlineEpisode.cMyRating] > 0) return;     // already rated

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

            new Thread((o) =>
            {
                DBEpisode epToRate = o as DBEpisode;
                if (epToRate == null) return;

                DBSeries series = Helper.getCorrespondingSeries(epToRate[DBOnlineEpisode.cSeriesID]);

                TraktRateEpisode rateObject = new TraktRateEpisode
                {
                    SeriesID = epToRate[DBOnlineEpisode.cSeriesID],
                    Title = series == null ? string.Empty : series.ToString(),
                    Episode = epToRate[DBOnlineEpisode.cEpisodeIndex],
                    Season = epToRate[DBOnlineEpisode.cSeasonIndex],
                    UserName = TraktSettings.Username,
                    Password = TraktSettings.Password
                };

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

                if (rating > 0)
                {
                    TraktLogger.Debug("Rating {0} as {1}/10", epToRate.ToString(), rating.ToString());
                    epToRate[DBOnlineEpisode.cMyRating] = rating;
                    epToRate.Commit();

                    // update the facade holding the episode objects
                    var listItem = FindEpisodeInFacade(episode);
                    if (listItem != null)
                    {
                        listItem.TVTag = epToRate;
                    }
                }
            })
            {
                Name = "Rate",
                IsBackground = true
            }.Start(episode);
        }
        /// <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);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Shows the Rate Episode Dialog after playback has ended
        /// </summary>
        /// <param name="episode">The episode being rated</param>
        private void ShowRateDialog(FileLocal episode)
        {
            new Thread((o) =>
            {
                FileLocal epToRate = o as FileLocal;
                if (epToRate == null) return;

                string seriesid = null;
                int seasonidx = 0;
                int episodeidx = 0;

                if (epToRate.AnimeEpisodes == null || epToRate.AnimeEpisodes.Count == 0 || !GetTVDBEpisodeInfo(epToRate.AnimeEpisodes[0], out seriesid, out seasonidx, out episodeidx))
                {
                    TraktLogger.Warning("Unable to rate episode, no AniDb/TVDb reference in database yet.");
                    return;
                }

                if (!TraktSettings.ShowRateDialogOnWatched) return;          // not enabled
                if (epToRate.AnimeEpisodes[0].UserRating > 0) return;        // already rated

                TraktLogger.Debug("Showing rate dialog for '{0}'", epToRate.AnimeEpisodes[0].EpisodeName);

                TraktRateEpisode rateObject = new TraktRateEpisode
                {
                    Title = epToRate.AniDB_File.AnimeSeries.SeriesName,
                    Year = GetStartYear(epToRate.AniDB_File.AnimeSeries),
                    Season = seasonidx.ToString(),
                    Episode = episodeidx.ToString(),
                    SeriesID = seriesid,
                    UserName = TraktSettings.Username,
                    Password = TraktSettings.Password
                };

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

                if (rating > 0)
                {
                    TraktLogger.Debug("Rating {0} as {1}/10", epToRate.AnimeEpisodes[0].EpisodeName, rating.ToString());
                    // note: can't set rating locally as its read only
                }
            })
            {
                Name = "Rate",
                IsBackground = true
            }.Start(episode);
        }
        private void RateEpisode(TraktCalendar.TraktEpisodes episode)
        {
            // default rating to love if not already set
            TraktRateEpisode rateObject = new TraktRateEpisode
            {
                SeriesID = episode.Show.Tvdb,
                Title = episode.Show.Title,
                Year = episode.Show.Year.ToString(),
                Episode = episode.Episode.Number.ToString(),
                Season = episode.Episode.Season.ToString(),
                Rating = episode.Episode.Rating,
                UserName = TraktSettings.Username,
                Password = TraktSettings.Password
            };

            string prevRating = episode.Episode.Rating;
            episode.Episode.Rating = GUIUtils.ShowRateDialog<TraktRateEpisode>(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 != episode.Episode.Rating)
            {
                if (prevRating == "false")
                {
                    episode.Episode.Ratings.Votes++;
                    if (episode.Episode.Rating == "love")
                        episode.Episode.Ratings.LovedCount++;
                    else
                        episode.Episode.Ratings.HatedCount++;
                }

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

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

                episode.Episode.Ratings.Percentage = (int)Math.Round(100 * (episode.Episode.Ratings.LovedCount / (float)episode.Episode.Ratings.Votes));
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Shows the Rate Episode Dialog after playback has ended
        /// </summary>
        /// <param name="episode">The episode being rated</param>
        private void ShowRateDialog(DBEpisode episode, bool isPlaylist)
        {
            if (DBOption.GetOptions(DBOption.cAskToRate)) return;               // tvseries dialog is enabled
            if (!TraktSettings.ShowRateDialogOnWatched) return;                 // not enabled
            if (episode[DBOnlineEpisode.cMyRating] > 0) return;                 // already rated
            if (isPlaylist && !TraktSettings.ShowRateDlgForPlaylists) return;   // disabled for playlists

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

            new Thread((o) =>
            {
                DBEpisode epToRate = o as DBEpisode;
                if (epToRate == null) return;

                DBSeries series = Helper.getCorrespondingSeries(epToRate[DBOnlineEpisode.cSeriesID]);

                TraktRateEpisode rateObject = new TraktRateEpisode
                {
                    SeriesID = epToRate[DBOnlineEpisode.cSeriesID],
                    Title = series == null ? string.Empty : series.ToString(),
                    Episode = epToRate[DBOnlineEpisode.cEpisodeIndex],
                    Season = epToRate[DBOnlineEpisode.cSeasonIndex],
                    UserName = TraktSettings.Username,
                    Password = TraktSettings.Password
                };

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

                if (rating > 0)
                {
                    TraktLogger.Debug("Rating {0} as {1}/10", epToRate.ToString(), rating.ToString());

                    epToRate[DBOnlineEpisode.cMyRating] = rating;
                    if (epToRate[DBOnlineEpisode.cRatingCount] == 0)
                    {
                        // not really needed but nice touch
                        // tvseries does not do this automatically on userrating insert
                        // we could do one step further and re-calculate rating for any vote count
                        epToRate[DBOnlineEpisode.cRatingCount] = 1;
                        epToRate[DBOnlineEpisode.cRating] = rating;
                    }
                    // ensure we force watched flag otherwise
                    // we will overwrite current state on facade with state before playback
                    epToRate[DBOnlineEpisode.cWatched] = true;
                    epToRate.Commit();

                    // update the facade holding the episode objects
                    var listItem = FindEpisodeInFacade(episode);
                    if (listItem != null)
                    {
                        listItem.TVTag = epToRate;
                    }
                }
            })
            {
                Name = "Rate",
                IsBackground = true
            }.Start(episode);
        }