diff --git a/Ombi.Core/CacheKeys.cs b/Ombi.Core/CacheKeys.cs index 3638875eb..5e6e6c1f3 100644 --- a/Ombi.Core/CacheKeys.cs +++ b/Ombi.Core/CacheKeys.cs @@ -37,6 +37,7 @@ namespace Ombi.Core public const string PlexEpisodes = nameof(PlexEpisodes); public const string TvDbToken = nameof(TvDbToken); public const string SonarrQualityProfiles = nameof(SonarrQualityProfiles); + public const string RadarrQualityProfiles = nameof(RadarrQualityProfiles); public const string SonarrQueued = nameof(SonarrQueued); public const string SickRageQualityProfiles = nameof(SickRageQualityProfiles); public const string SickRageQueued = nameof(SickRageQueued); diff --git a/Ombi.UI/Modules/Admin/AdminModule.cs b/Ombi.UI/Modules/Admin/AdminModule.cs index c0d79d183..81b0f8422 100644 --- a/Ombi.UI/Modules/Admin/AdminModule.cs +++ b/Ombi.UI/Modules/Admin/AdminModule.cs @@ -95,6 +95,8 @@ namespace Ombi.UI.Modules.Admin private ISettingsService NotifySettings { get; } private ISettingsService DiscordSettings { get; } private IDiscordApi DiscordApi { get; } + private ISettingsService RadarrSettings { get; } + private IRadarrApi RadarrApi { get; } private static Logger Log = LogManager.GetCurrentClassLogger(); public AdminModule(ISettingsService prService, @@ -122,7 +124,7 @@ namespace Ombi.UI.Modules.Admin ISettingsService notifyService, IRecentlyAdded recentlyAdded, ISettingsService watcherSettings , ISettingsService discord, - IDiscordApi discordapi + IDiscordApi discordapi, ISettingsService settings, IRadarrApi radarrApi , ISecurityExtensions security) : base("admin", prService, security) { PrService = prService; @@ -156,6 +158,8 @@ namespace Ombi.UI.Modules.Admin WatcherSettings = watcherSettings; DiscordSettings = discord; DiscordApi = discordapi; + RadarrSettings = settings; + RadarrApi = radarrApi; Before += (ctx) => Security.AdminLoginRedirect(Permissions.Administrator, ctx); @@ -178,11 +182,15 @@ namespace Ombi.UI.Modules.Admin Get["/sonarr"] = _ => Sonarr(); Post["/sonarr"] = _ => SaveSonarr(); + Post["/sonarrprofiles"] = _ => GetSonarrQualityProfiles(); + + Get["/radarr", true] = async (x, ct) => await Radarr(); + Post["/radarr"] = _ => SaveRadarr(); + Post["/radarrprofiles"] = _ => GetRadarrQualityProfiles(); Get["/sickrage"] = _ => Sickrage(); Post["/sickrage"] = _ => SaveSickrage(); - Post["/sonarrprofiles"] = _ => GetSonarrQualityProfiles(); Post["/cpprofiles", true] = async (x, ct) => await GetCpProfiles(); Post["/cpapikey"] = x => GetCpApiKey(); @@ -465,6 +473,49 @@ namespace Ombi.UI.Modules.Admin : new JsonResponseModel { Result = false, Message = "Could not update the settings, take a look at the logs." }); } + private async Task Radarr() + { + var settings = await RadarrSettings.GetSettingsAsync(); + + return View["Radarr", settings]; + } + + private Response SaveRadarr() + { + var sonarrSettings = this.Bind(); + + var valid = this.Validate(sonarrSettings); + if (!valid.IsValid) + { + return Response.AsJson(valid.SendJsonError()); + } + var sickRageEnabled = SickRageService.GetSettings().Enabled; + if (sickRageEnabled) + { + 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); + + return Response.AsJson(result + ? new JsonResponseModel { Result = true, Message = "Successfully Updated the Settings for Sonarr!" } + : new JsonResponseModel { Result = false, Message = "Could not update the settings, take a look at the logs." }); + } + + private Response GetRadarrQualityProfiles() + { + var settings = this.Bind(); + var profiles = RadarrApi.GetProfiles(settings.ApiKey, settings.FullUri); + + // set the cache + if (profiles != null) + { + Cache.Set(CacheKeys.RadarrQualityProfiles, profiles); + } + + return Response.AsJson(profiles); + } + private Negotiator Sickrage() { var settings = SickRageService.GetSettings(); diff --git a/Ombi.UI/Modules/ApplicationTesterModule.cs b/Ombi.UI/Modules/ApplicationTesterModule.cs index b0d4f2d17..a7608f547 100644 --- a/Ombi.UI/Modules/ApplicationTesterModule.cs +++ b/Ombi.UI/Modules/ApplicationTesterModule.cs @@ -46,7 +46,7 @@ namespace Ombi.UI.Modules public ApplicationTesterModule(ICouchPotatoApi cpApi, ISonarrApi sonarrApi, IPlexApi plexApi, ISickRageApi srApi, IHeadphonesApi hpApi, ISettingsService pr, ISecurityExtensions security, - IWatcherApi watcherApi) : base("test", pr, security) + IWatcherApi watcherApi, IRadarrApi radarrApi) : base("test", pr, security) { this.RequiresAuthentication(); @@ -56,9 +56,11 @@ namespace Ombi.UI.Modules SickRageApi = srApi; HeadphonesApi = hpApi; WatcherApi = watcherApi; + RadarrApi = radarrApi; Post["/cp"] = _ => CouchPotatoTest(); Post["/sonarr"] = _ => SonarrTest(); + Post["/radarr"] = _ => RadarrTest(); Post["/plex"] = _ => PlexTest(); Post["/sickrage"] = _ => SickRageTest(); Post["/headphones"] = _ => HeadphonesTest(); @@ -73,6 +75,7 @@ namespace Ombi.UI.Modules private ISickRageApi SickRageApi { get; } private IHeadphonesApi HeadphonesApi { get; } private IWatcherApi WatcherApi { get; } + private IRadarrApi RadarrApi { get; } private Response CouchPotatoTest() { @@ -148,7 +151,7 @@ namespace Ombi.UI.Modules : Response.AsJson(new JsonResponseModel { Result = false, Message = "Could not connect to Sonarr, please check your settings." }); } - catch (Exception e) // Exceptions are expected, if we cannot connect so we will just log and swallow them. + catch (Exception e) // Exceptions are expected, if we cannot connect so we will just log and swallow them. { Log.Warn("Exception thrown when attempting to get Sonarr's status: "); Log.Warn(e); @@ -161,6 +164,35 @@ namespace Ombi.UI.Modules } } + private Response RadarrTest() + { + var radarrSettings = this.Bind(); + var valid = this.Validate(radarrSettings); + if (!valid.IsValid) + { + return Response.AsJson(valid.SendJsonError()); + } + try + { + var status = RadarrApi.SystemStatus(radarrSettings.ApiKey, radarrSettings.FullUri); + return status?.version != null + ? Response.AsJson(new JsonResponseModel { Result = true, Message = "Connected to Radarr successfully!" }) + : Response.AsJson(new JsonResponseModel { Result = false, Message = "Could not connect to Radarr, please check your settings." }); + + } + catch (Exception e) // Exceptions are expected, if we cannot connect so we will just log and swallow them. + { + Log.Warn("Exception thrown when attempting to get Radarr's status: "); + Log.Warn(e); + var message = $"Could not connect to Radarr, please check your settings. Exception Message: {e.Message}"; + if (e.InnerException != null) + { + message = $"Could not connect to Radarr, please check your settings. Exception Message: {e.InnerException.Message}"; + } + return Response.AsJson(new JsonResponseModel { Result = false, Message = message }); + } + } + private Response PlexTest() { var plexSettings = this.Bind(); diff --git a/Ombi.UI/NinjectModules/ApiModule.cs b/Ombi.UI/NinjectModules/ApiModule.cs index 9de21af99..873a3c527 100644 --- a/Ombi.UI/NinjectModules/ApiModule.cs +++ b/Ombi.UI/NinjectModules/ApiModule.cs @@ -48,6 +48,7 @@ namespace Ombi.UI.NinjectModules Bind().To(); Bind().To(); Bind().To(); + Bind().To(); } } } \ No newline at end of file diff --git a/Ombi.UI/Startup.cs b/Ombi.UI/Startup.cs index e366901c1..ff8590da4 100644 --- a/Ombi.UI/Startup.cs +++ b/Ombi.UI/Startup.cs @@ -124,6 +124,10 @@ namespace Ombi.UI var slackService = container.Get>(); var slackSettings = slackService.GetSettings(); SubScribeOvserver(slackSettings, notificationService, new SlackNotification(container.Get(), slackService)); + + var discordSettings = container.Get>(); + var discordService = discordSettings.GetSettings(); + SubScribeOvserver(discordService, notificationService, new DiscordNotification(container.Get(), discordSettings)); } private void SubScribeOvserver(T settings, INotificationService notificationService, INotification notification) diff --git a/Ombi.UI/Views/Admin/Radarr.cshtml b/Ombi.UI/Views/Admin/Radarr.cshtml index bec991c71..e0ce08d07 100644 --- a/Ombi.UI/Views/Admin/Radarr.cshtml +++ b/Ombi.UI/Views/Admin/Radarr.cshtml @@ -67,26 +67,10 @@
- +
-
-
- - @if (Model.SeasonFolders) - { - - } - else - { - - } - - -
- -
@@ -124,7 +108,7 @@ $.ajax({ type: $form.prop("method"), data: $form.serialize(), - url: "sonarrprofiles", + url: "radarrprofiles", dataType: "json", success: function(response) { response.forEach(function(result) { @@ -202,7 +186,7 @@ $.ajax({ type: $form.prop("method"), data: $form.serialize(), - url: "sonarrprofiles", + url: "radarrprofiles", dataType: "json", success: function (response) { response.forEach(function (result) { @@ -219,7 +203,7 @@ }); var base = '@Html.GetBaseUrl()'; - $('#testSonarr').click(function (e) { + $('#testRadarr').click(function (e) { $('#spinner').attr("class", "fa fa-spinner fa-spin"); e.preventDefault(); @@ -230,7 +214,7 @@ var data = $form.serialize(); data = data + "&qualityProfile=" + qualityProfile; - var url = createBaseUrl(base, '/test/sonarr'); + var url = createBaseUrl(base, '/test/radarr'); $.ajax({ type: $form.prop("method"), url: url, diff --git a/Ombi.UI/Views/Shared/Partial/_Sidebar.cshtml b/Ombi.UI/Views/Shared/Partial/_Sidebar.cshtml index d38827cf8..a2b1dc021 100644 --- a/Ombi.UI/Views/Shared/Partial/_Sidebar.cshtml +++ b/Ombi.UI/Views/Shared/Partial/_Sidebar.cshtml @@ -11,6 +11,7 @@ @Html.GetSidebarUrl(Context, "/admin/plex", "Plex") @Html.GetSidebarUrl(Context, "/admin/couchpotato", "CouchPotato") @Html.GetSidebarUrl(Context, "/admin/watcher", "Watcher (beta)") + @Html.GetSidebarUrl(Context, "/admin/radarr", "Radarr (beta)") @Html.GetSidebarUrl(Context, "/admin/sonarr", "Sonarr") @Html.GetSidebarUrl(Context, "/admin/sickrage", "SickRage") @Html.GetSidebarUrl(Context, "/admin/headphones", "Headphones (beta)")