From 80595503c8d9c6e8238304b3b80f6a6ecf6f1a8b Mon Sep 17 00:00:00 2001 From: TidusJar Date: Fri, 22 Feb 2019 12:45:38 +0000 Subject: [PATCH] Populate the TV APi with slightly more information --- src/Ombi.Api.Trakt/ITraktApi.cs | 1 + src/Ombi.Api.Trakt/TraktApi.cs | 7 ++- src/Ombi.Core/Engine/V2/TvSearchEngineV2.cs | 47 ++++++++++++++----- .../V2/SearchFullInfoTvShowViewModel.cs | 1 + .../src/app/interfaces/ISearchTvResultV2.ts | 1 + .../{ => V1}/CustomPageController.cs | 0 src/Ombi/Controllers/V2/SearchController.cs | 3 +- 7 files changed, 45 insertions(+), 15 deletions(-) rename src/Ombi/Controllers/{ => V1}/CustomPageController.cs (100%) diff --git a/src/Ombi.Api.Trakt/ITraktApi.cs b/src/Ombi.Api.Trakt/ITraktApi.cs index 17c4203cb..087784e01 100644 --- a/src/Ombi.Api.Trakt/ITraktApi.cs +++ b/src/Ombi.Api.Trakt/ITraktApi.cs @@ -12,5 +12,6 @@ namespace Ombi.Api.Trakt Task> GetMostWatchesShows(TraktTimePeriod period = null, int? page = default(int?), int? limitPerPage = default(int?)); Task> GetPopularShows(int? page = default(int?), int? limitPerPage = default(int?)); Task> GetTrendingShows(int? page = default(int?), int? limitPerPage = default(int?)); + Task GetTvExtendedInfo(string imdbId); } } \ No newline at end of file diff --git a/src/Ombi.Api.Trakt/TraktApi.cs b/src/Ombi.Api.Trakt/TraktApi.cs index 23773eb87..2e09ec071 100644 --- a/src/Ombi.Api.Trakt/TraktApi.cs +++ b/src/Ombi.Api.Trakt/TraktApi.cs @@ -23,7 +23,7 @@ namespace Ombi.Api.Trakt public async Task> GetPopularShows(int? page = null, int? limitPerPage = null) { - var popular = await Client.Shows.GetPopularShowsAsync(new TraktExtendedInfo { Full = true, Images = true}, null, page ?? 1, limitPerPage ?? 10); + var popular = await Client.Shows.GetPopularShowsAsync(new TraktExtendedInfo { Full = true, Images = true }, null, page ?? 1, limitPerPage ?? 10); return popular.Value; } @@ -44,6 +44,11 @@ namespace Ombi.Api.Trakt var anticipatedShows = await Client.Shows.GetMostWatchedShowsAsync(period ?? TraktTimePeriod.Monthly, new TraktExtendedInfo { Full = true, Images = true }, null, page ?? 1, limitPerPage ?? 10); return anticipatedShows.Value; } + + public async Task GetTvExtendedInfo(string imdbId) + { + return await Client.Shows.GetShowAsync(imdbId, new TraktExtendedInfo { Full = true }); + } } } diff --git a/src/Ombi.Core/Engine/V2/TvSearchEngineV2.cs b/src/Ombi.Core/Engine/V2/TvSearchEngineV2.cs index 4a31f66e4..791298c6b 100644 --- a/src/Ombi.Core/Engine/V2/TvSearchEngineV2.cs +++ b/src/Ombi.Core/Engine/V2/TvSearchEngineV2.cs @@ -1,24 +1,25 @@ using AutoMapper; -using Ombi.Api.Trakt; -using Ombi.Api.TvMaze; -using Ombi.Core.Models.Requests; -using Ombi.Core.Models.Search; -using Ombi.Core.Models.Search.V2; -using Ombi.Core.Settings; -using Ombi.Core.Settings.Models.External; -using Ombi.Store.Repository; - using System.Collections.Generic; using System.Linq; using System.Security.Principal; using System.Threading.Tasks; +using TraktApiSharp.Objects.Get.Shows; + using Ombi.Core.Rule.Interfaces; using Ombi.Store.Repository.Requests; using Ombi.Core.Authentication; using Ombi.Helpers; using Ombi.Settings.Settings.Models; using Ombi.Store.Entities; +using Ombi.Api.Trakt; +using Ombi.Api.TvMaze; +using Ombi.Core.Models.Requests; +using Ombi.Core.Models.Search; +using Ombi.Core.Models.Search.V2; +using Ombi.Core.Settings; +using Ombi.Core.Settings.Models.External; +using Ombi.Store.Repository; namespace Ombi.Core.Engine.V2 { @@ -57,6 +58,13 @@ namespace Ombi.Core.Engine.V2 return null; } + // Setup the task so we can get the data later on if we have a IMDBID + Task traktInfoTask = new Task(() => null); + if (show.externals?.imdb.HasValue() ?? false) + { + traktInfoTask = TraktApi.GetTvExtendedInfo(show.externals?.imdb); + } + var mapped = Mapper.Map(show); foreach (var e in show._embedded.episodes) @@ -91,7 +99,7 @@ namespace Ombi.Core.Engine.V2 }); } } - return await ProcessResult(mapped); + return await ProcessResult(mapped, traktInfoTask); } private IEnumerable ProcessResults(IEnumerable items) @@ -109,7 +117,7 @@ namespace Ombi.Core.Engine.V2 return Mapper.Map(tvMazeSearch); } - private async Task ProcessResult(SearchFullInfoTvShowViewModel item) + private async Task ProcessResult(SearchFullInfoTvShowViewModel item, Task showInfoTask) { item.TheTvDbId = item.Id.ToString(); @@ -123,7 +131,22 @@ namespace Ombi.Core.Engine.V2 item.Available = oldModel.Available; item.Approved = oldModel.Approved; - return item; + return await GetExtraInfo(showInfoTask, item); + } + + private async Task GetExtraInfo(Task showInfoTask, SearchFullInfoTvShowViewModel model) + { + var result = await showInfoTask; + if(result == null) + { + return model; + } + + model.Trailer = result.Trailer; + model.Certification = result.Certification; + model.Homepage = result.Homepage; + + return model; } } } \ No newline at end of file diff --git a/src/Ombi.Core/Models/Search/V2/SearchFullInfoTvShowViewModel.cs b/src/Ombi.Core/Models/Search/V2/SearchFullInfoTvShowViewModel.cs index 8065d497e..8533bb2d7 100644 --- a/src/Ombi.Core/Models/Search/V2/SearchFullInfoTvShowViewModel.cs +++ b/src/Ombi.Core/Models/Search/V2/SearchFullInfoTvShowViewModel.cs @@ -25,6 +25,7 @@ namespace Ombi.Core.Models.Search.V2 public Images Images { get; set; } public List Cast { get; set; } public List Crew { get; set; } + public string Certification { get; set; } /// /// This is used from the Trakt API diff --git a/src/Ombi/ClientApp/src/app/interfaces/ISearchTvResultV2.ts b/src/Ombi/ClientApp/src/app/interfaces/ISearchTvResultV2.ts index 51395b9ec..ee2281bea 100644 --- a/src/Ombi/ClientApp/src/app/interfaces/ISearchTvResultV2.ts +++ b/src/Ombi/ClientApp/src/app/interfaces/ISearchTvResultV2.ts @@ -20,6 +20,7 @@ export interface ISearchTvResultV2 { siteRating: number; trailer: string; homepage: string; + certifcation: string; seasonRequests: INewSeasonRequests[]; requestAll: boolean; approved: boolean; diff --git a/src/Ombi/Controllers/CustomPageController.cs b/src/Ombi/Controllers/V1/CustomPageController.cs similarity index 100% rename from src/Ombi/Controllers/CustomPageController.cs rename to src/Ombi/Controllers/V1/CustomPageController.cs diff --git a/src/Ombi/Controllers/V2/SearchController.cs b/src/Ombi/Controllers/V2/SearchController.cs index 5000b41dc..3fc430ada 100644 --- a/src/Ombi/Controllers/V2/SearchController.cs +++ b/src/Ombi/Controllers/V2/SearchController.cs @@ -44,10 +44,9 @@ namespace Ombi.Controllers.V2 return await _multiSearchEngine.MultiSearch(searchTerm); } - // + /// /// Returns details for a single movie /// - /// [HttpGet("movie/{movieDbId}")] public async Task GetMovieInfo(int movieDbId) {