Localize genres filter

pull/4541/head
Florian Dupret 3 years ago
parent 76af4a193f
commit cdeb515151

@ -4,10 +4,15 @@ using System.Threading.Tasks;
using Ombi.Api.TheMovieDb.Models;
using Ombi.Core.Models.Search.V2;
// Due to conflicting Genre models in
// Ombi.TheMovieDbApi.Models and Ombi.Api.TheMovieDb.Models
using Genre = Ombi.TheMovieDbApi.Models.Genre;
namespace Ombi.Core.Engine.V2
{
public interface IMultiSearchEngine
{
Task<List<MultiSearchResult>> MultiSearch(string searchTerm, MultiSearchFilter filter, CancellationToken cancellationToken);
Task<IEnumerable<Genre>> GetGenres(string media, CancellationToken requestAborted);
}
}

@ -17,6 +17,10 @@ using Ombi.Settings.Settings.Models.External;
using Ombi.Store.Entities;
using Ombi.Store.Repository;
// Due to conflicting Genre models in
// Ombi.TheMovieDbApi.Models and Ombi.Api.TheMovieDb.Models
using Genre = Ombi.TheMovieDbApi.Models.Genre;
namespace Ombi.Core.Engine.V2
{
public class MultiSearchEngine : BaseMediaEngine, IMultiSearchEngine
@ -113,5 +117,11 @@ namespace Ombi.Core.Engine.V2
return model;
}
public async Task<IEnumerable<Genre>> GetGenres(string media, CancellationToken cancellationToken)
{
var lang = await DefaultLanguageCode(null);
return await _movieDbApi.GetGenres(media, cancellationToken, lang);
}
}
}

@ -40,7 +40,7 @@ namespace Ombi.Api.TheMovieDb
Task<TheMovidDbKeyValue> GetKeyword(int keywordId);
Task<WatchProviders> GetMovieWatchProviders(int theMoviedbId, CancellationToken token);
Task<WatchProviders> GetTvWatchProviders(int theMoviedbId, CancellationToken token);
Task<List<Genre>> GetGenres(string media, CancellationToken cancellationToken);
Task<List<Genre>> GetGenres(string media, CancellationToken cancellationToken, string languageCode);
Task<List<WatchProvidersResults>> SearchWatchProviders(string media, string searchTerm, CancellationToken cancellationToken);
Task<List<MovieDbSearchResult>> AdvancedSearch(DiscoverModel model, CancellationToken cancellationToken);
}

