pull/952/head
tidusjar 8 years ago
parent 02a1770b31
commit 4926255094

@ -34,6 +34,10 @@ namespace Ombi.Api.Models.Radarr
public class RadarrAddMovie
{
public RadarrAddMovie()
{
images = new List<string>();
}
public RadarrError Error { get; set; }
public RadarrAddOptions addOptions { get; set; }
public string title { get; set; }
@ -41,6 +45,7 @@ namespace Ombi.Api.Models.Radarr
public int qualityProfileId { get; set; }
public bool monitored { get; set; }
public int tmdbId { get; set; }
public List<string> images { get; set; }
public string cleanTitle { get; set; }
public string imdbId { get; set; }
public string titleSlug { get; set; }

@ -77,8 +77,8 @@ namespace Ombi.Api
tmdbId = tmdbId,
qualityProfileId = qualityId,
rootFolderPath = rootPath,
titleSlug = title
titleSlug = title,
monitored = true
};
if (searchNow)

@ -39,6 +39,7 @@ namespace Ombi.Core
public const string SonarrQualityProfiles = nameof(SonarrQualityProfiles);
public const string RadarrQualityProfiles = nameof(RadarrQualityProfiles);
public const string SonarrQueued = nameof(SonarrQueued);
public const string RadarrMovies = nameof(RadarrMovies);
public const string SickRageQualityProfiles = nameof(SickRageQualityProfiles);
public const string SickRageQueued = nameof(SickRageQueued);
public const string CouchPotatoQualityProfiles = nameof(CouchPotatoQualityProfiles);

@ -37,16 +37,20 @@ namespace Ombi.Core
public class MovieSender : IMovieSender
{
public MovieSender(ISettingsService<CouchPotatoSettings> cp, ISettingsService<WatcherSettings> watcher,
ICouchPotatoApi cpApi, IWatcherApi watcherApi)
ICouchPotatoApi cpApi, IWatcherApi watcherApi, IRadarrApi radarrApi, ISettingsService<RadarrSettings> radarrSettings)
{
CouchPotatoSettings = cp;
WatcherSettings = watcher;
CpApi = cpApi;
WatcherApi = watcherApi;
RadarrSettings = radarrSettings;
RadarrApi = radarrApi;
}
private ISettingsService<CouchPotatoSettings> CouchPotatoSettings { get; }
private ISettingsService<WatcherSettings> WatcherSettings { get; }
private ISettingsService<RadarrSettings> RadarrSettings { get; }
private IRadarrApi RadarrApi { get; }
private ICouchPotatoApi CpApi { get; }
private IWatcherApi WatcherApi { get; }
private static Logger Log = LogManager.GetCurrentClassLogger();
@ -55,6 +59,7 @@ namespace Ombi.Core
{
var cpSettings = await CouchPotatoSettings.GetSettingsAsync();
var watcherSettings = await WatcherSettings.GetSettingsAsync();
var radarrSettings = await RadarrSettings.GetSettingsAsync();
if (cpSettings.Enabled)
{
@ -66,6 +71,11 @@ namespace Ombi.Core
return SendToWatcher(model, watcherSettings);
}
if (radarrSettings.Enabled)
{
return SendToRadarr(model, radarrSettings);
}
return new MovieSenderResult { Result = false, MovieSendingEnabled = false };
}
@ -91,5 +101,23 @@ namespace Ombi.Core
var result = CpApi.AddMovie(model.ImdbId, settings.ApiKey, model.Title, settings.FullUri, qualityId);
return new MovieSenderResult { Result = result, MovieSendingEnabled = true };
}
private MovieSenderResult SendToRadarr(RequestedModel model, RadarrSettings settings)
{
var qualityProfile = 0;
int.TryParse(settings.QualityProfile, out qualityProfile);
var result = RadarrApi.AddMovie(model.ProviderId, model.Title, qualityProfile, settings.RootPath, settings.ApiKey, settings.FullUri, true);
if (!string.IsNullOrEmpty(result.Error?.message))
{
Log.Error(result.Error.message);
return new MovieSenderResult { Result = false };
}
if (!string.IsNullOrEmpty(result.title))
{
return new MovieSenderResult { Result = true, MovieSendingEnabled = true };
}
return new MovieSenderResult { Result = false, MovieSendingEnabled = true };
}
}
}

