|
|
|
@ -11,7 +11,6 @@ using Ombi.Core.Settings;
|
|
|
|
|
using Ombi.Helpers;
|
|
|
|
|
using Ombi.Hubs;
|
|
|
|
|
using Ombi.Notifications.Models;
|
|
|
|
|
using Ombi.Schedule.Jobs.Plex.Models;
|
|
|
|
|
using Ombi.Settings.Settings.Models.External;
|
|
|
|
|
using Ombi.Store.Entities;
|
|
|
|
|
using Ombi.Store.Repository;
|
|
|
|
@ -20,17 +19,13 @@ using Quartz;
|
|
|
|
|
|
|
|
|
|
namespace Ombi.Schedule.Jobs.Radarr
|
|
|
|
|
{
|
|
|
|
|
public class ArrAvailabilityChecker : IArrAvailabilityChecker
|
|
|
|
|
public class ArrAvailabilityChecker : AvailabilityChecker, IArrAvailabilityChecker
|
|
|
|
|
{
|
|
|
|
|
private readonly IExternalRepository<RadarrCache> _radarrRepo;
|
|
|
|
|
private readonly IExternalRepository<SonarrCache> _sonarrRepo;
|
|
|
|
|
private readonly ILogger<ArrAvailabilityChecker> _logger;
|
|
|
|
|
private readonly ISettingsService<RadarrSettings> _radarrSettings;
|
|
|
|
|
private readonly ISettingsService<SonarrSettings> _sonarrSettings;
|
|
|
|
|
private readonly IExternalRepository<SonarrEpisodeCache> _sonarrEpisodeRepo;
|
|
|
|
|
private readonly INotificationHelper _notification;
|
|
|
|
|
private readonly IHubContext<NotificationHub> _hub;
|
|
|
|
|
private readonly ITvRequestRepository _tvRequest;
|
|
|
|
|
private readonly IMovieRequestRepository _movies;
|
|
|
|
|
|
|
|
|
|
public ArrAvailabilityChecker(
|
|
|
|
@ -42,15 +37,12 @@ namespace Ombi.Schedule.Jobs.Radarr
|
|
|
|
|
ILogger<ArrAvailabilityChecker> log,
|
|
|
|
|
ISettingsService<RadarrSettings> radarrSettings,
|
|
|
|
|
ISettingsService<SonarrSettings> sonarrSettings)
|
|
|
|
|
: base(tvRequest, notification, log, hub)
|
|
|
|
|
{
|
|
|
|
|
_radarrRepo = radarrRepo;
|
|
|
|
|
_sonarrRepo = sonarrRepo;
|
|
|
|
|
_sonarrEpisodeRepo = sonarrEpisodeRepo;
|
|
|
|
|
_notification = notification;
|
|
|
|
|
_hub = hub;
|
|
|
|
|
_tvRequest = tvRequest;
|
|
|
|
|
_movies = movies;
|
|
|
|
|
_logger = log;
|
|
|
|
|
_radarrSettings = radarrSettings;
|
|
|
|
|
_sonarrSettings = sonarrSettings;
|
|
|
|
|
}
|
|
|
|
@ -82,7 +74,7 @@ namespace Ombi.Schedule.Jobs.Radarr
|
|
|
|
|
var available = availableRadarrMovies.FirstOrDefault(x => x.TheMovieDbId == movieRequest.TheMovieDbId);
|
|
|
|
|
if (available != null)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation($"Found move '{movieRequest.Title}' available in Radarr");
|
|
|
|
|
_log.LogInformation($"Found move '{movieRequest.Title}' available in Radarr");
|
|
|
|
|
if (available.Has4K && !movieRequest.Available4K)
|
|
|
|
|
{
|
|
|
|
|
itemsForAvailability.Add(new AvailabilityModel
|
|
|
|
@ -114,7 +106,7 @@ namespace Ombi.Schedule.Jobs.Radarr
|
|
|
|
|
}
|
|
|
|
|
foreach (var item in itemsForAvailability)
|
|
|
|
|
{
|
|
|
|
|
await _notification.Notify(new NotificationOptions
|
|
|
|
|
await _notificationService.Notify(new NotificationOptions
|
|
|
|
|
{
|
|
|
|
|
DateTime = DateTime.Now,
|
|
|
|
|
NotificationType = NotificationType.RequestAvailable,
|
|
|
|
@ -127,9 +119,9 @@ namespace Ombi.Schedule.Jobs.Radarr
|
|
|
|
|
|
|
|
|
|
public async Task ProcessTvShows()
|
|
|
|
|
{
|
|
|
|
|
var tv = await _tvRequest.GetChild().Where(x => !x.Available).ToListAsync();
|
|
|
|
|
var tv = await _tvRepo.GetChild().Where(x => !x.Available).ToListAsync();
|
|
|
|
|
var sonarrEpisodes = _sonarrEpisodeRepo.GetAll().Where(x => x.HasFile);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var child in tv)
|
|
|
|
|
{
|
|
|
|
|
var tvDbId = child.ParentRequest.TvDbId;
|
|
|
|
@ -140,85 +132,10 @@ namespace Ombi.Schedule.Jobs.Radarr
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//if (!seriesEpisodes.Any())
|
|
|
|
|
//{
|
|
|
|
|
// // Let's try and match the series by name
|
|
|
|
|
// seriesEpisodes = sonarrEpisodes.Where(x =>
|
|
|
|
|
// x.EpisodeNumber == child.Title &&
|
|
|
|
|
// x.Series.ReleaseYear == child.ParentRequest.ReleaseDate.Year.ToString());
|
|
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
var availableEpisode = new List<AvailabilityModel>();
|
|
|
|
|
foreach (var season in child.SeasonRequests)
|
|
|
|
|
{
|
|
|
|
|
foreach (var episode in season.Episodes)
|
|
|
|
|
{
|
|
|
|
|
if (episode.Available)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
var foundEp = await seriesEpisodes.AnyAsync(
|
|
|
|
|
x => x.EpisodeNumber == episode.EpisodeNumber &&
|
|
|
|
|
x.SeasonNumber == episode.Season.SeasonNumber);
|
|
|
|
|
|
|
|
|
|
if (foundEp)
|
|
|
|
|
{
|
|
|
|
|
availableEpisode.Add(new AvailabilityModel
|
|
|
|
|
{
|
|
|
|
|
Id = episode.Id,
|
|
|
|
|
EpisodeNumber = episode.EpisodeNumber,
|
|
|
|
|
SeasonNumber = episode.Season.SeasonNumber
|
|
|
|
|
});
|
|
|
|
|
episode.Available = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (availableEpisode.Any())
|
|
|
|
|
{
|
|
|
|
|
await _tvRequest.Save();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check to see if all of the episodes in all seasons are available for this request
|
|
|
|
|
var allAvailable = child.SeasonRequests.All(x => x.Episodes.All(c => c.Available));
|
|
|
|
|
if (allAvailable)
|
|
|
|
|
{
|
|
|
|
|
await _hub.Clients.Clients(NotificationHub.AdminConnectionIds)
|
|
|
|
|
.SendAsync(NotificationHub.NotificationEvent, "Sonarr Availability Checker found some new available Shows!");
|
|
|
|
|
child.Available = true;
|
|
|
|
|
child.MarkedAsAvailable = DateTime.UtcNow;
|
|
|
|
|
_logger.LogInformation("[ARR_AC] - Child request {0} is now available, sending notification", $"{child.Title} - {child.Id}");
|
|
|
|
|
// We have ful-fulled this request!
|
|
|
|
|
await _tvRequest.Save();
|
|
|
|
|
await _notification.Notify(new NotificationOptions
|
|
|
|
|
{
|
|
|
|
|
DateTime = DateTime.Now,
|
|
|
|
|
NotificationType = NotificationType.RequestAvailable,
|
|
|
|
|
RequestId = child.Id,
|
|
|
|
|
RequestType = RequestType.TvShow,
|
|
|
|
|
Recipient = child.RequestedUser.Email
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else if (availableEpisode.Any())
|
|
|
|
|
{
|
|
|
|
|
var notification = new NotificationOptions
|
|
|
|
|
{
|
|
|
|
|
DateTime = DateTime.Now,
|
|
|
|
|
NotificationType = NotificationType.PartiallyAvailable,
|
|
|
|
|
RequestId = child.Id,
|
|
|
|
|
RequestType = RequestType.TvShow,
|
|
|
|
|
Recipient = child.RequestedUser.Email,
|
|
|
|
|
};
|
|
|
|
|
notification.Substitutes.Add("Season", availableEpisode.First().SeasonNumber.ToString());
|
|
|
|
|
notification.Substitutes.Add("Episodes", string.Join(", ", availableEpisode.Select(x => x.EpisodeNumber)));
|
|
|
|
|
notification.Substitutes.Add("EpisodesCount", $"{availableEpisode.Count}");
|
|
|
|
|
notification.Substitutes.Add("SeasonEpisodes", string.Join(", ", availableEpisode.Select(x => $"{x.SeasonNumber}x{x.EpisodeNumber}" )));
|
|
|
|
|
await _notification.Notify(notification);
|
|
|
|
|
}
|
|
|
|
|
ProcessTvShow(seriesEpisodes, child);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await _tvRequest.Save();
|
|
|
|
|
await _tvRepo.Save();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool _disposed;
|
|
|
|
|