Example #1
0
        private async Task Check4K(MovieRequests movie)
        {
            var featureEnabled = await _featureService.FeatureEnabled(FeatureNames.Movie4KRequests);

            if (movie.Is4kRequest && featureEnabled)
            {
                movie.Approved4K = true;
            }
            else
            {
                movie.Approved = true;
            }
        }
        private async Task <bool> Check4KRequests(MovieRequests movie, MovieRequests existing)
        {
            var featureEnabled = await _featureService.FeatureEnabled(FeatureNames.Movie4KRequests);

            if (movie.Is4kRequest && existing.Has4KRequest && featureEnabled)
            {
                return(true);
            }
            if (!movie.Is4kRequest && !existing.Has4KRequest || !featureEnabled)
            {
                return(true);
            }

            return(false);
        }
Example #3
0
        public async Task <RuleResult> Execute(SearchViewModel obj)
        {
            EmbyContent item          = null;
            var         useImdb       = false;
            var         useTheMovieDb = false;
            var         useTvDb       = false;

            if (obj.ImdbId.HasValue())
            {
                item = await EmbyContentRepository.GetByImdbId(obj.ImdbId);

                if (item != null)
                {
                    useImdb = true;
                }
            }
            if (item == null)
            {
                if (obj.TheMovieDbId.HasValue())
                {
                    item = await EmbyContentRepository.GetByTheMovieDbId(obj.TheMovieDbId);

                    if (item != null)
                    {
                        useTheMovieDb = true;
                    }
                }

                if (item == null)
                {
                    if (obj.TheTvDbId.HasValue())
                    {
                        item = await EmbyContentRepository.GetByTvDbId(obj.TheTvDbId);

                        if (item != null)
                        {
                            useTvDb = true;
                        }
                    }
                }
            }

            if (item != null)
            {
                if (obj is SearchMovieViewModel movie)
                {
                    var is4kEnabled = await _featureService.FeatureEnabled(FeatureNames.Movie4KRequests);

                    if (item.Has4K && is4kEnabled)
                    {
                        movie.Available4K = true;
                        obj.EmbyUrl       = item.Url;
                    }
                    else
                    {
                        obj.Available = true;
                        obj.EmbyUrl   = item.Url;
                        obj.Quality   = item.Quality;
                    }

                    if (item.Quality.HasValue())
                    {
                        obj.Available = true;
                        obj.EmbyUrl   = item.Url;
                        obj.Quality   = item.Quality;
                    }
                }
                else
                {
                    obj.Available = true;
                    obj.EmbyUrl   = item.Url;
                }

                if (obj.Type == RequestType.TvShow)
                {
                    var search = (SearchTvShowViewModel)obj;
                    // Let's go through the episodes now
                    if (search.SeasonRequests.Any())
                    {
                        var allEpisodes = EmbyContentRepository.GetAllEpisodes().Include(x => x.Series);
                        foreach (var season in search.SeasonRequests)
                        {
                            foreach (var episode in season.Episodes)
                            {
                                await AvailabilityRuleHelper.SingleEpisodeCheck(useImdb, allEpisodes, episode, season, item, useTheMovieDb, useTvDb, Log);
                            }
                        }
                    }

                    AvailabilityRuleHelper.CheckForUnairedEpisodes(search);
                }
            }
            return(Success());
        }
Example #4
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
                });
            }
        }
