2017-08-21 19:48:45 +00:00
|
|
|
using System;
|
2014-08-03 07:26:55 +00:00
|
|
|
using System.Net;
|
|
|
|
using FluentValidation.Results;
|
|
|
|
using NLog;
|
2018-03-14 20:41:36 +00:00
|
|
|
using NzbDrone.Core.Movies;
|
2019-12-22 22:08:53 +00:00
|
|
|
using NzbDrone.Core.Rest;
|
2014-08-03 07:26:55 +00:00
|
|
|
|
2019-04-13 03:25:58 +00:00
|
|
|
namespace NzbDrone.Core.Notifications.Emby
|
2014-08-03 07:26:55 +00:00
|
|
|
{
|
|
|
|
public interface IMediaBrowserService
|
|
|
|
{
|
2015-10-03 17:45:26 +00:00
|
|
|
void Notify(MediaBrowserSettings settings, string title, string message);
|
2019-02-18 10:12:34 +00:00
|
|
|
void UpdateMovies(MediaBrowserSettings settings, Movie movie, string updateType);
|
2014-08-03 07:26:55 +00:00
|
|
|
ValidationFailure Test(MediaBrowserSettings settings);
|
|
|
|
}
|
|
|
|
|
|
|
|
public class MediaBrowserService : IMediaBrowserService
|
|
|
|
{
|
|
|
|
private readonly MediaBrowserProxy _proxy;
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
|
|
|
public MediaBrowserService(MediaBrowserProxy proxy, Logger logger)
|
|
|
|
{
|
|
|
|
_proxy = proxy;
|
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
2015-10-03 17:45:26 +00:00
|
|
|
public void Notify(MediaBrowserSettings settings, string title, string message)
|
2014-08-03 07:26:55 +00:00
|
|
|
{
|
|
|
|
_proxy.Notify(settings, title, message);
|
|
|
|
}
|
|
|
|
|
2019-02-18 10:12:34 +00:00
|
|
|
public void UpdateMovies(MediaBrowserSettings settings, Movie movie, string updateType)
|
2017-01-27 18:01:18 +00:00
|
|
|
{
|
2019-02-18 10:12:34 +00:00
|
|
|
_proxy.UpdateMovies(settings, movie.Path, updateType);
|
2017-01-27 18:01:18 +00:00
|
|
|
}
|
|
|
|
|
2014-08-03 07:26:55 +00:00
|
|
|
public ValidationFailure Test(MediaBrowserSettings settings)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
_logger.Debug("Testing connection to MediaBrowser: {0}", settings.Address);
|
|
|
|
|
2017-08-21 19:48:45 +00:00
|
|
|
Notify(settings, "Test from Radarr", "Success! MediaBrowser has been successfully configured!");
|
2014-08-03 07:26:55 +00:00
|
|
|
}
|
|
|
|
catch (RestException ex)
|
|
|
|
{
|
|
|
|
if (ex.Response.StatusCode == HttpStatusCode.Unauthorized)
|
|
|
|
{
|
2019-04-13 03:25:58 +00:00
|
|
|
return new ValidationFailure("ApiKey", "API Key is incorrect");
|
2014-08-03 07:26:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
2019-04-13 03:25:58 +00:00
|
|
|
_logger.Error(ex, "Unable to send test message");
|
2014-08-03 07:26:55 +00:00
|
|
|
return new ValidationFailure("Host", "Unable to send test message: " + ex.Message);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|