pull/3528/head
tidusjar 5 years ago
parent 82f41074ab
commit 4340dc44bf

@ -0,0 +1,41 @@
using Ombi.Api;
using Ombi.Core.Settings;
using Ombi.Core.Settings.Models.External;
using System.Threading.Tasks;
namespace Ombi.Api.Emby
{
public class EmbyApiFactory : IEmbyApiFactory
{
private readonly ISettingsService<EmbySettings> _embySettings;
private readonly IApi _api;
// TODO, if we need to derive futher, need to rework
public EmbyApiFactory(ISettingsService<EmbySettings> embySettings, IApi api)
{
_embySettings = embySettings;
_api = api;
}
public async Task<IEmbyApi> CreateClient()
{
var settings = await _embySettings.GetSettingsAsync();
return CreateClient(settings);
}
public IEmbyApi CreateClient(EmbySettings settings)
{
if (settings.IsJellyfin)
{
return new JellyfinApi(_api);
}
return new EmbyApi(_api);
}
}
public interface IEmbyApiFactory
{
Task<IEmbyApi> CreateClient();
IEmbyApi CreateClient(EmbySettings settings);
}
}

@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Ombi.Api.Emby.Models;
using Ombi.Api.Emby.Models.Media.Tv;
using Ombi.Api.Emby.Models.Movie;
namespace Ombi.Api.Emby
{
public interface IBaseEmbyApi
{
Task<EmbySystemInfo> GetSystemInformation(string apiKey, string baseUrl);
Task<List<EmbyUser>> GetUsers(string baseUri, string apiKey);
Task<EmbyUser> LogIn(string username, string password, string apiKey, string baseUri);
Task<EmbyItemContainer<EmbyMovie>> GetAllMovies(string apiKey, int startIndex, int count, string userId,
string baseUri);
Task<EmbyItemContainer<EmbyEpisodes>> GetAllEpisodes(string apiKey, int startIndex, int count, string userId,
string baseUri);
Task<EmbyItemContainer<EmbySeries>> GetAllShows(string apiKey, int startIndex, int count, string userId,
string baseUri);
Task<EmbyItemContainer<EmbyMovie>> GetCollection(string mediaId,
string apiKey, string userId, string baseUrl);
Task<SeriesInformation> GetSeriesInformation(string mediaId, string apiKey, string userId, string baseUrl);
Task<MovieInformation> GetMovieInformation(string mediaId, string apiKey, string userId, string baseUrl);
Task<EpisodeInformation> GetEpisodeInformation(string mediaId, string apiKey, string userId, string baseUrl);
Task<PublicInfo> GetPublicInformation(string baseUrl);
}
}

