Add adult movie filtering

pull/3215/head
Taylor Buchanan 5 years ago
parent c547777df7
commit 3008cd124d

@ -93,24 +93,7 @@ namespace Ombi.Api
public void AddQueryString(string key, string value)
{
if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(value)) return;
var builder = new UriBuilder(FullUri);
var startingTag = string.Empty;
var hasQuery = false;
if (string.IsNullOrEmpty(builder.Query))
{
startingTag = "?";
}
else
{
hasQuery = true;
startingTag = builder.Query.Contains("?") ? "&" : "?";
}
builder.Query = hasQuery
? $"{builder.Query}{startingTag}{key}={value}"
: $"{startingTag}{key}={value}";
_modified = builder.Uri;
_modified = FullUri.AddQueryParameter(key, value);
}
public void AddJsonBody(object obj)

@ -0,0 +1,9 @@
namespace Ombi.Core.Settings.Models.External
{
public sealed class TheMovieDbSettings : Ombi.Settings.Settings.Models.Settings
{
public bool ShowAdultMovies { get; set; }
public string ExcludedKeywordIds { get; set; }
}
}

@ -1,31 +1,36 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using AutoMapper;
using Nito.AsyncEx;
using Ombi.Api.TheMovieDb.Models;
using Ombi.Helpers;
using Ombi.Core.Settings;
using Ombi.Core.Settings.Models.External;
using Ombi.TheMovieDbApi.Models;
namespace Ombi.Api.TheMovieDb
{
public class TheMovieDbApi : IMovieDbApi
{
public TheMovieDbApi(IMapper mapper, IApi api)
public TheMovieDbApi(IMapper mapper, IApi api, ISettingsService<TheMovieDbSettings> settingsService)
{
Api = api;
Mapper = mapper;
Settings = new AsyncLazy<TheMovieDbSettings>(() => settingsService.GetSettingsAsync());
}
private const string ApiToken = "b8eabaf5608b88d0298aa189dd90bf00";
private const string BaseUri ="http://api.themoviedb.org/3/";
private IMapper Mapper { get; }
private readonly string ApiToken = "b8eabaf5608b88d0298aa189dd90bf00";
private static readonly string BaseUri ="http://api.themoviedb.org/3/";
private IApi Api { get; }
private AsyncLazy<TheMovieDbSettings> Settings { get; }
public async Task<MovieResponseDto> GetMovieInformation(int movieId)
{
var request = new Request($"movie/{movieId}", BaseUri, HttpMethod.Get);
request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken);
request.AddQueryString("api_key", ApiToken);
AddRetry(request);
var result = await Api.Request<MovieResponse>(request);
@ -35,7 +40,7 @@ namespace Ombi.Api.TheMovieDb
public async Task<FindResult> Find(string externalId, ExternalSource source)
{
var request = new Request($"find/{externalId}", BaseUri, HttpMethod.Get);
request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken);
request.AddQueryString("api_key", ApiToken);
AddRetry(request);
request.AddQueryString("external_source", source.ToString());
@ -46,9 +51,11 @@ namespace Ombi.Api.TheMovieDb
public async Task<TheMovieDbContainer<ActorResult>> SearchByActor(string searchTerm, string langCode)
{
var request = new Request($"search/person", BaseUri, HttpMethod.Get);
request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken);
request.FullUri = request.FullUri.AddQueryParameter("query", searchTerm);
request.FullUri = request.FullUri.AddQueryParameter("language", langCode);
request.AddQueryString("api_key", ApiToken);
request.AddQueryString("query", searchTerm);
request.AddQueryString("language", langCode);
var settings = await Settings;
request.AddQueryString("include_adult", settings.ShowAdultMovies.ToString().ToLower());
var result = await Api.Request<TheMovieDbContainer<ActorResult>>(request);
return result;
@ -57,8 +64,8 @@ namespace Ombi.Api.TheMovieDb
public async Task<ActorCredits> GetActorMovieCredits(int actorId, string langCode)
{
var request = new Request($"person/{actorId}/movie_credits", BaseUri, HttpMethod.Get);
request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken);
request.FullUri = request.FullUri.AddQueryParameter("language", langCode);
request.AddQueryString("api_key", ApiToken);
request.AddQueryString("language", langCode);
var result = await Api.Request<ActorCredits>(request);
return result;
@ -67,8 +74,8 @@ namespace Ombi.Api.TheMovieDb
public async Task<List<TvSearchResult>> SearchTv(string searchTerm)
{
var request = new Request($"search/tv", BaseUri, HttpMethod.Get);
request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken);
request.FullUri = request.FullUri.AddQueryParameter("query", searchTerm);
request.AddQueryString("api_key", ApiToken);
request.AddQueryString("query", searchTerm);
AddRetry(request);
var result = await Api.Request<TheMovieDbContainer<SearchResult>>(request);
@ -78,7 +85,7 @@ namespace Ombi.Api.TheMovieDb
public async Task<TvExternals> GetTvExternals(int theMovieDbId)
{
var request = new Request($"/tv/{theMovieDbId}/external_ids", BaseUri, HttpMethod.Get);
request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken);
request.AddQueryString("api_key", ApiToken);
AddRetry(request);
return await Api.Request<TvExternals>(request);
@ -87,9 +94,8 @@ namespace Ombi.Api.TheMovieDb
public async Task<List<MovieSearchResult>> SimilarMovies(int movieId, string langCode)
{
var request = new Request($"movie/{movieId}/similar", BaseUri, HttpMethod.Get);
request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken);
request.FullUri = request.FullUri.AddQueryParameter("language", langCode);
request.AddQueryString("api_key", ApiToken);
request.AddQueryString("language", langCode);
AddRetry(request);
var result = await Api.Request<TheMovieDbContainer<SearchResult>>(request);
@ -99,65 +105,95 @@ namespace Ombi.Api.TheMovieDb
public async Task<MovieResponseDto> GetMovieInformationWithExtraInfo(int movieId, string langCode = "en")
{
var request = new Request($"movie/{movieId}", BaseUri, HttpMethod.Get);
request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken);
request.FullUri = request.FullUri.AddQueryParameter("append_to_response", "videos,release_dates");
request.FullUri = request.FullUri.AddQueryParameter("language", langCode);
request.AddQueryString("api_key", ApiToken);
request.AddQueryString("append_to_response", "videos,release_dates");
request.AddQueryString("language", langCode);
AddRetry(request);
var result = await Api.Request<MovieResponse>(request);
return Mapper.Map<MovieResponseDto>(result);
}
public async Task<List<MovieSearchResult>> SearchMovie(string searchTerm, int? year, string langageCode)
public async Task<List<MovieSearchResult>> SearchMovie(string searchTerm, int? year, string langCode)
{
var request = new Request($"search/movie", BaseUri, HttpMethod.Get);
request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken);
request.FullUri = request.FullUri.AddQueryParameter("query", searchTerm);
request.FullUri = request.FullUri.AddQueryParameter("language", langageCode);
request.AddQueryString("api_key", ApiToken);
request.AddQueryString("query", searchTerm);
request.AddQueryString("language", langCode);
if (year.HasValue && year.Value > 0)
{
request.FullUri = request.FullUri.AddQueryParameter("year", year.Value.ToString());
request.AddQueryString("year", year.Value.ToString());
}
var settings = await Settings;
request.AddQueryString("include_adult", settings.ShowAdultMovies.ToString().ToLower());
AddRetry(request);
var result = await Api.Request<TheMovieDbContainer<SearchResult>>(request);
return Mapper.Map<List<MovieSearchResult>>(result.results);
}
public async Task<List<MovieSearchResult>> PopularMovies(string langageCode)
public async Task<List<MovieSearchResult>> PopularMovies(string langCode)
{
var request = new Request($"movie/popular", BaseUri, HttpMethod.Get);
request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken);
request.FullUri = request.FullUri.AddQueryParameter("language", langageCode);
var request = new Request($"discover/movie", BaseUri, HttpMethod.Get);
request.AddQueryString("api_key", ApiToken);
request.AddQueryString("language", langCode);
var settings = await Settings;
request.AddQueryString("include_adult", settings.ShowAdultMovies.ToString().ToLower());
request.AddQueryString("without_keywords", settings.ExcludedKeywordIds);
AddRetry(request);
var result = await Api.Request<TheMovieDbContainer<SearchResult>>(request);
return Mapper.Map<List<MovieSearchResult>>(result.results);
}
public async Task<List<MovieSearchResult>> TopRated(string langageCode)
public async Task<List<MovieSearchResult>> TopRated(string langCode)
{
var request = new Request($"movie/top_rated", BaseUri, HttpMethod.Get);
request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken);
request.FullUri = request.FullUri.AddQueryParameter("language", langageCode);
var request = new Request($"discover/movie", BaseUri, HttpMethod.Get);
request.AddQueryString("api_key", ApiToken);
request.AddQueryString("language", langCode);
request.AddQueryString("vote_count.gte", "250");
request.AddQueryString("sort_by", "vote_average.desc");
var settings = await Settings;
request.AddQueryString("include_adult", settings.ShowAdultMovies.ToString().ToLower());
request.AddQueryString("without_keywords", settings.ExcludedKeywordIds);
AddRetry(request);
var result = await Api.Request<TheMovieDbContainer<SearchResult>>(request);
return Mapper.Map<List<MovieSearchResult>>(result.results);
}
public async Task<List<MovieSearchResult>> Upcoming(string langageCode)
public async Task<List<MovieSearchResult>> Upcoming(string langCode)
{
var request = new Request($"movie/upcoming", BaseUri, HttpMethod.Get);
request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken);
request.FullUri = request.FullUri.AddQueryParameter("language", langageCode);
var request = new Request($"discover/movie", BaseUri, HttpMethod.Get);
request.AddQueryString("api_key", ApiToken);
request.AddQueryString("language", langCode);
request.AddQueryString("with_release_type", "2|3");
var startDate = DateTime.Today.AddDays(7);
request.AddQueryString("release_date.gte", startDate.ToString("yyyy-MM-dd"));
request.AddQueryString("release_date.lte", startDate.AddDays(17).ToString("yyyy-MM-dd"));
var settings = await Settings;
request.AddQueryString("include_adult", settings.ShowAdultMovies.ToString().ToLower());
request.AddQueryString("without_keywords", settings.ExcludedKeywordIds);
AddRetry(request);
var result = await Api.Request<TheMovieDbContainer<SearchResult>>(request);
return Mapper.Map<List<MovieSearchResult>>(result.results);
}
public async Task<List<MovieSearchResult>> NowPlaying(string langageCode)
public async Task<List<MovieSearchResult>> NowPlaying(string langCode)
{
var request = new Request($"movie/now_playing", BaseUri, HttpMethod.Get);
request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken);
request.FullUri = request.FullUri.AddQueryParameter("language", langageCode);
var request = new Request($"discover/movie", BaseUri, HttpMethod.Get);
request.AddQueryString("api_key", ApiToken);
request.AddQueryString("language", langCode);
request.AddQueryString("with_release_type", "2|3");
var today = DateTime.Today;
request.AddQueryString("release_date.gte", today.AddDays(-42).ToString("yyyy-MM-dd"));
request.AddQueryString("release_date.lte", today.AddDays(6).ToString("yyyy-MM-dd"));
var settings = await Settings;
request.AddQueryString("include_adult", settings.ShowAdultMovies.ToString().ToLower());
request.AddQueryString("without_keywords", settings.ExcludedKeywordIds);
AddRetry(request);
var result = await Api.Request<TheMovieDbContainer<SearchResult>>(request);
return Mapper.Map<List<MovieSearchResult>>(result.results);
@ -166,7 +202,7 @@ namespace Ombi.Api.TheMovieDb
public async Task<TvInfo> GetTVInfo(string themoviedbid)
{
var request = new Request($"/tv/{themoviedbid}", BaseUri, HttpMethod.Get);
request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken);
request.AddQueryString("api_key", ApiToken);
AddRetry(request);
return await Api.Request<TvInfo>(request);

