private async Task ProcessMovies() { // Get all non available var movies = _movieRepo.GetAll().Include(x => x.RequestedUser).Where(x => !x.Available); var itemsForAvailbility = new List <AvailabilityModel>(); foreach (var movie in movies) { if (movie.Available) { return; } PlexServerContent item = null; if (movie.ImdbId.HasValue()) { item = await _repo.Get(movie.ImdbId, ProviderType.ImdbId); } if (item == null) { if (movie.TheMovieDbId.ToString().HasValue()) { item = await _repo.Get(movie.TheMovieDbId.ToString(), ProviderType.TheMovieDbId); } } if (item == null) { // We don't yet have this continue; } _log.LogInformation("[PAC] - Movie request {0} is now available, sending notification", $"{movie.Title} - {movie.Id}"); movie.Available = true; movie.MarkedAsAvailable = DateTime.UtcNow; itemsForAvailbility.Add(new AvailabilityModel { Id = movie.Id, RequestedUser = movie.RequestedUser != null ? movie.RequestedUser.Email : string.Empty }); } if (itemsForAvailbility.Any()) { await _movieRepo.SaveChangesAsync(); } foreach (var i in itemsForAvailbility) { await _notificationService.Notify(new NotificationOptions { DateTime = DateTime.Now, NotificationType = NotificationType.RequestAvailable, RequestId = i.Id, RequestType = RequestType.Movie, Recipient = i.RequestedUser }); } //await _repo.SaveChangesAsync(); }
private async Task ProcessMovies() { var availableRadarrMovies = _radarrRepo.GetAll().Where(x => x.HasFile).ToImmutableHashSet(); var unavailableMovieRequests = _movies.GetAll().Where(x => !x.Available || (!x.Available4K && x.Has4KRequest)).ToImmutableHashSet(); var itemsForAvailability = new List <AvailabilityModel>(); foreach (var movieRequest in unavailableMovieRequests) { // Do we have an item in the radarr list var available = availableRadarrMovies.FirstOrDefault(x => x.TheMovieDbId == movieRequest.TheMovieDbId); if (available != null) { _logger.LogInformation($"Found move '{movieRequest.Title}' available in Radarr"); if (available.Has4K && !movieRequest.Available4K) { itemsForAvailability.Add(new AvailabilityModel { Id = movieRequest.Id, RequestedUser = movieRequest.RequestedUser != null ? movieRequest.RequestedUser.Email : string.Empty }); movieRequest.Available4K = true; movieRequest.MarkedAsAvailable4K = DateTime.UtcNow; } if (available.HasRegular) { itemsForAvailability.Add(new AvailabilityModel { Id = movieRequest.Id, RequestedUser = movieRequest.RequestedUser != null ? movieRequest.RequestedUser.Email : string.Empty }); movieRequest.Available = true; movieRequest.MarkedAsAvailable = DateTime.UtcNow; } await _movies.SaveChangesAsync(); } } if (itemsForAvailability.Any()) { await _hub.Clients.Clients(NotificationHub.AdminConnectionIds) .SendAsync(NotificationHub.NotificationEvent, "Radarr Availability Checker found some new available movies!"); } foreach (var item in itemsForAvailability) { await _notification.Notify(new NotificationOptions { DateTime = DateTime.Now, NotificationType = NotificationType.RequestAvailable, RequestId = item.Id, RequestType = RequestType.Movie, Recipient = item.RequestedUser }); } }
private async Task ProcessMovies() { var feature4kEnabled = await _featureService.FeatureEnabled(FeatureNames.Movie4KRequests); // Get all non available var movies = _movieRepo.GetAll().Include(x => x.RequestedUser).Where(x => !x.Available || (!x.Available4K && x.Has4KRequest)); var itemsForAvailbility = new List <AvailabilityModel>(); foreach (var movie in movies) { var has4kRequest = movie.Has4KRequest; PlexServerContent item = null; if (movie.ImdbId.HasValue()) { item = await _repo.Get(movie.ImdbId, ProviderType.ImdbId); } if (item == null) { if (movie.TheMovieDbId.ToString().HasValue()) { item = await _repo.Get(movie.TheMovieDbId.ToString(), ProviderType.TheMovieDbId); } } if (item == null) { // We don't yet have this continue; } _log.LogInformation($"[PAC] - Movie request {movie.Title} - {movie.Id} is now available, sending notification"); var notify = false; if (has4kRequest && item.Has4K && !movie.Available4K && feature4kEnabled) { movie.Available4K = true; movie.Approved4K = true; movie.MarkedAsAvailable4K = DateTime.Now; await _movieRepo.SaveChangesAsync(); notify = true; } if (!feature4kEnabled && !movie.Available) { movie.Available = true; movie.MarkedAsAvailable = DateTime.Now; await _movieRepo.SaveChangesAsync(); notify = true; } // If we have a non-4k versison then mark as available if (item.Quality != null && !movie.Available) { movie.Available = true; movie.Approved = true; movie.MarkedAsAvailable = DateTime.Now; await _movieRepo.SaveChangesAsync(); notify = true; } if (notify) { itemsForAvailbility.Add(new AvailabilityModel { Id = movie.Id, RequestedUser = movie.RequestedUser != null ? movie.RequestedUser.Email : string.Empty }); } } foreach (var i in itemsForAvailbility.DistinctBy(x => x.Id)) { await _notificationService.Notify(new NotificationOptions { DateTime = DateTime.Now, NotificationType = NotificationType.RequestAvailable, RequestId = i.Id, RequestType = RequestType.Movie, Recipient = i.RequestedUser }); } }