Skip to content

Commit

Permalink
feat: Localize genres filter
Browse files Browse the repository at this point in the history
Localize genres filter
  • Loading branch information
tidusjar authored Mar 17, 2022
2 parents 6998129 + cdeb515 commit 0aa3cd0
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 21 deletions.
5 changes: 5 additions & 0 deletions src/Ombi.Core/Engine/V2/IMultiSearchEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
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);
}
}
10 changes: 10 additions & 0 deletions src/Ombi.Core/Engine/V2/MultiSearchEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
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
Expand Down Expand Up @@ -113,5 +117,11 @@ public async Task<List<MultiSearchResult>> MultiSearch(string searchTerm, MultiS

return model;
}

public async Task<IEnumerable<Genre>> GetGenres(string media, CancellationToken cancellationToken)
{
var lang = await DefaultLanguageCode(null);
return await _movieDbApi.GetGenres(media, cancellationToken, lang);
}
}
}
2 changes: 1 addition & 1 deletion src/Ombi.TheMovieDbApi/IMovieDbApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public interface IMovieDbApi
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);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Ombi.TheMovieDbApi/TheMovieDbApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -427,10 +427,11 @@ public async Task<TheMovidDbKeyValue> GetKeyword(int keywordId)
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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});
}
Expand Down
7 changes: 6 additions & 1 deletion src/Ombi/ClientApp/src/app/services/searchV2.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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}`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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 => {
Expand All @@ -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 => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ 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",
templateUrl: "genre-select.component.html"
})
export class GenreSelectComponent {
constructor(
private tmdbService: TheMovieDbService
private searchService: SearchV2Service
) {}

@Input() public form: FormGroup;

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(''),
Expand Down
8 changes: 0 additions & 8 deletions src/Ombi/Controllers/V1/External/TheMovieDbController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,6 @@ public async Task<IActionResult> GetKeywords(int keywordId)
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>
Expand Down
14 changes: 14 additions & 0 deletions src/Ombi/Controllers/V2/SearchController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
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
Expand Down Expand Up @@ -55,6 +59,16 @@ public async Task<List<MultiSearchResult>> MultiSearch(string searchTerm, [FromB
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>
Expand Down

0 comments on commit 0aa3cd0

Please sign in to comment.