From ae0d0e614c2537715610533301c06bb775ec557d Mon Sep 17 00:00:00 2001 From: tidusjar Date: Mon, 31 Dec 2018 00:16:17 +0000 Subject: [PATCH] Made the search results the language specified in the search refinement --- .../Engine/Interfaces/IMovieEngine.cs | 2 +- src/Ombi.Core/Engine/MovieSearchEngine.cs | 4 +- src/Ombi.TheMovieDbApi/IMovieDbApi.cs | 2 +- src/Ombi.TheMovieDbApi/TheMovieDbApi.cs | 5 +- .../app/search/moviesearch.component.ts | 12 +++- .../ClientApp/app/services/search.service.ts | 4 ++ src/Ombi/Controllers/SearchController.cs | 59 +++++++++++++++++-- .../Models/SearchMovieExtraInfoRefineModel.cs | 8 +++ src/Ombi/Models/SearchMovieRefineModel.cs | 7 +-- 9 files changed, 85 insertions(+), 18 deletions(-) create mode 100644 src/Ombi/Models/SearchMovieExtraInfoRefineModel.cs diff --git a/src/Ombi.Core/Engine/Interfaces/IMovieEngine.cs b/src/Ombi.Core/Engine/Interfaces/IMovieEngine.cs index 94e78b004..4c22bcfc1 100644 --- a/src/Ombi.Core/Engine/Interfaces/IMovieEngine.cs +++ b/src/Ombi.Core/Engine/Interfaces/IMovieEngine.cs @@ -16,7 +16,7 @@ namespace Ombi.Core Task> UpcomingMovies(); - Task LookupImdbInformation(int theMovieDbId); + Task LookupImdbInformation(int theMovieDbId, string langCode = "en"); Task> SimilarMovies(int theMovieDbId); } diff --git a/src/Ombi.Core/Engine/MovieSearchEngine.cs b/src/Ombi.Core/Engine/MovieSearchEngine.cs index eac31bcf8..e4c624c56 100644 --- a/src/Ombi.Core/Engine/MovieSearchEngine.cs +++ b/src/Ombi.Core/Engine/MovieSearchEngine.cs @@ -43,9 +43,9 @@ namespace Ombi.Core.Engine /// /// The movie database identifier. /// - public async Task LookupImdbInformation(int theMovieDbId) + public async Task LookupImdbInformation(int theMovieDbId, string langCode = "en") { - var movieInfo = await MovieApi.GetMovieInformationWithExtraInfo(theMovieDbId); + var movieInfo = await MovieApi.GetMovieInformationWithExtraInfo(theMovieDbId, langCode); var viewMovie = Mapper.Map(movieInfo); return await ProcessSingleMovie(viewMovie, true); diff --git a/src/Ombi.TheMovieDbApi/IMovieDbApi.cs b/src/Ombi.TheMovieDbApi/IMovieDbApi.cs index c15801091..6f73c5f68 100644 --- a/src/Ombi.TheMovieDbApi/IMovieDbApi.cs +++ b/src/Ombi.TheMovieDbApi/IMovieDbApi.cs @@ -8,7 +8,7 @@ namespace Ombi.Api.TheMovieDb public interface IMovieDbApi { Task GetMovieInformation(int movieId); - Task GetMovieInformationWithExtraInfo(int movieId); + Task GetMovieInformationWithExtraInfo(int movieId, string langCode = "en"); Task> NowPlaying(); Task> PopularMovies(); Task> SearchMovie(string searchTerm, int? year, string languageCode); diff --git a/src/Ombi.TheMovieDbApi/TheMovieDbApi.cs b/src/Ombi.TheMovieDbApi/TheMovieDbApi.cs index d1b08b508..a66193768 100644 --- a/src/Ombi.TheMovieDbApi/TheMovieDbApi.cs +++ b/src/Ombi.TheMovieDbApi/TheMovieDbApi.cs @@ -73,11 +73,12 @@ namespace Ombi.Api.TheMovieDb return Mapper.Map>(result.results); } - public async Task GetMovieInformationWithExtraInfo(int movieId) + public async Task GetMovieInformationWithExtraInfo(int movieId, string langCode = "en") { var request = new Request($"movie/{movieId}", BaseUri, HttpMethod.Get); request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken); request.FullUri = request.FullUri.AddQueryParameter("append_to_response", "videos,release_dates"); + request.FullUri = request.FullUri.AddQueryParameter("language", langCode); AddRetry(request); var result = await Api.Request(request); return Mapper.Map(result); @@ -88,7 +89,7 @@ namespace Ombi.Api.TheMovieDb var request = new Request($"search/movie", BaseUri, HttpMethod.Get); request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken); request.FullUri = request.FullUri.AddQueryParameter("query", searchTerm); - request.FullUri = request.FullUri.AddQueryParameter("language", searchTerm); + request.FullUri = request.FullUri.AddQueryParameter("language", langageCode); if (year.HasValue && year.Value > 0) { request.FullUri = request.FullUri.AddQueryParameter("year", year.Value.ToString()); diff --git a/src/Ombi/ClientApp/app/search/moviesearch.component.ts b/src/Ombi/ClientApp/app/search/moviesearch.component.ts index 91464229c..ddf31c0b1 100644 --- a/src/Ombi/ClientApp/app/search/moviesearch.component.ts +++ b/src/Ombi/ClientApp/app/search/moviesearch.component.ts @@ -25,7 +25,7 @@ export class MovieSearchComponent implements OnInit { public result: IRequestEngineResult; public searchApplied = false; - public refineSearchEnabled = true; + public refineSearchEnabled = false; public searchYear?: number; public selectedLanguage: string; public langauges: ILanguageRefine[]; @@ -203,10 +203,18 @@ export class MovieSearchComponent implements OnInit { } val.background = this.sanitizer.bypassSecurityTrustStyle ("url(" + "https://image.tmdb.org/t/p/w1280" + val.backdropPath + ")"); - this.searchService.getMovieInformation(val.id) + + if (this.applyRefinedSearch) { + this.searchService.getMovieInformationWithRefined(val.id, this.selectedLanguage) + .subscribe(m => { + this.updateItem(val, m); + }); + } else { + this.searchService.getMovieInformation(val.id) .subscribe(m => { this.updateItem(val, m); }); + } }); } diff --git a/src/Ombi/ClientApp/app/services/search.service.ts b/src/Ombi/ClientApp/app/services/search.service.ts index 327bd2a5b..a6c0a2387 100644 --- a/src/Ombi/ClientApp/app/services/search.service.ts +++ b/src/Ombi/ClientApp/app/services/search.service.ts @@ -45,6 +45,10 @@ export class SearchService extends ServiceHelpers { return this.http.get(`${this.url}/Movie/info/${theMovieDbId}`); } + public getMovieInformationWithRefined(theMovieDbId: number, langCode: string): Observable { + return this.http.post(`${this.url}/Movie/info`, { theMovieDbId, languageCode: langCode }); + } + // TV public searchTv(searchTerm: string): Observable { return this.http.get(`${this.url}/Tv/${searchTerm}`, { headers: this.headers }); diff --git a/src/Ombi/Controllers/SearchController.cs b/src/Ombi/Controllers/SearchController.cs index 63786fef6..7d86de30d 100644 --- a/src/Ombi/Controllers/SearchController.cs +++ b/src/Ombi/Controllers/SearchController.cs @@ -1,14 +1,11 @@ using System.Collections.Generic; using System.Threading.Tasks; - using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; -using Ombi.Api.Lidarr.Models; using Ombi.Core; using Ombi.Core.Engine; using Ombi.Core.Engine.Interfaces; -using Ombi.Core.Models; using Ombi.Core.Models.Search; using Ombi.Models; using StackExchange.Profiling; @@ -42,6 +39,8 @@ namespace Ombi.Controllers /// The search term. /// [HttpGet("movie/{searchTerm}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesDefaultResponseType] public async Task> SearchMovie(string searchTerm) { using (MiniProfiler.Current.Step("SearchingMovie")) @@ -56,7 +55,7 @@ namespace Ombi.Controllers /// Searches for a movie. /// /// We use TheMovieDb as the Movie Provider - /// The refinement model, language code and year are both optional + /// The refinement model, language code and year are both optional. Language code uses ISO 639-1 /// [HttpPost("movie")] [ProducesResponseType(StatusCodes.Status200OK)] @@ -86,11 +85,35 @@ namespace Ombi.Controllers /// We use TheMovieDb as the Movie Provider /// [HttpGet("movie/info/{theMovieDbId}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesDefaultResponseType] public async Task GetExtraMovieInfo(int theMovieDbId) { return await MovieEngine.LookupImdbInformation(theMovieDbId); } + + /// + /// Gets extra information on the movie e.g. IMDBId + /// + /// TheMovieDb and Language Code, Pass in the language code (ISO 639-1) to get it back in a different lang + /// + /// + /// We use TheMovieDb as the Movie Provider + /// + [HttpPost("movie/info")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesDefaultResponseType] + public async Task GetExtraMovieInfo([FromBody] SearchMovieExtraInfoRefineModel model) + { + if (model == null) + { + return BadRequest(); + } + return Json(await MovieEngine.LookupImdbInformation(model.TheMovieDbId, model.LanguageCode)); + } + /// /// Returns similar movies to the movie id passed in /// @@ -99,6 +122,8 @@ namespace Ombi.Controllers /// We use TheMovieDb as the Movie Provider /// [HttpGet("movie/{theMovieDbId}/similar")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesDefaultResponseType] public async Task> SimilarMovies(int theMovieDbId) { return await MovieEngine.SimilarMovies(theMovieDbId); @@ -110,6 +135,8 @@ namespace Ombi.Controllers /// We use TheMovieDb as the Movie Provider /// [HttpGet("movie/popular")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesDefaultResponseType] public async Task> Popular() { return await MovieEngine.PopularMovies(); @@ -120,6 +147,8 @@ namespace Ombi.Controllers /// We use TheMovieDb as the Movie Provider /// [HttpGet("movie/nowplaying")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesDefaultResponseType] public async Task> NowPlayingMovies() { return await MovieEngine.NowPlayingMovies(); @@ -130,6 +159,8 @@ namespace Ombi.Controllers /// /// We use TheMovieDb as the Movie Provider [HttpGet("movie/toprated")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesDefaultResponseType] public async Task> TopRatedMovies() { return await MovieEngine.TopRatedMovies(); @@ -140,6 +171,8 @@ namespace Ombi.Controllers /// We use TheMovieDb as the Movie Provider /// [HttpGet("movie/upcoming")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesDefaultResponseType] public async Task> UpcomingMovies() { return await MovieEngine.UpcomingMovies(); @@ -152,6 +185,8 @@ namespace Ombi.Controllers /// We use TvMaze as the Provider /// [HttpGet("tv/{searchTerm}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesDefaultResponseType] public async Task> SearchTv(string searchTerm) { return await TvEngine.Search(searchTerm); @@ -164,6 +199,8 @@ namespace Ombi.Controllers /// We use TvMaze as the Provider /// [HttpGet("tv/info/{tvdbId}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesDefaultResponseType] public async Task GetShowInfo(int tvdbId) { return await TvEngine.GetShowInformation(tvdbId); @@ -175,6 +212,8 @@ namespace Ombi.Controllers /// We use Trakt.tv as the Provider /// [HttpGet("tv/popular")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesDefaultResponseType] public async Task> PopularTv() { return await TvEngine.Popular(); @@ -186,6 +225,8 @@ namespace Ombi.Controllers /// We use Trakt.tv as the Provider /// [HttpGet("tv/anticipated")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesDefaultResponseType] public async Task> AnticipatedTv() { return await TvEngine.Anticipated(); @@ -198,6 +239,8 @@ namespace Ombi.Controllers /// We use Trakt.tv as the Provider /// [HttpGet("tv/mostwatched")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesDefaultResponseType] public async Task> MostWatched() { return await TvEngine.MostWatches(); @@ -209,6 +252,8 @@ namespace Ombi.Controllers /// We use Trakt.tv as the Provider /// [HttpGet("tv/trending")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesDefaultResponseType] public async Task> Trending() { return await TvEngine.Trending(); @@ -220,6 +265,8 @@ namespace Ombi.Controllers /// We use Lidarr as the Provider /// [HttpGet("music/artist/{searchTerm}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesDefaultResponseType] public async Task> SearchArtist(string searchTerm) { return await MusicEngine.SearchArtist(searchTerm); @@ -231,6 +278,8 @@ namespace Ombi.Controllers /// We use Lidarr as the Provider /// [HttpGet("music/album/{searchTerm}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesDefaultResponseType] public async Task> SearchAlbum(string searchTerm) { return await MusicEngine.SearchAlbum(searchTerm); @@ -242,6 +291,8 @@ namespace Ombi.Controllers /// We use Lidarr as the Provider /// [HttpGet("music/artist/album/{foreignArtistId}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesDefaultResponseType] public async Task> GetAlbumsByArtist(string foreignArtistId) { return await MusicEngine.GetArtistAlbums(foreignArtistId); diff --git a/src/Ombi/Models/SearchMovieExtraInfoRefineModel.cs b/src/Ombi/Models/SearchMovieExtraInfoRefineModel.cs new file mode 100644 index 000000000..2e6b0280f --- /dev/null +++ b/src/Ombi/Models/SearchMovieExtraInfoRefineModel.cs @@ -0,0 +1,8 @@ +namespace Ombi.Models +{ + public class SearchMovieExtraInfoRefineModel + { + public int TheMovieDbId { get; set; } + public string LanguageCode { get; set; } = "en"; + } +} diff --git a/src/Ombi/Models/SearchMovieRefineModel.cs b/src/Ombi/Models/SearchMovieRefineModel.cs index 8ba1b367e..6794710f3 100644 --- a/src/Ombi/Models/SearchMovieRefineModel.cs +++ b/src/Ombi/Models/SearchMovieRefineModel.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace Ombi.Models +namespace Ombi.Models { public class SearchMovieRefineModel {