You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.8 KiB
C#

4 years ago
using System.Collections.Generic;
using System.Threading.Tasks;
using TMDbLib;
using TMDbLib.Client;
4 years ago
using TMDbLib.Objects.Find;
namespace Common.Library.TMDB
{
public class TMDBWrapper
{
private readonly string ApiKey;
4 years ago
private TMDbClient tMDbClient;
public TMDBWrapper(string apiKey)
{
ApiKey = apiKey;
4 years ago
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;
}
4 years ago
public List<string> GetPosterLinks(List<string> imdbIDs)
{
//> TODO: Refactor to make it better.
List<string> 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;
}
}
}