diff --git a/Ombi.Api.Interfaces/IEmbyApi.cs b/Ombi.Api.Interfaces/IEmbyApi.cs index ddc85868c..bc4697140 100644 --- a/Ombi.Api.Interfaces/IEmbyApi.cs +++ b/Ombi.Api.Interfaces/IEmbyApi.cs @@ -14,5 +14,6 @@ namespace Ombi.Api.Interfaces EmbyItemContainer ViewLibrary(string apiKey, string userId, Uri baseUri); EmbyInformation GetInformation(string mediaId, EmbyMediaType type, string apiKey, string userId, Uri baseUri); EmbyUser LogIn(string username, string password, string apiKey, Uri baseUri); + EmbySystemInfo GetSystemInformation(string apiKey, Uri baseUrl); } } \ No newline at end of file diff --git a/Ombi.Api.Models/Emby/EmbySystemInfo.cs b/Ombi.Api.Models/Emby/EmbySystemInfo.cs new file mode 100644 index 000000000..e4b6859fc --- /dev/null +++ b/Ombi.Api.Models/Emby/EmbySystemInfo.cs @@ -0,0 +1,63 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2017 Jamie Rees +// File: EmbySystemInfo.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 +namespace Ombi.Api.Models.Emby +{ + public class EmbySystemInfo + { + public string SystemUpdateLevel { get; set; } + public string OperatingSystemDisplayName { get; set; } + public bool SupportsRunningAsService { get; set; } + public string MacAddress { get; set; } + public bool HasPendingRestart { get; set; } + public bool SupportsLibraryMonitor { get; set; } + public object[] InProgressInstallations { get; set; } + public int WebSocketPortNumber { get; set; } + public object[] CompletedInstallations { get; set; } + public bool CanSelfRestart { get; set; } + public bool CanSelfUpdate { get; set; } + public object[] FailedPluginAssemblies { get; set; } + public string ProgramDataPath { get; set; } + public string ItemsByNamePath { get; set; } + public string CachePath { get; set; } + public string LogPath { get; set; } + public string InternalMetadataPath { get; set; } + public string TranscodingTempPath { get; set; } + public int HttpServerPortNumber { get; set; } + public bool SupportsHttps { get; set; } + public int HttpsPortNumber { get; set; } + public bool HasUpdateAvailable { get; set; } + public bool SupportsAutoRunAtStartup { get; set; } + public string EncoderLocationType { get; set; } + public string SystemArchitecture { get; set; } + public string LocalAddress { get; set; } + public string WanAddress { get; set; } + public string ServerName { get; set; } + public string Version { get; set; } + public string OperatingSystem { get; set; } + public string Id { get; set; } + } +} \ No newline at end of file diff --git a/Ombi.Api.Models/Ombi.Api.Models.csproj b/Ombi.Api.Models/Ombi.Api.Models.csproj index 3d5fc3460..eb3297999 100644 --- a/Ombi.Api.Models/Ombi.Api.Models.csproj +++ b/Ombi.Api.Models/Ombi.Api.Models.csproj @@ -71,6 +71,7 @@ + diff --git a/Ombi.Api/EmbyApi.cs b/Ombi.Api/EmbyApi.cs index 9625ffa4f..f703c0570 100644 --- a/Ombi.Api/EmbyApi.cs +++ b/Ombi.Api/EmbyApi.cs @@ -71,6 +71,26 @@ namespace Ombi.Api return obj; } + public EmbySystemInfo GetSystemInformation(string apiKey, Uri baseUrl) + { + var request = new RestRequest + { + Resource = "emby/System/Info", + Method = Method.GET + }; + + AddHeaders(request, apiKey); + + var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling GetSystemInformation for Emby, Retrying {0}", timespan), new[] { + TimeSpan.FromSeconds (1), + TimeSpan.FromSeconds(5) + }); + + var obj = policy.Execute(() => Api.ExecuteJson(request, baseUrl)); + + return obj; + } + public EmbyItemContainer ViewLibrary(string apiKey, string userId, Uri baseUri) { var request = new RestRequest diff --git a/Ombi.UI/Modules/LandingPageModule.cs b/Ombi.UI/Modules/LandingPageModule.cs index 5f1076be8..d544af2c3 100644 --- a/Ombi.UI/Modules/LandingPageModule.cs +++ b/Ombi.UI/Modules/LandingPageModule.cs @@ -40,12 +40,15 @@ namespace Ombi.UI.Modules public class LandingPageModule : BaseModule { public LandingPageModule(ISettingsService settingsService, ISettingsService landing, - ISettingsService ps, IPlexApi pApi, IResourceLinker linker, ISecurityExtensions security) : base("landing", settingsService, security) + ISettingsService ps, IPlexApi pApi, IResourceLinker linker, ISecurityExtensions security, ISettingsService emby, + IEmbyApi embyApi) : base("landing", settingsService, security) { LandingSettings = landing; PlexSettings = ps; PlexApi = pApi; Linker = linker; + EmbySettings = emby; + EmbyApi = embyApi; Get["LandingPageIndex","/", true] = async (x, ct) => { @@ -75,26 +78,49 @@ namespace Ombi.UI.Modules private ISettingsService LandingSettings { get; } private ISettingsService PlexSettings { get; } + private ISettingsService EmbySettings { get; } private IPlexApi PlexApi { get; } + private IEmbyApi EmbyApi { get; } private IResourceLinker Linker { get; } private async Task CheckStatus() { var plexSettings = await PlexSettings.GetSettingsAsync(); - if (string.IsNullOrEmpty(plexSettings.PlexAuthToken) || string.IsNullOrEmpty(plexSettings.Ip)) + if (plexSettings.Enable) { - return Response.AsJson(false); - } - try - { - var status = PlexApi.GetStatus(plexSettings.PlexAuthToken, plexSettings.FullUri); - return Response.AsJson(status != null); + if (string.IsNullOrEmpty(plexSettings.PlexAuthToken) || string.IsNullOrEmpty(plexSettings.Ip)) + { + return Response.AsJson(false); + } + try + { + var status = PlexApi.GetStatus(plexSettings.PlexAuthToken, plexSettings.FullUri); + return Response.AsJson(status != null); + } + catch (Exception) + { + return Response.AsJson(false); + } } - catch (Exception) + + var emby = await EmbySettings.GetSettingsAsync(); + if (emby.Enable) { - return Response.AsJson(false); + if (string.IsNullOrEmpty(emby.AdministratorId) || string.IsNullOrEmpty(emby.Ip)) + { + return Response.AsJson(false); + } + try + { + var status = EmbyApi.GetSystemInformation(emby.ApiKey, emby.FullUri); + return Response.AsJson(status?.Version != null); + } + catch (Exception) + { + return Response.AsJson(false); + } } - + return Response.AsJson(false); } } } \ No newline at end of file