From 6b716e722076e3d1e6bf2097c5263645d5ea9edf Mon Sep 17 00:00:00 2001 From: sephrat <34862846+sephrat@users.noreply.github.com> Date: Wed, 10 Nov 2021 09:37:35 +0100 Subject: [PATCH] fix(discover): TV shows now display on the Actor Pages (#4388) * Add TV shows to Actor discover page * Fix actor page not loading after actor change * Remove user filter from discover actor page * Clean up code --- .../Engine/Interfaces/ITvSearchEngineV2.cs | 2 ++ src/Ombi.Core/Engine/V2/TvSearchEngineV2.cs | 6 ++++ src/Ombi.TheMovieDbApi/IMovieDbApi.cs | 1 + src/Ombi.TheMovieDbApi/TheMovieDbApi.cs | 10 ++++++ .../actor/discover-actor.component.html | 2 +- .../actor/discover-actor.component.ts | 31 ++++++++++++------- .../src/app/services/searchV2.service.ts | 4 +++ src/Ombi/Controllers/V2/SearchController.cs | 13 ++++++++ 8 files changed, 57 insertions(+), 12 deletions(-) diff --git a/src/Ombi.Core/Engine/Interfaces/ITvSearchEngineV2.cs b/src/Ombi.Core/Engine/Interfaces/ITvSearchEngineV2.cs index 25a3c2621..2e01e739e 100644 --- a/src/Ombi.Core/Engine/Interfaces/ITvSearchEngineV2.cs +++ b/src/Ombi.Core/Engine/Interfaces/ITvSearchEngineV2.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; +using Ombi.Api.TheMovieDb.Models; using Ombi.Core.Models.Search; using Ombi.Core.Models.Search.V2; @@ -10,6 +11,7 @@ namespace Ombi.Core { Task GetShowInformation(string tvdbid, CancellationToken token); Task GetShowByRequest(int requestId, CancellationToken token); + Task GetTvByActor(int actorId, string langCode); Task> GetStreamInformation(int movieDbId, CancellationToken cancellationToken); Task> Popular(int currentlyLoaded, int amountToLoad, string langCustomCode = null); Task> Anticipated(int currentlyLoaded, int amountToLoad); diff --git a/src/Ombi.Core/Engine/V2/TvSearchEngineV2.cs b/src/Ombi.Core/Engine/V2/TvSearchEngineV2.cs index 26cba7c14..b3842a761 100644 --- a/src/Ombi.Core/Engine/V2/TvSearchEngineV2.cs +++ b/src/Ombi.Core/Engine/V2/TvSearchEngineV2.cs @@ -147,6 +147,12 @@ namespace Ombi.Core.Engine.V2 return await processed; } + public async Task GetTvByActor(int actorId, string langCode) + { + var result = await Cache.GetOrAddAsync(nameof(GetTvByActor) + actorId + langCode, + () => _movieApi.GetActorTvCredits(actorId, langCode), DateTimeOffset.Now.AddHours(12)); + return result; + } public async Task> GetStreamInformation(int movieDbId, CancellationToken cancellationToken) { diff --git a/src/Ombi.TheMovieDbApi/IMovieDbApi.cs b/src/Ombi.TheMovieDbApi/IMovieDbApi.cs index 6d0859cef..eadfb3a3a 100644 --- a/src/Ombi.TheMovieDbApi/IMovieDbApi.cs +++ b/src/Ombi.TheMovieDbApi/IMovieDbApi.cs @@ -31,6 +31,7 @@ namespace Ombi.Api.TheMovieDb Task GetTVInfo(string themoviedbid, string langCode = "en"); Task> SearchByActor(string searchTerm, string langCode); Task GetActorMovieCredits(int actorId, string langCode); + Task GetActorTvCredits(int actorId, string langCode); Task> MultiSearch(string searchTerm, string languageCode, CancellationToken cancellationToken); Task> DiscoverMovies(string langCode, int keywordId); Task GetFullMovieInfo(int movieId, CancellationToken cancellationToken, string langCode); diff --git a/src/Ombi.TheMovieDbApi/TheMovieDbApi.cs b/src/Ombi.TheMovieDbApi/TheMovieDbApi.cs index aa46b0c8e..0391c184a 100644 --- a/src/Ombi.TheMovieDbApi/TheMovieDbApi.cs +++ b/src/Ombi.TheMovieDbApi/TheMovieDbApi.cs @@ -139,6 +139,16 @@ namespace Ombi.Api.TheMovieDb var result = await Api.Request(request); return result; } + + public async Task GetActorTvCredits(int actorId, string langCode) + { + var request = new Request($"person/{actorId}/tv_credits", BaseUri, HttpMethod.Get); + request.AddQueryString("api_key", ApiToken); + request.AddQueryString("language", langCode); + + var result = await Api.Request(request); + return result; + } public async Task> SearchTv(string searchTerm, string year = default) { diff --git a/src/Ombi/ClientApp/src/app/discover/components/actor/discover-actor.component.html b/src/Ombi/ClientApp/src/app/discover/components/actor/discover-actor.component.html index a7f6a7847..67f243503 100644 --- a/src/Ombi/ClientApp/src/app/discover/components/actor/discover-actor.component.html +++ b/src/Ombi/ClientApp/src/app/discover/components/actor/discover-actor.component.html @@ -1,4 +1,4 @@ -
+
diff --git a/src/Ombi/ClientApp/src/app/discover/components/actor/discover-actor.component.ts b/src/Ombi/ClientApp/src/app/discover/components/actor/discover-actor.component.ts index 8cdb90436..290042d87 100644 --- a/src/Ombi/ClientApp/src/app/discover/components/actor/discover-actor.component.ts +++ b/src/Ombi/ClientApp/src/app/discover/components/actor/discover-actor.component.ts @@ -1,10 +1,12 @@ import { Component } from "@angular/core"; import { ActivatedRoute } from "@angular/router"; import { SearchV2Service } from "../../../services"; -import { IActorCredits } from "../../../interfaces/ISearchTvResultV2"; +import { IActorCredits, IActorCast } from "../../../interfaces/ISearchTvResultV2"; import { IDiscoverCardResult } from "../../interfaces"; import { RequestType } from "../../../interfaces"; import { AuthService } from "../../../auth/auth.service"; +import { forkJoin } from "rxjs"; +import { isEqual } from "lodash"; @Component({ templateUrl: "./discover-actor.component.html", @@ -12,7 +14,6 @@ import { AuthService } from "../../../auth/auth.service"; }) export class DiscoverActorComponent { public actorId: number; - public actorCredits: IActorCredits; public loadingFlag: boolean; public isAdmin: boolean; @@ -24,24 +25,32 @@ export class DiscoverActorComponent { this.route.params.subscribe((params: any) => { this.actorId = params.actorId; this.isAdmin = this.auth.isAdmin(); - this.loading(); - this.searchService.getMoviesByActor(this.actorId).subscribe(res => { - this.actorCredits = res; - this.createModel(); - }); + this.search(); }); } - private createModel() { - this.finishLoading(); + private search() { this.discoverResults = []; - this.actorCredits.cast.forEach(m => { + this.loading(); + + forkJoin([ + this.searchService.getMoviesByActor(this.actorId), + this.searchService.getTvByActor(this.actorId) + ]).subscribe(([movie, tv]) => { + this.pushDiscoverResults(movie.cast, RequestType.movie); + this.pushDiscoverResults(tv.cast, RequestType.tvShow); + this.finishLoading(); + }); + } + + pushDiscoverResults(cast: IActorCast[], type: RequestType) { + cast.forEach(m => { this.discoverResults.push({ available: false, posterPath: m.poster_path ? `https://image.tmdb.org/t/p/w300/${m.poster_path}` : "../../../images/default_movie_poster.png", requested: false, title: m.title, - type: RequestType.movie, + type: type, id: m.id, url: null, rating: 0, diff --git a/src/Ombi/ClientApp/src/app/services/searchV2.service.ts b/src/Ombi/ClientApp/src/app/services/searchV2.service.ts index 348db936b..17d91b10f 100644 --- a/src/Ombi/ClientApp/src/app/services/searchV2.service.ts +++ b/src/Ombi/ClientApp/src/app/services/searchV2.service.ts @@ -132,6 +132,10 @@ export class SearchV2Service extends ServiceHelpers { return this.http.get(`${this.url}/actor/${actorId}/movie`, { headers: this.headers }); } + public getTvByActor(actorId: number): Observable { + return this.http.get(`${this.url}/actor/${actorId}/tv`, { headers: this.headers }); + } + public getArtistInformation(artistId: string): Observable { return this.http.get(`${this.url}/artist/${artistId}`); } diff --git a/src/Ombi/Controllers/V2/SearchController.cs b/src/Ombi/Controllers/V2/SearchController.cs index 0b58244b3..bdd40b298 100644 --- a/src/Ombi/Controllers/V2/SearchController.cs +++ b/src/Ombi/Controllers/V2/SearchController.cs @@ -395,6 +395,19 @@ namespace Ombi.Controllers.V2 { return await _movieEngineV2.GetMoviesByActor(actorId, null); } + + /// + /// Returns all the tv shows that is by the actor id + /// + /// TheMovieDb Actor ID + /// + [HttpGet("actor/{actorId}/tv")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesDefaultResponseType] + public async Task GetTvByActor(int actorId) + { + return await _tvEngineV2.GetTvByActor(actorId, null); + } [HttpGet("artist/{artistId}")]