|
|
|
@ -13,6 +13,8 @@ using Ombi.Store.Entities.Requests;
|
|
|
|
|
using Ombi.Api.DogNzb;
|
|
|
|
|
using Ombi.Store.Entities;
|
|
|
|
|
using Ombi.Store.Repository;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Ombi.Api.Radarr.Models;
|
|
|
|
|
|
|
|
|
|
namespace Ombi.Core.Senders
|
|
|
|
|
{
|
|
|
|
@ -20,44 +22,47 @@ namespace Ombi.Core.Senders
|
|
|
|
|
{
|
|
|
|
|
public MovieSender(ISettingsService<RadarrSettings> radarrSettings, IRadarrApi api, ILogger<MovieSender> log,
|
|
|
|
|
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;
|
|
|
|
|
RadarrApi = api;
|
|
|
|
|
Log = log;
|
|
|
|
|
DogNzbSettings = dogSettings;
|
|
|
|
|
DogNzbApi = dogApi;
|
|
|
|
|
CouchPotatoSettings = cpSettings;
|
|
|
|
|
CouchPotatoApi = cpApi;
|
|
|
|
|
_radarrSettings = radarrSettings;
|
|
|
|
|
_radarrV2Api = api;
|
|
|
|
|
_log = log;
|
|
|
|
|
_dogNzbSettings = dogSettings;
|
|
|
|
|
_dogNzbApi = dogApi;
|
|
|
|
|
_couchPotatoSettings = cpSettings;
|
|
|
|
|
_couchPotatoApi = cpApi;
|
|
|
|
|
_userProfiles = userProfiles;
|
|
|
|
|
_requestQueuRepository = requestQueue;
|
|
|
|
|
_notificationHelper = notify;
|
|
|
|
|
_radarrV3Api = radarrV3Api;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ISettingsService<RadarrSettings> RadarrSettings { get; }
|
|
|
|
|
private IRadarrApi RadarrApi { get; }
|
|
|
|
|
private ILogger<MovieSender> Log { get; }
|
|
|
|
|
private IDogNzbApi DogNzbApi { get; }
|
|
|
|
|
private ISettingsService<DogNzbSettings> DogNzbSettings { get; }
|
|
|
|
|
private ISettingsService<CouchPotatoSettings> CouchPotatoSettings { get; }
|
|
|
|
|
private ICouchPotatoApi CouchPotatoApi { get; }
|
|
|
|
|
private readonly ISettingsService<RadarrSettings> _radarrSettings;
|
|
|
|
|
private readonly IRadarrApi _radarrV2Api;
|
|
|
|
|
private readonly ILogger<MovieSender> _log;
|
|
|
|
|
private readonly IDogNzbApi _dogNzbApi;
|
|
|
|
|
private readonly ISettingsService<DogNzbSettings> _dogNzbSettings;
|
|
|
|
|
private readonly ISettingsService<CouchPotatoSettings> _couchPotatoSettings;
|
|
|
|
|
private readonly ICouchPotatoApi _couchPotatoApi;
|
|
|
|
|
private readonly IRepository<UserQualityProfiles> _userProfiles;
|
|
|
|
|
private readonly IRepository<RequestQueue> _requestQueuRepository;
|
|
|
|
|
private readonly INotificationHelper _notificationHelper;
|
|
|
|
|
private readonly IRadarrV3Api _radarrV3Api;
|
|
|
|
|
|
|
|
|
|
public async Task<SenderResult> Send(MovieRequests model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var cpSettings = await CouchPotatoSettings.GetSettingsAsync();
|
|
|
|
|
var cpSettings = await _couchPotatoSettings.GetSettingsAsync();
|
|
|
|
|
//var watcherSettings = await WatcherSettings.GetSettingsAsync();
|
|
|
|
|
var radarrSettings = await RadarrSettings.GetSettingsAsync();
|
|
|
|
|
var radarrSettings = await _radarrSettings.GetSettingsAsync();
|
|
|
|
|
if (radarrSettings.Enabled)
|
|
|
|
|
{
|
|
|
|
|
return await SendToRadarr(model, radarrSettings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var dogSettings = await DogNzbSettings.GetSettingsAsync();
|
|
|
|
|
var dogSettings = await _dogNzbSettings.GetSettingsAsync();
|
|
|
|
|
if (dogSettings.Enabled)
|
|
|
|
|
{
|
|
|
|
|
await SendToDogNzb(model, dogSettings);
|
|
|
|
@ -75,7 +80,7 @@ namespace Ombi.Core.Senders
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
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 };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task<DogNzbMovieAddResult> SendToDogNzb(FullBaseRequest model, DogNzbSettings settings)
|
|
|
|
|
{
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var v3 = settings.V3;
|
|
|
|
|
var qualityToUse = int.Parse(settings.DefaultQualityProfile);
|
|
|
|
|
|
|
|
|
|
var rootFolderPath = settings.DefaultRootPath;
|
|
|
|
@ -129,7 +134,7 @@ namespace Ombi.Core.Senders
|
|
|
|
|
if (profiles != null)
|
|
|
|
|
{
|
|
|
|
|
if (profiles.RadarrRootPath > 0)
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
var tempPath = await RadarrRootPath(profiles.RadarrRootPath, settings);
|
|
|
|
|
if (tempPath.HasValue())
|
|
|
|
|
{
|
|
|
|
@ -152,18 +157,35 @@ namespace Ombi.Core.Senders
|
|
|
|
|
rootFolderPath = await RadarrRootPath(model.RootPathOverride, settings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<MovieResponse> movies;
|
|
|
|
|
// 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);
|
|
|
|
|
if (existingMovie == null)
|
|
|
|
|
{
|
|
|
|
|
var result = await RadarrApi.AddMovie(model.TheMovieDbId, model.Title, model.ReleaseDate.Year,
|
|
|
|
|
qualityToUse, rootFolderPath, settings.ApiKey, settings.FullUri, !settings.AddOnly,
|
|
|
|
|
settings.MinimumAvailability);
|
|
|
|
|
|
|
|
|
|
RadarrAddMovie result;
|
|
|
|
|
if (v3)
|
|
|
|
|
{
|
|
|
|
|
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))
|
|
|
|
|
{
|
|
|
|
|
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 };
|
|
|
|
|
}
|
|
|
|
|
if (!string.IsNullOrEmpty(result.title))
|
|
|
|
@ -177,11 +199,23 @@ namespace Ombi.Core.Senders
|
|
|
|
|
{
|
|
|
|
|
// let's set it to monitored and search for it
|
|
|
|
|
existingMovie.monitored = true;
|
|
|
|
|
await RadarrApi.UpdateMovie(existingMovie, settings.ApiKey, settings.FullUri);
|
|
|
|
|
// Search for it
|
|
|
|
|
if (!settings.AddOnly)
|
|
|
|
|
if (v3)
|
|
|
|
|
{
|
|
|
|
|
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 };
|
|
|
|
@ -192,9 +226,18 @@ namespace Ombi.Core.Senders
|
|
|
|
|
|
|
|
|
|
private async Task<string> RadarrRootPath(int overrideId, RadarrSettings settings)
|
|
|
|
|
{
|
|
|
|
|
var paths = await RadarrApi.GetRootFolders(settings.ApiKey, settings.FullUri);
|
|
|
|
|
var selectedPath = paths.FirstOrDefault(x => x.id == overrideId);
|
|
|
|
|
return selectedPath?.path ?? String.Empty;
|
|
|
|
|
if (settings.V3)
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|