コード例 #1
0
        internal static void SetEpisodeProperties(TraktShowSummary show, TraktEpisodeSummary episode)
        {
            if (episode == null) return;

            SetProperty("#Trakt.Episode.Id", episode.Ids.Trakt);
            SetProperty("#Trakt.Episode.TvdbId", episode.Ids.Tvdb);
            SetProperty("#Trakt.Episode.ImdbId", episode.Ids.Imdb);
            SetProperty("#Trakt.Episode.TmdbId", episode.Ids.Imdb);
            SetProperty("#Trakt.Episode.Number", episode.Number);
            SetProperty("#Trakt.Episode.Season", episode.Season);
            if (episode.FirstAired != null)
            {
                // FirstAired is converted to UTC from original countries timezone on trakt
                SetProperty("#Trakt.Episode.FirstAired", episode.FirstAired.FromISO8601().ToShortDateString());
                SetProperty("#Trakt.Episode.FirstAiredLocalized", episode.FirstAired.FromISO8601().ToLocalTime().ToShortDateString());
                SetProperty("#Trakt.Episode.FirstAiredLocalizedDayOfWeek", episode.FirstAired.FromISO8601().ToLocalTime().ToLocalisedDayOfWeek());
                SetProperty("#Trakt.Episode.FirstAiredLocalizedTime", episode.FirstAired.FromISO8601().ToLocalTime().ToShortTimeString());
            }
            SetProperty("#Trakt.Episode.Title", string.IsNullOrEmpty(episode.Title) ? string.Format("{0} {1}", Translation.Episode, episode.Number.ToString()) : episode.Title.RemapHighOrderChars());
            SetProperty("#Trakt.Episode.Url", string.Format("http://trakt.tv/shows/{0}/seasons/{1}/episodes/{2}", show.Ids.Slug, episode.Season, episode.Number));
            SetProperty("#Trakt.Episode.Overview", episode.Overview.ToNullIfEmpty() == null ? Translation.NoEpisodeSummary : episode.Overview.RemapHighOrderChars());
            SetProperty("#Trakt.Episode.Runtime", show.Runtime);
            SetProperty("#Trakt.Episode.InWatchList", episode.IsWatchlisted());
            SetProperty("#Trakt.Episode.InCollection", episode.IsCollected(show));
            SetProperty("#Trakt.Episode.Plays", episode.Plays(show));
            SetProperty("#Trakt.Episode.Watched", episode.IsWatched(show));
            SetProperty("#Trakt.Episode.Rating", episode.UserRating(show));
            SetProperty("#Trakt.Episode.Ratings.Percentage", episode.Rating.ToPercentage());
            SetProperty("#Trakt.Episode.Ratings.Votes", episode.Votes);
            SetProperty("#Trakt.Episode.Ratings.Icon", (episode.Rating >= 6) ? "love" : "hate");
            //if (episode.Images != null)
            //{
            //    SetProperty("#Trakt.Episode.EpisodeImageFilename", episode.Images.ScreenShot.LocalImageFilename(ArtworkType.EpisodeImage));
            //}
        }
コード例 #2
0
        internal static bool RateEpisode(TraktShowSummary show, TraktEpisodeSummary episode)
        {
            // this object will work without episode ids
            var rateObjectEx = new TraktSyncShowRatedEx
            {
                Ids = show.Ids,
                Title = show.Title,
                Year = show.Year,
                Seasons = new List<TraktSyncShowRatedEx.Season>
                {
                    new TraktSyncShowRatedEx.Season
                    {
                        Number = episode.Season,
                        Episodes = new List<TraktSyncShowRatedEx.Season.Episode>
                        {
                            new TraktSyncShowRatedEx.Season.Episode
                            {
                                Number = episode.Number,
                                RatedAt = DateTime.UtcNow.ToISO8601()
                            }
                        }
                    }
                }
            };

            // only use if we have episode ids
            var rateObject = new TraktSyncEpisodeRated
            {
                Ids = new TraktEpisodeId
                {
                    Trakt = episode.Ids.Trakt,
                    Imdb = episode.Ids.Imdb.ToNullIfEmpty(),
                    Tmdb = episode.Ids.Tmdb,
                    Tvdb = episode.Ids.Tvdb,
                    TvRage = episode.Ids.TvRage
                },
                Title = episode.Title,
                Season = episode.Season,
                Number = episode.Number,
                RatedAt = DateTime.UtcNow.ToISO8601()
            };

            int? prevRating = episode.UserRating(show);
            int newRating = 0;

            if (episode.Ids == null || episode.Ids.Trakt == null)
            {
                newRating = GUIUtils.ShowRateDialog<TraktSyncShowRatedEx>(rateObjectEx);
            }
            else
            {
                newRating = GUIUtils.ShowRateDialog<TraktSyncEpisodeRated>(rateObject);
            }

            if (newRating == -1) return false;

            // If previous rating not equal to current rating then
            // update skin properties to reflect changes
            if (prevRating == newRating)
                return false;

            if (prevRating == null || prevRating == 0)
            {
                // add to ratings
                TraktCache.AddEpisodeToRatings(show, episode, newRating);
                episode.Votes++;
            }
            else if (newRating == 0)
            {
                // remove from ratings
                TraktCache.RemoveEpisodeFromRatings(episode);
                episode.Votes--;
            }
            else
            {
                // rating changed, remove then add
                TraktCache.RemoveEpisodeFromRatings(episode);
                TraktCache.AddEpisodeToRatings(show, episode, newRating);
            }

            // update ratings until next online update
            // if we have the ratings distribution we could calculate correctly
            if (episode.Votes == 0)
            {
                episode.Rating = 0;
            }
            else if (episode.Votes == 1 && newRating > 0)
            {
                episode.Rating = newRating;
            }

            return true;
        }