Cleanup Conflicts in Sonarr/Lidarr Pulls

Co-Authored-By: Robin Dadswell <19610103+RobinDadswell@users.noreply.github.com>
This commit is contained in:
Qstick
2021-01-24 02:22:50 -05:00
parent ffc12656ee
commit 93ba5ade9e
298 changed files with 4460 additions and 4508 deletions
@@ -81,7 +81,7 @@ namespace NzbDrone.Core.DecisionEngine
else
{
// try parsing fuzzy
parsedBookInfo = _parsingService.ParseAlbumTitleFuzzy(report.Title);
parsedBookInfo = _parsingService.ParseBookTitleFuzzy(report.Title);
}
}
@@ -156,23 +156,23 @@ namespace NzbDrone.Core.DecisionEngine
if (searchCriteria != null)
{
if (parsedAlbumInfo == null)
if (parsedBookInfo == null)
{
parsedAlbumInfo = new ParsedAlbumInfo
parsedBookInfo = new ParsedBookInfo
{
Quality = QualityParser.ParseQuality(report.Title, null, 0)
Quality = QualityParser.ParseQuality(report.Title, null)
};
}
if (parsedAlbumInfo.ArtistName.IsNullOrWhiteSpace())
if (parsedBookInfo.AuthorName.IsNullOrWhiteSpace())
{
var remoteAlbum = new RemoteAlbum
var remoteBook = new RemoteBook
{
Release = report,
ParsedAlbumInfo = parsedAlbumInfo
ParsedBookInfo = parsedBookInfo
};
decision = new DownloadDecision(remoteAlbum, new Rejection("Unable to parse release"));
decision = new DownloadDecision(remoteBook, new Rejection("Unable to parse release"));
}
}
}
@@ -29,7 +29,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
/*
_logger.Debug("Beginning size check for: {0}", subject);
var quality = subject.ParsedAlbumInfo.Quality.Quality;
var quality = subject.ParsedBookInfo.Quality.Quality;
if (subject.Release.Size == 0)
{
@@ -52,15 +52,15 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
continue;
}
var historyForAlbum = _historyService.GetByBook(book.Id, null);
var lastGrabbed = historyForAlbum.FirstOrDefault(h => h.EventType == HistoryEventType.Grabbed);
var historyForBook = _historyService.GetByBook(book.Id, null);
var lastGrabbed = historyForBook.FirstOrDefault(h => h.EventType == HistoryEventType.Grabbed);
if (lastGrabbed == null)
{
continue;
}
var imported = historyForAlbum.FirstOrDefault(h =>
var imported = historyForBook.FirstOrDefault(h =>
h.EventType == HistoryEventType.DownloadImported &&
h.DownloadId == lastGrabbed.DownloadId);
@@ -23,12 +23,12 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
{
if (subject.ParsedBookInfo.Discography)
{
_logger.Debug("Checking if all albums in discography release have released. {0}", subject.Release.Title);
_logger.Debug("Checking if all books in discography release have released. {0}", subject.Release.Title);
if (subject.Books.Any(e => !e.ReleaseDate.HasValue || e.ReleaseDate.Value.After(DateTime.UtcNow)))
{
_logger.Debug("Discography release {0} rejected. All albums haven't released yet.", subject.Release.Title);
return Decision.Reject("Discography release rejected. All albums haven't released yet.");
_logger.Debug("Discography release {0} rejected. All books haven't released yet.", subject.Release.Title);
return Decision.Reject("Discography release rejected. All books haven't released yet.");
}
}
@@ -34,12 +34,12 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
public Decision IsSatisfiedBy(RemoteBook subject, SearchCriteriaBase searchCriteria)
{
var queue = _queueService.GetQueue();
var matchingAlbum = queue.Where(q => q.RemoteBook?.Author != null &&
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 matchingAlbum)
foreach (var queueItem in matchingBook)
{
var remoteBook = queueItem.RemoteBook;
var qualityProfile = subject.Author.QualityProfile.Value;
@@ -68,7 +68,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
_logger.Debug("Checking if release is higher quality than queued release. Queued: {0}", remoteBook.ParsedBookInfo.Quality);
if (!_upgradableSpecification.IsUpgradable(qualityProfile,
new List<QualityModel> { remoteBook.ParsedBookInfo.Quality },
remoteBook.ParsedBookInfo.Quality,
queuedItemPreferredWordScore,
subject.ParsedBookInfo.Quality,
subject.PreferredWordScore))
@@ -79,7 +79,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
_logger.Debug("Checking if profiles allow upgrading. Queued: {0}", remoteBook.ParsedBookInfo.Quality);
if (!_upgradableSpecification.IsUpgradeAllowed(qualityProfile,
new List<QualityModel> { remoteBook.ParsedBookInfo.Quality },
remoteBook.ParsedBookInfo.Quality,
subject.ParsedBookInfo.Quality))
{
return Decision.Reject("Another release is queued and the Quality profile does not allow upgrades");
@@ -60,8 +60,8 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
continue;
}
// The artist will be the same as the one in history since it's the same album.
// Instead of fetching the artist from the DB reuse the known artist.
// The author will be the same as the one in history since it's the same book.
// Instead of fetching the author from the DB reuse the known author.
var preferredWordScore = _preferredWordServiceCalculator.Calculate(subject.Author, mostRecent.SourceTitle, subject.Release?.IndexerId ?? 0);
var cutoffUnmet = _upgradableSpecification.CutoffNotMet(
@@ -73,7 +73,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
var upgradeable = _upgradableSpecification.IsUpgradable(
subject.Author.QualityProfile,
new List<QualityModel> { mostRecent.Quality },
mostRecent.Quality,
preferredWordScore,
subject.ParsedBookInfo.Quality,
subject.PreferredWordScore);
@@ -9,11 +9,11 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
{
public interface IUpgradableSpecification
{
bool IsUpgradable(QualityProfile profile, List<QualityModel> currentQualities, int currentScore, QualityModel newQuality, int newScore);
bool IsUpgradable(QualityProfile profile, QualityModel currentQualities, int currentScore, QualityModel newQuality, int newScore);
bool QualityCutoffNotMet(QualityProfile profile, QualityModel currentQuality, QualityModel newQuality = null);
bool CutoffNotMet(QualityProfile profile, List<QualityModel> currentQualities, int currentScore, QualityModel newQuality = null, int newScore = 0);
bool IsRevisionUpgrade(QualityModel currentQuality, QualityModel newQuality);
bool IsUpgradeAllowed(QualityProfile qualityProfile, List<QualityModel> currentQualities, QualityModel newQuality);
bool IsUpgradeAllowed(QualityProfile qualityProfile, QualityModel currentQuality, QualityModel newQuality);
}
public class UpgradableSpecification : IUpgradableSpecification
@@ -27,23 +27,20 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
_logger = logger;
}
private ProfileComparisonResult IsQualityUpgradable(QualityProfile profile, List<QualityModel> currentQualities, QualityModel newQuality = null)
private ProfileComparisonResult IsQualityUpgradable(QualityProfile profile, QualityModel currentQuality, QualityModel newQuality = null)
{
if (newQuality != null)
{
var totalCompare = 0;
foreach (var quality in currentQualities)
var compare = new QualityModelComparer(profile).Compare(newQuality, currentQuality);
totalCompare += compare;
if (compare < 0)
{
var compare = new QualityModelComparer(profile).Compare(newQuality, quality);
totalCompare += compare;
if (compare < 0)
{
// Not upgradable if new quality is a downgrade for any current quality
return ProfileComparisonResult.Downgrade;
}
// Not upgradable if new quality is a downgrade for any current quality
return ProfileComparisonResult.Downgrade;
}
// Not upgradable if new quality is equal to all current qualities
@@ -52,12 +49,13 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
return ProfileComparisonResult.Equal;
}
// Quality Treated as Equal if Propers are not Prefered
// Accept unless the user doesn't want to prefer propers, optionally they can
// use preferred words to prefer propers/repacks over non-propers/repacks.
if (_configService.DownloadPropersAndRepacks == ProperDownloadTypes.DoNotPrefer &&
newQuality.Revision.CompareTo(currentQualities.Min(q => q.Revision)) > 0)
{
return ProfileComparisonResult.Equal;
}
newQuality?.Revision.CompareTo(currentQuality.Revision) > 0)
{
return ProfileComparisonResult.Equal;
}
}
return ProfileComparisonResult.Upgrade;
@@ -70,7 +68,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
return newScore > currentScore;
}
public bool IsUpgradable(QualityProfile qualityProfile, List<QualityModel> currentQualities, int currentScore, QualityModel newQuality, int newScore)
public bool IsUpgradable(QualityProfile qualityProfile, QualityModel currentQualities, int currentScore, QualityModel newQuality, int newScore)
{
var qualityUpgrade = IsQualityUpgradable(qualityProfile, currentQualities, newQuality);
@@ -147,9 +145,9 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
return false;
}
public bool IsUpgradeAllowed(QualityProfile qualityProfile, List<QualityModel> currentQualities, QualityModel newQuality)
public bool IsUpgradeAllowed(QualityProfile qualityProfile, QualityModel currentQuality, QualityModel newQuality)
{
var isQualityUpgrade = IsQualityUpgradable(qualityProfile, currentQualities, newQuality);
var isQualityUpgrade = IsQualityUpgradable(qualityProfile, currentQuality, newQuality);
return CheckUpgradeAllowed(qualityProfile, isQualityUpgrade);
}
@@ -35,13 +35,10 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
continue;
}
// 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());
_logger.Debug("Comparing file quality with report. Existing files contain {0}", file.Quality);
if (!_upgradableSpecification.IsUpgradeAllowed(qualityProfile,
currentQualities,
file.Quality,
subject.ParsedBookInfo.Quality))
{
_logger.Debug("Upgrading is not allowed by the quality profile");
@@ -32,18 +32,16 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
{
if (file == null)
{
_logger.Debug("File is no longer available, skipping this file.");
continue;
return Decision.Accept();
}
if (!_upgradableSpecification.IsUpgradable(subject.Author.QualityProfile,
currentQualities,
_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}", currentQualities.ConcatToString());
}
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);
}
}