|
|
|
@ -4,6 +4,7 @@ using System.Collections.Immutable;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Microsoft.AspNetCore.SignalR;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Ombi.Core;
|
|
|
|
|
using Ombi.Helpers;
|
|
|
|
@ -17,7 +18,7 @@ using Quartz;
|
|
|
|
|
|
|
|
|
|
namespace Ombi.Schedule.Jobs.Radarr
|
|
|
|
|
{
|
|
|
|
|
public class ArrAvailabilityChecker
|
|
|
|
|
public class ArrAvailabilityChecker : IArrAvailabilityChecker
|
|
|
|
|
{
|
|
|
|
|
public ArrAvailabilityChecker(
|
|
|
|
|
IExternalRepository<RadarrCache> radarrRepo,
|
|
|
|
@ -48,10 +49,8 @@ namespace Ombi.Schedule.Jobs.Radarr
|
|
|
|
|
|
|
|
|
|
public async Task Execute(IJobExecutionContext job)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
await ProcessMovies();
|
|
|
|
|
await ProcessTvShows();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task ProcessMovies()
|
|
|
|
@ -66,6 +65,7 @@ namespace Ombi.Schedule.Jobs.Radarr
|
|
|
|
|
var available = availableRadarrMovies.Any(x => x.TheMovieDbId == movieRequest.TheMovieDbId);
|
|
|
|
|
if (available)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation($"Found move '{movieRequest.Title}' available in Radarr");
|
|
|
|
|
movieRequest.Available = true;
|
|
|
|
|
movieRequest.MarkedAsAvailable = DateTime.UtcNow;
|
|
|
|
|
itemsForAvailability.Add(new AvailabilityModel
|
|
|
|
@ -78,6 +78,8 @@ namespace Ombi.Schedule.Jobs.Radarr
|
|
|
|
|
|
|
|
|
|
if (itemsForAvailability.Any())
|
|
|
|
|
{
|
|
|
|
|
await _hub.Clients.Clients(NotificationHub.AdminConnectionIds)
|
|
|
|
|
.SendAsync(NotificationHub.NotificationEvent, "Radarr Availability Checker found some new available movies!");
|
|
|
|
|
await _movies.SaveChangesAsync();
|
|
|
|
|
}
|
|
|
|
|
foreach (var item in itemsForAvailability)
|
|
|
|
@ -96,8 +98,104 @@ namespace Ombi.Schedule.Jobs.Radarr
|
|
|
|
|
|
|
|
|
|
public async Task ProcessTvShows()
|
|
|
|
|
{
|
|
|
|
|
var tv = await _tvRequest.GetChild().Where(x => !x.Available).ToListAsync();
|
|
|
|
|
var sonarrEpisodes = _sonarrEpisodeRepo.GetAll().Where(x => x.HasFile);
|
|
|
|
|
|
|
|
|
|
foreach (var child in tv)
|
|
|
|
|
{
|
|
|
|
|
var tvDbId = child.ParentRequest.TvDbId;
|
|
|
|
|
IQueryable<SonarrEpisodeCache> seriesEpisodes = sonarrEpisodes.Where(x => x.TvDbId == tvDbId);
|
|
|
|
|
|
|
|
|
|
if (seriesEpisodes == null || !seriesEpisodes.Any())
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
});
|
|
|
|
|
episode.Available = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//TODO Partial avilability notifications here
|
|
|
|
|
if (availableEpisode.Any())
|
|
|
|
|
{
|
|
|
|
|
//await _hub.Clients.Clients(NotificationHub.AdminConnectionIds)
|
|
|
|
|
// .SendAsync(NotificationHub.NotificationEvent, "Sonarr Availability Checker found some new available episodes!");
|
|
|
|
|
await _tvRequest.Save();
|
|
|
|
|
}
|
|
|
|
|
//foreach(var c in availableEpisode)
|
|
|
|
|
//{
|
|
|
|
|
// await _tvRepo.MarkEpisodeAsAvailable(c.Id);
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await _tvRequest.Save();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool _disposed;
|
|
|
|
|
protected virtual void Dispose(bool disposing)
|
|
|
|
|
{
|
|
|
|
|
if (_disposed)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (disposing)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
_disposed = true;
|
|
|
|
|
}
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
Dispose(true);
|
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|