Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Localize genres filter #4541

Merged
merged 1 commit into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}")]
Copy link
Contributor Author

@sephrat sephrat Mar 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved this to SearchController for convenience (so that I could call DefaultLanguageCode()). It may make less sense for it to be there because the genres ID are TMDB-specific, but since we use these IDs in SearchController as well, I thought this would not smell that much.

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