mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-23 22:25:09 -04:00
New: Release Profiles, Frontend updates (#580)
* New: Release Profiles - UI Updates * New: Release Profiles - API Changes * New: Release Profiles - Test Updates * New: Release Profiles - Backend Updates * New: Interactive Artist Search * New: Change Montiored on Album Details Page * New: Show Duration on Album Details Page * Fixed: Manual Import not working if no albums are Missing * Fixed: Sort search input by sortTitle * Fixed: Queue columnLabel throwing JS error
This commit is contained in:
@@ -6,6 +6,7 @@ using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Common.Cache;
|
||||
using NzbDrone.Core.Profiles.Releases;
|
||||
|
||||
namespace NzbDrone.Core.DecisionEngine.Specifications
|
||||
{
|
||||
@@ -16,18 +17,21 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
|
||||
private readonly ITrackService _trackService;
|
||||
private readonly Logger _logger;
|
||||
private readonly ICached<bool> _missingFilesCache;
|
||||
private readonly IPreferredWordService _preferredWordServiceCalculator;
|
||||
|
||||
public CutoffSpecification(UpgradableSpecification upgradableSpecification,
|
||||
Logger logger,
|
||||
ICacheManager cacheManager,
|
||||
IMediaFileService mediaFileService,
|
||||
IPreferredWordService preferredWordServiceCalculator,
|
||||
ITrackService trackService)
|
||||
{
|
||||
_upgradableSpecification = upgradableSpecification;
|
||||
_logger = logger;
|
||||
_mediaFileService = mediaFileService;
|
||||
_trackService = trackService;
|
||||
_missingFilesCache = cacheManager.GetCache<bool>(GetType());
|
||||
_preferredWordServiceCalculator = preferredWordServiceCalculator;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public SpecificationPriority Priority => SpecificationPriority.Default;
|
||||
@@ -36,7 +40,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
|
||||
public virtual Decision IsSatisfiedBy(RemoteAlbum subject, SearchCriteriaBase searchCriteria)
|
||||
{
|
||||
|
||||
var profile = subject.Artist.Profile.Value;
|
||||
var profile = subject.Artist.QualityProfile.Value;
|
||||
|
||||
foreach (var album in subject.Albums)
|
||||
{
|
||||
@@ -54,7 +58,9 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
|
||||
subject.Artist.LanguageProfile,
|
||||
lowestQuality,
|
||||
trackFiles[0].Language,
|
||||
subject.ParsedAlbumInfo.Quality))
|
||||
_preferredWordServiceCalculator.Calculate(subject.Artist, trackFiles[0].GetSceneOrFileName()),
|
||||
subject.ParsedAlbumInfo.Quality,
|
||||
subject.PreferredWordScore))
|
||||
{
|
||||
_logger.Debug("Cutoff already met, rejecting.");
|
||||
var qualityCutoffIndex = profile.GetIndex(profile.Cutoff);
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
using NzbDrone.Core.IndexerSearch.Definitions;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
namespace NzbDrone.Core.DecisionEngine.Specifications
|
||||
{
|
||||
public interface IDecisionEngineSpecification
|
||||
{
|
||||
RejectionType Type { get; }
|
||||
|
||||
SpecificationPriority Priority { get; }
|
||||
|
||||
Decision IsSatisfiedBy(RemoteAlbum subject, SearchCriteriaBase searchCriteria);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -21,7 +21,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
|
||||
{
|
||||
_logger.Debug("Checking if report meets quality requirements. {0}", subject.ParsedAlbumInfo.Quality);
|
||||
|
||||
var profile = subject.Artist.Profile.Value;
|
||||
var profile = subject.Artist.QualityProfile.Value;
|
||||
var qualityIndex = profile.GetIndex(subject.ParsedAlbumInfo.Quality.Quality);
|
||||
var qualityOrGroup = profile.Items[qualityIndex.Index];
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Core.IndexerSearch.Definitions;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Profiles.Releases;
|
||||
using NzbDrone.Core.Queue;
|
||||
|
||||
namespace NzbDrone.Core.DecisionEngine.Specifications
|
||||
@@ -10,14 +11,17 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
|
||||
{
|
||||
private readonly IQueueService _queueService;
|
||||
private readonly UpgradableSpecification _upgradableSpecification;
|
||||
private readonly IPreferredWordService _preferredWordServiceCalculator;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public QueueSpecification(IQueueService queueService,
|
||||
UpgradableSpecification upgradableSpecification,
|
||||
IPreferredWordService preferredWordServiceCalculator,
|
||||
Logger logger)
|
||||
{
|
||||
_queueService = queueService;
|
||||
_upgradableSpecification = upgradableSpecification;
|
||||
_preferredWordServiceCalculator = preferredWordServiceCalculator;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
@@ -26,33 +30,43 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
|
||||
|
||||
public Decision IsSatisfiedBy(RemoteAlbum subject, SearchCriteriaBase searchCriteria)
|
||||
{
|
||||
var queue = _queueService.GetQueue()
|
||||
.Select(q => q.RemoteAlbum).ToList();
|
||||
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();
|
||||
|
||||
var matchingArtist = queue.Where(q => q.Artist.Id == subject.Artist.Id);
|
||||
var matchingAlbum = matchingArtist.Where(q => q.Albums.Select(e => e.Id).Intersect(subject.Albums.Select(e => e.Id)).Any());
|
||||
|
||||
foreach (var remoteAlbum in matchingAlbum)
|
||||
foreach (var queueItem in matchingAlbum)
|
||||
{
|
||||
var remoteAlbum = queueItem.RemoteAlbum;
|
||||
|
||||
_logger.Debug("Checking if existing release in queue meets cutoff. Queued quality is: {0} - {1}", remoteAlbum.ParsedAlbumInfo.Quality, remoteAlbum.ParsedAlbumInfo.Language);
|
||||
var queuedItemPreferredWordScore = _preferredWordServiceCalculator.Calculate(subject.Artist, queueItem.Title);
|
||||
|
||||
if (!_upgradableSpecification.CutoffNotMet(subject.Artist.Profile,
|
||||
if (!_upgradableSpecification.CutoffNotMet(subject.Artist.QualityProfile,
|
||||
subject.Artist.LanguageProfile,
|
||||
remoteAlbum.ParsedAlbumInfo.Quality,
|
||||
remoteAlbum.ParsedAlbumInfo.Language,
|
||||
subject.ParsedAlbumInfo.Quality))
|
||||
queuedItemPreferredWordScore,
|
||||
subject.ParsedAlbumInfo.Quality,
|
||||
subject.PreferredWordScore))
|
||||
|
||||
{
|
||||
return Decision.Reject("Quality for release in queue already meets cutoff: {0}", remoteAlbum.ParsedAlbumInfo.Quality);
|
||||
}
|
||||
|
||||
_logger.Debug("Checking if release is higher quality than queued release. Queued quality is: {0} - {1}", remoteAlbum.ParsedAlbumInfo.Quality, remoteAlbum.ParsedAlbumInfo.Language);
|
||||
|
||||
if (!_upgradableSpecification.IsUpgradable(subject.Artist.Profile,
|
||||
if (!_upgradableSpecification.IsUpgradable(subject.Artist.QualityProfile,
|
||||
subject.Artist.LanguageProfile,
|
||||
remoteAlbum.ParsedAlbumInfo.Quality,
|
||||
remoteAlbum.ParsedAlbumInfo.Language,
|
||||
queuedItemPreferredWordScore,
|
||||
subject.ParsedAlbumInfo.Quality,
|
||||
subject.ParsedAlbumInfo.Language))
|
||||
subject.ParsedAlbumInfo.Language,
|
||||
subject.PreferredWordScore))
|
||||
{
|
||||
return Decision.Reject("Quality for release in queue is of equal or higher preference: {0} - {1}", remoteAlbum.ParsedAlbumInfo.Quality, remoteAlbum.ParsedAlbumInfo.Language);
|
||||
}
|
||||
|
||||
@@ -5,20 +5,20 @@ using NLog;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.IndexerSearch.Definitions;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Restrictions;
|
||||
using NzbDrone.Core.Profiles.Releases;
|
||||
|
||||
namespace NzbDrone.Core.DecisionEngine.Specifications
|
||||
{
|
||||
public class ReleaseRestrictionsSpecification : IDecisionEngineSpecification
|
||||
{
|
||||
private readonly IRestrictionService _restrictionService;
|
||||
private readonly Logger _logger;
|
||||
private readonly IReleaseProfileService _releaseProfileService;
|
||||
private readonly ITermMatcher _termMatcher;
|
||||
|
||||
public ReleaseRestrictionsSpecification(ITermMatcher termMatcher, IRestrictionService restrictionService, Logger logger)
|
||||
public ReleaseRestrictionsSpecification(ITermMatcher termMatcher, IReleaseProfileService releaseProfileService, Logger logger)
|
||||
{
|
||||
_restrictionService = restrictionService;
|
||||
_logger = logger;
|
||||
_releaseProfileService = releaseProfileService;
|
||||
_termMatcher = termMatcher;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
|
||||
_logger.Debug("Checking if release meets restrictions: {0}", subject);
|
||||
|
||||
var title = subject.Release.Title;
|
||||
var restrictions = _restrictionService.AllForTags(subject.Artist.Tags);
|
||||
var restrictions = _releaseProfileService.AllForTags(subject.Artist.Tags);
|
||||
|
||||
var required = restrictions.Where(r => r.Required.IsNotNullOrWhiteSpace());
|
||||
var ignored = restrictions.Where(r => r.Ignored.IsNotNullOrWhiteSpace());
|
||||
|
||||
@@ -7,6 +7,7 @@ using NzbDrone.Core.Profiles.Delay;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Languages;
|
||||
using NzbDrone.Core.Profiles.Releases;
|
||||
|
||||
namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
|
||||
{
|
||||
@@ -16,18 +17,21 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
|
||||
private readonly IUpgradableSpecification _upgradableSpecification;
|
||||
private readonly IDelayProfileService _delayProfileService;
|
||||
private readonly IMediaFileService _mediaFileService;
|
||||
private readonly IPreferredWordService _preferredWordServiceCalculator;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public DelaySpecification(IPendingReleaseService pendingReleaseService,
|
||||
IUpgradableSpecification qualityUpgradableSpecification,
|
||||
IDelayProfileService delayProfileService,
|
||||
IMediaFileService mediaFileService,
|
||||
IPreferredWordService preferredWordServiceCalculator,
|
||||
Logger logger)
|
||||
{
|
||||
_pendingReleaseService = pendingReleaseService;
|
||||
_upgradableSpecification = qualityUpgradableSpecification;
|
||||
_delayProfileService = delayProfileService;
|
||||
_mediaFileService = mediaFileService;
|
||||
_preferredWordServiceCalculator = preferredWordServiceCalculator;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
@@ -42,7 +46,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
|
||||
return Decision.Accept();
|
||||
}
|
||||
|
||||
var profile = subject.Artist.Profile.Value;
|
||||
var qualityProfile = subject.Artist.QualityProfile.Value;
|
||||
var languageProfile = subject.Artist.LanguageProfile.Value;
|
||||
var delayProfile = _delayProfileService.BestForTags(subject.Artist.Tags);
|
||||
var delay = delayProfile.GetProtocolDelay(subject.Release.DownloadProtocol);
|
||||
@@ -54,8 +58,8 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
|
||||
return Decision.Accept();
|
||||
}
|
||||
|
||||
var comparer = new QualityModelComparer(profile);
|
||||
var comparerLanguage = new LanguageComparer(languageProfile);
|
||||
var qualityComparer = new QualityModelComparer(qualityProfile);
|
||||
var languageComparer = new LanguageComparer(languageProfile);
|
||||
|
||||
if (isPreferredProtocol)
|
||||
{
|
||||
@@ -66,12 +70,14 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
|
||||
if (trackFiles.Any())
|
||||
{
|
||||
var lowestQuality = trackFiles.Select(c => c.Quality).OrderBy(c => c.Quality.Id).First();
|
||||
var upgradable = _upgradableSpecification.IsUpgradable(profile,
|
||||
var upgradable = _upgradableSpecification.IsUpgradable(qualityProfile,
|
||||
languageProfile,
|
||||
lowestQuality,
|
||||
trackFiles[0].Language,
|
||||
_preferredWordServiceCalculator.Calculate(subject.Artist, trackFiles[0].GetSceneOrFileName()),
|
||||
subject.ParsedAlbumInfo.Quality,
|
||||
subject.ParsedAlbumInfo.Language);
|
||||
subject.ParsedAlbumInfo.Language,
|
||||
subject.PreferredWordScore);
|
||||
if (upgradable)
|
||||
{
|
||||
_logger.Debug("New quality is a better revision for existing quality, skipping delay");
|
||||
@@ -82,9 +88,9 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
|
||||
}
|
||||
|
||||
// If quality meets or exceeds the best allowed quality in the profile accept it immediately
|
||||
var bestQualityInProfile = profile.LastAllowedQuality();
|
||||
var isBestInProfile = comparer.Compare(subject.ParsedAlbumInfo.Quality.Quality, bestQualityInProfile) >= 0;
|
||||
var isBestInProfileLanguage = comparerLanguage.Compare(subject.ParsedAlbumInfo.Language, languageProfile.LastAllowedLanguage()) >= 0;
|
||||
var bestQualityInProfile = qualityProfile.LastAllowedQuality();
|
||||
var isBestInProfile = qualityComparer.Compare(subject.ParsedAlbumInfo.Quality.Quality, bestQualityInProfile) >= 0;
|
||||
var isBestInProfileLanguage = languageComparer.Compare(subject.ParsedAlbumInfo.Language, languageProfile.LastAllowedLanguage()) >= 0;
|
||||
|
||||
if (isBestInProfile && isBestInProfileLanguage && isPreferredProtocol)
|
||||
{
|
||||
|
||||
@@ -5,6 +5,7 @@ using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.History;
|
||||
using NzbDrone.Core.IndexerSearch.Definitions;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Profiles.Releases;
|
||||
|
||||
namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
|
||||
{
|
||||
@@ -13,16 +14,19 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
|
||||
private readonly IHistoryService _historyService;
|
||||
private readonly UpgradableSpecification _upgradableSpecification;
|
||||
private readonly IConfigService _configService;
|
||||
private readonly IPreferredWordService _preferredWordServiceCalculator;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public HistorySpecification(IHistoryService historyService,
|
||||
UpgradableSpecification qualityUpgradableSpecification,
|
||||
IConfigService configService,
|
||||
IPreferredWordService preferredWordServiceCalculator,
|
||||
Logger logger)
|
||||
{
|
||||
_historyService = historyService;
|
||||
_upgradableSpecification = qualityUpgradableSpecification;
|
||||
_configService = configService;
|
||||
_preferredWordServiceCalculator = preferredWordServiceCalculator;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
@@ -48,8 +52,28 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
|
||||
if (mostRecent != null && mostRecent.EventType == HistoryEventType.Grabbed)
|
||||
{
|
||||
var recent = mostRecent.Date.After(DateTime.UtcNow.AddHours(-12));
|
||||
var cutoffUnmet = _upgradableSpecification.CutoffNotMet(subject.Artist.Profile, subject.Artist.LanguageProfile, mostRecent.Quality, mostRecent.Language, subject.ParsedAlbumInfo.Quality);
|
||||
var upgradeable = _upgradableSpecification.IsUpgradable(subject.Artist.Profile, subject.Artist.LanguageProfile, mostRecent.Quality, mostRecent.Language, subject.ParsedAlbumInfo.Quality, subject.ParsedAlbumInfo.Language);
|
||||
// The artist will be the same as the one in history since it's the same episode.
|
||||
// Instead of fetching the series from the DB reuse the known series.
|
||||
var preferredWordScore = _preferredWordServiceCalculator.Calculate(subject.Artist, mostRecent.SourceTitle);
|
||||
|
||||
var cutoffUnmet = _upgradableSpecification.CutoffNotMet(
|
||||
subject.Artist.QualityProfile,
|
||||
subject.Artist.LanguageProfile,
|
||||
mostRecent.Quality,
|
||||
mostRecent.Language,
|
||||
preferredWordScore,
|
||||
subject.ParsedAlbumInfo.Quality,
|
||||
subject.PreferredWordScore);
|
||||
|
||||
var upgradeable = _upgradableSpecification.IsUpgradable(
|
||||
subject.Artist.QualityProfile,
|
||||
subject.Artist.LanguageProfile,
|
||||
mostRecent.Quality,
|
||||
mostRecent.Language,
|
||||
preferredWordScore,
|
||||
subject.ParsedAlbumInfo.Quality,
|
||||
subject.ParsedAlbumInfo.Language,
|
||||
subject.PreferredWordScore);
|
||||
|
||||
if (!recent && cdhEnabled)
|
||||
{
|
||||
|
||||
+16
-2
@@ -30,7 +30,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
|
||||
|
||||
if (!subject.Artist.Monitored)
|
||||
{
|
||||
_logger.Debug("{0} is present in the DB but not tracked. skipping.", subject.Artist);
|
||||
_logger.Debug("{0} is present in the DB but not tracked. Rejecting.", subject.Artist);
|
||||
return Decision.Reject("Artist is not monitored");
|
||||
}
|
||||
|
||||
@@ -40,7 +40,21 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
|
||||
return Decision.Accept();
|
||||
}
|
||||
|
||||
_logger.Debug("Only {0}/{1} albums are monitored. skipping.", monitoredCount, subject.Albums.Count);
|
||||
if (subject.Albums.Count == 1)
|
||||
{
|
||||
_logger.Debug("Album is not monitored. Rejecting", monitoredCount, subject.Albums.Count);
|
||||
return Decision.Reject("Album is not monitored");
|
||||
}
|
||||
|
||||
if (monitoredCount == 0)
|
||||
{
|
||||
_logger.Debug("No albums in the release are monitored. Rejecting", monitoredCount, subject.Albums.Count);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Debug("Only {0}/{1} albums in the release are monitored. Rejecting", monitoredCount, subject.Albums.Count);
|
||||
}
|
||||
|
||||
return Decision.Reject("Album is not monitored");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Music;
|
||||
|
||||
namespace NzbDrone.Core.DecisionEngine.Specifications
|
||||
{
|
||||
public class SameTracksSpecification
|
||||
{
|
||||
private readonly ITrackService _trackService;
|
||||
|
||||
public SameTracksSpecification(ITrackService trackService)
|
||||
{
|
||||
_trackService = trackService;
|
||||
}
|
||||
|
||||
public bool IsSatisfiedBy(List<Track> tracks)
|
||||
{
|
||||
var trackIds = tracks.SelectList(e => e.Id);
|
||||
var trackFileIds = tracks.Where(c => c.TrackFileId != 0).Select(c => c.TrackFileId).Distinct();
|
||||
|
||||
foreach (var trackFileId in trackFileIds)
|
||||
{
|
||||
var tracksInFile = _trackService.GetTracksByFileId(trackFileId);
|
||||
|
||||
if (tracksInFile.Select(e => e.Id).Except(trackIds).Any())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
using System;
|
||||
using NLog;
|
||||
using NzbDrone.Core.IndexerSearch.Definitions;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
namespace NzbDrone.Core.DecisionEngine.Specifications.Search
|
||||
{
|
||||
public class SeasonMatchSpecification : IDecisionEngineSpecification
|
||||
{
|
||||
private readonly Logger _logger;
|
||||
|
||||
public SeasonMatchSpecification(Logger logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public SpecificationPriority Priority => SpecificationPriority.Default;
|
||||
public RejectionType Type => RejectionType.Permanent;
|
||||
|
||||
public virtual Decision IsSatisfiedBy(RemoteAlbum subject, SearchCriteriaBase searchCriteria)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
-45
@@ -1,45 +0,0 @@
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Core.IndexerSearch.Definitions;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
namespace NzbDrone.Core.DecisionEngine.Specifications.Search
|
||||
{
|
||||
public class SingleEpisodeMatchSpecification : IDecisionEngineSpecification
|
||||
{
|
||||
private readonly Logger _logger;
|
||||
|
||||
public SingleEpisodeMatchSpecification(Logger logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public string RejectionReason
|
||||
{
|
||||
get
|
||||
{
|
||||
return "Episode doesn't match";
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsSatisfiedBy(RemoteEpisode remoteEpisode, SearchDefinitionBase searchDefinitionBase)
|
||||
{
|
||||
var singleEpisodeSpec = searchDefinitionBase as SingleEpisodeSearchDefinition;
|
||||
if (singleEpisodeSpec == null) return true;
|
||||
|
||||
if (singleEpisodeSpec.SeasonNumber != remoteEpisode.ParsedEpisodeInfo.SeasonNumber)
|
||||
{
|
||||
_logger.Trace("Season number does not match searched season number, skipping.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!remoteEpisode.Episodes.Select(c => c.EpisodeNumber).Contains(singleEpisodeSpec.EpisodeNumber))
|
||||
{
|
||||
_logger.Trace("Episode number does not match searched episode number, skipping.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
using NLog;
|
||||
using NzbDrone.Core.Languages;
|
||||
using NzbDrone.Core.Profiles.Languages;
|
||||
using NzbDrone.Core.Profiles.Qualities;
|
||||
using NzbDrone.Core.Qualities;
|
||||
|
||||
namespace NzbDrone.Core.DecisionEngine.Specifications
|
||||
{
|
||||
public interface IUpgradableSpecification
|
||||
{
|
||||
bool IsUpgradable(QualityProfile profile, LanguageProfile languageProfile, QualityModel currentQuality, Language currentLanguage, int currentScore, QualityModel newQuality, Language newLanguage, int newScore);
|
||||
bool QualityCutoffNotMet(QualityProfile profile, QualityModel currentQuality, QualityModel newQuality = null);
|
||||
bool LanguageCutoffNotMet(LanguageProfile languageProfile, Language currentLanguage);
|
||||
bool CutoffNotMet(QualityProfile profile, LanguageProfile languageProfile, QualityModel currentQuality, Language currentLanguage, int currentScore, QualityModel newQuality = null, int newScore = 0);
|
||||
bool IsRevisionUpgrade(QualityModel currentQuality, QualityModel newQuality);
|
||||
}
|
||||
|
||||
public class UpgradableSpecification : IUpgradableSpecification
|
||||
{
|
||||
private readonly Logger _logger;
|
||||
|
||||
public UpgradableSpecification(Logger logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
private bool IsLanguageUpgradable(LanguageProfile profile, Language currentLanguage, Language newLanguage = null)
|
||||
{
|
||||
if (newLanguage != null)
|
||||
{
|
||||
var compare = new LanguageComparer(profile).Compare(newLanguage, currentLanguage);
|
||||
if (compare <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool IsQualityUpgradable(QualityProfile profile, QualityModel currentQuality, QualityModel newQuality = null)
|
||||
{
|
||||
if (newQuality != null)
|
||||
{
|
||||
var compare = new QualityModelComparer(profile).Compare(newQuality, currentQuality);
|
||||
|
||||
if (compare <= 0)
|
||||
{
|
||||
_logger.Debug("Existing item has better quality, skipping");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool IsPreferredWordUpgradable(int currentScore, int newScore)
|
||||
{
|
||||
return newScore > currentScore;
|
||||
}
|
||||
|
||||
public bool IsUpgradable(QualityProfile qualityProfile, LanguageProfile languageProfile, QualityModel currentQuality, Language currentLanguage, int currentScore, QualityModel newQuality, Language newLanguage, int newScore)
|
||||
{
|
||||
if (IsQualityUpgradable(qualityProfile, currentQuality, newQuality) && qualityProfile.UpgradeAllowed)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (new QualityModelComparer(qualityProfile).Compare(newQuality, currentQuality) < 0)
|
||||
{
|
||||
_logger.Debug("Existing item has better quality, skipping");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (IsLanguageUpgradable(languageProfile, currentLanguage, newLanguage) && languageProfile.UpgradeAllowed)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (new LanguageComparer(languageProfile).Compare(newLanguage, currentLanguage) < 0)
|
||||
{
|
||||
_logger.Debug("Existing item has better language, skipping");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!IsPreferredWordUpgradable(currentScore, newScore))
|
||||
{
|
||||
_logger.Debug("Existing item has a better preferred word score, skipping");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!IsPreferredWordUpgradable(currentScore, newScore))
|
||||
{
|
||||
_logger.Debug("Existing item has a better preferred word score, skipping");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool QualityCutoffNotMet(QualityProfile profile, QualityModel currentQuality, QualityModel newQuality = null)
|
||||
{
|
||||
var qualityCompare = new QualityModelComparer(profile).Compare(currentQuality.Quality.Id, profile.Cutoff);
|
||||
|
||||
if (qualityCompare < 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (qualityCompare == 0 && newQuality != null && IsRevisionUpgrade(currentQuality, newQuality))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool LanguageCutoffNotMet(LanguageProfile languageProfile, Language currentLanguage)
|
||||
{
|
||||
var languageCompare = new LanguageComparer(languageProfile).Compare(currentLanguage, languageProfile.Cutoff);
|
||||
|
||||
return languageCompare < 0;
|
||||
}
|
||||
|
||||
public bool CutoffNotMet(QualityProfile profile, LanguageProfile languageProfile, QualityModel currentQuality, Language currentLanguage, int currentScore, QualityModel newQuality = null, int newScore = 0)
|
||||
{
|
||||
// If we can upgrade the language (it is not the cutoff) then the quality doesn't
|
||||
// matter as we can always get same quality with prefered language.
|
||||
if (LanguageCutoffNotMet(languageProfile, currentLanguage))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (QualityCutoffNotMet(profile, currentQuality, newQuality))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (IsPreferredWordUpgradable(currentScore, newScore))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
_logger.Debug("Existing item meets cut-off. skipping.");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IsRevisionUpgrade(QualityModel currentQuality, QualityModel newQuality)
|
||||
{
|
||||
var compare = newQuality.Revision.CompareTo(currentQuality.Revision);
|
||||
|
||||
// Comparing the quality directly because we don't want to upgrade to a proper for a webrip from a webdl or vice versa
|
||||
if (currentQuality.Quality == newQuality.Quality && compare > 0)
|
||||
{
|
||||
_logger.Debug("New quality is a better revision for existing quality");
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Common.Cache;
|
||||
using NzbDrone.Core.Profiles.Releases;
|
||||
|
||||
namespace NzbDrone.Core.DecisionEngine.Specifications
|
||||
{
|
||||
@@ -14,6 +15,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
|
||||
private readonly IMediaFileService _mediaFileService;
|
||||
private readonly ITrackService _trackService;
|
||||
private readonly UpgradableSpecification _upgradableSpecification;
|
||||
private readonly IPreferredWordService _preferredWordServiceCalculator;
|
||||
private readonly Logger _logger;
|
||||
private readonly ICached<bool> _missingFilesCache;
|
||||
|
||||
@@ -21,11 +23,13 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
|
||||
IMediaFileService mediaFileService,
|
||||
ITrackService trackService,
|
||||
ICacheManager cacheManager,
|
||||
IPreferredWordService preferredWordServiceCalculator,
|
||||
Logger logger)
|
||||
{
|
||||
_upgradableSpecification = qualityUpgradableSpecification;
|
||||
_mediaFileService = mediaFileService;
|
||||
_trackService = trackService;
|
||||
_preferredWordServiceCalculator = preferredWordServiceCalculator;
|
||||
_logger = logger;
|
||||
_missingFilesCache = cacheManager.GetCache<bool>(GetType());
|
||||
}
|
||||
@@ -46,14 +50,16 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
|
||||
{
|
||||
var lowestQuality = trackFiles.Select(c => c.Quality).OrderBy(c => c.Quality.Id).First();
|
||||
|
||||
if (!_upgradableSpecification.IsUpgradable(subject.Artist.Profile,
|
||||
if (!_upgradableSpecification.IsUpgradable(subject.Artist.QualityProfile,
|
||||
subject.Artist.LanguageProfile,
|
||||
lowestQuality,
|
||||
trackFiles[0].Language,
|
||||
_preferredWordServiceCalculator.Calculate(subject.Artist, trackFiles[0].GetSceneOrFileName()),
|
||||
subject.ParsedAlbumInfo.Quality,
|
||||
subject.ParsedAlbumInfo.Language))
|
||||
subject.ParsedAlbumInfo.Language,
|
||||
subject.PreferredWordScore))
|
||||
{
|
||||
return Decision.Reject("Quality for existing file on disk is of equal or higher preference: {0}", lowestQuality);
|
||||
return Decision.Reject("Existing file on disk is of equal or higher preference: {0} - {1}", lowestQuality, trackFiles[0].Language);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user