Esempio n. 1
0
        private async Task ProcessMovies()
        {
            var movies = _movieRepo.GetAll().Include(x => x.RequestedUser).Where(x => !x.Available || (!x.Available4K && x.Has4KRequest));

            foreach (var movie in movies)
            {
                var             has4kRequest    = movie.Has4KRequest;
                JellyfinContent jellyfinContent = null;
                if (movie.TheMovieDbId > 0)
                {
                    jellyfinContent = await _repo.GetByTheMovieDbId(movie.TheMovieDbId.ToString());
                }
                else if (movie.ImdbId.HasValue())
                {
                    jellyfinContent = await _repo.GetByImdbId(movie.ImdbId);
                }

                if (jellyfinContent == null)
                {
                    // We don't have this yet
                    continue;
                }

                _log.LogInformation("We have found the request {0} on Jellyfin, sending the notification", movie?.Title ?? string.Empty);

                var notify = false;

                if (has4kRequest && jellyfinContent.Has4K && !movie.Available4K)
                {
                    movie.Available4K         = true;
                    movie.MarkedAsAvailable4K = DateTime.Now;
                    notify = true;
                }

                // If we have a non-4k versison then mark as available
                if (jellyfinContent.Quality != null && !movie.Available)
                {
                    movie.Available         = true;
                    movie.MarkedAsAvailable = DateTime.Now;
                    notify = true;
                }

                if (notify)
                {
                    var recipient = movie.RequestedUser.Email.HasValue() ? movie.RequestedUser.Email : string.Empty;

                    _log.LogDebug("MovieId: {0}, RequestUser: {1}", movie.Id, recipient);

                    await _notificationService.Notify(new NotificationOptions
                    {
                        DateTime         = DateTime.Now,
                        NotificationType = NotificationType.RequestAvailable,
                        RequestId        = movie.Id,
                        RequestType      = RequestType.Movie,
                        Recipient        = recipient,
                    });
                }
            }
            await _movieRepo.Save();
        }
Esempio n. 2
0
        private async Task ProcessMovies()
        {
            var movies = _movieRepo.GetAll().Include(x => x.RequestedUser).Where(x => !x.Available);

            foreach (var movie in movies)
            {
                var embyContent = await _repo.Get(movie.ImdbId);

                if (embyContent == null)
                {
                    // We don't have this yet
                    continue;
                }

                _log.LogInformation("We have found the request {0} on Emby, sending the notification", movie?.Title ?? string.Empty);

                movie.Available = true;
                if (movie.Available)
                {
                    var recipient = movie.RequestedUser.Email.HasValue() ? movie.RequestedUser.Email : string.Empty;

                    _log.LogDebug("MovieId: {0}, RequestUser: {1}", movie.Id, recipient);

                    BackgroundJob.Enqueue(() => _notificationService.Publish(new NotificationOptions
                    {
                        DateTime         = DateTime.Now,
                        NotificationType = NotificationType.RequestAvailable,
                        RequestId        = movie.Id,
                        RequestType      = RequestType.Movie,
                        Recipient        = recipient,
                    }));
                }
            }
            await _movieRepo.Save();
        }
Esempio n. 3
0
        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();
        }
Esempio n. 4
0
        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
                });
            }
        }
Esempio n. 5
0
        public Task <List <CalendarViewModel> > GetCalendarData()
        {
            var viewModel = new List <CalendarViewModel>();
            var movies    = _movieRepo.GetAll().Where(x =>
                                                      x.ReleaseDate > DaysAgo && x.ReleaseDate < DaysAhead);
            var episodes = _tvRepo.GetChild().SelectMany(x => x.SeasonRequests.SelectMany(e => e.Episodes
                                                                                          .Where(w => w.AirDate > DaysAgo && w.AirDate < DaysAhead)));

            foreach (var e in episodes)
            {
                viewModel.Add(new CalendarViewModel
                {
                    Title           = e.Title,
                    Start           = e.AirDate.Date,
                    Type            = RequestType.TvShow,
                    BackgroundColor = GetBackgroundColor(e),
                    ExtraParams     = new List <ExtraParams>
                    {
                        new ExtraParams
                        {
                            Overview      = e.Season?.ChildRequest?.ParentRequest?.Overview ?? string.Empty,
                            ProviderId    = e.Season?.ChildRequest?.ParentRequest?.ExternalProviderId ?? 0,
                            Type          = RequestType.TvShow,
                            ReleaseDate   = e.AirDate,
                            RequestStatus = e.RequestStatus
                        }
                    }
                });
            }

            foreach (var m in movies)
            {
                viewModel.Add(new CalendarViewModel
                {
                    Title           = m.Title,
                    Start           = m.ReleaseDate.Date,
                    BackgroundColor = GetBackgroundColor(m),
                    Type            = RequestType.Movie,
                    ExtraParams     = new List <ExtraParams>
                    {
                        new ExtraParams
                        {
                            Overview      = m.Overview,
                            ProviderId    = m.TheMovieDbId,
                            Type          = RequestType.Movie,
                            ReleaseDate   = m.ReleaseDate,
                            RequestStatus = m.RequestStatus
                        }
                    }
                });
            }

            return(Task.FromResult(viewModel));
        }
