@ -1,6 +1,6 @@
using System.Collections.Generic ;
using System.Linq ;
using System.Linq ;
using NLog ;
using NLog ;
using NzbDrone.Common.Extensions ;
using NzbDrone.Core.Configuration ;
using NzbDrone.Core.Configuration ;
using NzbDrone.Core.CustomFormats ;
using NzbDrone.Core.CustomFormats ;
using NzbDrone.Core.DecisionEngine ;
using NzbDrone.Core.DecisionEngine ;
@ -13,22 +13,23 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications
public class UpgradeSpecification : IImportDecisionEngineSpecification
public class UpgradeSpecification : IImportDecisionEngineSpecification
{
{
private readonly IConfigService _configService ;
private readonly IConfigService _configService ;
private readonly ICustomFormatCalculationService _ customFormatCalculation Service;
private readonly ICustomFormatCalculationService _ format Service;
private readonly Logger _logger ;
private readonly Logger _logger ;
public UpgradeSpecification ( IConfigService configService ,
public UpgradeSpecification ( IConfigService configService ,
ICustomFormatCalculationService customFormatCalculation Service,
ICustomFormatCalculationService format Service,
Logger logger )
Logger logger )
{
{
_configService = configService ;
_configService = configService ;
_ customFormatCalculationService = customFormatCalculation Service;
_ formatService = format Service;
_logger = logger ;
_logger = logger ;
}
}
public Decision IsSatisfiedBy ( LocalEpisode localEpisode , DownloadClientItem downloadClientItem )
public Decision IsSatisfiedBy ( LocalEpisode localEpisode , DownloadClientItem downloadClientItem )
{
{
var downloadPropersAndRepacks = _configService . DownloadPropersAndRepacks ;
var downloadPropersAndRepacks = _configService . DownloadPropersAndRepacks ;
var qualityComparer = new QualityModelComparer ( localEpisode . Series . QualityProfile ) ;
var qualityProfile = localEpisode . Series . QualityProfile . Value ;
var qualityComparer = new QualityModelComparer ( qualityProfile ) ;
foreach ( var episode in localEpisode . Episodes . Where ( e = > e . EpisodeFileId > 0 ) )
foreach ( var episode in localEpisode . Episodes . Where ( e = > e . EpisodeFileId > 0 ) )
{
{
@ -44,13 +45,11 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications
if ( qualityCompare < 0 )
if ( qualityCompare < 0 )
{
{
_logger . Debug ( "This file isn't a quality upgrade for all episodes. New Quality is {0}. Skipping {1}" , localEpisode . Quality . Quality , localEpisode . Path ) ;
_logger . Debug ( "This file isn't a quality upgrade for all episodes. Existing quality: {0}. New Quality {1}. Skipping {2}", episodeFile . Quality . Quality , localEpisode . Quality . Quality , localEpisode . Path ) ;
return Decision . Reject ( "Not an upgrade for existing episode file(s). New Quality is {0}" , localEpisode . Quality . Quality ) ;
return Decision . Reject ( "Not an upgrade for existing episode file(s). Existing quality: {0}. New Quality {1}.", episodeFile . Quality . Quality , localEpisode . Quality . Quality ) ;
}
}
// Same quality, is not a language upgrade, propers/repacks are preferred and it is not a revision update
// Same quality, propers/repacks are preferred and it is not a revision update. Reject revision downgrade.
// This will allow language upgrades of a lower revision to be imported, which are allowed to be grabbed,
// they just don't import automatically.
if ( qualityCompare = = 0 & &
if ( qualityCompare = = 0 & &
downloadPropersAndRepacks ! = ProperDownloadTypes . DoNotPrefer & &
downloadPropersAndRepacks ! = ProperDownloadTypes . DoNotPrefer & &
@ -59,6 +58,18 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications
_logger . Debug ( "This file isn't a quality revision upgrade for all episodes. Skipping {0}" , localEpisode . Path ) ;
_logger . Debug ( "This file isn't a quality revision upgrade for all episodes. Skipping {0}" , localEpisode . Path ) ;
return Decision . Reject ( "Not a quality revision upgrade for existing episode file(s)" ) ;
return Decision . Reject ( "Not a quality revision upgrade for existing episode file(s)" ) ;
}
}
var currentFormats = _formatService . ParseCustomFormat ( episodeFile ) ;
var currentScore = qualityProfile . CalculateCustomFormatScore ( currentFormats ) ;
if ( localEpisode . CustomFormatScore < currentScore )
{
_logger . Debug ( "New file's custom formats [{0}] do not improve on [{1}], skipping" ,
localEpisode . CustomFormats . ConcatToString ( ) ,
currentFormats . ConcatToString ( ) ) ;
return Decision . Reject ( "Not a Custom Format upgrade for existing episode file(s)" ) ;
}
}
}
return Decision . Accept ( ) ;
return Decision . Accept ( ) ;