@ -245,3 +245,8 @@ export interface IVoteSettings extends ISettings {
musicVoteMax: number;
tvShowVoteMax: number;
}
export interface ITheMovieDbSettings extends ISettings {
showAdultMovies: boolean;
excludedKeywordIds: string;
}

@ -32,6 +32,7 @@ import {
ISlackNotificationSettings,
ISonarrSettings,
ITelegramNotifcationSettings,
ITheMovieDbSettings,
IUpdateSettings,
IUserManagementSettings,
IVoteSettings,
@ -301,6 +302,14 @@ export class SettingsService extends ServiceHelpers {
return this.http.post<boolean>(`${this.url}/vote`, JSON.stringify(settings), {headers: this.headers});
}
public getTheMovieDbSettings(): Observable<ITheMovieDbSettings> {
return this.http.get<ITheMovieDbSettings>(`${this.url}/themoviedb`, {headers: this.headers});
}
public saveTheMovieDbSettings(settings: ITheMovieDbSettings) {
return this.http.post<boolean>(`${this.url}/themoviedb`, JSON.stringify(settings), {headers: this.headers});
}
public getNewsletterSettings(): Observable<INewsletterNotificationSettings> {
return this.http.get<INewsletterNotificationSettings>(`${this.url}/notifications/newsletter`, {headers: this.headers});
}

@ -36,6 +36,7 @@ import { PushbulletComponent } from "./notifications/pushbullet.component";
import { PushoverComponent } from "./notifications/pushover.component";
import { SlackComponent } from "./notifications/slack.component";
import { TelegramComponent } from "./notifications/telegram.component";
import { TheMovieDbComponent } from "./themoviedb/themoviedb.component";
import { OmbiComponent } from "./ombi/ombi.component";
import { PlexComponent } from "./plex/plex.component";
import { RadarrComponent } from "./radarr/radarr.component";
@ -80,6 +81,7 @@ const routes: Routes = [
{ path: "Newsletter", component: NewsletterComponent, canActivate: [AuthGuard] },
{ path: "Lidarr", component: LidarrComponent, canActivate: [AuthGuard] },
{ path: "Vote", component: VoteComponent, canActivate: [AuthGuard] },
{ path: "TheMovieDb", component: TheMovieDbComponent, canActivate: [AuthGuard] },
{ path: "FailedRequests", component: FailedRequestsComponent, canActivate: [AuthGuard] },
];
@ -135,6 +137,7 @@ const routes: Routes = [
NewsletterComponent,
LidarrComponent,
VoteComponent,
TheMovieDbComponent,
FailedRequestsComponent,
],
exports: [

@ -13,6 +13,7 @@
<li [routerLinkActive]="['active']"><a [routerLink]="['/Settings/UserManagement']">User Importer</a></li>
<li [routerLinkActive]="['active']"><a [routerLink]="['/Settings/Authentication']">Authentication</a></li>
<li [routerLinkActive]="['active']"><a [routerLink]="['/Settings/Vote']">Vote</a></li>
<li [routerLinkActive]="['active']"><a [routerLink]="['/Settings/TheMovieDb']">The Movie Database</a></li>
</ul>
</li>

@ -0,0 +1,29 @@
<settings-menu></settings-menu>
<fieldset *ngIf="settings">
<legend>The Movie Database</legend>
<div class="col-md-6">
<div class="form-group">
<div class="checkbox">
<input type="checkbox" id="showAdultMovies" name="showAdultMovies" [(ngModel)]="settings.showAdultMovies">
<label for="showAdultMovies" tooltipPosition="top" pTooltip="Include adult movies (pornography) in results">Show Adult Movies</label>
</div>
</div>
<div class="form-group">
<label for="excludedKeywordIds" class="control-label" pTooltip="Prevent movies with certain keywords from being suggested. May require a restart to take effect.">
Excluded Keyword IDs for Movie Suggestions
</label>
<div>
<input type="text" [(ngModel)]="settings.excludedKeywordIds" class="form-control form-control-custom " id="excludedKeywordIds"
name="excludedKeywordIds" placeholder="155477,190370,250773" value="{{settings.excludedKeywordIds}}">
</div>
</div>
<div class="form-group">
<div>
<button (click)="save()" type="submit" id="save" class="btn btn-primary-outline">Submit</button>
</div>
</div>
</div>
</fieldset>

@ -0,0 +1,32 @@
import { Component, OnInit } from "@angular/core";
import { ITheMovieDbSettings } from "../../interfaces";
import { NotificationService } from "../../services";
import { SettingsService } from "../../services";
@Component({
templateUrl: "./themoviedb.component.html",
})
export class TheMovieDbComponent implements OnInit {
public settings: ITheMovieDbSettings;
public advanced: boolean;
constructor(private settingsService: SettingsService, private notificationService: NotificationService) { }
public ngOnInit() {
this.settingsService.getTheMovieDbSettings().subscribe(x => {
this.settings = x;
});
}
public save() {
this.settingsService.saveTheMovieDbSettings(this.settings).subscribe(x => {
if (x) {
this.notificationService.success("Successfully saved The Movie Database settings");
} else {
this.notificationService.success("There was an error when saving The Movie Database settings");
}
});
}
}

@ -659,6 +659,25 @@ namespace Ombi.Controllers
return vote.Enabled;
}
/// <summary>
/// Save The Movie DB settings.
/// </summary>
/// <param name="settings">The settings.</param>
[HttpPost("themoviedb")]
public async Task<bool> TheMovieDbSettings([FromBody]TheMovieDbSettings settings)
{
return await Save(settings);
}
/// <summary>
/// Get The Movie DB settings.
/// </summary>
[HttpGet("themoviedb")]
public async Task<TheMovieDbSettings> TheMovieDbSettings()
{
return await Get<TheMovieDbSettings>();
}
/// <summary>
/// Saves the email notification settings.
/// </summary>

Loading…
Cancel
Save