/// <summary> /// Returns detailed information for a single <see cref="OmDbMovie"/> with given <paramref name="id"/>. This method caches request /// to same movies using the cache path given in <see cref="OmDbApiV1"/> constructor. /// </summary> /// <param name="id">IMDB id of movie</param> /// <returns>Movie information</returns> public async Task <OmDbMovie> GetMovie(string id, bool cacheOnly) { string cache = CreateAndGetCacheName(id, "Movie"); OmDbMovie returnValue = null; if (!string.IsNullOrEmpty(cache) && File.Exists(cache)) { returnValue = await _downloader.ReadCacheAsync <OmDbMovie>(cache).ConfigureAwait(false); } else { if (cacheOnly) { return(null); } string url = GetUrl(URL_GETIMDBIDMOVIE, 0, true, true, id); returnValue = await _downloader.DownloadAsync <OmDbMovie>(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 UpdateFromOnlineMovie(MovieInfo movie, string language, bool cacheOnly) { try { OmDbMovie movieDetail = null; if (!string.IsNullOrEmpty(movie.ImdbId)) { movieDetail = _omDbHandler.GetMovie(movie.ImdbId, cacheOnly); } if (movieDetail == null) { return(false); } movie.ImdbId = movieDetail.ImdbID; movie.MovieName = new SimpleTitle(movieDetail.Title, true); movie.Summary = new SimpleTitle(movieDetail.Plot, true); movie.Certification = movieDetail.Rated; movie.Revenue = movieDetail.Revenue.HasValue ? movieDetail.Revenue.Value : 0; movie.Runtime = movieDetail.Runtime.HasValue ? movieDetail.Runtime.Value : 0; movie.ReleaseDate = movieDetail.Released; List <string> awards = new List <string>(); if (!string.IsNullOrEmpty(movieDetail.Awards)) { if (movieDetail.Awards.IndexOf("Won ", StringComparison.InvariantCultureIgnoreCase) >= 0 || movieDetail.Awards.IndexOf(" Oscar", StringComparison.InvariantCultureIgnoreCase) >= 0) { awards.Add("Oscar"); } if (movieDetail.Awards.IndexOf("Won ", StringComparison.InvariantCultureIgnoreCase) >= 0 || movieDetail.Awards.IndexOf(" Golden Globe", StringComparison.InvariantCultureIgnoreCase) >= 0) { awards.Add("Golden Globe"); } movie.Awards = awards; } if (movieDetail.ImdbRating.HasValue) { MetadataUpdater.SetOrUpdateRatings(ref movie.Rating, new SimpleRating(movieDetail.ImdbVotes, movieDetail.ImdbVotes)); } if (movieDetail.TomatoRating.HasValue) { MetadataUpdater.SetOrUpdateRatings(ref movie.Rating, new SimpleRating(movieDetail.TomatoRating, movieDetail.TomatoTotalReviews)); } if (movieDetail.TomatoUserRating.HasValue) { MetadataUpdater.SetOrUpdateRatings(ref movie.Rating, new SimpleRating(movieDetail.TomatoUserRating, movieDetail.TomatoUserTotalReviews)); } movie.Genres = movieDetail.Genres.Select(s => new GenreInfo { Name = s }).ToList(); //Only use these if absolutely necessary because there is no way to ID them if (movie.Actors.Count == 0) { movie.Actors = ConvertToPersons(movieDetail.Actors, PersonAspect.OCCUPATION_ACTOR, movieDetail.Title); } if (movie.Writers.Count == 0) { movie.Writers = ConvertToPersons(movieDetail.Writers, PersonAspect.OCCUPATION_WRITER, movieDetail.Title); } if (movie.Directors.Count == 0) { movie.Directors = ConvertToPersons(movieDetail.Directors, PersonAspect.OCCUPATION_DIRECTOR, movieDetail.Title); } return(true); } catch (Exception ex) { ServiceRegistration.Get <ILogger>().Debug("OmDbWrapper: Exception while processing movie {0}", ex, movie.ToString()); return(false); } }