Esempio n. 1
0
        public virtual Decision IsSatisfiedBy(RemoteAlbum subject, SearchCriteriaBase searchCriteria)
        {
            var qualityProfile = subject.Artist.QualityProfile.Value;

            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())
                {
                    // Get a distinct list of all current track qualities for a given album
                    var currentQualities = trackFiles.Select(c => c.Quality).Distinct().ToList();

                    _logger.Debug("Comparing file quality with report. Existing files contain {0}", currentQualities.ConcatToString());

                    if (!_upgradableSpecification.CutoffNotMet(qualityProfile,
                                                               currentQualities,
                                                               _preferredWordServiceCalculator.Calculate(subject.Artist, trackFiles[0].GetSceneOrFileName()),
                                                               subject.ParsedAlbumInfo.Quality,
                                                               subject.PreferredWordScore))
                    {
                        _logger.Debug("Cutoff already met by existing files, rejecting.");

                        var qualityCutoffIndex = qualityProfile.GetIndex(qualityProfile.Cutoff);
                        var qualityCutoff      = qualityProfile.Items[qualityCutoffIndex.Index];

                        return(Decision.Reject("Existing files meets cutoff: {0}", qualityCutoff));
                    }
                }
            }

            return(Decision.Accept());
        }
Esempio n. 2
0
        public virtual Decision IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria)
        {
            var qualityProfile  = subject.Series.QualityProfile.Value;
            var languageProfile = subject.Series.LanguageProfile.Value;

            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.CutoffNotMet(qualityProfile,
                                                           languageProfile,
                                                           file.Quality,
                                                           file.Language,
                                                           _episodeFilePreferredWordCalculator.Calculate(subject.Series, file),
                                                           subject.ParsedEpisodeInfo.Quality,
                                                           subject.PreferredWordScore))
                {
                    _logger.Debug("Cutoff already met, rejecting.");

                    var qualityCutoffIndex = qualityProfile.GetIndex(qualityProfile.Cutoff);
                    var qualityCutoff      = qualityProfile.Items[qualityCutoffIndex.Index];

                    return(Decision.Reject("Existing file meets cutoff: {0} - {1}", qualityCutoff, languageProfile.Cutoff));
                }
            }

            return(Decision.Accept());
        }
Esempio n. 3
0
        public virtual Decision IsSatisfiedBy(RemoteBook subject, SearchCriteriaBase searchCriteria)
        {
            var qualityProfile = subject.Author.QualityProfile.Value;

            foreach (var file in subject.Books.SelectMany(b => b.BookFiles.Value))
            {
                // Get a distinct list of all current track qualities for a given book
                var currentQualities = new List <QualityModel> {
                    file.Quality
                };

                _logger.Debug("Comparing file quality with report. Existing files contain {0}", currentQualities.ConcatToString());

                if (!_upgradableSpecification.CutoffNotMet(qualityProfile,
                                                           currentQualities,
                                                           _preferredWordServiceCalculator.Calculate(subject.Author, file.GetSceneOrFileName()),
                                                           subject.ParsedBookInfo.Quality,
                                                           subject.PreferredWordScore))
                {
                    _logger.Debug("Cutoff already met by existing files, rejecting.");

                    var qualityCutoffIndex = qualityProfile.GetIndex(qualityProfile.Cutoff);
                    var qualityCutoff      = qualityProfile.Items[qualityCutoffIndex.Index];

                    return(Decision.Reject("Existing files meets cutoff: {0}", qualityCutoff));
                }
            }

            return(Decision.Accept());
        }
Esempio n. 4
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());
        }
Esempio n. 5
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());
        }
Esempio n. 6
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());
        }