@ -427,10 +427,11 @@ namespace Ombi.Api.TheMovieDb
return keyword == null || keyword.Id == 0 ? null : keyword;
}
public async Task<List<Genre>> GetGenres(string media, CancellationToken cancellationToken)
public async Task<List<Genre>> GetGenres(string media, CancellationToken cancellationToken, string languageCode)
{
var request = new Request($"genre/{media}/list", BaseUri, HttpMethod.Get);
request.AddQueryString("api_key", ApiToken);
request.AddQueryString("language", languageCode);
AddRetry(request);
var result = await Api.Request<GenreContainer<Genre>>(request, cancellationToken);

@ -25,10 +25,6 @@ export class TheMovieDbService extends ServiceHelpers {
.pipe(catchError((error: HttpErrorResponse) => error.status === 404 ? empty() : throwError(error)));
}
public getGenres(media: string): Observable<IMovieDbKeyword[]> {
return this.http.get<IMovieDbKeyword[]>(`${this.url}/Genres/${media}`, { headers: this.headers })
}
public getWatchProviders(media: string): Observable<IWatchProvidersResults[]> {
return this.http.get<IWatchProvidersResults[]>(`${this.url}/WatchProviders/${media}`, {headers: this.headers});
}

@ -4,7 +4,7 @@ import { Injectable, Inject } from "@angular/core";
import { HttpClient } from "@angular/common/http";
import { Observable } from "rxjs";
import { IDiscoverModel, IMultiSearchResult, ISearchMovieResult, ISearchTvResult } from "../interfaces";
import { IDiscoverModel, IMovieDbKeyword, IMultiSearchResult, ISearchMovieResult, ISearchTvResult } from "../interfaces";
import { ServiceHelpers } from "./service.helpers";
import { ISearchMovieResultV2 } from "../interfaces/ISearchMovieResultV2";
@ -23,6 +23,11 @@ export class SearchV2Service extends ServiceHelpers {
public multiSearch(searchTerm: string, filter: SearchFilter): Observable<IMultiSearchResult[]> {
return this.http.post<IMultiSearchResult[]>(`${this.url}/multi/${encodeURIComponent(searchTerm)}`, filter);
}
public getGenres(media: string): Observable<IMovieDbKeyword[]> {
return this.http.get<IMovieDbKeyword[]>(`${this.url}/Genres/${media}`, { headers: this.headers })
}
public getFullMovieDetails(theMovieDbId: number): Observable<ISearchMovieResultV2> {
return this.http.get<ISearchMovieResultV2>(`${this.url}/Movie/${theMovieDbId}`);
}

@ -5,7 +5,7 @@ import { IMovieDbKeyword, ITheMovieDbSettings } from "../../interfaces";
import { debounceTime, switchMap } from "rxjs/operators";
import { MatAutocomplete } from "@angular/material/autocomplete";
import { NotificationService } from "../../services";
import { NotificationService, SearchV2Service } from "../../services";
import { SettingsService } from "../../services";
import { TheMovieDbService } from "../../services";
@ -33,6 +33,7 @@ export class TheMovieDbComponent implements OnInit {
constructor(private settingsService: SettingsService,
private notificationService: NotificationService,
private tmdbService: TheMovieDbService,
private searchService: SearchV2Service,
private fb: FormBuilder) { }
public ngOnInit() {
@ -71,7 +72,7 @@ export class TheMovieDbComponent implements OnInit {
}))
: [];
this.tmdbService.getGenres("movie").subscribe(results => {
this.searchService.getGenres("movie").subscribe(results => {
this.filteredMovieGenres = results;
this.excludedMovieGenres.forEach(genre => {
@ -92,7 +93,7 @@ export class TheMovieDbComponent implements OnInit {
}))
: [];
this.tmdbService.getGenres("tv").subscribe(results => {
this.searchService.getGenres("tv").subscribe(results => {
this.filteredTvGenres = results;
this.excludedTvGenres.forEach(genre => {

@ -5,7 +5,7 @@ import { debounceTime, distinctUntilChanged, map, startWith, switchMap } from "r
import { IMovieDbKeyword } from "../../../interfaces";
import { MatAutocompleteSelectedEvent } from "@angular/material/autocomplete";
import { Observable } from "rxjs";
import { TheMovieDbService } from "../../../services";
import { SearchV2Service } from "../../../services";
@Component({
selector: "genre-select",
@ -13,7 +13,7 @@ import { TheMovieDbService } from "../../../services";
})
export class GenreSelectComponent {
constructor(
private tmdbService: TheMovieDbService
private searchService: SearchV2Service
) {}
@Input() public form: FormGroup;
@ -21,7 +21,7 @@ export class GenreSelectComponent {
private _mediaType: string;
@Input() set mediaType(type: string) {
this._mediaType = type;
this.tmdbService.getGenres(this._mediaType).subscribe((res) => {
this.searchService.getGenres(this._mediaType).subscribe((res) => {
this.genres = res;
this.filteredKeywords = this.control.valueChanges.pipe(
startWith(''),

@ -39,14 +39,6 @@ namespace Ombi.Controllers.External
return keyword == null ? NotFound() : Ok(keyword);
}
/// <summary>
/// Gets the genres for either Tv or Movies depending on media type
/// </summary>
/// <param name="media">Either `tv` or `movie`.</param>
[HttpGet("Genres/{media}")]
public async Task<IEnumerable<Genre>> GetGenres(string media) =>
await TmdbApi.GetGenres(media, HttpContext.RequestAborted);
/// <summary>
/// Searches for the watch providers matching the specified term.
/// </summary>

@ -16,6 +16,10 @@ using Ombi.Api.RottenTomatoes.Models;
using Ombi.Api.RottenTomatoes;
using Ombi.Helpers;
// Due to conflicting Genre models in
// Ombi.TheMovieDbApi.Models and Ombi.Api.TheMovieDb.Models
using Genre = Ombi.TheMovieDbApi.Models.Genre;
namespace Ombi.Controllers.V2
{
public class SearchController : V2Controller
@ -55,6 +59,16 @@ namespace Ombi.Controllers.V2
return await _multiSearchEngine.MultiSearch(Uri.UnescapeDataString(searchTerm), filter, Request.HttpContext.RequestAborted);
}
/// <summary>
/// Gets the genres for either Tv or Movies depending on media type
/// </summary>
/// <param name="media">Either `tv` or `movie`.</param>
[HttpGet("Genres/{media}")]
public Task<IEnumerable<Genre>> GetGenres(string media)
{
return _multiSearchEngine.GetGenres(media, HttpContext.RequestAborted);
}
/// <summary>
/// Returns details for a single movie
/// </summary>

Loading…
Cancel
Save