@ -1,34 +1,10 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Threading.Tasks;
using Ombi.Api.Emby.Models;
using Ombi.Api.Emby.Models.Media.Tv;
using Ombi.Api.Emby.Models.Movie;
namespace Ombi.Api.Emby
{
public interface IEmbyApi
{
Task<EmbySystemInfo> GetSystemInformation(string apiKey, string baseUrl);
Task<List<EmbyUser>> GetUsers(string baseUri, string apiKey);
Task<EmbyUser> LogIn(string username, string password, string apiKey, string baseUri);
public interface IEmbyApi : IBaseEmbyApi
{
Task<EmbyConnectUser> LoginConnectUser(string username, string password);
Task<EmbyItemContainer<EmbyMovie>> GetAllMovies(string apiKey, int startIndex, int count, string userId,
string baseUri);
Task<EmbyItemContainer<EmbyEpisodes>> GetAllEpisodes(string apiKey, int startIndex, int count, string userId,
string baseUri);
Task<EmbyItemContainer<EmbySeries>> GetAllShows(string apiKey, int startIndex, int count, string userId,
string baseUri);
Task<EmbyItemContainer<EmbyMovie>> GetCollection(string mediaId,
string apiKey, string userId, string baseUrl);
Task<SeriesInformation> GetSeriesInformation(string mediaId, string apiKey, string userId, string baseUrl);
Task<MovieInformation> GetMovieInformation(string mediaId, string apiKey, string userId, string baseUrl);
Task<EpisodeInformation> GetEpisodeInformation(string mediaId, string apiKey, string userId, string baseUrl);
Task<PublicInfo> GetPublicInformation(string baseUrl);
}
}

@ -0,0 +1,180 @@
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore.Internal;
using Newtonsoft.Json;
using Ombi.Api.Emby.Models;
using Ombi.Api.Emby.Models.Media.Tv;
using Ombi.Api.Emby.Models.Movie;
using Ombi.Helpers;
namespace Ombi.Api.Emby
{
public class JellyfinApi : IEmbyApi
{
public JellyfinApi(IApi api)
{
Api = api;
}
private IApi Api { get; }
/// <summary>
/// Returns all users from the Emby Instance
/// </summary>
/// <param name="baseUri"></param>
/// <param name="apiKey"></param>
public async Task<List<EmbyUser>> GetUsers(string baseUri, string apiKey)
{
var request = new Request("jellyfin/users", baseUri, HttpMethod.Get);
AddHeaders(request, apiKey);
var obj = await Api.Request<List<EmbyUser>>(request);
return obj;
}
public async Task<EmbySystemInfo> GetSystemInformation(string apiKey, string baseUrl)
{
var request = new Request("jellyfin/System/Info", baseUrl, HttpMethod.Get);
AddHeaders(request, apiKey);
var obj = await Api.Request<EmbySystemInfo>(request);
return obj;
}
public async Task<PublicInfo> GetPublicInformation(string baseUrl)
{
var request = new Request("jellyfin/System/Info/public", baseUrl, HttpMethod.Get);
AddHeaders(request, string.Empty);
var obj = await Api.Request<PublicInfo>(request);
return obj;
}
public async Task<EmbyUser> LogIn(string username, string password, string apiKey, string baseUri)
{
var request = new Request("jellyfin/users/authenticatebyname", baseUri, HttpMethod.Post);
var body = new
{
username,
pw = password,
};
request.AddJsonBody(body);
request.AddHeader("X-Emby-Authorization",
$"MediaBrowser Client=\"Ombi\", Device=\"Ombi\", DeviceId=\"v3\", Version=\"v3\"");
AddHeaders(request, apiKey);
var obj = await Api.Request<EmbyUser>(request);
return obj;
}
public async Task<EmbyItemContainer<EmbyMovie>> GetCollection(string mediaId, string apiKey, string userId, string baseUrl)
{
var request = new Request($"jellyfin/users/{userId}/items?parentId={mediaId}", baseUrl, HttpMethod.Get);
AddHeaders(request, apiKey);
request.AddQueryString("Fields", "ProviderIds,Overview");
request.AddQueryString("IsVirtualItem", "False");
return await Api.Request<EmbyItemContainer<EmbyMovie>>(request);
}
public async Task<EmbyItemContainer<EmbyMovie>> GetAllMovies(string apiKey, int startIndex, int count, string userId, string baseUri)
{
return await GetAll<EmbyMovie>("Movie", apiKey, userId, baseUri, true, startIndex, count);
}
public async Task<EmbyItemContainer<EmbyEpisodes>> GetAllEpisodes(string apiKey, int startIndex, int count, string userId, string baseUri)
{
return await GetAll<EmbyEpisodes>("Episode", apiKey, userId, baseUri, false, startIndex, count);
}
public async Task<EmbyItemContainer<EmbySeries>> GetAllShows(string apiKey, int startIndex, int count, string userId, string baseUri)
{
return await GetAll<EmbySeries>("Series", apiKey, userId, baseUri, false, startIndex, count);
}
public async Task<SeriesInformation> GetSeriesInformation(string mediaId, string apiKey, string userId, string baseUrl)
{
return await GetInformation<SeriesInformation>(mediaId, apiKey, userId, baseUrl);
}
public async Task<MovieInformation> GetMovieInformation(string mediaId, string apiKey, string userId, string baseUrl)
{
return await GetInformation<MovieInformation>(mediaId, apiKey, userId, baseUrl);
}
public async Task<EpisodeInformation> GetEpisodeInformation(string mediaId, string apiKey, string userId, string baseUrl)
{
return await GetInformation<EpisodeInformation>(mediaId, apiKey, userId, baseUrl);
}
private async Task<T> GetInformation<T>(string mediaId, string apiKey, string userId, string baseUrl)
{
var request = new Request($"jellyfin/users/{userId}/items/{mediaId}", baseUrl, HttpMethod.Get);
AddHeaders(request, apiKey);
var response = await Api.RequestContent(request);
return JsonConvert.DeserializeObject<T>(response);
}
private async Task<EmbyItemContainer<T>> GetAll<T>(string type, string apiKey, string userId, string baseUri, bool includeOverview = false)
{
var request = new Request($"jellyfin/users/{userId}/items", baseUri, HttpMethod.Get);
request.AddQueryString("Recursive", true.ToString());
request.AddQueryString("IncludeItemTypes", type);
request.AddQueryString("Fields", includeOverview ? "ProviderIds,Overview" : "ProviderIds");
request.AddQueryString("IsVirtualItem", "False");
AddHeaders(request, apiKey);
var obj = await Api.Request<EmbyItemContainer<T>>(request);
return obj;
}
private async Task<EmbyItemContainer<T>> GetAll<T>(string type, string apiKey, string userId, string baseUri, bool includeOverview, int startIndex, int count)
{
var request = new Request($"jellyfin/users/{userId}/items", baseUri, HttpMethod.Get);
request.AddQueryString("Recursive", true.ToString());
request.AddQueryString("IncludeItemTypes", type);
request.AddQueryString("Fields", includeOverview ? "ProviderIds,Overview" : "ProviderIds");
request.AddQueryString("startIndex", startIndex.ToString());
request.AddQueryString("limit", count.ToString());
request.AddQueryString("IsVirtualItem", "False");
AddHeaders(request, apiKey);
var obj = await Api.Request<EmbyItemContainer<T>>(request);
return obj;
}
private static void AddHeaders(Request req, string apiKey)
{
if (!string.IsNullOrEmpty(apiKey))
{
req.AddHeader("X-MediaBrowser-Token", apiKey);
}
req.AddHeader("Accept", "application/json");
req.AddContentHeader("Content-Type", "application/json");
req.AddHeader("Device", "Ombi");
}
public Task<EmbyConnectUser> LoginConnectUser(string username, string password)
{
throw new System.NotImplementedException();
}
}
}

@ -49,7 +49,7 @@ namespace Ombi.Core.Authentication
IPasswordHasher<OmbiUser> passwordHasher, IEnumerable<IUserValidator<OmbiUser>> userValidators,
IEnumerable<IPasswordValidator<OmbiUser>> passwordValidators, ILookupNormalizer keyNormalizer,
IdentityErrorDescriber errors, IServiceProvider services, ILogger<UserManager<OmbiUser>> logger, IPlexApi plexApi,
IEmbyApi embyApi, ISettingsService<EmbySettings> embySettings, ISettingsService<AuthenticationSettings> auth)
IEmbyApiFactory embyApi, ISettingsService<EmbySettings> embySettings, ISettingsService<AuthenticationSettings> auth)
: base(store, optionsAccessor, passwordHasher, userValidators, passwordValidators, keyNormalizer, errors, services, logger)
{
_plexApi = plexApi;
@ -59,7 +59,7 @@ namespace Ombi.Core.Authentication
}
private readonly IPlexApi _plexApi;
private readonly IEmbyApi _embyApi;
private readonly IEmbyApiFactory _embyApi;
private readonly ISettingsService<EmbySettings> _embySettings;
private readonly ISettingsService<AuthenticationSettings> _authSettings;
@ -146,9 +146,12 @@ namespace Ombi.Core.Authentication
/// <returns></returns>
private async Task<bool> CheckEmbyPasswordAsync(OmbiUser user, string password)
{
var embySettings = await _embySettings.GetSettingsAsync();
var client = _embyApi.CreateClient(embySettings);
if (user.IsEmbyConnect)
{
var result = await _embyApi.LoginConnectUser(user.UserName, password);
var result = await client.LoginConnectUser(user.UserName, password);
if (result.AccessToken.HasValue())
{
// We cannot update the email address in the user importer due to there is no way
@ -165,12 +168,11 @@ namespace Ombi.Core.Authentication
}
}
var embySettings = await _embySettings.GetSettingsAsync();
foreach (var server in embySettings.Servers)
{
try
{
var result = await _embyApi.LogIn(user.UserName, password, server.ApiKey, server.FullUri);
var result = await client.LogIn(user.UserName, password, server.ApiKey, server.FullUri);
if (result != null)
{
return true;

@ -151,6 +151,8 @@ namespace Ombi.DependencyInjection
services.AddTransient<IMusicBrainzApi, MusicBrainzApi>();
services.AddTransient<IWhatsAppApi, WhatsAppApi>();
services.AddTransient<ICloudMobileNotification, CloudMobileNotification>();
services.AddTransient<IBaseEmbyApi, JellyfinApi>();
services.AddTransient<IEmbyApiFactory, EmbyApiFactory>();
}
public static void RegisterStore(this IServiceCollection services) {

@ -25,17 +25,18 @@ namespace Ombi.HealthChecks.Checks
using (var scope = CreateScope())
{
var settingsProvider = scope.ServiceProvider.GetRequiredService<ISettingsService<EmbySettings>>();
var api = scope.ServiceProvider.GetRequiredService<IEmbyApi>();
var api = scope.ServiceProvider.GetRequiredService<IEmbyApiFactory>();
var settings = await settingsProvider.GetSettingsAsync();
if (settings == null)
{
return HealthCheckResult.Healthy("Emby is not configured.");
}
var client = api.CreateClient(settings);
var taskResult = new List<Task<EmbySystemInfo>>();
foreach (var server in settings.Servers)
{
taskResult.Add(api.GetSystemInformation(server.ApiKey, server.FullUri));
taskResult.Add(client.GetSystemInformation(server.ApiKey, server.FullUri));
}
try

@ -20,28 +20,30 @@ namespace Ombi.Schedule.Jobs.Emby
{
public class EmbyContentSync : IEmbyContentSync
{
public EmbyContentSync(ISettingsService<EmbySettings> settings, IEmbyApi api, ILogger<EmbyContentSync> logger,
public EmbyContentSync(ISettingsService<EmbySettings> settings, IEmbyApiFactory api, ILogger<EmbyContentSync> logger,
IEmbyContentRepository repo, IHubContext<NotificationHub> notification)
{
_logger = logger;
_settings = settings;
_api = api;
_apiFactory = api;
_repo = repo;
_notification = notification;
}
private readonly ILogger<EmbyContentSync> _logger;
private readonly ISettingsService<EmbySettings> _settings;
private readonly IEmbyApi _api;
private readonly IEmbyApiFactory _apiFactory;
private readonly IEmbyContentRepository _repo;
private readonly IHubContext<NotificationHub> _notification;
private IEmbyApi Api { get; set; }
public async Task Execute(IJobExecutionContext job)
{
var embySettings = await _settings.GetSettingsAsync();
if (!embySettings.Enable)
return;
Api = _apiFactory.CreateClient(embySettings);
await _notification.Clients.Clients(NotificationHub.AdminConnectionIds)
.SendAsync(NotificationHub.NotificationEvent, "Emby Content Sync Started");
@ -76,7 +78,7 @@ namespace Ombi.Schedule.Jobs.Emby
//await _repo.ExecuteSql("DELETE FROM EmbyEpisode");
//await _repo.ExecuteSql("DELETE FROM EmbyContent");
var movies = await _api.GetAllMovies(server.ApiKey, 0, 200, server.AdministratorId, server.FullUri);
var movies = await Api.GetAllMovies(server.ApiKey, 0, 200, server.AdministratorId, server.FullUri);
var totalCount = movies.TotalRecordCount;
var processed = 1;
@ -89,7 +91,7 @@ namespace Ombi.Schedule.Jobs.Emby
if (movie.Type.Equals("boxset", StringComparison.InvariantCultureIgnoreCase))
{
var movieInfo =
await _api.GetCollection(movie.Id, server.ApiKey, server.AdministratorId, server.FullUri);
await Api.GetCollection(movie.Id, server.ApiKey, server.AdministratorId, server.FullUri);
foreach (var item in movieInfo.Items)
{
await ProcessMovies(item, mediaToAdd, server);
@ -106,7 +108,7 @@ namespace Ombi.Schedule.Jobs.Emby
}
// Get the next batch
movies = await _api.GetAllMovies(server.ApiKey, processed, 200, server.AdministratorId, server.FullUri);
movies = await Api.GetAllMovies(server.ApiKey, processed, 200, server.AdministratorId, server.FullUri);
await _repo.AddRange(mediaToAdd);
mediaToAdd.Clear();
@ -114,7 +116,7 @@ namespace Ombi.Schedule.Jobs.Emby
// TV Time
var tv = await _api.GetAllShows(server.ApiKey, 0, 200, server.AdministratorId, server.FullUri);
var tv = await Api.GetAllShows(server.ApiKey, 0, 200, server.AdministratorId, server.FullUri);
var totalTv = tv.TotalRecordCount;
processed = 1;
while (processed < totalTv)
@ -160,7 +162,7 @@ namespace Ombi.Schedule.Jobs.Emby
}
}
// Get the next batch
tv = await _api.GetAllShows(server.ApiKey, processed, 200, server.AdministratorId, server.FullUri);
tv = await Api.GetAllShows(server.ApiKey, processed, 200, server.AdministratorId, server.FullUri);
await _repo.AddRange(mediaToAdd);
mediaToAdd.Clear();
}

@ -44,10 +44,10 @@ namespace Ombi.Schedule.Jobs.Emby
{
public class EmbyEpisodeSync : IEmbyEpisodeSync
{
public EmbyEpisodeSync(ISettingsService<EmbySettings> s, IEmbyApi api, ILogger<EmbyEpisodeSync> l, IEmbyContentRepository repo
public EmbyEpisodeSync(ISettingsService<EmbySettings> s, IEmbyApiFactory api, ILogger<EmbyEpisodeSync> l, IEmbyContentRepository repo
, IHubContext<NotificationHub> notification)
{
_api = api;
_apiFactory = api;
_logger = l;
_settings = s;
_repo = repo;
@ -55,16 +55,18 @@ namespace Ombi.Schedule.Jobs.Emby
}
private readonly ISettingsService<EmbySettings> _settings;
private readonly IEmbyApi _api;
private readonly IEmbyApiFactory _apiFactory;
private readonly ILogger<EmbyEpisodeSync> _logger;
private readonly IEmbyContentRepository _repo;
private readonly IHubContext<NotificationHub> _notification;
private IEmbyApi Api { get; set; }
public async Task Execute(IJobExecutionContext job)
{
var settings = await _settings.GetSettingsAsync();
Api = _apiFactory.CreateClient(settings);
await _notification.Clients.Clients(NotificationHub.AdminConnectionIds)
.SendAsync(NotificationHub.NotificationEvent, "Emby Episode Sync Started");
foreach (var server in settings.Servers)
@ -80,7 +82,7 @@ namespace Ombi.Schedule.Jobs.Emby
private async Task CacheEpisodes(EmbyServers server)
{
var allEpisodes = await _api.GetAllEpisodes(server.ApiKey, 0, 200, server.AdministratorId, server.FullUri);
var allEpisodes = await Api.GetAllEpisodes(server.ApiKey, 0, 200, server.AdministratorId, server.FullUri);
var total = allEpisodes.TotalRecordCount;
var processed = 1;
var epToAdd = new HashSet<EmbyEpisode>();
@ -147,7 +149,7 @@ namespace Ombi.Schedule.Jobs.Emby
await _repo.AddRange(epToAdd);
epToAdd.Clear();
allEpisodes = await _api.GetAllEpisodes(server.ApiKey, processed, 200, server.AdministratorId, server.FullUri);
allEpisodes = await Api.GetAllEpisodes(server.ApiKey, processed, 200, server.AdministratorId, server.FullUri);
}
if (epToAdd.Any())

@ -45,10 +45,10 @@ namespace Ombi.Schedule.Jobs.Emby
{
public class EmbyUserImporter : IEmbyUserImporter
{
public EmbyUserImporter(IEmbyApi api, UserManager<OmbiUser> um, ILogger<EmbyUserImporter> log,
public EmbyUserImporter(IEmbyApiFactory api, UserManager<OmbiUser> um, ILogger<EmbyUserImporter> log,
ISettingsService<EmbySettings> embySettings, ISettingsService<UserManagementSettings> ums, IHubContext<NotificationHub> notification)
{
_api = api;
_apiFactory = api;
_userManager = um;
_log = log;
_embySettings = embySettings;
@ -56,12 +56,13 @@ namespace Ombi.Schedule.Jobs.Emby
_notification = notification;
}
private readonly IEmbyApi _api;
private readonly IEmbyApiFactory _apiFactory;
private readonly UserManager<OmbiUser> _userManager;
private readonly ILogger<EmbyUserImporter> _log;
private readonly ISettingsService<EmbySettings> _embySettings;
private readonly ISettingsService<UserManagementSettings> _userManagementSettings;
private readonly IHubContext<NotificationHub> _notification;
private IEmbyApi Api { get; set; }
public async Task Execute(IJobExecutionContext job)
{
@ -76,6 +77,8 @@ namespace Ombi.Schedule.Jobs.Emby
return;
}
Api = _apiFactory.CreateClient(settings);
await _notification.Clients.Clients(NotificationHub.AdminConnectionIds)
.SendAsync(NotificationHub.NotificationEvent, "Emby User Importer Started");
var allUsers = await _userManager.Users.Where(x => x.UserType == UserType.EmbyUser).ToListAsync();
@ -86,7 +89,7 @@ namespace Ombi.Schedule.Jobs.Emby
continue;
}
var embyUsers = await _api.GetUsers(server.FullUri, server.ApiKey);
var embyUsers = await Api.GetUsers(server.FullUri, server.ApiKey);
foreach (var embyUser in embyUsers)
{
// Check if we should import this user

@ -23,7 +23,7 @@ namespace Ombi.Schedule.Jobs.Ombi
{
public RefreshMetadata(IPlexContentRepository plexRepo, IEmbyContentRepository embyRepo,
ILogger<RefreshMetadata> log, ITvMazeApi tvApi, ISettingsService<PlexSettings> plexSettings,
IMovieDbApi movieApi, ISettingsService<EmbySettings> embySettings, IEmbyApi embyApi, IHubContext<NotificationHub> notification)
IMovieDbApi movieApi, ISettingsService<EmbySettings> embySettings, IEmbyApiFactory embyApi, IHubContext<NotificationHub> notification)
{
_plexRepo = plexRepo;
_embyRepo = embyRepo;
@ -32,7 +32,7 @@ namespace Ombi.Schedule.Jobs.Ombi
_tvApi = tvApi;
_plexSettings = plexSettings;
_embySettings = embySettings;
_embyApi = embyApi;
_embyApiFactory = embyApi;
_notification = notification;
}
@ -43,8 +43,9 @@ namespace Ombi.Schedule.Jobs.Ombi
private readonly ITvMazeApi _tvApi;
private readonly ISettingsService<PlexSettings> _plexSettings;
private readonly ISettingsService<EmbySettings> _embySettings;
private readonly IEmbyApi _embyApi;
private readonly IEmbyApiFactory _embyApiFactory;
private readonly IHubContext<NotificationHub> _notification;
private IEmbyApi EmbyApi { get; set; }
public async Task Execute(IJobExecutionContext job)
{
@ -94,6 +95,7 @@ namespace Ombi.Schedule.Jobs.Ombi
private async Task StartEmby(EmbySettings s)
{
EmbyApi = _embyApiFactory.CreateClient(s);
await StartEmbyMovies(s);
await StartEmbyTv();
}
@ -221,7 +223,7 @@ namespace Ombi.Schedule.Jobs.Ombi
foreach (var server in settings.Servers)
{
_log.LogInformation($"Checking server {server.Name} for upto date metadata");
var movieInfo = await _embyApi.GetMovieInformation(movie.EmbyId, server.ApiKey, server.AdministratorId,
var movieInfo = await EmbyApi.GetMovieInformation(movie.EmbyId, server.ApiKey, server.AdministratorId,
server.FullUri);
if (movieInfo.ProviderIds?.Imdb.HasValue() ?? false)

@ -24,13 +24,13 @@ namespace Ombi.Controllers.V1.External
/// </summary>
/// <param name="emby"></param>
/// <param name="embySettings"></param>
public EmbyController(IEmbyApi emby, ISettingsService<EmbySettings> embySettings)
public EmbyController(IEmbyApiFactory emby, ISettingsService<EmbySettings> embySettings)
{
EmbyApi = emby;
EmbySettings = embySettings;
}
private IEmbyApi EmbyApi { get; }
private IEmbyApiFactory EmbyApi { get; }
private ISettingsService<EmbySettings> EmbySettings { get; }
/// <summary>
@ -46,10 +46,11 @@ namespace Ombi.Controllers.V1.External
var settings = await EmbySettings.GetSettingsAsync();
if (settings?.Servers?.Any() ?? false) return null;
var client = await EmbyApi.CreateClient();
request.Enable = true;
var firstServer = request.Servers.FirstOrDefault();
// Test that we can connect
var result = await EmbyApi.GetUsers(firstServer.FullUri, firstServer.ApiKey);
var result = await client.GetUsers(firstServer.FullUri, firstServer.ApiKey);
if (result != null && result.Any())
{
@ -64,7 +65,8 @@ namespace Ombi.Controllers.V1.External
[HttpPost("info")]
public async Task<PublicInfo> GetServerInfo([FromBody] EmbyServers server)
{
var result = await EmbyApi.GetPublicInformation(server.FullUri);
var client = await EmbyApi.CreateClient();
var result = await client.GetPublicInformation(server.FullUri);
return result;
}
@ -77,9 +79,10 @@ namespace Ombi.Controllers.V1.External
{
var vm = new List<UsersViewModel>();
var s = await EmbySettings.GetSettingsAsync();
var client = EmbyApi.CreateClient(s);
foreach (var server in s?.Servers ?? new List<EmbyServers>())
{
var users = await EmbyApi.GetUsers(server.FullUri, server.ApiKey);
var users = await client.GetUsers(server.FullUri, server.ApiKey);
if (users != null && users.Any())
{
vm.AddRange(users.Select(u => new UsersViewModel

@ -42,7 +42,7 @@ namespace Ombi.Controllers.V1.External
/// </summary>
public TesterController(INotificationService service, IDiscordNotification notification, IEmailNotification emailN,
IPushbulletNotification pushbullet, ISlackNotification slack, IPushoverNotification po, IMattermostNotification mm,
IPlexApi plex, IEmbyApi emby, IRadarrApi radarr, ISonarrApi sonarr, ILogger<TesterController> log, IEmailProvider provider,
IPlexApi plex, IEmbyApiFactory emby, IRadarrApi radarr, ISonarrApi sonarr, ILogger<TesterController> log, IEmailProvider provider,
ICouchPotatoApi cpApi, ITelegramNotification telegram, ISickRageApi srApi, INewsletterJob newsletter, ILegacyMobileNotification mobileNotification,
ILidarrApi lidarrApi, IGotifyNotification gotifyNotification, IWhatsAppApi whatsAppApi, OmbiUserManager um, IWebhookNotification webhookNotification)
{
@ -82,7 +82,7 @@ namespace Ombi.Controllers.V1.External
private IMattermostNotification MattermostNotification { get; }
private IPlexApi PlexApi { get; }
private IRadarrApi RadarrApi { get; }
private IEmbyApi EmbyApi { get; }
private IEmbyApiFactory EmbyApi { get; }
private ISonarrApi SonarrApi { get; }
private ICouchPotatoApi CouchPotatoApi { get; }
private ILogger<TesterController> Log { get; }
@ -322,8 +322,8 @@ namespace Ombi.Controllers.V1.External
{
try
{
var result = await EmbyApi.GetUsers(settings.FullUri, settings.ApiKey);
var client = await EmbyApi.CreateClient();
var result = await client.GetUsers(settings.FullUri, settings.ApiKey);
return result.Any();
}
catch (Exception e)

@ -18,7 +18,7 @@ namespace Ombi.Controllers.V1
public class LandingPageController : ControllerBase
{
public LandingPageController(ISettingsService<PlexSettings> plex, ISettingsService<EmbySettings> emby,
IPlexApi plexApi, IEmbyApi embyApi)
IPlexApi plexApi, IEmbyApiFactory embyApi)
{
_plexSettings = plex;
_embySettings = emby;
@ -27,7 +27,7 @@ namespace Ombi.Controllers.V1
}
private readonly IPlexApi _plexApi;
private readonly IEmbyApi _embyApi;
private readonly IEmbyApiFactory _embyApi;
private readonly ISettingsService<PlexSettings> _plexSettings;
private readonly ISettingsService<EmbySettings> _embySettings;
@ -65,11 +65,12 @@ namespace Ombi.Controllers.V1
var emby = await _embySettings.GetSettingsAsync();
if (emby.Enable)
{
var client = _embyApi.CreateClient(emby);
foreach (var server in emby.Servers)
{
try
{
var result = await _embyApi.GetUsers(server.FullUri, server.ApiKey);
var result = await client.GetUsers(server.FullUri, server.ApiKey);
if (result.Any())
{
model.ServersAvailable++;

@ -45,7 +45,7 @@ namespace Ombi.Controllers.V1
public SettingsController(ISettingsResolver resolver,
IMapper mapper,
INotificationTemplatesRepository templateRepo,
IEmbyApi embyApi,
IEmbyApiFactory embyApi,
ICacheService memCache,
IGithubApi githubApi,
IRecentlyAddedEngine engine)
@ -62,7 +62,7 @@ namespace Ombi.Controllers.V1
private ISettingsResolver SettingsResolver { get; }
private IMapper Mapper { get; }
private INotificationTemplatesRepository TemplateRepository { get; }
private readonly IEmbyApi _embyApi;
private readonly IEmbyApiFactory _embyApi;
private readonly ICacheService _cache;
private readonly IGithubApi _githubApi;
private readonly IRecentlyAddedEngine _recentlyAdded;
@ -212,9 +212,10 @@ namespace Ombi.Controllers.V1
{
if (emby.Enable)
{
var client = await _embyApi.CreateClient();
foreach (var server in emby.Servers)
{
var users = await _embyApi.GetUsers(server.FullUri, server.ApiKey);
var users = await client.GetUsers(server.FullUri, server.ApiKey);
var admin = users.FirstOrDefault(x => x.Policy.IsAdministrator);
server.AdministratorId = admin?.Id;
}

Loading…
Cancel
Save