public virtual Decision IsSatisfiedBy(RemoteMovie subject, SearchCriteriaBase searchCriteria)
        {
            if (subject.Movie.MovieFile == null)
            {
                return(Decision.Accept());
            }

            var profile = subject.Movie.Profile;
            var file    = subject.Movie.MovieFile;

            file.Movie = subject.Movie;
            var customFormats = _formatService.ParseCustomFormat(file);

            _logger.Debug("Comparing file quality with report. Existing file is {0} [{1}]", file.Quality, customFormats.ConcatToString());

            if (!_qualityUpgradableSpecification.IsUpgradable(profile,
                                                              file.Quality,
                                                              customFormats,
                                                              subject.ParsedMovieInfo.Quality,
                                                              subject.CustomFormats))
            {
                return(Decision.Reject("Quality for existing file on disk is of equal or higher preference: {0} [{1}]", file.Quality, customFormats.ConcatToString()));
            }

            return(Decision.Accept());
        }
Example #2
0
        public virtual Decision IsSatisfiedBy(RemoteAlbum subject, SearchCriteriaBase searchCriteria)
        {
            foreach (var album in subject.Albums)
            {
                var tracksMissing = _missingFilesCache.Get(album.Id.ToString(),
                                                           () => _trackService.TracksWithoutFiles(album.Id).Any(),
                                                           TimeSpan.FromSeconds(30));
                var trackFiles = _mediaFileService.GetFilesByAlbum(album.Id);

                if (!tracksMissing && trackFiles.Any())
                {
                    var currentQualities = trackFiles.Select(c => c.Quality).Distinct().ToList();

                    if (!_upgradableSpecification.IsUpgradable(subject.Artist.QualityProfile,
                                                               currentQualities,
                                                               _preferredWordServiceCalculator.Calculate(subject.Artist, trackFiles[0].GetSceneOrFileName(), subject.Release?.IndexerId ?? 0),
                                                               subject.ParsedAlbumInfo.Quality,
                                                               subject.PreferredWordScore))
                    {
                        return(Decision.Reject("Existing files on disk is of equal or higher preference: {0}", currentQualities.ConcatToString()));
                    }
                }
            }

            return(Decision.Accept());
        }
        public virtual Decision IsSatisfiedBy(RemoteBook subject, SearchCriteriaBase searchCriteria)
        {
            foreach (var file in subject.Books.SelectMany(c => c.BookFiles.Value))
            {
                if (file == null)
                {
                    _logger.Debug("File is no longer available, skipping this file.");
                    continue;
                }

                _logger.Debug("Comparing file quality and language with report. Existing file is {0}", file.Quality);

                if (!_upgradableSpecification.IsUpgradable(subject.Author.QualityProfile,
                                                           new List <QualityModel> {
                    file.Quality
                },
                                                           _preferredWordServiceCalculator.Calculate(subject.Author, file.GetSceneOrFileName()),
                                                           subject.ParsedBookInfo.Quality,
                                                           subject.PreferredWordScore))
                {
                    return(Decision.Reject("Existing file on disk is of equal or higher preference: {0}", file.Quality));
                }
            }

            return(Decision.Accept());
        }
Example #4
0
        public virtual Decision IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria)
        {
            foreach (var file in subject.Episodes.Where(c => c.EpisodeFileId != 0).Select(c => c.EpisodeFile.Value))
            {
                if (file == null)
                {
                    _logger.Debug("File is no longer available, skipping this file.");
                    continue;
                }

                _logger.Debug("Comparing file quality and language with report. Existing file is {0} - {1}", file.Quality, file.Language);

                if (!_upgradableSpecification.IsUpgradable(subject.Series.QualityProfile,
                                                           subject.Series.LanguageProfile,
                                                           file.Quality,
                                                           file.Language,
                                                           _episodeFilePreferredWordCalculator.Calculate(subject.Series, file),
                                                           subject.ParsedEpisodeInfo.Quality,
                                                           subject.ParsedEpisodeInfo.Language,
                                                           subject.PreferredWordScore))
                {
                    return(Decision.Reject("Existing file on disk is of equal or higher preference: {0} - {1}", file.Quality, file.Language));
                }
            }

            return(Decision.Accept());
        }
