using System.Collections.Generic; using System.Threading.Tasks; using TMDbLib; using TMDbLib.Client; using TMDbLib.Objects.Find; namespace Common.Library.TMDB { public class TMDBWrapper { private readonly string ApiKey; private TMDbClient tMDbClient; public TMDBWrapper(string apiKey) { ApiKey = apiKey; tMDbClient = new(ApiKey); } public string GetPosterLink(string imdbID) { string posterLink = null; FindContainer container = tMDbClient.FindAsync(FindExternalSource.Imdb, imdbID).Result; if (container.MovieResults.Count > 0) { posterLink = container.MovieResults[0].PosterPath; } else if(container.TvResults.Count > 0) { posterLink = container.TvResults[0].PosterPath; } return !string.IsNullOrWhiteSpace(posterLink) ? $"https://www.themoviedb.org/t/p/original{posterLink}" : null; } public List GetPosterLinks(List imdbIDs) { //> TODO: Refactor to make it better. List returnLinks = new(); imdbIDs.ForEach(imdbID => { FindContainer find = tMDbClient.FindAsync(FindExternalSource.Imdb, imdbID).Result; if(find.MovieResults.Count > 0) { returnLinks.Add($"https://www.themoviedb.org/t/p/original{find.MovieResults[0].PosterPath}"); } else if(find.TvResults.Count > 0) { returnLinks.Add($"https://www.themoviedb.org/t/p/original{find.TvResults[0].PosterPath}"); } }); return returnLinks; } } }