|
|
@ -13,6 +13,8 @@ using Ombi.Store.Entities.Requests;
|
|
|
|
using Ombi.Api.DogNzb;
|
|
|
|
using Ombi.Api.DogNzb;
|
|
|
|
using Ombi.Store.Entities;
|
|
|
|
using Ombi.Store.Entities;
|
|
|
|
using Ombi.Store.Repository;
|
|
|
|
using Ombi.Store.Repository;
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
using Ombi.Api.Radarr.Models;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Ombi.Core.Senders
|
|
|
|
namespace Ombi.Core.Senders
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -20,44 +22,47 @@ namespace Ombi.Core.Senders
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public MovieSender(ISettingsService<RadarrSettings> radarrSettings, IRadarrApi api, ILogger<MovieSender> log,
|
|
|
|
public MovieSender(ISettingsService<RadarrSettings> radarrSettings, IRadarrApi api, ILogger<MovieSender> log,
|
|
|
|
ISettingsService<DogNzbSettings> dogSettings, IDogNzbApi dogApi, ISettingsService<CouchPotatoSettings> cpSettings,
|
|
|
|
ISettingsService<DogNzbSettings> dogSettings, IDogNzbApi dogApi, ISettingsService<CouchPotatoSettings> cpSettings,
|
|
|
|
ICouchPotatoApi cpApi, IRepository<UserQualityProfiles> userProfiles, IRepository<RequestQueue> requestQueue, INotificationHelper notify)
|
|
|
|
ICouchPotatoApi cpApi, IRepository<UserQualityProfiles> userProfiles, IRepository<RequestQueue> requestQueue, INotificationHelper notify,
|
|
|
|
|
|
|
|
IRadarrV3Api radarrV3Api)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
RadarrSettings = radarrSettings;
|
|
|
|
_radarrSettings = radarrSettings;
|
|
|
|
RadarrApi = api;
|
|
|
|
_radarrV2Api = api;
|
|
|
|
Log = log;
|
|
|
|
_log = log;
|
|
|
|
DogNzbSettings = dogSettings;
|
|
|
|
_dogNzbSettings = dogSettings;
|
|
|
|
DogNzbApi = dogApi;
|
|
|
|
_dogNzbApi = dogApi;
|
|
|
|
CouchPotatoSettings = cpSettings;
|
|
|
|
_couchPotatoSettings = cpSettings;
|
|
|
|
CouchPotatoApi = cpApi;
|
|
|
|
_couchPotatoApi = cpApi;
|
|
|
|
_userProfiles = userProfiles;
|
|
|
|
_userProfiles = userProfiles;
|
|
|
|
_requestQueuRepository = requestQueue;
|
|
|
|
_requestQueuRepository = requestQueue;
|
|
|
|
_notificationHelper = notify;
|
|
|
|
_notificationHelper = notify;
|
|
|
|
|
|
|
|
_radarrV3Api = radarrV3Api;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private ISettingsService<RadarrSettings> RadarrSettings { get; }
|
|
|
|
private readonly ISettingsService<RadarrSettings> _radarrSettings;
|
|
|
|
private IRadarrApi RadarrApi { get; }
|
|
|
|
private readonly IRadarrApi _radarrV2Api;
|
|
|
|
private ILogger<MovieSender> Log { get; }
|
|
|
|
private readonly ILogger<MovieSender> _log;
|
|
|
|
private IDogNzbApi DogNzbApi { get; }
|
|
|
|
private readonly IDogNzbApi _dogNzbApi;
|
|
|
|
private ISettingsService<DogNzbSettings> DogNzbSettings { get; }
|
|
|
|
private readonly ISettingsService<DogNzbSettings> _dogNzbSettings;
|
|
|
|
private ISettingsService<CouchPotatoSettings> CouchPotatoSettings { get; }
|
|
|
|
private readonly ISettingsService<CouchPotatoSettings> _couchPotatoSettings;
|
|
|
|
private ICouchPotatoApi CouchPotatoApi { get; }
|
|
|
|
private readonly ICouchPotatoApi _couchPotatoApi;
|
|
|
|
private readonly IRepository<UserQualityProfiles> _userProfiles;
|
|
|
|
private readonly IRepository<UserQualityProfiles> _userProfiles;
|
|
|
|
private readonly IRepository<RequestQueue> _requestQueuRepository;
|
|
|
|
private readonly IRepository<RequestQueue> _requestQueuRepository;
|
|
|
|
private readonly INotificationHelper _notificationHelper;
|
|
|
|
private readonly INotificationHelper _notificationHelper;
|
|
|
|
|
|
|
|
private readonly IRadarrV3Api _radarrV3Api;
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<SenderResult> Send(MovieRequests model)
|
|
|
|
public async Task<SenderResult> Send(MovieRequests model)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var cpSettings = await CouchPotatoSettings.GetSettingsAsync();
|
|
|
|
var cpSettings = await _couchPotatoSettings.GetSettingsAsync();
|
|
|
|
//var watcherSettings = await WatcherSettings.GetSettingsAsync();
|
|
|
|
//var watcherSettings = await WatcherSettings.GetSettingsAsync();
|
|
|
|
var radarrSettings = await RadarrSettings.GetSettingsAsync();
|
|
|
|
var radarrSettings = await _radarrSettings.GetSettingsAsync();
|
|
|
|
if (radarrSettings.Enabled)
|
|
|
|
if (radarrSettings.Enabled)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return await SendToRadarr(model, radarrSettings);
|
|
|
|
return await SendToRadarr(model, radarrSettings);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var dogSettings = await DogNzbSettings.GetSettingsAsync();
|
|
|
|
var dogSettings = await _dogNzbSettings.GetSettingsAsync();
|
|
|
|
if (dogSettings.Enabled)
|
|
|
|
if (dogSettings.Enabled)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
await SendToDogNzb(model, dogSettings);
|
|
|
|
await SendToDogNzb(model, dogSettings);
|
|
|
@ -75,7 +80,7 @@ namespace Ombi.Core.Senders
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Log.LogError(e, "Error when sending movie to DVR app, added to the request queue");
|
|
|
|
_log.LogError(e, "Error when sending movie to DVR app, added to the request queue");
|
|
|
|
|
|
|
|
|
|
|
|
// Check if already in request quee
|
|
|
|
// Check if already in request quee
|
|
|
|
var existingQueue = await _requestQueuRepository.FirstOrDefaultAsync(x => x.RequestId == model.Id);
|
|
|
|
var existingQueue = await _requestQueuRepository.FirstOrDefaultAsync(x => x.RequestId == model.Id);
|
|
|
@ -108,19 +113,19 @@ namespace Ombi.Core.Senders
|
|
|
|
|
|
|
|
|
|
|
|
private async Task<SenderResult> SendToCp(FullBaseRequest model, CouchPotatoSettings cpSettings, string cpSettingsDefaultProfileId)
|
|
|
|
private async Task<SenderResult> SendToCp(FullBaseRequest model, CouchPotatoSettings cpSettings, string cpSettingsDefaultProfileId)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var result = await CouchPotatoApi.AddMovie(model.ImdbId, cpSettings.ApiKey, model.Title, cpSettings.FullUri, cpSettingsDefaultProfileId);
|
|
|
|
var result = await _couchPotatoApi.AddMovie(model.ImdbId, cpSettings.ApiKey, model.Title, cpSettings.FullUri, cpSettingsDefaultProfileId);
|
|
|
|
return new SenderResult { Success = result, Sent = true };
|
|
|
|
return new SenderResult { Success = result, Sent = true };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async Task<DogNzbMovieAddResult> SendToDogNzb(FullBaseRequest model, DogNzbSettings settings)
|
|
|
|
private async Task<DogNzbMovieAddResult> SendToDogNzb(FullBaseRequest model, DogNzbSettings settings)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var id = model.ImdbId;
|
|
|
|
var id = model.ImdbId;
|
|
|
|
return await DogNzbApi.AddMovie(settings.ApiKey, id);
|
|
|
|
return await _dogNzbApi.AddMovie(settings.ApiKey, id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async Task<SenderResult> SendToRadarr(MovieRequests model, RadarrSettings settings)
|
|
|
|
private async Task<SenderResult> SendToRadarr(MovieRequests model, RadarrSettings settings)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
var v3 = settings.V3;
|
|
|
|
var qualityToUse = int.Parse(settings.DefaultQualityProfile);
|
|
|
|
var qualityToUse = int.Parse(settings.DefaultQualityProfile);
|
|
|
|
|
|
|
|
|
|
|
|
var rootFolderPath = settings.DefaultRootPath;
|
|
|
|
var rootFolderPath = settings.DefaultRootPath;
|
|
|
@ -129,7 +134,7 @@ namespace Ombi.Core.Senders
|
|
|
|
if (profiles != null)
|
|
|
|
if (profiles != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (profiles.RadarrRootPath > 0)
|
|
|
|
if (profiles.RadarrRootPath > 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var tempPath = await RadarrRootPath(profiles.RadarrRootPath, settings);
|
|
|
|
var tempPath = await RadarrRootPath(profiles.RadarrRootPath, settings);
|
|
|
|
if (tempPath.HasValue())
|
|
|
|
if (tempPath.HasValue())
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -152,18 +157,35 @@ namespace Ombi.Core.Senders
|
|
|
|
rootFolderPath = await RadarrRootPath(model.RootPathOverride, settings);
|
|
|
|
rootFolderPath = await RadarrRootPath(model.RootPathOverride, settings);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<MovieResponse> movies;
|
|
|
|
// Check if the movie already exists? Since it could be unmonitored
|
|
|
|
// Check if the movie already exists? Since it could be unmonitored
|
|
|
|
var movies = await RadarrApi.GetMovies(settings.ApiKey, settings.FullUri);
|
|
|
|
if (settings.V3)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
movies = await _radarrV3Api.GetMovies(settings.ApiKey, settings.FullUri);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
movies = await _radarrV2Api.GetMovies(settings.ApiKey, settings.FullUri);
|
|
|
|
|
|
|
|
}
|
|
|
|
var existingMovie = movies.FirstOrDefault(x => x.tmdbId == model.TheMovieDbId);
|
|
|
|
var existingMovie = movies.FirstOrDefault(x => x.tmdbId == model.TheMovieDbId);
|
|
|
|
if (existingMovie == null)
|
|
|
|
if (existingMovie == null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var result = await RadarrApi.AddMovie(model.TheMovieDbId, model.Title, model.ReleaseDate.Year,
|
|
|
|
RadarrAddMovie result;
|
|
|
|
qualityToUse, rootFolderPath, settings.ApiKey, settings.FullUri, !settings.AddOnly,
|
|
|
|
if (v3)
|
|
|
|
settings.MinimumAvailability);
|
|
|
|
{
|
|
|
|
|
|
|
|
result = await _radarrV3Api.AddMovie(model.TheMovieDbId, model.Title, model.ReleaseDate.Year,
|
|
|
|
|
|
|
|
qualityToUse, rootFolderPath, settings.ApiKey, settings.FullUri, !settings.AddOnly,
|
|
|
|
|
|
|
|
settings.MinimumAvailability);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
result = await _radarrV2Api.AddMovie(model.TheMovieDbId, model.Title, model.ReleaseDate.Year,
|
|
|
|
|
|
|
|
qualityToUse, rootFolderPath, settings.ApiKey, settings.FullUri, !settings.AddOnly,
|
|
|
|
|
|
|
|
settings.MinimumAvailability);
|
|
|
|
|
|
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(result.Error?.message))
|
|
|
|
if (!string.IsNullOrEmpty(result.Error?.message))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Log.LogError(LoggingEvents.RadarrCacher, result.Error.message);
|
|
|
|
_log.LogError(LoggingEvents.RadarrCacher, result.Error.message);
|
|
|
|
return new SenderResult { Success = false, Message = result.Error.message, Sent = false };
|
|
|
|
return new SenderResult { Success = false, Message = result.Error.message, Sent = false };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(result.title))
|
|
|
|
if (!string.IsNullOrEmpty(result.title))
|
|
|
@ -177,11 +199,23 @@ namespace Ombi.Core.Senders
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// let's set it to monitored and search for it
|
|
|
|
// let's set it to monitored and search for it
|
|
|
|
existingMovie.monitored = true;
|
|
|
|
existingMovie.monitored = true;
|
|
|
|
await RadarrApi.UpdateMovie(existingMovie, settings.ApiKey, settings.FullUri);
|
|
|
|
if (v3)
|
|
|
|
// Search for it
|
|
|
|
|
|
|
|
if (!settings.AddOnly)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
await RadarrApi.MovieSearch(new[] { existingMovie.id }, settings.ApiKey, settings.FullUri);
|
|
|
|
await _radarrV3Api.UpdateMovie(existingMovie, settings.ApiKey, settings.FullUri);
|
|
|
|
|
|
|
|
// Search for it
|
|
|
|
|
|
|
|
if (!settings.AddOnly)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
await _radarrV3Api.MovieSearch(new[] { existingMovie.id }, settings.ApiKey, settings.FullUri);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
await _radarrV2Api.UpdateMovie(existingMovie, settings.ApiKey, settings.FullUri);
|
|
|
|
|
|
|
|
// Search for it
|
|
|
|
|
|
|
|
if (!settings.AddOnly)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
await _radarrV2Api.MovieSearch(new[] { existingMovie.id }, settings.ApiKey, settings.FullUri);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return new SenderResult { Success = true, Sent = true };
|
|
|
|
return new SenderResult { Success = true, Sent = true };
|
|
|
@ -192,9 +226,18 @@ namespace Ombi.Core.Senders
|
|
|
|
|
|
|
|
|
|
|
|
private async Task<string> RadarrRootPath(int overrideId, RadarrSettings settings)
|
|
|
|
private async Task<string> RadarrRootPath(int overrideId, RadarrSettings settings)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var paths = await RadarrApi.GetRootFolders(settings.ApiKey, settings.FullUri);
|
|
|
|
if (settings.V3)
|
|
|
|
var selectedPath = paths.FirstOrDefault(x => x.id == overrideId);
|
|
|
|
{
|
|
|
|
return selectedPath?.path ?? String.Empty;
|
|
|
|
var paths = await _radarrV3Api.GetRootFolders(settings.ApiKey, settings.FullUri);
|
|
|
|
|
|
|
|
var selectedPath = paths.FirstOrDefault(x => x.id == overrideId);
|
|
|
|
|
|
|
|
return selectedPath?.path ?? string.Empty;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var paths = await _radarrV2Api.GetRootFolders(settings.ApiKey, settings.FullUri);
|
|
|
|
|
|
|
|
var selectedPath = paths.FirstOrDefault(x => x.id == overrideId);
|
|
|
|
|
|
|
|
return selectedPath?.path ?? string.Empty;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|