mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-14 02:26:55 -07:00
Add backend API calls for genres
This commit is contained in:
parent
341f6583de
commit
c217235d56
7 changed files with 93 additions and 10 deletions
|
@ -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<Keyword> GetKeyword(int keywordId);
|
||||
Task<WatchProviders> GetMovieWatchProviders(int theMoviedbId, CancellationToken token);
|
||||
Task<WatchProviders> GetTvWatchProviders(int theMoviedbId, CancellationToken token);
|
||||
Task<List<Genre>> GetGenres(string media);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,4 +36,9 @@ namespace Ombi.TheMovieDbApi.Models
|
|||
public int total_results { get; set; }
|
||||
public int total_pages { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
public class GenreContainer<T>
|
||||
{
|
||||
public List<T> genres { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<List<Genre>> 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<GenreContainer<Genre>>(request);
|
||||
return result.genres ?? new List<Genre>();
|
||||
}
|
||||
|
||||
public Task<TheMovieDbContainer<MultiSearch>> MultiSearch(string searchTerm, string languageCode, CancellationToken cancellationToken)
|
||||
{
|
||||
var request = new Request("search/multi", BaseUri, HttpMethod.Get);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<IMovieDbKeyword>(`${this.url}/Keywords/${keywordId}`, { headers: this.headers })
|
||||
.pipe(catchError((error: HttpErrorResponse) => error.status === 404 ? empty() : throwError(error)));
|
||||
}
|
||||
|
||||
public getGenres(media: string): Observable<IMovieDbGenre[]> {
|
||||
return this.http.get<IMovieDbGenre[]>(`${this.url}/Genres/${media}`, { headers: this.headers })
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/// <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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue