/// <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(TraktRateEpisodes 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>(); }
private TraktRateEpisodes GetRateEpisodeData(IEnumerable<Dictionary<string, string>> episodes) { var traktEpisodes = new List<TraktEpisode>(); foreach(var episode in episodes) { // 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)); 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 = GetTraktEpisodeRateData(episode, showSummary); if (traktEpisode == null) continue; traktEpisodes.Add(traktEpisode); } var episodeRateData = new TraktRateEpisodes { Username = AppSettings.TraktUsername, Password = AppSettings.TraktPassword, Episodes = traktEpisodes }; return episodeRateData; }
private TraktRateEpisodes 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); } TraktRateEpisodes episodeRateData = new TraktRateEpisodes { Username = AppSettings.TraktUsername, Password = AppSettings.TraktPassword, Episodes = episodes, }; return episodeRateData; }