Esempio n. 6
0
        private async Task ProcessMovieRequests(DateTime date)
        {
            var requestsToDelete = await _movieRequests.GetAll().Where(x => x.Available && x.MarkedAsAvailable.HasValue && x.MarkedAsAvailable.Value < date).ToListAsync();

            _logger.LogInformation($"Deleting {requestsToDelete.Count} movie requests that have now been scheduled for deletion, All available requests before {date::MM/dd/yyyy} will be deleted");
            foreach (var r in requestsToDelete)
            {
                _logger.LogInformation($"Deleting movie title {r.Title} as it was approved on {r.MarkedAsApproved:MM/dd/yyyy hh:mm tt}");
            }

            await _movieRequests.DeleteRange(requestsToDelete);
        }
Esempio n. 7
0
        public async Task Start()
        {
            // Get all the failed ones!
            var failedRequests = _requestQueue.GetAll().Where(x => !x.Completed.HasValue);

            foreach (var request in failedRequests)
            {
                if (request.Type == RequestType.Movie)
                {
                    var movieRequest = await _movieRequestRepository.GetAll().FirstOrDefaultAsync(x => x.Id == request.RequestId);

                    var result = await _movieSender.Send(movieRequest);

                    if (result.Success)
                    {
                        request.Completed = DateTime.UtcNow;
                        await _requestQueue.SaveChangesAsync();
                    }
                }
                if (request.Type == RequestType.TvShow)
                {
                    var tvRequest = await _tvRequestRepository.GetChild().FirstOrDefaultAsync(x => x.Id == request.RequestId);

                    var result = await _tvSender.Send(tvRequest);

                    if (result.Success)
                    {
                        request.Completed = DateTime.UtcNow;
                        await _requestQueue.SaveChangesAsync();
                    }
                }
                if (request.Type == RequestType.Album)
                {
                    var musicRequest = await _musicRequestRepository.GetAll().FirstOrDefaultAsync(x => x.Id == request.RequestId);

                    var result = await _musicSender.Send(musicRequest);

                    if (result.Success)
                    {
                        request.Completed = DateTime.UtcNow;
                        await _requestQueue.SaveChangesAsync();
                    }
                }
            }
        }
Esempio n. 8
0
        private async Task ProcessMovies()
        {
            // Get all non available
            var movies = _movieRepo.GetAll().Include(x => x.RequestedUser).Where(x => !x.Available);

            foreach (var movie in movies)
            {
                PlexServerContent item = null;
                if (movie.ImdbId.HasValue())
                {
                    item = await _repo.Get(movie.ImdbId);
                }
                if (item == null)
                {
                    if (movie.TheMovieDbId.ToString().HasValue())
                    {
                        item = await _repo.Get(movie.TheMovieDbId.ToString());
                    }
                }
                if (item == null)
                {
                    // We don't yet have this
                    continue;
                }

                movie.Available         = true;
                movie.MarkedAsAvailable = DateTime.Now;
                item.RequestId          = movie.Id;

                _log.LogInformation("[PAC] - Movie request {0} is now available, sending notification", $"{movie.Title} - {movie.Id}");
                await _notificationService.Notify(new NotificationOptions
                {
                    DateTime         = DateTime.Now,
                    NotificationType = NotificationType.RequestAvailable,
                    RequestId        = movie.Id,
                    RequestType      = RequestType.Movie,
                    Recipient        = movie.RequestedUser != null ? movie.RequestedUser.Email : string.Empty
                });
            }

            await _movieRepo.Save();

            await _repo.SaveChangesAsync();
        }
Esempio n. 9
0
        private async Task ProcessMovies()
        {
            // Get all non available
            var movies = _movieRepo.GetAll().Include(x => x.RequestedUser).Where(x => !x.Available);

            foreach (var movie in movies)
            {
                PlexServerContent item = null;
                if (movie.ImdbId.HasValue())
                {
                    item = await _repo.Get(movie.ImdbId);
                }
                if (item == null)
                {
                    if (movie.TheMovieDbId.ToString().HasValue())
                    {
                        item = await _repo.Get(movie.TheMovieDbId.ToString());
                    }
                }
                if (item == null)
                {
                    // We don't yet have this
                    continue;
                }

                movie.Available         = true;
                movie.MarkedAsAvailable = DateTime.Now;
                if (movie.Available)
                {
                    _backgroundJobClient.Enqueue(() => _notificationService.Publish(new NotificationOptions
                    {
                        DateTime         = DateTime.Now,
                        NotificationType = NotificationType.RequestAvailable,
                        RequestId        = movie.Id,
                        RequestType      = RequestType.Movie,
                        Recipient        = movie.RequestedUser != null ? movie.RequestedUser.Email : string.Empty
                    }));
                }
            }

            await _movieRepo.Save();
        }
