mirror of
https://github.com/Sonarr/Sonarr
synced 2025-12-06 08:28:37 +01:00
Improve Emby/Jellyfin connection test
This commit is contained in:
parent
dfb6fdfbeb
commit
8b7f9daab0
2 changed files with 36 additions and 18 deletions
|
|
@ -1,7 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
|
||||||
using NLog;
|
using NLog;
|
||||||
using NzbDrone.Common.Http;
|
using NzbDrone.Common.Http;
|
||||||
using NzbDrone.Common.Serializer;
|
using NzbDrone.Common.Serializer;
|
||||||
|
|
@ -20,6 +19,16 @@ public MediaBrowserProxy(IHttpClient httpClient, Logger logger)
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void TestConnection(MediaBrowserSettings settings)
|
||||||
|
{
|
||||||
|
var path = "/System/Configuration";
|
||||||
|
var request = BuildRequest(path, settings);
|
||||||
|
request.Headers.Add("X-MediaBrowser-Token", settings.ApiKey);
|
||||||
|
|
||||||
|
var response = _httpClient.Get(request);
|
||||||
|
_logger.Trace("Response: {0}", response.Content);
|
||||||
|
}
|
||||||
|
|
||||||
public void Notify(MediaBrowserSettings settings, string title, string message)
|
public void Notify(MediaBrowserSettings settings, string title, string message)
|
||||||
{
|
{
|
||||||
var path = "/Notifications/Admin";
|
var path = "/Notifications/Admin";
|
||||||
|
|
@ -34,21 +43,7 @@ public void Notify(MediaBrowserSettings settings, string title, string message)
|
||||||
ImageUrl = "https://raw.github.com/Sonarr/Sonarr/develop/Logo/64.png"
|
ImageUrl = "https://raw.github.com/Sonarr/Sonarr/develop/Logo/64.png"
|
||||||
}.ToJson());
|
}.ToJson());
|
||||||
|
|
||||||
try
|
ProcessRequest(request, settings);
|
||||||
{
|
|
||||||
ProcessRequest(request, settings);
|
|
||||||
}
|
|
||||||
catch (HttpException e)
|
|
||||||
{
|
|
||||||
if (e.Response.StatusCode == HttpStatusCode.NotFound)
|
|
||||||
{
|
|
||||||
_logger.Warn("Unable to send notification to Emby. If you're using Jellyfin disable 'Send Notifications'");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashSet<string> GetPaths(MediaBrowserSettings settings, Series series)
|
public HashSet<string> GetPaths(MediaBrowserSettings settings, Series series)
|
||||||
|
|
|
||||||
|
|
@ -62,8 +62,7 @@ public ValidationFailure Test(MediaBrowserSettings settings)
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_logger.Debug("Testing connection to Emby/Jellyfin : {0}", settings.Address);
|
_logger.Debug("Testing connection to Emby/Jellyfin : {0}", settings.Address);
|
||||||
|
_proxy.TestConnection(settings);
|
||||||
Notify(settings, "Test from Sonarr", "Success! MediaBrowser has been successfully configured!");
|
|
||||||
}
|
}
|
||||||
catch (HttpException ex)
|
catch (HttpException ex)
|
||||||
{
|
{
|
||||||
|
|
@ -71,6 +70,11 @@ public ValidationFailure Test(MediaBrowserSettings settings)
|
||||||
{
|
{
|
||||||
return new ValidationFailure("ApiKey", _localizationService.GetLocalizedString("NotificationsValidationInvalidApiKey"));
|
return new ValidationFailure("ApiKey", _localizationService.GetLocalizedString("NotificationsValidationInvalidApiKey"));
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.Trace(ex, "Error when connecting to Emby/Jellyfin");
|
||||||
|
return new ValidationFailure("Host", _localizationService.GetLocalizedString("NotificationsValidationUnableToSendTestMessage", new Dictionary<string, object> { { "exceptionMessage", ex.Message } }));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
@ -78,6 +82,25 @@ public ValidationFailure Test(MediaBrowserSettings settings)
|
||||||
return new ValidationFailure("Host", _localizationService.GetLocalizedString("NotificationsValidationUnableToSendTestMessage", new Dictionary<string, object> { { "exceptionMessage", ex.Message } }));
|
return new ValidationFailure("Host", _localizationService.GetLocalizedString("NotificationsValidationUnableToSendTestMessage", new Dictionary<string, object> { { "exceptionMessage", ex.Message } }));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (settings.Notify)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Notify(settings, "Test from Sonarr", "Success! MediaBrowser has been successfully configured!");
|
||||||
|
}
|
||||||
|
catch (HttpException ex)
|
||||||
|
{
|
||||||
|
if (ex.Response.StatusCode == HttpStatusCode.NotFound)
|
||||||
|
{
|
||||||
|
return new ValidationFailure("Notify", "Unable to send notification to Emby. If you're using Jellyfin disable 'Send Notifications'");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue