updated wrapper
parent
c5b3ebce80
commit
52f0f8f52c
@ -1,15 +1,61 @@
|
||||
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 $"https://www.themoviedb.org/t/p/original{posterLink}";
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue