示例#1
0
        private TraktEpisodes GetRateEpisodeData(TVDbEpisodeRatings episodeRatings, TVDbShow showInfo)
        {
            List<TraktEpisode> episodes = new List<TraktEpisode>();

            foreach (var episode in episodeRatings.Episodes)
            {
                // get season/episode info from showInfo object
                var tvdbEpisode = showInfo.Episodes.Find(e => e.Id == episode.Id);
                if (tvdbEpisode == null) continue;

                var traktEpisode = new TraktEpisode
                {
                    Episode = tvdbEpisode.EpisodeNumber,
                    Season = tvdbEpisode.SeasonNumber,
                    TVDbId = episodeRatings.Show.Id,
                    Rating = episode.UserRating,
                    Title = showInfo.Show.Name
                };
                episodes.Add(traktEpisode);
            }

            TraktEpisodes episodeRateData = new TraktEpisodes
            {
                Username = AppSettings.TraktUsername,
                Password = AppSettings.TraktPassword,
                Episodes = episodes,
            };

            return episodeRateData;
        }
示例#2
0
        public static TraktEpisodes GetEpisodeData(IEnumerable<Dictionary<string, string>> episodes, bool ratings=true)
        {
            var traktEpisodes = new List<TraktEpisode>();

            foreach (var episode in episodes)
            {
                if (ratings && string.IsNullOrEmpty(episode[IMDbFieldMapping.cRating]))
                    continue;

                // get the show information
                string showTitle = GetShowName(episode[IMDbFieldMapping.cTitle]);
                if (string.IsNullOrEmpty(showTitle)) continue;

                // get slug of show title
                string slug = showTitle.GenerateSlug();
                if (string.IsNullOrEmpty(slug)) continue;

                TraktShowSummary showSummary = new TraktShowSummary();

                if (!ShowSummaries.TryGetValue(showTitle, out showSummary))
                {
                    // get from online
                    UIUtils.UpdateStatus(string.Format("Retrieving data for {0}", showTitle));

                    // Note: IMDb ID will be the TV Show IMDb if syncing from Web, otherwise it uses the Episode IMDb ID
                    // The Summary method will not work with the Episode IMDb so fallback to Title slug.

                    // Check the field count to determine if its a Web/CSV episode
                    if (episode[IMDbFieldMapping.cProvider] == "web")
                        slug = episode[IMDbFieldMapping.cIMDbID];

                    showSummary = TraktAPI.TraktAPI.GetShowSummary(slug);
                    if (showSummary == null || showSummary.Seasons == null || showSummary.Seasons.Count == 0)
                    {
                        // trakt may not have the IMDb for the show, try using title slug
                        if (!slug.StartsWith("tt"))
                        {
                            showSummary = TraktAPI.TraktAPI.GetShowSummary(slug);
                        }
                        if (showSummary == null || showSummary.Seasons == null || showSummary.Seasons.Count == 0)
                        {
                            UIUtils.UpdateStatus(string.Format("Unable to get info for {0}", showTitle), true);
                            continue;
                        }
                    }

                    // store show summary
                    ShowSummaries.Add(showTitle, showSummary);
                }

                var traktEpisode = GetTraktEpisodeData(episode, showSummary, ratings);
                if (traktEpisode == null) continue;

                traktEpisodes.Add(traktEpisode);
            }

            var episodeData = new TraktEpisodes
            {
                Username = AppSettings.TraktUsername,
                Password = AppSettings.TraktPassword,
                Episodes = traktEpisodes
            };

            return episodeData;
        }
示例#3
0
        /// <summary>
        /// Rates a list of episodes on trakt
        /// </summary>
        /// <param name="data">The object containing the list of episodes to be rated</param>       
        /// <returns>The response from trakt</returns>
        public static TraktRatingsResponse RateEpisodes(TraktEpisodes data)
        {
            // check that we have everything we need
            if (data == null || data.Episodes.Count == 0)
                return null;

            // serialize data to JSON and send to server
            string response = TraktWeb.Transmit(TraktURIs.RateEpisodes, data.ToJSON());

            // return success or failure
            return response.FromJSON<TraktRatingsResponse>();
        }