Example #5
0
        /// <summary>
        /// Requests the movie.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <returns></returns>
        public async Task <RequestEngineResult> RequestMovie(MovieRequestViewModel model)
        {
            var movieInfo = await MovieApi.GetMovieInformationWithExtraInfo(model.TheMovieDbId, model.LanguageCode);

            if (movieInfo == null || movieInfo.Id == 0)
            {
                return(new RequestEngineResult
                {
                    Result = false,
                    Message = "There was an issue adding this movie!",
                    ErrorMessage = $"Please try again later"
                });
            }

            var fullMovieName =
                $"{movieInfo.Title}{(!string.IsNullOrEmpty(movieInfo.ReleaseDate) ? $" ({DateTime.Parse(movieInfo.ReleaseDate).Year})" : string.Empty)}";

            var userDetails = await GetUser();

            var canRequestOnBehalf = model.RequestOnBehalf.HasValue();

            var isAdmin = await UserManager.IsInRoleAsync(userDetails, OmbiRoles.PowerUser) ||
                          await UserManager.IsInRoleAsync(userDetails, OmbiRoles.Admin);

            if (canRequestOnBehalf && !isAdmin)
            {
                return(new RequestEngineResult
                {
                    Result = false,
                    Message = "You do not have the correct permissions to request on behalf of users!",
                    ErrorMessage = $"You do not have the correct permissions to request on behalf of users!"
                });
            }

            if ((model.RootFolderOverride.HasValue || model.QualityPathOverride.HasValue) && !isAdmin)
            {
                return(new RequestEngineResult
                {
                    Result = false,
                    Message = "You do not have the correct permissions!",
                    ErrorMessage = $"You do not have the correct permissions!"
                });
            }

            var is4kFeatureEnabled = await _featureService.FeatureEnabled(FeatureNames.Movie4KRequests);

            var is4kRequest = is4kFeatureEnabled && model.Is4kRequest;

            MovieRequests requestModel;
            bool          isExisting = false;
            // Do we already have a request? 4k or non 4k
            var existingRequest = await MovieRepository.GetRequestAsync(movieInfo.Id);

            if (existingRequest != null && is4kFeatureEnabled)
            {
                if (model.Is4kRequest)
                {
                    existingRequest.Is4kRequest     = true;
                    existingRequest.RequestedDate4k = DateTime.Now;
                }
                else
                {
                    existingRequest.RequestedDate = DateTime.Now;
                }
                isExisting   = true;
                requestModel = existingRequest;
            }
            else
            {
                requestModel = new MovieRequests
                {
                    TheMovieDbId = movieInfo.Id,
                    RequestType  = RequestType.Movie,
                    Overview     = movieInfo.Overview,
                    ImdbId       = movieInfo.ImdbId,
                    PosterPath   = PosterPathHelper.FixPosterPath(movieInfo.PosterPath),
                    Title        = movieInfo.Title,
                    ReleaseDate  = !string.IsNullOrEmpty(movieInfo.ReleaseDate)
                        ? DateTime.Parse(movieInfo.ReleaseDate)
                        : DateTime.MinValue,
                    Status           = movieInfo.Status,
                    RequestedDate    = model.Is4kRequest ? DateTime.MinValue : DateTime.Now,
                    Approved         = false,
                    RequestedUserId  = canRequestOnBehalf ? model.RequestOnBehalf : userDetails.Id,
                    Background       = movieInfo.BackdropPath,
                    LangCode         = model.LanguageCode,
                    RequestedByAlias = model.RequestedByAlias,
                    RootPathOverride = model.RootFolderOverride.GetValueOrDefault(),
                    QualityOverride  = model.QualityPathOverride.GetValueOrDefault(),
                    RequestedDate4k  = model.Is4kRequest ? DateTime.Now : DateTime.MinValue,
                    Is4kRequest      = model.Is4kRequest,
                    Source           = model.Source
                };
            }

            var usDates = movieInfo.ReleaseDates?.Results?.FirstOrDefault(x => x.IsoCode == "US");

            requestModel.DigitalReleaseDate = usDates?.ReleaseDate
                                              ?.FirstOrDefault(x => x.Type == ReleaseDateType.Digital)?.ReleaseDate;

            var ruleResults       = (await RunRequestRules(requestModel)).ToList();
            var ruleResultInError = ruleResults.Find(x => !x.Success);

            if (ruleResultInError != null)
            {
                return(new RequestEngineResult
                {
                    ErrorMessage = ruleResultInError.Message,
                    ErrorCode = ruleResultInError.ErrorCode
                });
            }

            if (requestModel.Approved) // The rules have auto approved this
            {
                var requestEngineResult = await AddMovieRequest(requestModel, fullMovieName, model.RequestOnBehalf, isExisting, is4kRequest);

                if (requestEngineResult.Result)
                {
                    var result = await ApproveMovie(requestModel, model.Is4kRequest);

                    if (result.IsError)
                    {
                        Logger.LogWarning("Tried auto sending movie but failed. Message: {0}", result.Message);
                        return(new RequestEngineResult
                        {
                            Message = result.Message,
                            ErrorMessage = result.Message,
                            Result = false
                        });
                    }

                    return(requestEngineResult);
                }

                // If there are no providers then it's successful but movie has not been sent
            }

            return(await AddMovieRequest(requestModel, fullMovieName, model.RequestOnBehalf, isExisting, is4kRequest));
        }
