示例#1
0
        /// <summary>
        /// Returns detailed information for a single <see cref="OmDbEpisode"/> with given <paramref name="id"/>. This method caches request
        /// to same episodes using the cache path given in <see cref="OmDbApiV1"/> constructor.
        /// </summary>
        /// <param name="id">IMDB id of series</param>
        /// <param name="season">Season number</param>
        /// <param name="episode">Episode number</param>
        /// <returns>Episode information</returns>
        public async Task <OmDbEpisode> GetSeriesEpisodeAsync(string id, int season, int episode, bool cacheOnly)
        {
            string      cache       = CreateAndGetCacheName(id, string.Format("Season{0}_Episode{1}", season, episode));
            OmDbEpisode returnValue = null;

            if (!string.IsNullOrEmpty(cache) && File.Exists(cache))
            {
                returnValue = await _downloader.ReadCacheAsync <OmDbEpisode>(cache).ConfigureAwait(false);
            }
            else
            {
                if (cacheOnly)
                {
                    return(null);
                }
                string url = GetUrl(URL_GETIMDBIDEPISODE, 0, true, true, id, season, episode);
                returnValue = await _downloader.DownloadAsync <OmDbEpisode>(url, cache).ConfigureAwait(false);
            }
            if (returnValue == null)
            {
                return(null);
            }
            if (returnValue.ResponseValid == false)
            {
                return(null);
            }
            if (returnValue != null)
            {
                returnValue.AssignProperties();
            }
            return(returnValue);
        }
        public override bool UpdateFromOnlineSeriesEpisode(EpisodeInfo episode, string language, bool cacheOnly)
        {
            try
            {
                List <EpisodeInfo> episodeDetails = new List <EpisodeInfo>();
                OmDbEpisode        episodeDetail  = null;

                if (!string.IsNullOrEmpty(episode.SeriesImdbId) && episode.SeasonNumber.HasValue && episode.EpisodeNumbers.Count > 0)
                {
                    OmDbSeason seasonDetail = _omDbHandler.GetSeriesSeason(episode.SeriesImdbId, 1, cacheOnly);

                    foreach (int episodeNumber in episode.EpisodeNumbers)
                    {
                        episodeDetail = _omDbHandler.GetSeriesEpisode(episode.SeriesImdbId, episode.SeasonNumber.Value, episodeNumber, cacheOnly);
                        if (episodeDetail == null)
                        {
                            continue;
                        }
                        if (episodeDetail.EpisodeNumber <= 0)
                        {
                            continue;
                        }

                        EpisodeInfo info = new EpisodeInfo()
                        {
                            ImdbId = episodeDetail.ImdbID,

                            SeriesImdbId     = episodeDetail.ImdbSeriesID,
                            SeriesName       = new SimpleTitle(seasonDetail.Title, true),
                            SeriesFirstAired = seasonDetail != null && seasonDetail.Episodes != null && seasonDetail.Episodes.Count > 0 ?
                                               seasonDetail.Episodes[0].Released : default(DateTime?),

                            SeasonNumber   = episodeDetail.SeasonNumber,
                            EpisodeNumbers = episodeDetail.EpisodeNumber.HasValue ? new List <int>(new int[] { episodeDetail.EpisodeNumber.Value }) : null,
                            FirstAired     = episodeDetail.Released,
                            EpisodeName    = new SimpleTitle(episodeDetail.Title, true),
                            Summary        = new SimpleTitle(episodeDetail.Plot, true),
                            Genres         = episodeDetail.Genres.Select(s => new GenreInfo {
                                Name = s
                            }).ToList(),
                        };

                        if (episodeDetail.ImdbRating.HasValue)
                        {
                            MetadataUpdater.SetOrUpdateRatings(ref info.Rating, new SimpleRating(episodeDetail.ImdbRating, episodeDetail.ImdbVotes));
                        }
                        if (episodeDetail.TomatoRating.HasValue)
                        {
                            MetadataUpdater.SetOrUpdateRatings(ref info.Rating, new SimpleRating(episodeDetail.TomatoRating, episodeDetail.TomatoTotalReviews));
                        }
                        if (episodeDetail.TomatoUserRating.HasValue)
                        {
                            MetadataUpdater.SetOrUpdateRatings(ref info.Rating, new SimpleRating(episodeDetail.TomatoUserRating, episodeDetail.TomatoUserTotalReviews));
                        }

                        //Only use these if absolutely necessary because there is no way to ID them
                        if (episode.Actors == null || episode.Actors.Count == 0)
                        {
                            info.Actors = ConvertToPersons(episodeDetail.Actors, PersonAspect.OCCUPATION_ARTIST, episodeDetail.Title, seasonDetail.Title);
                        }
                        if (episode.Directors == null || episode.Directors.Count == 0)
                        {
                            info.Directors = ConvertToPersons(episodeDetail.Writers, PersonAspect.OCCUPATION_DIRECTOR, episodeDetail.Title, seasonDetail.Title);
                        }
                        if (episode.Writers == null || episode.Writers.Count == 0)
                        {
                            info.Writers = ConvertToPersons(episodeDetail.Directors, PersonAspect.OCCUPATION_WRITER, episodeDetail.Title, seasonDetail.Title);
                        }

                        episodeDetails.Add(info);
                    }
                }
                if (episodeDetails.Count > 1)
                {
                    SetMultiEpisodeDetails(episode, episodeDetails);
                    return(true);
                }
                else if (episodeDetails.Count > 0)
                {
                    SetEpisodeDetails(episode, episodeDetails[0]);
                    return(true);
                }
                return(false);
            }
            catch (Exception ex)
            {
                ServiceRegistration.Get <ILogger>().Debug("OmDbWrapper: Exception while processing episode {0}", ex, episode.ToString());
                return(false);
            }
        }