Пример #1
0
        static TraktEpisode GetTraktEpisodeData(Dictionary<string, string> episode, TraktShowSummary showSummary, bool ratings = true)
        {
            if (showSummary == null || showSummary.Seasons == null || showSummary.Seasons.Count == 0)
                return null;

            string episodeTitle = GetEpisodeName(episode[IMDbFieldMapping.cTitle]);

            // find episode title in list of episodes from show summary
            if (!string.IsNullOrEmpty(episodeTitle))
            {
                TraktShowSummary.TraktSeason.TraktEpisode match = null;
                foreach (var season in showSummary.Seasons)
                {
                    if (match != null) continue;
                    match = season.Episodes.FirstOrDefault(e => string.Equals(e.Title, episodeTitle, StringComparison.InvariantCultureIgnoreCase));
                }

                if (match != null)
                {
                    var traktEpisode = new TraktEpisode
                    {
                        Episode = match.Episode,
                        Season = match.Season,
                        TVDbId = showSummary.TVDbId,
                        Title = showSummary.Title,
                        Year = showSummary.Year,
                        LastPlayed = GetLastPlayedDate(episode)
                    };

                    if (ratings)
                        traktEpisode.Rating = int.Parse(episode[IMDbFieldMapping.cRating]);

                    return traktEpisode;
                }
            }

            // we can also lookup by airDate
            string episodeAirDate = null;
            episode.TryGetValue(IMDbFieldMapping.cReleaseDate, out episodeAirDate);

            if (!string.IsNullOrEmpty(episodeAirDate))
            {
                // get epoch date
                long dateTimeEpoch = 0;
                try
                {
                    var splitDate = episodeAirDate.Split('-');
                    // parse date and add 8hours for PST
                    DateTime dateTime = new DateTime(int.Parse(splitDate[0]), int.Parse(splitDate[1]), int.Parse(splitDate[2])).AddHours(8);
                    dateTimeEpoch = dateTime.ToEpoch();
                }
                catch
                {
                    UIUtils.UpdateStatus(string.Format("Unable to get info for {0}", episode[IMDbFieldMapping.cTitle]), true);
                    return null;
                }

                TraktShowSummary.TraktSeason.TraktEpisode match = null;
                foreach (var season in showSummary.Seasons)
                {
                    if (match != null) continue;
                    match = season.Episodes.FirstOrDefault(e => e.FirstAired == dateTimeEpoch);
                }

                if (match != null)
                {
                    var traktEpisode = new TraktEpisode
                    {
                        Episode = match.Episode,
                        Season = match.Season,
                        TVDbId = match.TVDbId,
                        Title = showSummary.Title,
                        Year = showSummary.Year
                    };

                    if (ratings)
                        traktEpisode.Rating = int.Parse(episode[IMDbFieldMapping.cRating]);

                    return traktEpisode;
                }
            }

            UIUtils.UpdateStatus(string.Format("Unable to get info for {0}", episode[IMDbFieldMapping.cTitle]), true);
            return null;
        }
Пример #2
0
        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;
        }