Example #5
0
        public Decision IsSatisfiedBy(RemoteMovie subject, SearchCriteriaBase searchCriteria)
        {
            var queue          = _queueService.GetQueue();
            var matchingMovies = queue.Where(q => q.RemoteMovie?.Movie != null &&
                                             q.RemoteMovie.Movie.Id == subject.Movie.Id)
                                 .ToList();

            foreach (var queueItem in matchingMovies)
            {
                var remoteMovie    = queueItem.RemoteMovie;
                var qualityProfile = subject.Movie.Profile;

                // To avoid a race make sure it's not FailedPending (failed awaiting removal/search).
                // Failed items (already searching for a replacement) won't be part of the queue since
                // it's a copy, of the tracked download, not a reference.
                if (queueItem.TrackedDownloadState == TrackedDownloadState.FailedPending)
                {
                    continue;
                }

                var customFormats = _formatService.ParseCustomFormat(remoteMovie.ParsedMovieInfo);

                _logger.Debug("Checking if existing release in queue meets cutoff. Queued quality is: {0} - {1}",
                              remoteMovie.ParsedMovieInfo.Quality,
                              customFormats.ConcatToString());

                if (!_upgradableSpecification.CutoffNotMet(qualityProfile,
                                                           remoteMovie.ParsedMovieInfo.Quality,
                                                           customFormats,
                                                           subject.ParsedMovieInfo.Quality))
                {
                    return(Decision.Reject("Quality for release in queue already meets cutoff: {0}", remoteMovie.ParsedMovieInfo.Quality));
                }

                _logger.Debug("Checking if release is higher quality than queued release. Queued quality is: {0}", remoteMovie.ParsedMovieInfo.Quality);

                if (!_upgradableSpecification.IsUpgradable(qualityProfile,
                                                           remoteMovie.ParsedMovieInfo.Quality,
                                                           remoteMovie.CustomFormats,
                                                           subject.ParsedMovieInfo.Quality,
                                                           subject.CustomFormats))
                {
                    return(Decision.Reject("Quality for release in queue is of equal or higher preference: {0}", remoteMovie.ParsedMovieInfo.Quality));
                }

                _logger.Debug("Checking if profiles allow upgrading. Queued: {0}", remoteMovie.ParsedMovieInfo.Quality);

                if (!_upgradableSpecification.IsUpgradeAllowed(subject.Movie.Profile,
                                                               remoteMovie.ParsedMovieInfo.Quality,
                                                               remoteMovie.CustomFormats,
                                                               subject.ParsedMovieInfo.Quality,
                                                               subject.CustomFormats))
                {
                    return(Decision.Reject("Another release is queued and the Quality profile does not allow upgrades"));
                }
            }

            return(Decision.Accept());
        }
Example #6
0
        public Decision IsSatisfiedBy(RemoteBook subject, SearchCriteriaBase searchCriteria)
        {
            var queue        = _queueService.GetQueue();
            var matchingBook = queue.Where(q => q.RemoteBook?.Author != null &&
                                           q.RemoteBook.Author.Id == subject.Author.Id &&
                                           q.RemoteBook.Books.Select(e => e.Id).Intersect(subject.Books.Select(e => e.Id)).Any())
                               .ToList();

            foreach (var queueItem in matchingBook)
            {
                var remoteBook     = queueItem.RemoteBook;
                var qualityProfile = subject.Author.QualityProfile.Value;

                // To avoid a race make sure it's not FailedPending (failed awaiting removal/search).
                // Failed items (already searching for a replacement) won't be part of the queue since
                // it's a copy, of the tracked download, not a reference.
                if (queueItem.TrackedDownloadState == TrackedDownloadState.DownloadFailedPending)
                {
                    continue;
                }

                _logger.Debug("Checking if existing release in queue meets cutoff. Queued quality is: {0}", remoteBook.ParsedBookInfo.Quality);

                var queuedItemPreferredWordScore = _preferredWordServiceCalculator.Calculate(subject.Author, queueItem.Title, subject.Release?.IndexerId ?? 0);

                if (!_upgradableSpecification.CutoffNotMet(qualityProfile,
                                                           new List <QualityModel> {
                    remoteBook.ParsedBookInfo.Quality
                },
                                                           queuedItemPreferredWordScore,
                                                           subject.ParsedBookInfo.Quality,
                                                           subject.PreferredWordScore))
                {
                    return(Decision.Reject("Release in queue already meets cutoff: {0}", remoteBook.ParsedBookInfo.Quality));
                }

                _logger.Debug("Checking if release is higher quality than queued release. Queued: {0}", remoteBook.ParsedBookInfo.Quality);

                if (!_upgradableSpecification.IsUpgradable(qualityProfile,
                                                           remoteBook.ParsedBookInfo.Quality,
                                                           queuedItemPreferredWordScore,
                                                           subject.ParsedBookInfo.Quality,
                                                           subject.PreferredWordScore))
                {
                    return(Decision.Reject("Release in queue is of equal or higher preference: {0}", remoteBook.ParsedBookInfo.Quality));
                }

                _logger.Debug("Checking if profiles allow upgrading. Queued: {0}", remoteBook.ParsedBookInfo.Quality);

                if (!_upgradableSpecification.IsUpgradeAllowed(qualityProfile,
                                                               remoteBook.ParsedBookInfo.Quality,
                                                               subject.ParsedBookInfo.Quality))
                {
                    return(Decision.Reject("Another release is queued and the Quality profile does not allow upgrades"));
                }
            }

            return(Decision.Accept());
        }
