Improve Emby/Jellyfin connection test

This commit is contained in:
Stevie Robinson 2025-07-08 02:35:32 +02:00 committed by GitHub
parent dfb6fdfbeb
commit 8b7f9daab0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 36 additions and 18 deletions

View file

@ -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,22 +43,8 @@ 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)
{ {

View file

@ -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;
} }
} }