public bool GetBackdrop(DBMovieInfo movie) { if (movie == null) { return(false); } // if we already have a backdrop move on for now if (movie.BackdropFullPath.Trim().Length > 0) { return(true); } // do we have an id? string tmdbID = getTheMovieDbId(movie, true); if (tmdbID == null) { return(false); } // try to get movie artwork var movieArtwork = TheMovieDbAPI.GetMovieImages(tmdbID); if (movieArtwork == null || movieArtwork.Backdrops == null || movieArtwork.Backdrops.Count == 0) { return(false); } // filter out minimum size images int minWidth = MovingPicturesCore.Settings.MinimumBackdropWidth; int minHeight = MovingPicturesCore.Settings.MinimumBackdropHeight; movieArtwork.Backdrops.RemoveAll(b => b.Width < minWidth || b.Height < minHeight); if (movieArtwork.Backdrops.Count == 0) { return(false); } // sort by highest rated / most popular var backdrops = movieArtwork.Backdrops.OrderByDescending(p => p.Score); // get the base url for images string baseImageUrl = getImageBaseUrl(); if (string.IsNullOrEmpty(baseImageUrl)) { return(false); } // moving pics currently only supports 1 backdrop per movie string backdropURL = baseImageUrl + backdrops.First().FilePath; if (backdropURL.Trim().Length > 0) { if (movie.AddBackdropFromURL(backdropURL) == ImageLoadResults.SUCCESS) { movie.GetSourceMovieInfo(SourceInfo).Identifier = tmdbID; return(true); } } // if we get here we didn't manage to find a proper backdrop // so return false return(false); }
public bool GetArtwork(DBMovieInfo movie) { if (movie == null) { return(false); } // do we have an id? string tmdbID = getTheMovieDbId(movie, true); if (tmdbID == null) { return(false); } // try to get movie artwork var movieArtwork = TheMovieDbAPI.GetMovieImages(tmdbID); if (movieArtwork == null || movieArtwork.Posters == null || movieArtwork.Posters.Count == 0) { return(false); } // filter out minimum size images int minWidth = MovingPicturesCore.Settings.MinimumCoverWidth; int minHeight = MovingPicturesCore.Settings.MinimumCoverHeight; movieArtwork.Posters.RemoveAll(p => p.Width < minWidth || p.Height < minHeight); if (movieArtwork.Posters.Count == 0) { return(false); } // filter posters by language var langPosters = movieArtwork.Posters.Where(p => p.LanguageCode == MovingPicturesCore.Settings.DataProviderLanguageCode); if (MovingPicturesCore.Settings.DataProviderLanguageCode == "en") { // include no language posters with english (sometimes language is not assigned) langPosters = langPosters.Union(movieArtwork.Posters.Where(p => p.LanguageCode == null)); } // if no localised posters available use all posters if (langPosters.Count() == 0) { langPosters = movieArtwork.Posters; } // sort by highest rated / most popular langPosters = langPosters.OrderByDescending(p => p.Score); // grab coverart loading settings int maxCovers = MovingPicturesCore.Settings.MaxCoversPerMovie; int maxCoversInSession = MovingPicturesCore.Settings.MaxCoversPerSession; int coversAdded = 0; // get the base url for images string baseImageUrl = getImageBaseUrl(); if (string.IsNullOrEmpty(baseImageUrl)) { return(false); } // download posters foreach (var poster in langPosters) { // if we have hit our limit quit if (movie.AlternateCovers.Count >= maxCovers || coversAdded >= maxCoversInSession) { return(true); } // get url for cover and load it via the movie object string coverPath = baseImageUrl + poster.FilePath; if (coverPath.Trim() != string.Empty) { if (movie.AddCoverFromURL(coverPath) == ImageLoadResults.SUCCESS) { coversAdded++; } } } if (coversAdded > 0) { // Update source info movie.GetSourceMovieInfo(SourceInfo).Identifier = tmdbID; return(true); } return(false); }