diff --git a/src/Ombi.TheMovieDbApi/IMovieDbApi.cs b/src/Ombi.TheMovieDbApi/IMovieDbApi.cs index ea2465c1d..fb15aab5f 100644 --- a/src/Ombi.TheMovieDbApi/IMovieDbApi.cs +++ b/src/Ombi.TheMovieDbApi/IMovieDbApi.cs @@ -4,6 +4,10 @@ using System.Threading.Tasks; using Ombi.Api.TheMovieDb.Models; using Ombi.TheMovieDbApi.Models; +// Due to conflicting Genre models in +// Ombi.TheMovieDbApi.Models and Ombi.Api.TheMovieDb.Models +using Genre = Ombi.TheMovieDbApi.Models.Genre; + namespace Ombi.Api.TheMovieDb { public interface IMovieDbApi @@ -34,5 +38,6 @@ namespace Ombi.Api.TheMovieDb Task GetKeyword(int keywordId); Task GetMovieWatchProviders(int theMoviedbId, CancellationToken token); Task GetTvWatchProviders(int theMoviedbId, CancellationToken token); + Task> GetGenres(string media); } -} \ No newline at end of file +} diff --git a/src/Ombi.TheMovieDbApi/Models/TheMovieDbContainer.cs b/src/Ombi.TheMovieDbApi/Models/TheMovieDbContainer.cs index 72f58dd02..5eb5dbeac 100644 --- a/src/Ombi.TheMovieDbApi/Models/TheMovieDbContainer.cs +++ b/src/Ombi.TheMovieDbApi/Models/TheMovieDbContainer.cs @@ -36,4 +36,9 @@ namespace Ombi.TheMovieDbApi.Models public int total_results { get; set; } public int total_pages { get; set; } } -} \ No newline at end of file + + public class GenreContainer + { + public List genres { get; set; } + } +} diff --git a/src/Ombi.TheMovieDbApi/TheMovieDbApi.cs b/src/Ombi.TheMovieDbApi/TheMovieDbApi.cs index 74c849d59..1439c1c93 100644 --- a/src/Ombi.TheMovieDbApi/TheMovieDbApi.cs +++ b/src/Ombi.TheMovieDbApi/TheMovieDbApi.cs @@ -13,6 +13,10 @@ using Ombi.Core.Settings.Models.External; using Ombi.Helpers; using Ombi.TheMovieDbApi.Models; +// Due to conflicting Genre models in +// Ombi.TheMovieDbApi.Models and Ombi.Api.TheMovieDb.Models +using Genre = Ombi.TheMovieDbApi.Models.Genre; + namespace Ombi.Api.TheMovieDb { public class TheMovieDbApi : IMovieDbApi @@ -344,6 +348,16 @@ namespace Ombi.Api.TheMovieDb return keyword == null || keyword.Id == 0 ? null : keyword; } + public async Task> GetGenres(string media) + { + var request = new Request($"genre/{media}/list", BaseUri, HttpMethod.Get); + request.AddQueryString("api_key", ApiToken); + AddRetry(request); + + var result = await Api.Request>(request); + return result.genres ?? new List(); + } + public Task> MultiSearch(string searchTerm, string languageCode, CancellationToken cancellationToken) { var request = new Request("search/multi", BaseUri, HttpMethod.Get); diff --git a/src/Ombi/ClientApp/src/app/interfaces/ISettings.ts b/src/Ombi/ClientApp/src/app/interfaces/ISettings.ts index d73fdddc8..5dfaa3e15 100644 --- a/src/Ombi/ClientApp/src/app/interfaces/ISettings.ts +++ b/src/Ombi/ClientApp/src/app/interfaces/ISettings.ts @@ -284,6 +284,8 @@ export interface IVoteSettings extends ISettings { export interface ITheMovieDbSettings extends ISettings { showAdultMovies: boolean; excludedKeywordIds: number[]; + excludedMovieGenreIds: number[]; + excludedTvGenreIds: number[] } export interface IUpdateModel diff --git a/src/Ombi/ClientApp/src/app/services/applications/themoviedb.service.ts b/src/Ombi/ClientApp/src/app/services/applications/themoviedb.service.ts index 677034143..c8303f58c 100644 --- a/src/Ombi/ClientApp/src/app/services/applications/themoviedb.service.ts +++ b/src/Ombi/ClientApp/src/app/services/applications/themoviedb.service.ts @@ -4,7 +4,7 @@ import { Injectable, Inject } from "@angular/core"; import { empty, Observable, throwError } from "rxjs"; import { catchError } from "rxjs/operators"; -import { IMovieDbKeyword } from "../../interfaces"; +import { IMovieDbGenre, IMovieDbKeyword } from "../../interfaces"; import { ServiceHelpers } from "../service.helpers"; @Injectable() @@ -22,4 +22,8 @@ export class TheMovieDbService extends ServiceHelpers { return this.http.get(`${this.url}/Keywords/${keywordId}`, { headers: this.headers }) .pipe(catchError((error: HttpErrorResponse) => error.status === 404 ? empty() : throwError(error))); } + + public getGenres(media: string): Observable { + return this.http.get(`${this.url}/Genres/${media}`, { headers: this.headers }) + } } diff --git a/src/Ombi/ClientApp/src/app/settings/themoviedb/themoviedb.component.ts b/src/Ombi/ClientApp/src/app/settings/themoviedb/themoviedb.component.ts index d0686ef4d..c3c78324d 100644 --- a/src/Ombi/ClientApp/src/app/settings/themoviedb/themoviedb.component.ts +++ b/src/Ombi/ClientApp/src/app/settings/themoviedb/themoviedb.component.ts @@ -18,6 +18,7 @@ interface IKeywordTag { interface IGenres { id: number; name: string; + initial: boolean; } @Component({ @@ -48,6 +49,8 @@ export class TheMovieDbComponent implements OnInit { }); this.settingsService.getTheMovieDbSettings().subscribe(settings => { this.settings = settings; + + // Map Keyword ids -> keyword name this.excludedKeywords = settings.excludedKeywordIds ? settings.excludedKeywordIds.map(id => ({ id, @@ -55,13 +58,52 @@ export class TheMovieDbComponent implements OnInit { initial: true, })) : []; - this.excludedKeywords.forEach(key => { - this.tmdbService.getKeyword(key.id).subscribe(keyResult => { - this.excludedKeywords.filter((val, idx) => { - val.name = keyResult.name; + + this.excludedKeywords.forEach(key => { + this.tmdbService.getKeyword(key.id).subscribe(keyResult => { + this.excludedKeywords.filter((val, idx) => { + val.name = keyResult.name; + }) + }); + }); + + // Map Movie Genre ids -> genre name + this.excludedMovieGenres = settings.excludedMovieGenreIds + ? settings.excludedMovieGenreIds.map(id => ({ + id, + name: "", + initial: true, + })) + : []; + + this.tmdbService.getGenres("movie").subscribe(results => { + results.forEach(genre => { + this.excludedMovieGenres.forEach(key => { + this.excludedMovieGenres.filter((val, idx) => { + val.name = genre.name + }) + }) + }); + }); + + // Map Tv Genre ids -> genre name + this.excludedTvGenres = settings.excludedTvGenreIds + ? settings.excludedTvGenreIds.map(id => ({ + id, + name: "", + initial: true, + })) + : []; + + this.tmdbService.getGenres("tv").subscribe(results => { + results.forEach(genre => { + this.excludedTvGenres.forEach(key => { + this.excludedTvGenres.filter((val, idx) => { + val.name = genre.name }) - }); + }) }); + }); }); this.tagForm @@ -75,7 +117,6 @@ export class TheMovieDbComponent implements OnInit { }) ) .subscribe((r) => (this.filteredTags = r)); - } public remove(tag: IKeywordTag): void { diff --git a/src/Ombi/Controllers/V1/External/TheMovieDbController.cs b/src/Ombi/Controllers/V1/External/TheMovieDbController.cs index 714831633..ac4bb4eea 100644 --- a/src/Ombi/Controllers/V1/External/TheMovieDbController.cs +++ b/src/Ombi/Controllers/V1/External/TheMovieDbController.cs @@ -5,6 +5,10 @@ using Ombi.Attributes; using System.Collections.Generic; using System.Threading.Tasks; +// Due to conflicting Genre models in +// Ombi.TheMovieDbApi.Models and Ombi.Api.TheMovieDb.Models +using Genre = Ombi.TheMovieDbApi.Models.Genre; + namespace Ombi.Controllers.External { [Admin] @@ -34,5 +38,13 @@ namespace Ombi.Controllers.External var keyword = await TmdbApi.GetKeyword(keywordId); return keyword == null ? NotFound() : (IActionResult)Ok(keyword); } + + /// + /// Gets the genres for either Tv or Movies depending on media type + /// + /// Either `tv` or `movie`. + [HttpGet("Genres/{media}")] + public async Task> GetGenres(string media) => + await TmdbApi.GetGenres(media); } }