From c47cc7f8f2b104d90f2b87a7dd042db115979aab Mon Sep 17 00:00:00 2001 From: tidusjar Date: Wed, 28 Feb 2018 12:17:03 +0000 Subject: [PATCH] Added a similar button to the movie searches. Makes movie discoverablility easier --- src/Ombi.Core/Engine/Interfaces/IMovieEngine.cs | 2 ++ src/Ombi.Core/Engine/MovieSearchEngine.cs | 16 ++++++++++++++++ src/Ombi.TheMovieDbApi/IMovieDbApi.cs | 1 + src/Ombi.TheMovieDbApi/TheMovieDbApi.cs | 9 +++++++++ .../app/search/moviesearch.component.html | 9 +++++---- .../app/search/moviesearch.component.ts | 9 +++++++++ .../ClientApp/app/services/search.service.ts | 3 +++ src/Ombi/Controllers/SearchController.cs | 13 +++++++++++++ src/Ombi/wwwroot/translations/en.json | 1 + 9 files changed, 59 insertions(+), 4 deletions(-) diff --git a/src/Ombi.Core/Engine/Interfaces/IMovieEngine.cs b/src/Ombi.Core/Engine/Interfaces/IMovieEngine.cs index 1f65b5a15..91b6404db 100644 --- a/src/Ombi.Core/Engine/Interfaces/IMovieEngine.cs +++ b/src/Ombi.Core/Engine/Interfaces/IMovieEngine.cs @@ -17,5 +17,7 @@ namespace Ombi.Core Task> UpcomingMovies(); Task LookupImdbInformation(int theMovieDbId); + + Task> SimilarMovies(int theMovieDbId); } } \ No newline at end of file diff --git a/src/Ombi.Core/Engine/MovieSearchEngine.cs b/src/Ombi.Core/Engine/MovieSearchEngine.cs index c5bf7238a..33107e5af 100644 --- a/src/Ombi.Core/Engine/MovieSearchEngine.cs +++ b/src/Ombi.Core/Engine/MovieSearchEngine.cs @@ -63,6 +63,22 @@ namespace Ombi.Core.Engine return null; } + /// + /// Get similar movies to the id passed in + /// + /// + /// + public async Task> SimilarMovies(int theMovieDbId) + { + var result = await MovieApi.SimilarMovies(theMovieDbId); + if (result != null) + { + Logger.LogDebug("Search Result: {result}", result); + return await TransformMovieResultsToResponse(result.Take(10)); // Take 10 to stop us overloading the API + } + return null; + } + /// /// Gets popular movies. /// diff --git a/src/Ombi.TheMovieDbApi/IMovieDbApi.cs b/src/Ombi.TheMovieDbApi/IMovieDbApi.cs index aaa106b21..dd0d0e92c 100644 --- a/src/Ombi.TheMovieDbApi/IMovieDbApi.cs +++ b/src/Ombi.TheMovieDbApi/IMovieDbApi.cs @@ -14,5 +14,6 @@ namespace Ombi.Api.TheMovieDb Task> SearchMovie(string searchTerm); Task> TopRated(); Task> Upcoming(); + Task> SimilarMovies(int movieId); } } \ No newline at end of file diff --git a/src/Ombi.TheMovieDbApi/TheMovieDbApi.cs b/src/Ombi.TheMovieDbApi/TheMovieDbApi.cs index 6e8dfeb8e..1fbfe9aaf 100644 --- a/src/Ombi.TheMovieDbApi/TheMovieDbApi.cs +++ b/src/Ombi.TheMovieDbApi/TheMovieDbApi.cs @@ -30,6 +30,15 @@ namespace Ombi.Api.TheMovieDb return Mapper.Map(result); } + public async Task> SimilarMovies(int movieId) + { + var request = new Request($"movie/{movieId}/similar", BaseUri, HttpMethod.Get); + request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken); + + var result = await Api.Request>(request); + return Mapper.Map>(result.results); + } + public async Task GetMovieInformationWithExtraInfo(int movieId) { var request = new Request($"movie/{movieId}", BaseUri, HttpMethod.Get); diff --git a/src/Ombi/ClientApp/app/search/moviesearch.component.html b/src/Ombi/ClientApp/app/search/moviesearch.component.html index 6f8602d5a..58d8415fb 100644 --- a/src/Ombi/ClientApp/app/search/moviesearch.component.html +++ b/src/Ombi/ClientApp/app/search/moviesearch.component.html @@ -41,9 +41,9 @@