@ -46,5 +46,6 @@ namespace Ombi.Core.SettingModels
public int FaultQueueHandler { get; set; }
public int PlexContentCacher { get; set; }
public int PlexUserChecker { get; set; }
public int RadarrCacher { get; set; }
}
}

@ -0,0 +1,11 @@
using System.Collections.Generic;
using Ombi.Services.Models;
namespace Ombi.Services.Interfaces
{
public interface IRadarrCacher
{
void Queued();
int[] QueuedIds();
}
}

@ -32,6 +32,7 @@ namespace Ombi.Services.Jobs
public const string CpCacher = "CouchPotato Cacher";
public const string WatcherCacher = "Watcher Cacher";
public const string SonarrCacher = "Sonarr Cacher";
public const string RadarrCacher = "Radarr Cacher";
public const string SrCacher = "SickRage Cacher";
public const string PlexChecker = "Plex Availability Cacher";
public const string PlexCacher = "Plex Cacher";

@ -0,0 +1,102 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: PlexAvailabilityChecker.cs
// Created By: Jamie Rees
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
using System.Collections.Generic;
using System.Linq;
using NLog;
using Ombi.Api.Interfaces;
using Ombi.Api.Models.Radarr;
using Ombi.Core;
using Ombi.Core.SettingModels;
using Ombi.Helpers;
using Ombi.Services.Interfaces;
using Quartz;
namespace Ombi.Services.Jobs
{
public class RadarrCacher : IJob, IRadarrCacher
{
public RadarrCacher(ISettingsService<RadarrSettings> radarrService, IRadarrApi radarrApi, ICacheProvider cache, IJobRecord rec)
{
RadarrSettings = radarrService;
RadarrApi = radarrApi;
Job = rec;
Cache = cache;
}
private ISettingsService<RadarrSettings> RadarrSettings { get; }
private ICacheProvider Cache { get; }
private IRadarrApi RadarrApi { get; }
private IJobRecord Job { get; }
private static Logger Log = LogManager.GetCurrentClassLogger();
public void Queued()
{
var settings = RadarrSettings.GetSettings();
if (settings.Enabled)
{
Job.SetRunning(true, JobNames.RadarrCacher);
try
{
var movies = RadarrApi.GetMovies(settings.ApiKey, settings.FullUri);
if (movies != null)
{
var movieIds = movies.Select(x => x.tmdbId).ToList();
Cache.Set(CacheKeys.RadarrMovies, movieIds, CacheKeys.TimeFrameMinutes.SchedulerCaching);
}
}
catch (System.Exception ex)
{
Log.Error(ex, "Failed caching queued items from Radarr");
}
finally
{
Job.Record(JobNames.RadarrCacher);
Job.SetRunning(false, JobNames.RadarrCacher);
}
}
}
// we do not want to set here...
public int[] QueuedIds()
{
var retVal = new List<int>();
var movies = Cache.Get<List<int>>(CacheKeys.RadarrMovies);
if (movies != null)
{
retVal.AddRange(movies);
}
return retVal.ToArray();
}
public void Execute(IJobExecutionContext context)
{
Queued();
}
}
}

@ -86,9 +86,11 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Interfaces\IRadarrCacher.cs" />
<Compile Include="Interfaces\IWatcherCacher.cs" />
<Compile Include="Interfaces\IJobRecord.cs" />
<Compile Include="Interfaces\INotificationEngine.cs" />
<Compile Include="Jobs\RadarrCacher.cs" />
<Compile Include="Jobs\WatcherCacher.cs" />
<Compile Include="Jobs\HtmlTemplateGenerator.cs" />
<Compile Include="Jobs\IPlexContentCacher.cs" />