Example #6
0
        public async Task <RuleResult> Execute(SearchViewModel obj)
        {
            PlexServerContent item = null;
            var useImdb            = false;
            var useTheMovieDb      = false;
            var useId   = false;
            var useTvDb = false;

            MediaType type = ConvertType(obj.Type);

            if (obj.ImdbId.HasValue())
            {
                item = await PlexContentRepository.GetByType(obj.ImdbId, ProviderType.ImdbId, type);

                if (item != null)
                {
                    useImdb = true;
                }
            }
            if (item == null)
            {
                if (obj.Id > 0)
                {
                    item = await PlexContentRepository.GetByType(obj.Id.ToString(), ProviderType.TheMovieDbId, type);

                    if (item != null)
                    {
                        useId = true;
                    }
                }
                if (obj.TheMovieDbId.HasValue())
                {
                    item = await PlexContentRepository.GetByType(obj.TheMovieDbId, ProviderType.TheMovieDbId, type);

                    if (item != null)
                    {
                        useTheMovieDb = true;
                    }
                }

                if (item == null)
                {
                    if (obj.TheTvDbId.HasValue())
                    {
                        item = await PlexContentRepository.GetByType(obj.TheTvDbId, ProviderType.TvDbId, type);

                        if (item != null)
                        {
                            useTvDb = true;
                        }
                    }
                }
            }

            if (item != null)
            {
                var settings = await _plexSettings.GetSettingsAsync();

                var firstServer = settings.Servers.FirstOrDefault();
                var host        = string.Empty;
                if (firstServer != null)
                {
                    host = firstServer.ServerHostname;
                }
                if (useId)
                {
                    obj.TheMovieDbId = obj.Id.ToString();
                    useTheMovieDb    = true;
                }

                if (obj is SearchMovieViewModel movie)
                {
                    var is4kEnabled = await _featureService.FeatureEnabled(FeatureNames.Movie4KRequests);

                    if (item.Has4K && is4kEnabled)
                    {
                        movie.Available4K = true;
                    }
                    else
                    {
                        obj.Available = true;
                        obj.Quality   = item.Quality;
                    }

                    if (item.Quality.HasValue())
                    {
                        obj.Available = true;
                        obj.Quality   = item.Quality;
                    }
                }
                else
                {
                    obj.Available = true;
                }

                if (item.Url.StartsWith("http"))
                {
                    obj.PlexUrl = item.Url;
                }
                else
                {
                    // legacy content
                    obj.PlexUrl = PlexHelper.BuildPlexMediaUrl(item.Url, host);
                }

                if (obj is SearchTvShowViewModel search)
                {
                    // Let's go through the episodes now
                    if (search.SeasonRequests.Any())
                    {
                        var allEpisodes = PlexContentRepository.GetAllEpisodes();
                        foreach (var season in search.SeasonRequests.ToList())
                        {
                            foreach (var episode in season.Episodes.ToList())
                            {
                                await AvailabilityRuleHelper.SingleEpisodeCheck(useImdb, allEpisodes, episode, season, item, useTheMovieDb, useTvDb, Log);
                            }
                        }

                        AvailabilityRuleHelper.CheckForUnairedEpisodes(search);
                    }
                }
            }
            return(Success());
        }