Example #7
0
        public Decision IsSatisfiedBy(RemoteAlbum subject, SearchCriteriaBase searchCriteria)
        {
            var queue         = _queueService.GetQueue();
            var matchingAlbum = queue.Where(q => q.RemoteAlbum != null &&
                                            q.RemoteAlbum.Artist != null &&
                                            q.RemoteAlbum.Artist.Id == subject.Artist.Id &&
                                            q.RemoteAlbum.Albums.Select(e => e.Id).Intersect(subject.Albums.Select(e => e.Id)).Any())
                                .ToList();


            foreach (var queueItem in matchingAlbum)
            {
                var remoteAlbum    = queueItem.RemoteAlbum;
                var qualityProfile = subject.Artist.QualityProfile.Value;

                _logger.Debug("Checking if existing release in queue meets cutoff. Queued quality is: {0}", remoteAlbum.ParsedAlbumInfo.Quality);
                var queuedItemPreferredWordScore = _preferredWordServiceCalculator.Calculate(subject.Artist, queueItem.Title);

                if (!_upgradableSpecification.CutoffNotMet(qualityProfile,
                                                           new List <QualityModel> {
                    remoteAlbum.ParsedAlbumInfo.Quality
                },
                                                           queuedItemPreferredWordScore,
                                                           subject.ParsedAlbumInfo.Quality,
                                                           subject.PreferredWordScore))

                {
                    return(Decision.Reject("Release in queue already meets cutoff: {0}", remoteAlbum.ParsedAlbumInfo.Quality));
                }

                _logger.Debug("Checking if release is higher quality than queued release. Queued: {0}", remoteAlbum.ParsedAlbumInfo.Quality);

                if (!_upgradableSpecification.IsUpgradable(qualityProfile,
                                                           new List <QualityModel> {
                    remoteAlbum.ParsedAlbumInfo.Quality
                },
                                                           queuedItemPreferredWordScore,
                                                           subject.ParsedAlbumInfo.Quality,
                                                           subject.PreferredWordScore))
                {
                    return(Decision.Reject("Release in queue is of equal or higher preference: {0}", remoteAlbum.ParsedAlbumInfo.Quality));
                }

                _logger.Debug("Checking if profiles allow upgrading. Queued: {0}", remoteAlbum.ParsedAlbumInfo.Quality);

                if (!_upgradableSpecification.IsUpgradeAllowed(qualityProfile,
                                                               new List <QualityModel> {
                    remoteAlbum.ParsedAlbumInfo.Quality
                },
                                                               subject.ParsedAlbumInfo.Quality))
                {
                    return(Decision.Reject("Another release is queued and the Quality profile does not allow upgrades"));
                }
            }

            return(Decision.Accept());
        }
        public virtual Decision IsSatisfiedBy(RemoteBook subject, SearchCriteriaBase searchCriteria)
        {
            foreach (var file in subject.Books.SelectMany(c => c.BookFiles.Value))
            {
                if (file == null)
                {
                    return(Decision.Accept());
                }

                if (!_upgradableSpecification.IsUpgradable(subject.Author.QualityProfile,
                                                           file.Quality,
                                                           _preferredWordServiceCalculator.Calculate(subject.Author, file.GetSceneOrFileName(), subject.Release?.IndexerId ?? 0),
                                                           subject.ParsedBookInfo.Quality,
                                                           subject.PreferredWordScore))
                {
                    return(Decision.Reject("Existing files on disk is of equal or higher preference: {0}", file.Quality));
                }
            }

            return(Decision.Accept());
        }