@ -75,6 +75,7 @@ namespace Ombi.UI.Jobs
JobBuilder.Create<UserRequestLimitResetter>().WithIdentity("UserRequestLimiter", "Request").Build(),
JobBuilder.Create<RecentlyAdded>().WithIdentity("RecentlyAddedModel", "Email").Build(),
JobBuilder.Create<FaultQueueHandler>().WithIdentity("FaultQueueHandler", "Fault").Build(),
JobBuilder.Create<RadarrCacher>().WithIdentity("RadarrCacher", "Cache").Build(),
};
jobs.AddRange(jobList);
@ -170,6 +171,10 @@ namespace Ombi.UI.Jobs
{
s.PlexUserChecker = 24;
}
if (s.RadarrCacher == 0)
{
s.RadarrCacher = 60;
}
var triggers = new List<ITrigger>();
@ -222,6 +227,14 @@ namespace Ombi.UI.Jobs
.WithSimpleSchedule(x => x.WithIntervalInMinutes(s.WatcherCacher).RepeatForever())
.Build();
var radarrCacher =
TriggerBuilder.Create()
.WithIdentity("RadarrCacher", "Cache")
.StartNow()
//.StartAt(DateBuilder.FutureDate(2, IntervalUnit.Minute))
.WithSimpleSchedule(x => x.WithIntervalInMinutes(s.RadarrCacher).RepeatForever())
.Build();
var storeBackup =
TriggerBuilder.Create()
.WithIdentity("StoreBackup", "Database")
@ -280,6 +293,7 @@ namespace Ombi.UI.Jobs
triggers.Add(fault);
triggers.Add(plexCacher);
triggers.Add(plexUserChecker);
triggers.Add(radarrCacher);
return triggers;
}

@ -175,7 +175,7 @@ namespace Ombi.UI.Modules.Admin
Get["/getusers"] = _ => GetUsers();
Get["/couchpotato"] = _ => CouchPotato();
Post["/couchpotato"] = _ => SaveCouchPotato();
Post["/couchpotato", true] = async (x, ct) => await SaveCouchPotato();
Get["/plex"] = _ => Plex();
Post["/plex", true] = async (x, ct) => await SavePlex();
@ -185,7 +185,7 @@ namespace Ombi.UI.Modules.Admin
Post["/sonarrprofiles"] = _ => GetSonarrQualityProfiles();
Get["/radarr", true] = async (x, ct) => await Radarr();
Post["/radarr"] = _ => SaveRadarr();
Post["/radarr", true] = async (x, ct) => await SaveRadarr();
Post["/radarrprofiles"] = _ => GetRadarrQualityProfiles();
Get["/sickrage"] = _ => Sickrage();
@ -385,7 +385,7 @@ namespace Ombi.UI.Modules.Admin
return View["CouchPotato", settings];
}
private Response SaveCouchPotato()
private async Task<Response> SaveCouchPotato()
{
var couchPotatoSettings = this.Bind<CouchPotatoSettings>();
var valid = this.Validate(couchPotatoSettings);
@ -394,7 +394,7 @@ namespace Ombi.UI.Modules.Admin
return Response.AsJson(valid.SendJsonError());
}
var watcherSettings = WatcherSettings.GetSettings();
var watcherSettings = await WatcherSettings.GetSettingsAsync();
if (watcherSettings.Enabled)
{
@ -406,8 +406,20 @@ namespace Ombi.UI.Modules.Admin
});
}
var radarrSettings = await RadarrSettings.GetSettingsAsync();
if (radarrSettings.Enabled)
{
return
Response.AsJson(new JsonResponseModel
{
Result = false,
Message = "Cannot have Radarr and CouchPotato both enabled."
});
}
couchPotatoSettings.ApiKey = couchPotatoSettings.ApiKey.Trim();
var result = CpService.SaveSettings(couchPotatoSettings);
var result = await CpService.SaveSettingsAsync(couchPotatoSettings);
return Response.AsJson(result
? new JsonResponseModel { Result = true, Message = "Successfully Updated the Settings for CouchPotato!" }
: new JsonResponseModel { Result = false, Message = "Could not update the settings, take a look at the logs." });
@ -465,6 +477,7 @@ namespace Ombi.UI.Modules.Admin
{
return Response.AsJson(new JsonResponseModel { Result = false, Message = "SickRage is enabled, we cannot enable Sonarr and SickRage" });
}
sonarrSettings.ApiKey = sonarrSettings.ApiKey.Trim();
var result = SonarrService.SaveSettings(sonarrSettings);
@ -480,25 +493,34 @@ namespace Ombi.UI.Modules.Admin
return View["Radarr", settings];
}
private Response SaveRadarr()
private async Task<Response> SaveRadarr()
{
var sonarrSettings = this.Bind<SonarrSettings>();
var radarrSettings = this.Bind<RadarrSettings>();
var valid = this.Validate(sonarrSettings);
if (!valid.IsValid)
//Check Watcher and CP make sure they are not enabled
var watcher = await WatcherSettings.GetSettingsAsync();
if (watcher.Enabled)
{
return Response.AsJson(valid.SendJsonError());
return Response.AsJson(new JsonResponseModel { Result = false, Message = "Watcher is enabled, we cannot enable Watcher and Radarr" });
}
var sickRageEnabled = SickRageService.GetSettings().Enabled;
if (sickRageEnabled)
var cp = await CpService.GetSettingsAsync();
if (cp.Enabled)
{
return Response.AsJson(new JsonResponseModel { Result = false, Message = "SickRage is enabled, we cannot enable Sonarr and SickRage" });
return Response.AsJson(new JsonResponseModel { Result = false, Message = "CouchPotato is enabled, we cannot enable Watcher and CouchPotato" });
}
sonarrSettings.ApiKey = sonarrSettings.ApiKey.Trim();
var result = SonarrService.SaveSettings(sonarrSettings);
var valid = this.Validate(radarrSettings);
if (!valid.IsValid)
{
return Response.AsJson(valid.SendJsonError());
}
radarrSettings.ApiKey = radarrSettings.ApiKey.Trim();
var result = await RadarrSettings.SaveSettingsAsync(radarrSettings);
return Response.AsJson(result
? new JsonResponseModel { Result = true, Message = "Successfully Updated the Settings for Sonarr!" }
? new JsonResponseModel { Result = true, Message = "Successfully Updated the Settings for Radarr!" }
: new JsonResponseModel { Result = false, Message = "Could not update the settings, take a look at the logs." });
}

