Exemplo n.º 1
0
        /// <summary>
        /// Returns detailed information for a single <see cref="OmDbSeason"/> with given <paramref name="id"/>. This method caches request
        /// to same seasons 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>
        /// <returns>Season information</returns>
        public async Task <OmDbSeason> GetSeriesSeasonAsync(string id, int season, bool cacheOnly)
        {
            string     cache       = CreateAndGetCacheName(id, string.Format("Season{0}", season));
            OmDbSeason returnValue = null;

            if (!string.IsNullOrEmpty(cache) && File.Exists(cache))
            {
                returnValue = await _downloader.ReadCacheAsync <OmDbSeason>(cache).ConfigureAwait(false);
            }
            else
            {
                if (cacheOnly)
                {
                    return(null);
                }
                string url = GetUrl(URL_GETIMDBIDSEASON, 0, true, true, id, season);
                returnValue = await _downloader.DownloadAsync <OmDbSeason>(url, cache).ConfigureAwait(false);
            }
            if (returnValue == null)
            {
                return(null);
            }
            if (returnValue.ResponseValid == false)
            {
                return(null);
            }
            if (returnValue != null)
            {
                returnValue.InitEpisodes();
            }
            return(returnValue);
        }
Exemplo n.º 2
0
        public override bool UpdateFromOnlineSeriesSeason(SeasonInfo season, string language, bool cacheOnly)
        {
            try
            {
                OmDbSeason seasonDetail = null;
                if (!string.IsNullOrEmpty(season.SeriesImdbId) && season.SeasonNumber.HasValue)
                {
                    seasonDetail = _omDbHandler.GetSeriesSeason(season.SeriesImdbId, season.SeasonNumber.Value, cacheOnly);
                }
                if (seasonDetail == null)
                {
                    return(false);
                }

                season.SeriesName    = new SimpleTitle(seasonDetail.Title, true);
                season.FirstAired    = seasonDetail.Episodes != null && seasonDetail.Episodes.Count > 0 ? seasonDetail.Episodes[0].Released : default(DateTime?);
                season.SeasonNumber  = seasonDetail.SeasonNumber;
                season.TotalEpisodes = seasonDetail.Episodes.Count;

                return(true);
            }
            catch (Exception ex)
            {
                ServiceRegistration.Get <ILogger>().Debug("OmDbWrapper: Exception while processing season {0}", ex, season.ToString());
                return(false);
            }
        }
Exemplo n.º 3
0
        public override bool SearchSeriesEpisode(EpisodeInfo episodeSearch, string language, out List <EpisodeInfo> episodes)
        {
            episodes = null;
            SeriesInfo seriesSearch = null;

            if (string.IsNullOrEmpty(episodeSearch.SeriesImdbId))
            {
                seriesSearch = episodeSearch.CloneBasicInstance <SeriesInfo>();
                if (!SearchSeriesUniqueAndUpdate(seriesSearch, language))
                {
                    return(false);
                }
                episodeSearch.CopyIdsFrom(seriesSearch);
            }

            if (!string.IsNullOrEmpty(episodeSearch.SeriesImdbId) && episodeSearch.SeasonNumber.HasValue)
            {
                OmDbSeason season = _omDbHandler.GetSeriesSeason(episodeSearch.SeriesImdbId, episodeSearch.SeasonNumber.Value, false);
                if (season != null && season.Episodes != null)
                {
                    foreach (OmDbSeasonEpisode episode in season.Episodes)
                    {
                        if ((episode.EpisodeNumber.HasValue && episodeSearch.EpisodeNumbers.Contains(episode.EpisodeNumber.Value)) || episodeSearch.EpisodeNumbers.Count == 0)
                        {
                            if (episodes == null)
                            {
                                episodes = new List <EpisodeInfo>();
                            }

                            EpisodeInfo info = new EpisodeInfo()
                            {
                                ImdbId       = episode.ImdbID,
                                SeriesName   = new SimpleTitle(season.Title, true),
                                SeasonNumber = episodeSearch.SeasonNumber.Value,
                                EpisodeName  = new SimpleTitle(episode.Title, false),
                            };
                            if (episode.EpisodeNumber.HasValue)
                            {
                                info.EpisodeNumbers.Add(episode.EpisodeNumber.Value);
                            }
                            info.CopyIdsFrom(episodeSearch.CloneBasicInstance <SeriesInfo>());
                            episodes.Add(info);
                        }
                    }
                }
            }

            if (episodes == null)
            {
                episodes = new List <EpisodeInfo>();
                EpisodeInfo info = new EpisodeInfo()
                {
                    SeriesName   = seriesSearch == null ? episodeSearch.SeriesName : seriesSearch.SeriesName,
                    SeasonNumber = episodeSearch.SeasonNumber,
                    EpisodeName  = episodeSearch.EpisodeName,
                };
                info.CopyIdsFrom(seriesSearch);
                CollectionUtils.AddAll(info.EpisodeNumbers, episodeSearch.EpisodeNumbers);
                episodes.Add(info);
                return(true);
            }

            return(episodes != null);
        }
