From 52f0f8f52c265f56fcc789e3ced167f43d96d2a5 Mon Sep 17 00:00:00 2001 From: Don Oerkfitz Date: Sat, 13 Mar 2021 02:09:22 -0600 Subject: [PATCH] updated wrapper --- .../JasonNeumannAudio.com/WorkPageDAO.cs | 25 ++++++++++ Common.Library/TMDB/TMDBWrapper.cs | 48 ++++++++++++++++++- 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/Common.Library.DataLayer/DAO/Websites/JasonNeumannAudio.com/WorkPageDAO.cs b/Common.Library.DataLayer/DAO/Websites/JasonNeumannAudio.com/WorkPageDAO.cs index 2a9aa8f..1e932f8 100644 --- a/Common.Library.DataLayer/DAO/Websites/JasonNeumannAudio.com/WorkPageDAO.cs +++ b/Common.Library.DataLayer/DAO/Websites/JasonNeumannAudio.com/WorkPageDAO.cs @@ -83,5 +83,30 @@ namespace Common.Library.DataLayer.DAO.Websites.JasonNeumannAudio.com DisposeConnection(); } } + + // public void InsertWorkPageItem(WorkPageDTO item) + // { + // InitConnection(); + // WorkPageDTOCollection items = new(); + + // try + // { + // DBCommand.CommandType = CommandType.StoredProcedure; + // DBCommand.CommandText = "work_page_insert_work_page_item"; + + // // DBCommand.Parameters.AddWithValue("@TypeID", (int)workPageType); + + + // DBCommand.ExecuteNonQuery(); + // } + // catch (Exception) + // { + // throw; + // } + // finally + // { + // DisposeConnection(); + // } + // } } } \ No newline at end of file diff --git a/Common.Library/TMDB/TMDBWrapper.cs b/Common.Library/TMDB/TMDBWrapper.cs index 8e59c3a..f9dd28b 100644 --- a/Common.Library/TMDB/TMDBWrapper.cs +++ b/Common.Library/TMDB/TMDBWrapper.cs @@ -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 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; + } } } \ No newline at end of file