Esempio n. 1
0
        /// <summary>
        /// Returns detailed information for a single <see cref="OmDbSeries"/> with given <paramref name="id"/>. This method caches request
        /// to same series using the cache path given in <see cref="OmDbApiV1"/> constructor.
        /// </summary>
        /// <param name="id">IMDB id of series</param>
        /// <returns>Series information</returns>
        public async Task <OmDbSeries> GetSeriesAsync(string id, bool cacheOnly)
        {
            string     cache       = CreateAndGetCacheName(id, "Series");
            OmDbSeries returnValue = null;

            if (!string.IsNullOrEmpty(cache) && File.Exists(cache))
            {
                returnValue = await _downloader.ReadCacheAsync <OmDbSeries>(cache).ConfigureAwait(false);
            }
            else
            {
                if (cacheOnly)
                {
                    return(null);
                }
                string url = GetUrl(URL_GETIMDBIDSERIES, 0, true, true, id);
                returnValue = await _downloader.DownloadAsync <OmDbSeries>(url, cache).ConfigureAwait(false);
            }
            if (returnValue == null)
            {
                return(null);
            }
            if (returnValue.ResponseValid == false)
            {
                return(null);
            }
            if (returnValue != null)
            {
                returnValue.AssignProperties();
            }
            return(returnValue);
        }
Esempio n. 2
0
 /// <summary>
 /// Returns detailed information for a single <see cref="OmDbSeries"/> with given <paramref name="id"/>. This method caches request
 /// to same series using the cache path given in <see cref="OmDbApiV1"/> constructor.
 /// </summary>
 /// <param name="id">IMDB id of series</param>
 /// <returns>Series information</returns>
 public OmDbSeries GetSeries(string id, bool cacheOnly)
 {
     lock (_seriesSync)
     {
         string     cache       = CreateAndGetCacheName(id, "Series");
         OmDbSeries returnValue = null;
         if (!string.IsNullOrEmpty(cache) && File.Exists(cache))
         {
             returnValue = _downloader.ReadCache <OmDbSeries>(cache);
         }
         else
         {
             if (cacheOnly)
             {
                 return(null);
             }
             string url = GetUrl(URL_GETIMDBIDSERIES, 0, true, true, id);
             returnValue = _downloader.Download <OmDbSeries>(url, cache);
         }
         if (returnValue == null)
         {
             return(null);
         }
         if (returnValue.ResponseValid == false)
         {
             return(null);
         }
         if (returnValue != null)
         {
             returnValue.AssignProperties();
         }
         return(returnValue);
     }
 }
Esempio n. 3
0
        public override bool UpdateFromOnlineSeries(SeriesInfo series, string language, bool cacheOnly)
        {
            try
            {
                OmDbSeries seriesDetail = null;
                if (!string.IsNullOrEmpty(series.ImdbId))
                {
                    seriesDetail = _omDbHandler.GetSeries(series.ImdbId, cacheOnly);
                }
                if (seriesDetail == null)
                {
                    return(false);
                }

                series.ImdbId = seriesDetail.ImdbID;

                series.SeriesName  = new SimpleTitle(seriesDetail.Title, true);
                series.FirstAired  = seriesDetail.Released;
                series.Description = new SimpleTitle(seriesDetail.Plot, true);
                if (seriesDetail.EndYear.HasValue)
                {
                    series.IsEnded = true;
                }
                series.Certification = seriesDetail.Rated;

                List <string> awards = new List <string>();
                if (!string.IsNullOrEmpty(seriesDetail.Awards))
                {
                    if (seriesDetail.Awards.IndexOf("Won ", StringComparison.InvariantCultureIgnoreCase) >= 0 ||
                        seriesDetail.Awards.IndexOf(" Oscar", StringComparison.InvariantCultureIgnoreCase) >= 0)
                    {
                        awards.Add("Oscar");
                    }
                    if (seriesDetail.Awards.IndexOf("Won ", StringComparison.InvariantCultureIgnoreCase) >= 0 ||
                        seriesDetail.Awards.IndexOf(" Golden Globe", StringComparison.InvariantCultureIgnoreCase) >= 0)
                    {
                        awards.Add("Golden Globe");
                    }
                    series.Awards = awards;
                }

                if (seriesDetail.ImdbRating.HasValue)
                {
                    MetadataUpdater.SetOrUpdateRatings(ref series.Rating, new SimpleRating(seriesDetail.ImdbRating, seriesDetail.ImdbVotes));
                }
                if (seriesDetail.TomatoRating.HasValue)
                {
                    MetadataUpdater.SetOrUpdateRatings(ref series.Rating, new SimpleRating(seriesDetail.TomatoRating, seriesDetail.TomatoTotalReviews));
                }
                if (seriesDetail.TomatoUserRating.HasValue)
                {
                    MetadataUpdater.SetOrUpdateRatings(ref series.Rating, new SimpleRating(seriesDetail.TomatoUserRating, seriesDetail.TomatoUserTotalReviews));
                }
                series.Genres = seriesDetail.Genres.Select(s => new GenreInfo {
                    Name = s
                }).ToList();

                //Only use these if absolutely necessary because there is no way to ID them
                if (seriesDetail.Actors == null || seriesDetail.Actors.Count == 0)
                {
                    series.Actors = ConvertToPersons(seriesDetail.Actors, PersonAspect.OCCUPATION_ACTOR, null, seriesDetail.Title);
                }

                //Episode listing is currently not optimal
                //OmDbSeason seasonDetails = null;
                //OmDbSeasonEpisode nextEpisode = null;
                //int seasonNumber = 1;
                //while (true)
                //{
                //  seasonDetails = _omDbHandler.GetSeriesSeason(series.ImdbId, seasonNumber, cacheOnly);
                //  if (seasonDetails != null)
                //  {
                //    SeasonInfo seasonInfo = new SeasonInfo()
                //    {
                //      SeriesImdbId = seriesDetail.ImdbID,
                //      SeriesName = new SimpleTitle(seriesDetail.Title, true),
                //      SeasonNumber = seasonDetails.SeasonNumber,
                //      FirstAired = seasonDetails.Episodes.First().Released,
                //      TotalEpisodes = seasonDetails.Episodes.Count
                //    };
                //    if (!series.Seasons.Contains(seasonInfo))
                //      series.Seasons.Add(seasonInfo);

                //    foreach (OmDbSeasonEpisode episodeDetail in seasonDetails.Episodes)
                //    {
                //      if (episodeDetail.EpisodeNumber <= 0) continue;

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

                //        SeriesImdbId = seriesDetail.ImdbID,
                //        SeriesName = new SimpleTitle(seriesDetail.Title, true),
                //        SeriesFirstAired = series.FirstAired,

                //        SeasonNumber = seasonNumber,
                //        EpisodeNumbers = new List<int>(new int[] { episodeDetail.EpisodeNumber }),
                //        FirstAired = episodeDetail.Released,
                //        EpisodeName = new SimpleTitle(episodeDetail.Title, true),
                //      };

                //      series.Episodes.Add(info);

                //      if (nextEpisode == null && episodeDetail.Released > DateTime.Now)
                //      {
                //        series.NextEpisodeName = new SimpleTitle(episodeDetail.Title, true);
                //        series.NextEpisodeAirDate = episodeDetail.Released;
                //        series.NextEpisodeSeasonNumber = seasonDetails.SeasonNumber;
                //        series.NextEpisodeNumber = episodeDetail.EpisodeNumber;
                //      }
                //    }
                //    seasonNumber++;
                //  }
                //  else
                //  {
                //    break;
                //  }
                //}
                series.TotalSeasons  = series.Seasons.Count;
                series.TotalEpisodes = series.Episodes.Count;

                return(true);
            }
            catch (Exception ex)
            {
                ServiceRegistration.Get <ILogger>().Debug("OmDbWrapper: Exception while processing series {0}", ex, series.ToString());
                return(false);
            }
        }