From 4d486e68a5c6bc28bfb5b42e247537a03cdf5340 Mon Sep 17 00:00:00 2001 From: TidusJar Date: Fri, 27 Apr 2018 21:25:34 +0100 Subject: [PATCH] Get the Tv Backdrop !wip --- src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs | 26 +++++-- src/Ombi.TheMovieDbApi/IMovieDbApi.cs | 1 + src/Ombi.TheMovieDbApi/Models/TvInfo.cs | 74 ++++++++++++++++++++ src/Ombi.TheMovieDbApi/TheMovieDbApi.cs | 9 +++ 4 files changed, 105 insertions(+), 5 deletions(-) create mode 100644 src/Ombi.TheMovieDbApi/Models/TvInfo.cs diff --git a/src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs b/src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs index 14cbcad1a..6fb39ef70 100644 --- a/src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs +++ b/src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs @@ -452,7 +452,7 @@ namespace Ombi.Schedule.Jobs.Ombi { // Swallow, couldn't parse the date } - + AddTitle(sb, $"https://www.imdb.com/title/{info.ImdbId}/", $"{info.Title} {releaseDate}"); AddParagraph(sb, info.Overview); @@ -529,9 +529,17 @@ namespace Ombi.Schedule.Jobs.Ombi { banner = banner.Replace("http", "https"); // Always use the Https banners } + + var tvInfo = await _movieApi.GetTVInfo(t.TheMovieDbId); + if (tvInfo != null && tvInfo.backdrop_path.HasValue()) + { - //GET BACKGROUND URL HERE AND CALL - AddBackgroundInsideTable(sb, $"https://image.tmdb.org/t/p/w1280/"); + AddBackgroundInsideTable(sb, $"https://image.tmdb.org/t/p/w500{tvInfo.backdrop_path}"); + } + else + { + AddBackgroundInsideTable(sb, $"https://image.tmdb.org/t/p/w1280/"); + } AddPosterInsideTable(sb, banner); AddMediaServerUrl(sb, t.Url, overlay); AddInfoTable(sb); @@ -649,8 +657,16 @@ namespace Ombi.Schedule.Jobs.Ombi banner = banner.Replace("http", "https"); // Always use the Https banners } - //GET BACKGROUND URL HERE AND CALL - AddBackgroundInsideTable(sb, $"https://image.tmdb.org/t/p/w1280/"); + var tvInfo = await _movieApi.GetTVInfo(t.TheMovieDbId); + if (tvInfo != null && tvInfo.backdrop_path.HasValue()) + { + + AddBackgroundInsideTable(sb, $"https://image.tmdb.org/t/p/w500{tvInfo.backdrop_path}"); + } + else + { + AddBackgroundInsideTable(sb, $"https://image.tmdb.org/t/p/w1280/"); + } AddPosterInsideTable(sb, banner); AddMediaServerUrl(sb, t.Url, overlay); AddInfoTable(sb); diff --git a/src/Ombi.TheMovieDbApi/IMovieDbApi.cs b/src/Ombi.TheMovieDbApi/IMovieDbApi.cs index 5d0a89992..0b24bd55c 100644 --- a/src/Ombi.TheMovieDbApi/IMovieDbApi.cs +++ b/src/Ombi.TheMovieDbApi/IMovieDbApi.cs @@ -18,5 +18,6 @@ namespace Ombi.Api.TheMovieDb Task> SimilarMovies(int movieId); Task Find(string externalId, ExternalSource source); Task GetTvExternals(int theMovieDbId); + Task GetTVInfo(string themoviedbid); } } \ No newline at end of file diff --git a/src/Ombi.TheMovieDbApi/Models/TvInfo.cs b/src/Ombi.TheMovieDbApi/Models/TvInfo.cs new file mode 100644 index 000000000..5692fcc17 --- /dev/null +++ b/src/Ombi.TheMovieDbApi/Models/TvInfo.cs @@ -0,0 +1,74 @@ +namespace Ombi.Api.TheMovieDb.Models +{ + public class TvInfo + { + public string backdrop_path { get; set; } + public Created_By[] created_by { get; set; } + public int[] episode_run_time { get; set; } + public string first_air_date { get; set; } + public Genre[] genres { get; set; } + public string homepage { get; set; } + public int id { get; set; } + public bool in_production { get; set; } + public string[] languages { get; set; } + public string last_air_date { get; set; } + public string name { get; set; } + public Network[] networks { get; set; } + public int number_of_episodes { get; set; } + public int number_of_seasons { get; set; } + public string[] origin_country { get; set; } + public string original_language { get; set; } + public string original_name { get; set; } + public string overview { get; set; } + public float popularity { get; set; } + public string poster_path { get; set; } + public Production_Companies[] production_companies { get; set; } + public Season[] seasons { get; set; } + public string status { get; set; } + public string type { get; set; } + public float vote_average { get; set; } + public int vote_count { get; set; } + } + + public class Created_By + { + public int id { get; set; } + public string name { get; set; } + public int gender { get; set; } + public string profile_path { get; set; } + } + + public class Genre + { + public int id { get; set; } + public string name { get; set; } + } + + public class Network + { + public string name { get; set; } + public int id { get; set; } + public string logo_path { get; set; } + public string origin_country { get; set; } + } + + public class Production_Companies + { + public int id { get; set; } + public string logo_path { get; set; } + public string name { get; set; } + public string origin_country { get; set; } + } + + public class Season + { + public string air_date { get; set; } + public int episode_count { get; set; } + public int id { get; set; } + public string name { get; set; } + public string overview { get; set; } + public string poster_path { get; set; } + public int season_number { get; set; } + } + +} \ No newline at end of file diff --git a/src/Ombi.TheMovieDbApi/TheMovieDbApi.cs b/src/Ombi.TheMovieDbApi/TheMovieDbApi.cs index ccd0e52e6..af9423f5d 100644 --- a/src/Ombi.TheMovieDbApi/TheMovieDbApi.cs +++ b/src/Ombi.TheMovieDbApi/TheMovieDbApi.cs @@ -129,6 +129,15 @@ namespace Ombi.Api.TheMovieDb var result = await Api.Request>(request); return Mapper.Map>(result.results); } + + public async Task GetTVInfo(string themoviedbid) + { + var request = new Request($"/tv/{themoviedbid}", BaseUri, HttpMethod.Get); + request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken); + AddRetry(request); + + return await Api.Request(request); + } private static void AddRetry(Request request) { request.Retry = true;