@ -97,6 +97,18 @@ namespace Ombi.UI.Modules.Admin
});
}
var watcherSettings = await WatcherSettings.GetSettingsAsync();
if (watcherSettings.Enabled)
{
return
Response.AsJson(new JsonResponseModel
{
Result = false,
Message = "Cannot have Watcher and CouchPotato both enabled."
});
}
settings.ApiKey = settings.ApiKey.Trim();
var result = await WatcherSettings.SaveSettingsAsync(settings);
return Response.AsJson(result

@ -76,7 +76,7 @@ namespace Ombi.UI.Modules
ISettingsService<PlexSettings> plexService, ISettingsService<AuthenticationSettings> auth,
IRepository<UsersToNotify> u, ISettingsService<EmailNotificationSettings> email,
IIssueService issue, IAnalytics a, IRepository<RequestLimit> rl, ITransientFaultQueue tfQueue, IRepository<PlexContent> content,
ISecurityExtensions security, IMovieSender movieSender)
ISecurityExtensions security, IMovieSender movieSender, IRadarrCacher radarrCacher)
: base("search", prSettings, security)
{
Auth = auth;
@ -108,6 +108,7 @@ namespace Ombi.UI.Modules
PlexContentRepository = content;
MovieSender = movieSender;
WatcherCacher = watcherCacher;
RadarrCacher = radarrCacher;
Get["SearchIndex", "/", true] = async (x, ct) => await RequestLoad();
@ -157,6 +158,7 @@ namespace Ombi.UI.Modules
private IAnalytics Analytics { get; }
private ITransientFaultQueue FaultQueue { get; }
private IRepository<RequestLimit> RequestLimitRepo { get; }
private IRadarrCacher RadarrCacher { get; }
private static Logger Log = LogManager.GetCurrentClassLogger();
private async Task<Negotiator> RequestLoad()
@ -236,6 +238,7 @@ namespace Ombi.UI.Modules
var cpCached = CpCacher.QueuedIds();
var watcherCached = WatcherCacher.QueuedIds();
var radarrCached = RadarrCacher.QueuedIds();
var content = PlexContentRepository.GetAll();
var plexMovies = Checker.GetPlexMovies(content);
var viewMovies = new List<SearchMovieViewModel>();
@ -288,13 +291,19 @@ namespace Ombi.UI.Modules
}
else if (cpCached.Contains(movie.Id) && canSee) // compare to the couchpotato db
{
viewMovie.Approved = true;
viewMovie.Requested = true;
}
else if(watcherCached.Contains(imdbId) && canSee) // compare to the watcher db
{
viewMovie.Approved = true;
viewMovie.Requested = true;
}
else if (radarrCached.Contains(movie.Id) && canSee)
{
viewMovie.Approved = true;
viewMovie.Requested = true;
}
viewMovies.Add(viewMovie);
}