Esempio n. 10
0
        public async Task Execute(IJobExecutionContext job)
        {
            // Get all the failed ones!
            var failedRequests = _requestQueue.GetAll().Where(x => x.Completed == null);

            foreach (var request in failedRequests)
            {
                if (request.Type == RequestType.Movie)
                {
                    var movieRequest = await _movieRequestRepository.GetAll().FirstOrDefaultAsync(x => x.Id == request.RequestId);

                    if (movieRequest == null)
                    {
                        await _requestQueue.Delete(request);

                        await _requestQueue.SaveChangesAsync();

                        continue;
                    }
                    var result = await _movieSender.Send(movieRequest);

                    if (result.Success)
                    {
                        request.Completed = DateTime.UtcNow;
                        await _requestQueue.SaveChangesAsync();
                    }
                }
                if (request.Type == RequestType.TvShow)
                {
                    var tvRequest = await _tvRequestRepository.GetChild().FirstOrDefaultAsync(x => x.Id == request.RequestId);

                    if (tvRequest == null)
                    {
                        await _requestQueue.Delete(request);

                        await _requestQueue.SaveChangesAsync();

                        continue;
                    }
                    var result = await _tvSender.Send(tvRequest);

                    if (result.Success)
                    {
                        request.Completed = DateTime.UtcNow;
                        await _requestQueue.SaveChangesAsync();
                    }
                }
                if (request.Type == RequestType.Album)
                {
                    var musicRequest = await _musicRequestRepository.GetAll().FirstOrDefaultAsync(x => x.Id == request.RequestId);

                    if (musicRequest == null)
                    {
                        await _requestQueue.Delete(request);

                        await _requestQueue.SaveChangesAsync();

                        continue;
                    }
                    var result = await _musicSender.Send(musicRequest);

                    if (result.Success)
                    {
                        request.Completed = DateTime.UtcNow;
                        await _requestQueue.SaveChangesAsync();
                    }
                }
            }
        }
Esempio n. 11
0
        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
                });
            }
        }
Esempio n. 12
0
        public async Task <IdentityResult> DeleteUser(OmbiUser userToDelete)
        {
            var userId = userToDelete.Id;
            // We need to delete all the requests first
            var moviesUserRequested     = _movieRepository.GetAll().Where(x => x.RequestedUserId == userId);
            var tvUserRequested         = _tvRepository.GetChild().Where(x => x.RequestedUserId == userId);
            var musicRequested          = _musicRepository.GetAll().Where(x => x.RequestedUserId == userId);
            var notificationPreferences = _userNotificationPreferences.GetAll().Where(x => x.UserId == userId);
            var userQuality             = await _userQualityProfiles.GetAll().FirstOrDefaultAsync(x => x.UserId == userId);

            if (moviesUserRequested.Any())
            {
                await _movieRepository.DeleteRange(moviesUserRequested);
            }
            if (tvUserRequested.Any())
            {
                await _tvRepository.DeleteChildRange(tvUserRequested);
            }
            if (musicRequested.Any())
            {
                await _musicRepository.DeleteRange(musicRequested);
            }
            if (notificationPreferences.Any())
            {
                await _userNotificationPreferences.DeleteRange(notificationPreferences);
            }
            if (userQuality != null)
            {
                await _userQualityProfiles.Delete(userQuality);
            }

            // Delete any issues and request logs
            var issues        = _issuesRepository.GetAll().Where(x => x.UserReportedId == userId);
            var issueComments = _issueCommentsRepository.GetAll().Where(x => x.UserId == userId);
            var requestLog    = _requestLogRepository.GetAll().Where(x => x.UserId == userId);

            if (issueComments.Any())
            {
                await _issueCommentsRepository.DeleteRange(issueComments);
            }
            if (issues.Any())
            {
                var extraComments = new List <IssueComments>();
                var issueIds      = issues.Select(x => x.Id).Distinct();
                foreach (var issue in issueIds)
                {
                    // Get all the comments for this issue and delete them, since the issue will be deleted
                    var extra = _issueCommentsRepository.GetAll().Where(x => x.IssuesId == issue);
                    extraComments.AddRange(extra.ToList());
                }
                await _issuesRepository.DeleteRange(issues);
            }
            if (requestLog.Any())
            {
                await _requestLogRepository.DeleteRange(requestLog);
            }

            // Delete the Subscriptions and mobile notification ids
            var subs       = _requestSubscriptionRepository.GetAll().Where(x => x.UserId == userId);
            var mobileIds  = _notificationRepository.GetAll().Where(x => x.UserId == userId);
            var votes      = _voteRepository.GetAll().Where(x => x.UserId == userId);
            var newMobiles = _mobileDevicesRepository.GetAll().Where(x => x.UserId == userId);

            if (subs.Any())
            {
                await _requestSubscriptionRepository.DeleteRange(subs);
            }
            if (mobileIds.Any())
            {
                await _notificationRepository.DeleteRange(mobileIds);
            }
            if (votes.Any())
            {
                await _voteRepository.DeleteRange(votes);
            }
            if (newMobiles.Any())
            {
                await _mobileDevicesRepository.DeleteRange(newMobiles);
            }

            var result = await _userManager.DeleteAsync(userToDelete);

            return(result);
        }