Exemplo n.º 4
0
        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);
            }
        }
Exemplo n.º 5
0
        public override async Task <List <EpisodeInfo> > SearchSeriesEpisodeAsync(EpisodeInfo episodeSearch, string language)
        {
            SeriesInfo seriesSearch = null;

            if (string.IsNullOrEmpty(episodeSearch.SeriesImdbId))
            {
                seriesSearch = episodeSearch.CloneBasicInstance <SeriesInfo>();
                if (!await SearchSeriesUniqueAndUpdateAsync(seriesSearch, language))
                {
                    return(null);
                }
                episodeSearch.CopyIdsFrom(seriesSearch);
            }

            List <EpisodeInfo> episodes = null;

            if (!string.IsNullOrEmpty(episodeSearch.SeriesImdbId) && episodeSearch.SeasonNumber.HasValue)
            {
                OmDbSeason season = await _omDbHandler.GetSeriesSeasonAsync(episodeSearch.SeriesImdbId, episodeSearch.SeasonNumber.Value, false).ConfigureAwait(false);

                if (season != null && season.Episodes != null)
                {
                    foreach (OmDbSeasonEpisode episode in season.Episodes)
                    {
                        if ((episode.EpisodeNumber.HasValue && episodeSearch.EpisodeNumbers.Contains(episode.EpisodeNumber.Value)) || episodeSearch.EpisodeNumbers.Count == 0)
                        {
                            if (episodes == null)
                            {
                                episodes = new List <EpisodeInfo>();
                            }

                            EpisodeInfo info = new EpisodeInfo()
                            {
                                ImdbId       = episode.ImdbID,
                                SeriesName   = new SimpleTitle(season.Title, true),
                                SeasonNumber = episodeSearch.SeasonNumber.Value,
                                EpisodeName  = new SimpleTitle(episode.Title, false),
                            };
                            if (episode.EpisodeNumber.HasValue)
                            {
                                info.EpisodeNumbers.Add(episode.EpisodeNumber.Value);
                            }
                            info.CopyIdsFrom(episodeSearch.CloneBasicInstance <SeriesInfo>());
                            episodes.Add(info);
                        }
                    }
                }
            }

            if (episodes == null)
            {
                episodes = new List <EpisodeInfo>();
                EpisodeInfo info = new EpisodeInfo()
                {
                    SeriesName   = seriesSearch == null ? episodeSearch.SeriesName : seriesSearch.SeriesName,
                    SeasonNumber = episodeSearch.SeasonNumber,
                    EpisodeName  = episodeSearch.EpisodeName,
                };
                info.CopyIdsFrom(seriesSearch);
                info.EpisodeNumbers = info.EpisodeNumbers.Union(episodeSearch.EpisodeNumbers).ToList();
                episodes.Add(info);
            }

            return(episodes);
        }