{{result.title}} ({{result.releaseDate | date: 'yyyy'}})

- - {{ 'Search.TheatricalRelease' | translate: {date: result.releaseDate | date: 'mediumDate'} }} - {{ 'Search.DigitalDate' | translate: {date: result.digitalReleaseDate | date: 'mediumDate'} }} + + {{ 'Search.TheatricalRelease' | translate: {date: result.releaseDate | date: 'mediumDate'} }} + {{ 'Search.DigitalDate' | translate: {date: result.digitalReleaseDate | date: 'mediumDate'} }} @@ -80,7 +80,8 @@ {{ 'Common.Request' | translate }} - + +
View On Plex diff --git a/src/Ombi/ClientApp/app/search/moviesearch.component.ts b/src/Ombi/ClientApp/app/search/moviesearch.component.ts index 6be32becc..819463c4f 100644 --- a/src/Ombi/ClientApp/app/search/moviesearch.component.ts +++ b/src/Ombi/ClientApp/app/search/moviesearch.component.ts @@ -146,6 +146,15 @@ export class MovieSearchComponent implements OnInit { this.issueProviderId = req.id.toString(); } + public similarMovies(theMovieDbId: number) { + this.clearResults(); + this.searchService.similarMovies(theMovieDbId) + .subscribe(x => { + this.movieResults = x; + this.getExtraInfo(); + }); + } + private getExtraInfo() { this.movieResults.forEach((val, index) => { diff --git a/src/Ombi/ClientApp/app/services/search.service.ts b/src/Ombi/ClientApp/app/services/search.service.ts index 1cbe70233..522b7dddf 100644 --- a/src/Ombi/ClientApp/app/services/search.service.ts +++ b/src/Ombi/ClientApp/app/services/search.service.ts @@ -19,6 +19,9 @@ export class SearchService extends ServiceHelpers { public searchMovie(searchTerm: string): Observable { return this.http.get(`${this.url}/Movie/` + searchTerm); } + public similarMovies(theMovieDbId: number): Observable { + return this.http.get(`${this.url}/Movie/${theMovieDbId}/similar`); + } public popularMovies(): Observable { return this.http.get(`${this.url}/Movie/Popular`); diff --git a/src/Ombi/Controllers/SearchController.cs b/src/Ombi/Controllers/SearchController.cs index 44a00a656..7060a973e 100644 --- a/src/Ombi/Controllers/SearchController.cs +++ b/src/Ombi/Controllers/SearchController.cs @@ -61,6 +61,19 @@ namespace Ombi.Controllers return await MovieEngine.LookupImdbInformation(theMovieDbId); } + /// + /// Returns similar movies to the movie id passed in + /// + /// ID of the movie + /// + /// We use TheMovieDb as the Movie Provider + /// + [HttpGet("movie/{theMovieDbId}/similar")] + public async Task> SimilarMovies(int theMovieDbId) + { + return await MovieEngine.SimilarMovies(theMovieDbId); + } + /// /// Returns Popular Movies /// diff --git a/src/Ombi/wwwroot/translations/en.json b/src/Ombi/wwwroot/translations/en.json index 83cfcd353..c6660b9c0 100644 --- a/src/Ombi/wwwroot/translations/en.json +++ b/src/Ombi/wwwroot/translations/en.json @@ -81,6 +81,7 @@ "TheatricalRelease":"Theatrical Release: {{date}}", "ViewOnPlex": "View On Plex", "RequestAdded": "Request for {{title}} has been added successfully", + "Similar":"Similar", "Movies": { "PopularMovies": "Popular Movies", "UpcomingMovies": "Upcoming Movies",