@ -48,6 +48,7 @@ namespace Ombi.UI.NinjectModules
Bind<ISonarrCacher>().To<SonarrCacher>();
Bind<ISickRageCacher>().To<SickRageCacher>();
Bind<IRecentlyAdded>().To<RecentlyAdded>();
Bind<IRadarrCacher>().To<RadarrCacher>();
Bind<IPlexContentCacher>().To<PlexContentCacher>();
Bind<IJobFactory>().To<CustomJobFactory>();
Bind<IMovieSender>().To<MovieSender>();

@ -288,6 +288,7 @@
</Compile>
<Compile Include="Start\StartupOptions.cs" />
<Compile Include="Start\UpdateValue.cs" />
<Compile Include="Validators\RadarrValidator.cs" />
<Compile Include="Validators\WatcherValidator.cs" />
<Compile Include="Validators\SlackSettingsValidator.cs" />
<Compile Include="Validators\UserViewModelValidator.cs" />

@ -0,0 +1,43 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: SonarrValidator.cs
// Created By: Jamie Rees
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
using FluentValidation;
using Ombi.Core.SettingModels;
namespace Ombi.UI.Validators
{
public class RadarrValidator : AbstractValidator<RadarrSettings>
{
public RadarrValidator()
{
RuleFor(request => request.ApiKey).NotEmpty().WithMessage("You must specify a Api Key.");
RuleFor(request => request.Ip).NotEmpty().WithMessage("You must specify a IP/Host name.");
RuleFor(request => request.Port).NotEmpty().WithMessage("You must specify a Port.");
RuleFor(request => request.QualityProfile).NotEmpty().WithMessage("You must specify a Quality Profile.");
}
}
}

@ -73,7 +73,7 @@
<div class="form-group">
<div>
<button id="testSonarr" type="submit" class="btn btn-primary-outline">Test Connectivity <div id="spinner"/></button>
<button id="testRadarr" type="button" class="btn btn-primary-outline">Test Connectivity <div id="spinner"/></button>
</div>
</div>

@ -45,6 +45,14 @@
<label for="CouchPotatoCacher" class="control-label">Couch Potato Cacher (min)</label>
<input type="text" class="form-control form-control-custom " id="CouchPotatoCacher" name="CouchPotatoCacher" value="@Model.CouchPotatoCacher">
</div>
<div class="form-group">
<label for="WatcherCacher" class="control-label">Wactcher Cacher (min)</label>
<input type="text" class="form-control form-control-custom " id="WatcherCacher" name="WatcherCacher" value="@Model.WatcherCacher">
</div>
<div class="form-group">
<label for="RadarrCacher" class="control-label">Radarr Cacher (min)</label>
<input type="text" class="form-control form-control-custom " id="RadarrCacher" name="RadarrCacher" value="@Model.RadarrCacher">
</div>
<small>Please note, the minimum time for this to run is 11 hours, if set below 11 then we will ignore that value. This is a very resource intensive job, the less we run it the better.</small>
<div class="form-group">

Loading…
Cancel
Save